google / gemma_pytorch

The official PyTorch implementation of Google's Gemma models
https://ai.google.dev/gemma
Apache License 2.0
5.19k stars 492 forks source link

Memory saving loading weight for non-quant models #56

Closed KaneGreen closed 2 weeks ago

KaneGreen commented 3 months ago

Trying to fix #51 And this also increase the speed of loading weights. (in my computer, about 1min vs 2min) Tested on 1.1-7b-it and 7b-it model.

but:

  1. This method is not suitable for the int8 data type, so the original loading method is still used when using the quant model.
  2. The new loading method will automatically reset the requires_grad of nn.Parameter in Linear and Embedding to True after the loading is completed. (I don't know why some nn.Parameters in model.py have requires_grad as False and others as default True) But I think, this shouldn't affect since forward function of GemmaForCausalLM has @torch.no_grad().
google-cla[bot] commented 3 months ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

KaneGreen commented 3 months ago

@pengchongjin @michaelmoynihan Any idea on this PR?

pengchongjin commented 3 months ago

Thanks, @KaneGreen ! Coould you please sign the CLA in order to pass the pre-check?

KaneGreen commented 3 months ago

@pengchongjin I've signed that. But it doesn't update. Any way to re-run this check?

KaneGreen commented 3 months ago

@pengchongjin CLA has been signed