Skip to content

Conversation

@danielvegamyhre
Copy link
Contributor

Summary

Document the E2E training => inference flow with examples.

@danielvegamyhre danielvegamyhre added the topic: documentation Use this tag if this PR adds or improves documentation label May 9, 2025
@pytorch-bot
Copy link

pytorch-bot bot commented May 9, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/2190

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 723088a with merge base cdced21 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 9, 2025
@danielvegamyhre danielvegamyhre requested review from drisspg and vkuzo May 9, 2025 16:16
@danielvegamyhre
Copy link
Contributor Author

cc @andrewor14

@danielvegamyhre danielvegamyhre marked this pull request as draft May 9, 2025 16:40
@danielvegamyhre danielvegamyhre changed the title [float8] document e2e training -> inference flow [WIP] document e2e training -> inference flow May 9, 2025
@danielvegamyhre danielvegamyhre changed the title [WIP] document e2e training -> inference flow [float] document e2e training -> inference flow May 9, 2025
@danielvegamyhre danielvegamyhre marked this pull request as ready for review May 9, 2025 17:23
Copy link
Contributor

@andrewor14 andrewor14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this out locally too, works for me. Thanks!

@andrewor14
Copy link
Contributor

(Might need to add a distributed checkpoint section but we can do that in a separate PR)


# save the model
torch.save({
'model': m,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice the model would be in some modeling file, and the training code and inference code would both import it separately, in order to avoid the need to deserialize the python model definition w/ torch.load(...., weights_only=False), which has some security risks.

However, I was aiming to have these be copy/paste-able runnable standalone examples, which seemed to require this bad practice. Thoughts @andrewor14 @vkuzo?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a good way to do it as as follows:

  1. create a reproducible model definition
  2. create a new instance of (1), train it, save weights to checkpoint
  3. create a new instance of (1), load weights from checkpoint, finetune it or do inference

there is no saving of model definition with torch.save needed in the flow as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I originally tried actually, but it doesn't work because the weights in the serialized/checkpointed model from step (2) are registered under different names (prefixed with _orig_mod) than the freshly initialized model in step (3).

I solved this by saving the converted model definition directly in torch.save and loading the model state dict into that, but it's not ideal imo. I'm curious how torchtitan/torchtune do this as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok going to merge this for now, we can discuss alternatives async if you want.

@danielvegamyhre danielvegamyhre merged commit a0a0969 into main May 13, 2025
18 checks passed
liangel-02 pushed a commit that referenced this pull request Aug 25, 2025
* document e2e training -> inference flow

* add save/load checkpoint

* update to how we load checkpoint

* remove debugging

* add more detail

* remove unused import

* lower lr to prevent large optimizer step into weight territory which produces inf

* use actual loss function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. topic: documentation Use this tag if this PR adds or improves documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants