Skip to content

Fix TorchFT config overrides before model construction - #4534

Merged
tianyu-l merged 1 commit into
pytorch:mainfrom
jojoinfra:fix/torchft-config-overrides
Sep 10, 2026
Merged

tianyu-l merged 1 commit into
pytorch:mainfrom
jojoinfra:fix/torchft-config-overrides

Conversation

@jojoinfra

@jojoinfra jojoinfra commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

I encountered this issue while using a custom override with FaultTolerantTrainer: the override was configured through override.imports, but was silently ignored.

Unlike the regular Trainer, the FT trainer's initializer did not call apply_overrides before model construction.

To demonstrate the issue without requiring the original downstream setup, this PR adds a small FFN LoRA regression test using upstream TorchTitan components. Before the fix, ordinary Linear projections are built instead of the requested LoRALinear projections.

Changes

  • Apply overrides after model_config.update_from_config() and before model construction.
  • Re-run config.__post_init__() to validate the overridden configuration, matching the current Trainer behavior.
  • Add a pytest regression test to the existing CPU unit test suite, with shared override registration and distributed state restored after the test.

The test is automatically collected by the existing CPU CI workflow. No .github changes are included.

Existing initialization order is unchanged. This PR does not address overrides for the tokenizer or dataloader, which are already built before this point.

Testing

With TorchTitan's dependencies and pytest installed, run from the repository root:

python -m pytest tests/unit_tests/cpu/test_torchft_trainer.py -q
  • Before the fix: fails with AssertionError: FT ignored the FFN LoRA override.
  • After the fix: 1 passed.

The test bypasses hardware, dataset and process-group setup, then stops initialization after constructing the first FFN on the meta device. Config updates, override application and FFN construction remain real. No accelerator, dataset or torchft installation is required.

@meta-cla

meta-cla Bot commented Sep 9, 2026

Copy link
Copy Markdown

Hi @jojoinfra!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@jojoinfra
jojoinfra force-pushed the fix/torchft-config-overrides branch from f67d837 to 7be31e7 Compare September 9, 2026 12:48
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 9, 2026
@jojoinfra

Copy link
Copy Markdown
Contributor Author

@tianyu-l Thanks for the review!

It looks like the TorchFT 8-GPU failure may be related to #4538, which landed shortly after this run.

Could you help retrigger the CI, or should I update the PR to the latest main first?

Thanks!

@tianyu-l

Copy link
Copy Markdown
Contributor

I think you need to rebase first

@jojoinfra
jojoinfra force-pushed the fix/torchft-config-overrides branch from 7be31e7 to 854a774 Compare September 10, 2026 02:39
1. Apply overrides after model config updates so FT honors FFN LoRA settings.
2. Revalidate overridden configs using the current Trainer validation path.
3. Add a pytest regression test collected by the existing CPU unit test suite.
@jojoinfra
jojoinfra force-pushed the fix/torchft-config-overrides branch from 854a774 to fb505df Compare September 10, 2026 03:36
@tianyu-l
tianyu-l merged commit cd890fe into pytorch:main Sep 10, 2026
17 checks passed
submartingales pushed a commit to botcanlearn/torchtitan-npu-upstream that referenced this pull request Sep 22, 2026
Co-authored-by: hwcaifubi<[email protected]>



# message auto-generated for no-merge-commit merge:
!893 merge master-add-patches into master

fix: backport merged TorchFT fixes for torchtitan v0.3.0

Created-by: hwcaifubi
Commit-by: hwcaifubi
Merged-by: cann-robot
Description: ## 描述
Torchft相关的bugfix已合入上游社区,但是当前torchtitan-npu使用的是v0.3.0,还未包含这部分代码。当前先通过打patch的方式支持,等后续配套版本升级后可以完全删除。

| [#4534](pytorch/torchtitan#4534) | 在 TorchFT 模型构造前应用配置 override 并重新校验配置,对应 `experiments/torchft/trainer.py` |
| [#4575](pytorch/torchtitan#4575) | 为 TorchFT 的 chunked loss 绑定 `lm_head`,覆盖普通训练及 PP 最后阶段,对应 `experiments/torchft/trainer.py` |
| [#4578](pytorch/torchtitan#4578) | 消除 TorchFT optimizer 递归分派,保留一次容器 hook 调用,对应 `experiments/torchft/optimizer.py` |
| [#4598](pytorch/torchtitan#4598) | 导出副本恢复状态前刷新缓存中的学习率等元数据,对应 `experiments/torchft/optimizer.py` 和 `checkpoint.py` |
| [#4663](pytorch/torchtitan#4663) | 按当前参与副本数平均 TorchFT 日志 loss,对应 `experiments/torchft/trainer.py` |
| [#4664](pytorch/torchtitan#4664) | 为每个 FSDP 参数组注册 TorchFT 梯度平均 hook,对应 `experiments/torchft/manager.py` |

## 类型
- [x] Bug 修复
- [ ] 新功能
- [ ] 重构(即不是新增功能,也不是修改bug的代码变动)
- [ ] 构建过程或辅助工具的变动
- [ ] 文档内容更新

## Checklist:
- [x] 我的代码遵循这个项目的代码风格
- [x] 我已经自己测试过我的代码
- [x] 我已经更新了相应的文档
- [x] 我已经在标题中正确使用了类型标签(例如:`feat`, `fix`, `refactor`, `docs`, `test`)

## 如何测试
简要描述测试方案,并附上自验证记录。

## 其他信息
在这里可以添加任何与这个 Pull Request 相关的其他说明。


See merge request: cann/torchtitan-npu!893
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 Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants