Uh oh!
There was an error while loading. Please reload this page.
[PyTorch] Fixed bug with loading calibrated weights - #771
Conversation
ptrendx
commented
Apr 15, 2024
@pggPL Yes, please add the unit test. In the proposed implementation the set_extra_state would be called twice - maybe we should remove the extra state from the dict before calling the parent function? |
pggPL
commented
May 3, 2024
Unfortunately removing extra_state key from the dictionary will result with error when I modified the test, instead of adding new. This test wasn't passing for me, because there was no implementation of abstract method |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
sudhakarsingh27
commented
May 8, 2024
Also, this test was never run in the CI, so we should enable that as well by adding the call to this test in |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
sudhakarsingh27
commented
May 13, 2024
/te-ci pytorch |
@timmoon10 could you please take a look at how the test has been modified now? |
sudhakarsingh27
commented
May 15, 2024
@pggPL, could you revert back files' permissions? |
sudhakarsingh27
commented
May 15, 2024
/te-ci pytorch |
sudhakarsingh27
commented
May 16, 2024
@pggPL I think your last commit doesn't have a signoff and so the DCO cribs. Could you fix that? |
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
phu0ngng
commented
May 16, 2024
/te-ci pytorch |
sudhakarsingh27
commented
May 16, 2024
/te-ci pytorch |
1 similar comment
timmoon10
commented
May 17, 2024
/te-ci pytorch |
* Calibration fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> * Lint fix Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> --------- Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com> Co-authored-by: Pawel Gadzinski <pgadzinski@nvidia.com>
I encountered the bug related to calibration of scaling factors and loading the model.
When I calibrate the scaling factors with model with weights in bf16, the model parameters are in stored bf16 and scaling factors are stored in parameters which are dumped into "*._extra_state" in state_dict(). Suppose I want to load these weights to model initialized within fp8_model_init=True context. Then in load_state_dict():
In the forward() of many modules we can see the usage of a function:
for example in
layernorm_mlp.pyforward:which overrides the fp8_meta scale_inv in the module by the value of this parameter in the tensor, which is clearly wrong.
The result of this bug is demonstrated in code below:
I propose a fix - override
_load_from_state_dictsuch that _extra_state is copied before, not after, tensors.I have also one question - should I add also add the unit test?