Skip to content

Commit

Permalink
Make transpose contiguous for fan-in-fan-out (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgaddair authored Dec 14, 2023
1 parent 7256d15 commit 9febb95
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ class FlashGPT2ForCausalLM(FlashGPT2PreTrainedModel):
def __init__(self, config, weights):
super().__init__(config)
self.transformer = FlashGPT2Model(config, weights)
self.wte_t = self.transformer.wte.weight.T.contiguous()

def forward(
self,
Expand Down Expand Up @@ -393,6 +394,6 @@ def forward(

# lm_head reuses the weights of the embedding layer
# https://github.com/huggingface/transformers/issues/6291
logits = hidden_states @ self.transformer.wte.weight.T
logits = hidden_states @ self.wte_t
logits = logits[:, :self.transformer.config.vocab_size]
return logits
2 changes: 1 addition & 1 deletion server/lorax_server/utils/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def get_linear(weight, bias, quantize, fan_in_fan_out=False):
# https://huggingface.co/docs/peft/package_reference/tuners#peft.LoraConfig.fan_in_fan_out
# Set to True if replacing a Conv1D layer with a Linear layer
if fan_in_fan_out:
weight = weight.T
weight = weight.T.contiguous()

if quantize is None:
linear = FastLinear(weight, bias)
Expand Down

0 comments on commit 9febb95

Please sign in to comment.