Skip to content

Possible bug in subtraction dimension? #57

@veritas9872

Description

@veritas9872

linear.weight.data = W_ - W_.mean(dim=-2, keepdim=True)

Hello. I have a question concerning how to bake mean subtraction from LayerNorm into the Linear layer.
I have managed to solve by hand that it is possible to merge mean subtraction from the layernorm into the linear layer by subtracting the mean of each column of the weight matrix.
However, because the nn.Linear class holds the weights transposed for memory contiguity, I think that one should do
W_ - W_.mean(dim=-1, keepdim=True) instead of W_ - W_.mean(dim=-2, keepdim=True) to subtract from the columns of the weights.

To summarize, since nn.Linear does x@self.weight.T, I think that the dimensions should be flipped.
Please correct me if I am wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions