Skip to content

Commit

Permalink
fix(qlinear): speed up weights transfer
Browse files Browse the repository at this point in the history
By instantiating the QLinear weights directly on the device, it saves
two copies: from device to cpu and back.
  • Loading branch information
dacorvo committed Feb 13, 2024
1 parent f9e7779 commit ba8ff36
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bench/generation/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ def main():
# Very simple calibration to avoid completely off results
with Calibration():
generate(model, tokenizer, device, prompt=CALIBRATION_PROMPT)
print("Freezing")
freeze(model)
print(f"Finished: {time.time()-start}")
print(f"Finished: {time.time()-start:.2f}")

memory = get_device_memory(device)
if memory is not None:
Expand Down
1 change: 1 addition & 0 deletions quanto/nn/qlinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def from_module(cls, module, weights=torch.int8, activations: Optional[torch.dty
dtype=module.weight.dtype,
weights=weights,
activations=activations,
device=module.weight.device,
)
with torch.no_grad():
qmodule.weight.copy_(module.weight)
Expand Down

0 comments on commit ba8ff36

Please sign in to comment.