Fix remaining nonexistent AdamOptions::beta1 calls in C++ frontend tutorial#3934
Fix remaining nonexistent AdamOptions::beta1 calls in C++ frontend tutorial#3934David-Wu1119 wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/3934
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
Hi @David-Wu1119! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
There was a problem hiding this comment.
Pull request overview
This PR updates the C++ frontend tutorial (advanced_source/cpp_frontend.rst) so the checkpoint-restore code snippet compiles with current LibTorch by removing calls to the nonexistent AdamOptions::beta1 setter and using AdamOptions::betas(...) instead.
Changes:
- Replace
torch::optim::AdamOptions(...).beta1(0.5)withtorch::optim::AdamOptions(...).betas(std::make_tuple(...))in the checkpoint-restore snippet. - Align the checkpoint-restore snippet with the approach already applied elsewhere in the tutorial (per PR #2260).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| torch::optim::Adam generator_optimizer( | ||
| generator->parameters(), torch::optim::AdamOptions(2e-4).beta1(0.5)); | ||
| generator->parameters(), torch::optim::AdamOptions(2e-4).betas(std::make_tuple(0.5, 0.5))); | ||
| torch::optim::Adam discriminator_optimizer( | ||
| discriminator->parameters(), torch::optim::AdamOptions(2e-4).beta1(0.5)); | ||
| discriminator->parameters(), torch::optim::AdamOptions(2e-4).betas(std::make_tuple(0.5, 0.5))); |
There was a problem hiding this comment.
Good catch on the learning rate — fixed in 25ed93f. The checkpoint-restore snippet's discriminator was 2e-4 while the training loop above uses 5e-4; the two blocks are now byte-identical, which is the point of that snippet (it reconstructs the same optimizers).
On beta2 I went the other way deliberately. .beta1(0.5) did leave beta2 at 0.999, but the training-loop block this snippet mirrors already uses betas(std::make_tuple(0.5, 0.5)) (lines 969/971, set by #2260). Using (0.5, 0.999) here would make the restored optimizers differ from the ones actually used for training — a worse inconsistency than the one it fixes. Matching #2260's existing convention keeps the tutorial self-consistent.
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Fixes pytorch/pytorch#47351
The checkpoint-restore snippet in the C++ frontend tutorial still uses
torch::optim::AdamOptions(2e-4).beta1(0.5)— thebeta1member no longer exists (adam.hdefines onlyTORCH_ARG(betas_t, betas)), so the snippet doesn't compile.#2260 fixed the identical calls earlier in the tutorial (training-loop section) but missed these two occurrences in the checkpoint-restore block. This applies the same
betas(std::make_tuple(0.5, 0.5))form to the remaining two, making the file consistent.(Prepared with AI assistance; reviewed by the author.)