Skip to content

Require torch>=2.7.0 - #7752

Closed
albertvillanova wants to merge 2 commits into
mainfrom
require-torch-2-7
Closed

albertvillanova wants to merge 2 commits into
mainfrom
require-torch-2-7

Conversation

@albertvillanova

@albertvillanova albertvillanova commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

This PR declares a torch floor of 2.7.0 and removes the fallbacks that existed for older torch.

Part of #7644. Alternative to #7642, which sets the floor at 2.6.0.

Motivation

TRL names no torch version at all, so the effective floor is whatever the stack enforces: torch>=2.2 from transformers 4.56.2. torch 2.7.0 was released on 2025-04-23, about 18 months ago, so it meets the 1-year criterion in #7116.

2.7.0 instead of 2.6.0 because torch 2.6.0 (cu124) ships NVRTC 12.4.127, which switches Python's default text encoding to ASCII after the first runtime kernel compile (#7720). Training with TRL on torch 2.6.0 then fails when saving a checkpoint, as soon as the model card is generated. torch 2.7.0 ships NVRTC 12.6.77, which does not have the problem.

The branches below exist only to support torch versions below 2.7:

  • torch.accelerator was introduced in 2.6, with the older path hard-coding "cuda"
  • FSDPModule, MixedPrecisionPolicy and fully_shard became public as torch.distributed.fsdp in 2.6, previously torch.distributed._composable.fsdp
  • fully_shard accepts ignored_params from 2.7
  • torch.get_device_module exists from 2.4, DTensor is public in torch.distributed.tensor from 2.5, and nn.Buffer exists from 2.5

Changes

  • Add torch>=2.7.0 to the project dependencies and pin torch==2.7.0 in the minimum versions job
  • Import FSDPModule, MixedPrecisionPolicy and fully_shard from the public torch.distributed.fsdp unconditionally
  • Pass ignored_params to fully_shard unconditionally
  • Read the accelerator type from torch.accelerator unconditionally in activation offloading, the experimental online DPO trainer and trl env
  • Import DTensor from torch.distributed.tensor and check nn.Buffer unconditionally in activation offloading

The torch>=2.8.0 guard stays, since it is above this floor.


Note

Medium Risk
Raises the install floor and simplifies FSDP2/distributed paths; users on torch 2.2–2.6 can no longer install, but behavior for supported versions should be unchanged aside from always passing ignored_params on FSDP2.

Overview
Requires PyTorch 2.7.0+ and drops compatibility shims for older torch.

pyproject.toml now lists torch>=2.7.0 (documented as avoiding torch 2.6’s NVRTC-related ASCII text I/O bug during checkpoint/model-card writes). CI’s minimum-versions job pins torch==2.7.0.

Runtime code assumes modern torch APIs: torch.accelerator / torch.get_device_module in activation offloading, online DPO vLLM setup, and trl env; public torch.distributed.fsdp imports (FSDPModule, fully_shard, MixedPrecisionPolicy) with ignored_params always passed to fully_shard; DTensor from torch.distributed.tensor and nn.Buffer checks without legacy import paths.

Reviewed by Cursor Bugbot for commit 407a6d7. Bugbot is set up for automated code reviews on this repo. Configure here.

@bot-ci-comment

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@qgallouedec

Copy link
Copy Markdown
Member

I think #7642 is better: #7720 is fixed by #7755 so no real need to drop 2.6.

@albertvillanova

Copy link
Copy Markdown
Member Author

Closing in favor of #7642, now merged with the torch 2.6.0 floor: #7720 was fixed in TRL by #7755 (and #7764 for the tests), so dropping 2.6 is no longer needed. The minimum-versions job on main is green with torch 2.6.0.

@albertvillanova
albertvillanova deleted the require-torch-2-7 branch October 21, 2026 13:30
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.

2 participants