Skip to content

Conversation

@albertvillanova
Copy link
Member

@albertvillanova albertvillanova commented Sep 11, 2025

Hotfix: Add ParallelismConfig fallback for transformers with old accelerate.

Fix TrainingArguments.parallelism_config NameError with accelerate<1.10.1:

RuntimeError: Type resolution failed for <class 'trl.trainer.dpo_config.DPOConfig'>. Try declaring the class in global scope or removing line of `from __future__ import annotations` which opts in Postponed Evaluation of Annotations (PEP 563)
E           NameError: name 'ParallelismConfig' is not defined

Problem

When accelerate<1.10.1, the module accelerate.parallelism_config does not exist.
Transformers’ TrainingArguments currently annotates:

parallelism_config: Optional["ParallelismConfig"] = field(default=None)

This creates a ForwardRef. On Python ≥3.12, when TRL constructs its CLI parsers, transformers.HfArgumentParser calls typing.get_type_hints(TrainingArguments). Since ParallelismConfig is undefined in transformers.training_args, a NameError is raised:

NameError: name 'ParallelismConfig' is not defined

Fix

This PR add a compat helper that pre-binds transformers.training_args.ParallelismConfig = Any if the name is missing. This ensures get_type_hints can always resolve the reference. The helper is called early before any HfArgumentParser is created.

Upstream

The proper fix is proposed in:

@HuggingFaceDocBuilderDev

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.

@albertvillanova
Copy link
Member Author

Copy link
Member

@qgallouedec qgallouedec left a comment

Choose a reason for hiding this comment

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

Lgtm!

@albertvillanova albertvillanova merged commit 44ddc28 into huggingface:main Sep 11, 2025
9 of 10 checks passed
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.

3 participants