Skip to content

change uses of Embedding.weight to Embedding.asLinear #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
davidkoski opened this issue Mar 10, 2025 · 0 comments
Closed

change uses of Embedding.weight to Embedding.asLinear #231

davidkoski opened this issue Mar 10, 2025 · 0 comments
Labels
good first issue Good for newcomers

Comments

@davidkoski
Copy link
Collaborator

There are several Modules that use

open class Embedding: Module, UnaryLayer, Quantizable {
    public let weight: MLXArray

directly instead of using:

    /// Call the embedding layer as a linear layer.
    ///
    /// Use this for example when input embedding and output projection
    /// weights are tied.
    open func asLinear(_ x: MLXArray) -> MLXArray {
        matmul(x, weight.T)
    }

e.g. Cohere, Starcoder2, OpenELM (this last is fixed recently).

        out = matmul(out, model.embedTokens.weight.T)

should be:

        out = model.embedTokens.asLinear(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant