Skip to content

Commit 867c96a

Browse files
jackzhxngfacebook-github-bot
authored andcommitted
Fix weights not updating during training (#6039)
Summary: Loaded weights were not updating in ET because the returned weights were clones, not the original weights. Pull Request resolved: #6039 Test Plan: ``` > buck2 run fbcode//executorch/examples/llm_pte_finetuning:runner -- --cfg=fbcode/executorch/examples/llm_pte_finetuning/phi3_config.yaml --model_file=phi3_mini_lora.pte Evaluating the model before training... 100%|██████████████████████████████████████████████████████████████████████████████████████| 3/3 [31:23<00:00, 627.98s/it] Eval loss: tensor(2.3778) grad_start:`1` param_start:`129` 100%|██████████████████████████████████████████████████████████████████████████████████████| 5/5 [52:29<00:00, 629.84s/it] Losses: [2.7152762413024902, 0.7890686988830566, 2.249271869659424, 1.4777560234069824, 0.8378427624702454] 100%|██████████████████████████████████████████████████████████████████████████████████████| 3/3 [30:35<00:00, 611.90s/it] Eval loss: tensor(0.8464) ``` Reviewed By: dpalmasan Differential Revision: D64084552 Pulled By: dvorjackz fbshipit-source-id: 9d478dda02f7bcaa5964d83d257d0db5bfe9feab
1 parent a6f754a commit 867c96a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

examples/llm_pte_finetuning/runner.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ def main() -> None:
9494
else:
9595
labels = F.pad(labels, (0, max_seq_len - labels_size), value=0)
9696

97-
out = et_mod.forward((tokens, labels))
97+
# Do not clone outputs, since we want the original weights to be returned
98+
# for us to update with the gradients in-place.
99+
# See https://github.com/pytorch/executorch/blob/main/extension/pybindings/pybindings.cpp#L736
100+
# for more info.
101+
out = et_mod.forward((tokens, labels), clone_outputs=False) # pyre-ignore
98102

99103
loss = out[0]
100104
losses.append(loss.item())

0 commit comments

Comments
 (0)