Skip to content

Update torchtune component paths from utils to training in torchtune notebook#634

Open
johndmulhausen wants to merge 1 commit into
mainfrom
fix/issue-579-torchtune-paths
Open

Update torchtune component paths from utils to training in torchtune notebook#634
johndmulhausen wants to merge 1 commit into
mainfrom
fix/issue-579-torchtune-paths

Conversation

@johndmulhausen

Copy link
Copy Markdown
Contributor

What

Running the config generated by colabs/torchtune/torchtune_and_wandb.ipynb fails with:

AttributeError: module 'torchtune.utils' has no attribute 'metric_logging'

torchtune relocated these APIs out of torchtune.utils (and one out of torchtune.modules) into torchtune.training. This PR updates the stale _component_ paths in the notebook's markdown YAML snippet and the %%writefile mistral_wandb_lora.yaml cell:

Old path New path
torchtune.utils.metric_logging.WandBLogger torchtune.training.metric_logging.WandBLogger
torchtune.utils.FullModelHFCheckpointer torchtune.training.FullModelHFCheckpointer
torchtune.utils.profiler torchtune.training.setup_torch_profiler
torchtune.modules.get_cosine_schedule_with_warmup torchtune.training.lr_schedulers.get_cosine_schedule_with_warmup

The lr_scheduler and profiler paths match the ones used in torchtune's own bundled recipes/configs/mistral/7B_lora_single_device.yaml. The profiler path is also the only value the lora_finetune_single_device recipe accepts (it asserts _component_ == torchtune.training.setup_torch_profiler). Inline # <--- comments and all other YAML content are unchanged; the diff is 5 lines.

Verification (against torchtune 0.6.1, torch 2.8.0)

  • from torchtune.training.metric_logging import WandBLogger imports cleanly.
  • Extracted the full YAML from the edited %%writefile cell, walked every _component_: value, and resolved each with torchtune.config._utils._get_component_from_path (the exact code path that crashed in the issue) — all 9 components resolve:
OK   tokenizer:     torchtune.models.mistral.mistral_tokenizer
OK   dataset:       torchtune.datasets.alpaca_dataset
OK   model:         torchtune.models.mistral.lora_mistral_7b
OK   checkpointer:  torchtune.training.FullModelHFCheckpointer
OK   optimizer:     torch.optim.AdamW
OK   lr_scheduler:  torchtune.training.lr_schedulers.get_cosine_schedule_with_warmup
OK   loss:          torch.nn.CrossEntropyLoss
OK   metric_logger: torchtune.training.metric_logging.WandBLogger
OK   profiler:      torchtune.training.setup_torch_profiler
  • tune validate mistral_wandb_lora.yaml on the extracted config reports Config is well-formed!
  • The lora_finetune_single_device recipe used by the notebook still exists in tune ls.
  • nbformat.validate passes; no other torchtune.utils references remain in the notebook.

Notes

  • The notebook installs torchtune from an unpinned git clone --depth 1 of pytorch/torchtune main, so the hardcoded component paths track a moving upstream — the same drift that caused this breakage. Left as-is to keep the diff minimal, but pinning a release could prevent a repeat.
  • A full training run was not executed (needs the Mistral-7B checkpoint download and a GPU); verification covers config parsing and component resolution, which is where the reported crash occurred.

Fixes #579

🤖 Generated with Claude Code

torchtune relocated several APIs out of torchtune.utils, so the
notebook's generated config crashed with:
AttributeError: module 'torchtune.utils' has no attribute 'metric_logging'

Updated component paths (verified against torchtune 0.6.1):
- torchtune.utils.metric_logging.WandBLogger
    -> torchtune.training.metric_logging.WandBLogger
- torchtune.utils.FullModelHFCheckpointer
    -> torchtune.training.FullModelHFCheckpointer
- torchtune.utils.profiler
    -> torchtune.training.setup_torch_profiler
- torchtune.modules.get_cosine_schedule_with_warmup
    -> torchtune.training.lr_schedulers.get_cosine_schedule_with_warmup

Fixes #579

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 17, 2026 17:21
@review-notebook-app

Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the torchtune notebook’s YAML _component_ references to match torchtune’s newer module layout (torchtune.training), fixing runtime config instantiation failures caused by stale torchtune.utils / torchtune.modules paths.

Changes:

  • Update W&B metric logger component path to torchtune.training.metric_logging.WandBLogger (in both the markdown snippet and the written YAML cell).
  • Update checkpointer component path to torchtune.training.FullModelHFCheckpointer.
  • Update LR scheduler and profiler component paths to torchtune.training.lr_schedulers.get_cosine_schedule_with_warmup and torchtune.training.setup_torch_profiler.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@johndmulhausen
johndmulhausen marked this pull request as ready for review July 21, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:AttributeError: module 'torchtune.utils' has no attribute 'metric_logging'

2 participants