ImportError: cannot import name 'X' from 'peft', 'trl' or 'accelerate' (or their submodules): which releases have it
The library named after "from" is too old for the name, or too new because the name was removed. The common ones: trl removed DataCollatorForCompletionOnlyLM in 0.20.0 (use SFTConfig(completion_only_loss=True)), setup_chat_format in 0.26.0 (use clone_chat_template), and 33 top-level names in 0.29.0, PPOTrainer and ORPOTrainer among them, most of which were then importable from trl.experimental. peft removed prepare_model_for_int8_training in 0.10.0 (use prepare_model_for_kbit_training). accelerate.utils has is_npu_available only from 0.21.0, which is why an older accelerate breaks import peft. For any other name, in any module of the three libraries, paste the error below.
Corrected on 2026-12-05: this page read only the first release of each minor version, so a name added or removed in a patch release was dated to the next minor. For example, from trl import SFTTrainer works from trl 0.4.2 (2023-06-07), not only from 0.5.0. Every release was then read once from PyPI: 36 top-level names of trl (1,123 module-and-name pairs), 0 of peft (90) and 0 of accelerate (14) differ in some patch release from the first release of the same minor. The lookup now gives those patch releases. The per-minor ranges are unchanged.
Examples:
Runs in your browser on peft.json, trl.json and accelerate.json (454 KB in all, loaded as needed); nothing you paste is sent anywhere. Understands cannot import name, No module named, module ... has no attribute, Failed to import and plain import lines. Covers 14,806 module-and-name pairs.
The import is inside another library. Which package do I change?
The one in quotes after "from". ImportError: cannot import name 'is_npu_available' from 'accelerate.utils' raised while running from peft import LoraConfig means peft needs a newer accelerate, not that peft is broken: upgrade accelerate to 0.21.0 or later. cannot import name 'PartialState' from 'accelerate' raised from inside transformers means the same for accelerate 0.17.0. Pinning the other library down to match is the other way out, and the lookup gives the range for that too.
What did each trl release remove from from trl import ...?
85 of the 146 names that from trl import has ever accepted are gone from 1.18.1; this is every one, by the release that dropped it. To keep old code running, pin below that release, for example pip install "trl<0.20.0" for DataCollatorForCompletionOnlyLM.
| Release | Date (PyPI) | Module | Names | Removed names |
|---|---|---|---|---|
| 1.15.0 | 2026-10-08 | trl | 1 | prepare_multimodal_messages_vllm |
| 1.14.0 | 2026-09-25 | trl | 1 | losses |
| 1.11.0 | 2026-08-26 | trl | 1 | skills |
| 1.8.0 | 2026-07-09 | trl | 1 | get_kbit_device_map |
| 1.0.0 | 2026-03-30 | trl | 1 | truncate_dataset |
| 0.29.0 | 2026-02-25 | trl | 33 | AllTrueJudge, AutoModelForCausalLMWithValueHead, AutoModelForSeq2SeqLMWithValueHead, BCOConfig, BCOTrainer, BaseBinaryJudge, BaseJudge, BasePairwiseJudge, BaseRankJudge, CPOConfig, CPOTrainer, FDivergenceConstants, FDivergenceType, GKDConfig, GKDTrainer, HfPairwiseJudge, NashMDConfig, NashMDTrainer, ORPOConfig, ORPOTrainer, OnlineDPOConfig, OnlineDPOTrainer, OpenAIPairwiseJudge, PPOConfig, PPOTrainer, PRMConfig, PRMTrainer, PairRMJudge, PreTrainedModelWrapper, WinRateCallback, XPOConfig, XPOTrainer, mergekit_utils |
| 0.27.0 | 2026-01-16 | trl | 2 | MergeModelCallback, SUPPORTED_ARCHITECTURES |
| 0.26.0 | 2025-12-09 | trl | 1 | setup_chat_format |
| 0.25.0 | 2025-11-05 | trl | 2 | BestOfNSampler, core |
| 0.24.0 | 2025-10-16 | trl | 10 | AlignPropConfig, AlignPropTrainer, DDPOConfig, DDPOPipelineOutput, DDPOSchedulerOutput, DDPOStableDiffusionPipeline, DDPOTrainer, DefaultDDPOStableDiffusionPipeline, IterativeSFTConfig, IterativeSFTTrainer |
| 0.21.0 | 2025-08-05 | trl | 3 | TextEnvironment, TextHistory, environment |
| 0.20.0 | 2025-07-29 | trl | 2 | DataCollatorForCompletionOnlyLM, pack_examples |
| 0.17.0 | 2025-04-24 | trl | 7 | is_deepspeed_available, is_diffusers_available, is_llm_blender_available, is_mergekit_available, is_rich_available, is_unsloth_available, is_vllm_available |
| 0.16.0 | 2025-03-22 | trl | 1 | compute_token_accuracy |
| 0.14.0 | 2025-01-29 | trl | 1 | set_seed |
| 0.13.0 | 2024-12-16 | trl | 9 | DPOScriptArguments, PPOv2Config, PPOv2Trainer, RandomPairwiseJudge, RandomRankJudge, SFTScriptArguments, commands, env_utils, utils |
| 0.12.0 | 2024-11-01 | trl | 2 | is_liger_kernel_available, is_llmblender_available |
| 0.11.0 | 2024-09-19 | trl | 7 | is_bitsandbytes_available, is_npu_available, is_openai_available, is_peft_available, is_pil_available, is_wandb_available, is_xpu_available |
trl 0.29.0: where did PPOTrainer, ORPOTrainer and the rest go?
30 of the 33 names removed from the top level in 0.29.0 (2026-02-25) were importable from a module under trl.experimental in that release. trl 0.28.0 already pointed there: importing PPOTrainer from the old place warned that it "is now located in trl.experimental". Some experimental modules were removed later (trl.experimental.ppo is gone since 1.13.0); the lookup says which are still there in 1.18.1.
Removed from trl in 0.29.0 | Importable in 0.29.0 from |
|---|---|
AllTrueJudge | trl.experimental.judges, trl.experimental.judges.judges |
AutoModelForCausalLMWithValueHead | trl.experimental.ppo, trl.experimental.ppo.modeling_value_head |
AutoModelForSeq2SeqLMWithValueHead | trl.experimental.ppo, trl.experimental.ppo.modeling_value_head |
BCOConfig | trl.experimental.bco, trl.experimental.bco.bco_config, trl.experimental.bco.bco_trainer |
BCOTrainer | trl.experimental.bco, trl.experimental.bco.bco_trainer |
BaseBinaryJudge | trl.experimental.judges, trl.experimental.judges.judges |
BaseJudge | trl.experimental.judges, trl.experimental.judges.judges |
BasePairwiseJudge | trl.experimental.judges, trl.experimental.judges.judges, trl.experimental.nash_md.nash_md_trainer, trl.experimental.online_dpo.online_dpo_trainer, trl.experimental.xpo.xpo_trainer |
BaseRankJudge | trl.experimental.judges, trl.experimental.judges.judges |
CPOConfig | trl.experimental.cpo, trl.experimental.cpo.cpo_config, trl.experimental.cpo.cpo_trainer |
CPOTrainer | trl.experimental.cpo, trl.experimental.cpo.cpo_trainer |
FDivergenceConstants | not in trl.experimental |
FDivergenceType | not in trl.experimental |
GKDConfig | trl.experimental.gkd, trl.experimental.gkd.gkd_config, trl.experimental.gkd.gkd_trainer |
GKDTrainer | trl.experimental.gkd, trl.experimental.gkd.gkd_trainer |
HfPairwiseJudge | trl.experimental.judges, trl.experimental.judges.judges |
NashMDConfig | trl.experimental.nash_md, trl.experimental.nash_md.nash_md_config, trl.experimental.nash_md.nash_md_trainer |
NashMDTrainer | trl.experimental.nash_md, trl.experimental.nash_md.nash_md_trainer |
ORPOConfig | trl.experimental.orpo, trl.experimental.orpo.orpo_config, trl.experimental.orpo.orpo_trainer |
ORPOTrainer | trl.experimental.orpo, trl.experimental.orpo.orpo_trainer |
OnlineDPOConfig | trl.experimental.online_dpo, trl.experimental.nash_md.nash_md_config, trl.experimental.online_dpo.online_dpo_config, trl.experimental.online_dpo.online_dpo_trainer, trl.experimental.xpo.xpo_config |
OnlineDPOTrainer | trl.experimental.online_dpo, trl.experimental.nash_md.nash_md_trainer, trl.experimental.online_dpo.online_dpo_trainer, trl.experimental.xpo.xpo_trainer |
OpenAIPairwiseJudge | trl.experimental.judges, trl.experimental.judges.judges |
PPOConfig | trl.experimental.ppo, trl.experimental.ppo.ppo_config, trl.experimental.ppo.ppo_trainer |
PPOTrainer | trl.experimental.ppo, trl.experimental.ppo.ppo_trainer |
PRMConfig | trl.experimental.prm, trl.experimental.prm.prm_config, trl.experimental.prm.prm_trainer |
PRMTrainer | trl.experimental.prm, trl.experimental.prm.prm_trainer |
PairRMJudge | trl.experimental.judges, trl.experimental.judges.judges |
PreTrainedModelWrapper | trl.experimental.ppo, trl.experimental.ppo.modeling_value_head |
WinRateCallback | trl.experimental.winrate_callback |
XPOConfig | trl.experimental.xpo, trl.experimental.xpo.xpo_config, trl.experimental.xpo.xpo_trainer |
XPOTrainer | trl.experimental.xpo, trl.experimental.xpo.xpo_trainer |
mergekit_utils | not in trl.experimental |
What did peft remove?
peft removes few names: 17 from peft and peft.utils in all. The one people hit is prepare_model_for_int8_training, gone in 0.10.0 (2024-03-21).
| Release | Date (PyPI) | Module | Names | Removed names |
|---|---|---|---|---|
| 0.19.0 | 2026-04-14 | peft | 2 | BoneConfig, BoneModel |
| 0.19.0 | 2026-04-14 | peft.utils | 2 | TRANSFORMERS_MODELS_TO_BONE_TARGET_MODULES_MAPPING, get_auto_gptq_quant_linear |
| 0.10.0 | 2024-03-21 | peft | 1 | prepare_model_for_int8_training |
| 0.10.0 | 2024-03-21 | peft.utils | 1 | prepare_model_for_int8_training |
| 0.8.0 | 2024-01-30 | peft.utils | 1 | COMMON_LAYERS_PATTERN |
| 0.7.0 | 2023-12-06 | peft.utils | 2 | hub_file_exists, hub_utils |
| 0.6.0 | 2023-11-03 | peft.utils | 1 | add_library_to_model_card |
| 0.5.0 | 2023-08-22 | peft.utils | 4 | CLAMP_QUANTILE, PeftConfig, PromptLearningConfig, config |
| 0.3.0 | 2023-05-03 | peft.utils | 1 | adapters_utils |
| 0.1.0 | 2023-02-10 | peft | 1 | peft_model_load_and_dispatch |
| 0.1.0 | 2023-02-10 | peft.utils | 1 | peft_model_load_and_dispatch |
What did accelerate remove from accelerate and accelerate.utils?
57 names, most of them in 0.8.0, when accelerate.utils became a package and stopped re-exporting what it imported. The ones that still turn up in errors: is_safetensors_available (gone in 0.25.0) and is_tpu_available (gone from accelerate.utils in 0.28.0; use is_torch_xla_available).
| Release | Date (PyPI) | Module | Names | Removed names |
|---|---|---|---|---|
| 1.16.0 | 2026-11-16 | accelerate | 2 | inference, prepare_pippy |
| 1.16.0 | 2026-11-16 | accelerate.utils | 7 | FP8RecipeKwargs, MITA_PROFILING_AVAILABLE_PYTORCH_VERSION, MSAMPRecipeKwargs, XPU_PROFILING_AVAILABLE_PYTORCH_VERSION, is_msamp_available, is_pippy_available, is_weights_only_available |
| 1.13.0 | 2026-03-04 | accelerate.utils | 3 | get_ccl_version, is_ccl_available, is_ipex_available |
| 1.5.0 | 2025-03-12 | accelerate.utils | 1 | check_fp8_capability |
| 1.0.0 | 2024-10-07 | accelerate.utils | 1 | shard_checkpoint |
| 0.31.0 | 2024-06-07 | accelerate.utils | 1 | megatron_lm_prepare_model |
| 0.28.0 | 2024-03-12 | accelerate.utils | 1 | is_tpu_available |
| 0.25.0 | 2023-12-01 | accelerate.utils | 1 | is_safetensors_available |
| 0.21.0 | 2023-07-13 | accelerate.utils | 1 | get_launch_prefix |
| 0.20.0 | 2023-06-07 | accelerate.utils | 1 | IntelPyTorchExtensionPlugin |
| 0.19.0 | 2023-05-08 | accelerate.utils | 1 | is_apex_available |
| 0.10.0 | 2022-06-15 | accelerate.utils | 1 | is_tensorflow_available |
| 0.8.0 | 2022-05-12 | accelerate | 2 | deepspeed_utils, kwargs_handlers |
| 0.8.0 | 2022-05-12 | accelerate.utils | 34 | AcceleratorState, Any, BaseEnum, Callable, ConvertOutputsToFp32, DeepSpeedEngine, Enum, EnumMeta, EnumWithContains, Iterable, List, Mapping, Optional, ReduceOp, Union, _cpu_gather, _cpu_gather_object, _gpu_broadcast, _gpu_gather, _gpu_gather_object, _tpu_broadcast, _tpu_gather, contextmanager, dataclass, field, functools, importlib, np, os, torch, typing, update_wrapper, version, xm |
Which trl names are listed but cannot be imported?
11 entries of trl's lazy import tables point at a file that is not there or that lacks the name. The name shows up in dir(trl) and in autocompletion, but importing it fails. For example, trl.trainer in 0.13.0 still lists PPOv2Trainer, but the file behind it was already gone.
| Import | Fails in | Why |
|---|---|---|
from trl import DpoArgumentParser | 0.8.0 to 0.8.6 | the entry points to commands.utils, a file that is not there |
from trl import MultitaskPromptEmbedding | 0.8.0 to 0.11.4 | the entry points to multitask_prompt_tuning, a file that is not there |
from trl import MultitaskPromptTuningConfig | 0.8.0 to 0.11.4 | the entry points to multitask_prompt_tuning, a file that is not there |
from trl import MultitaskPromptTuningInit | 0.8.0 to 0.11.4 | the entry points to multitask_prompt_tuning, a file that is not there |
from trl import SftArgumentParser | 0.8.0 to 0.8.6 | the entry points to commands.utils, a file that is not there |
from trl import TrlParser | 0.8.0 to 0.8.6 | the entry points to commands.utils, a file that is not there |
from trl import init_zero_verbose | 0.8.0 to 0.8.6 | the entry points to commands.utils, a file that is not there |
from trl.commands import SftArgumentParser | 0.8.0 to 0.8.6 | the entry points to cli_utils, which does not define the name |
from trl.commands import YamlConfigParser | 0.8.0 to 0.8.6 | the entry points to config_parser, a file that is not there |
from trl.trainer import PPOv2Config | 0.13.0 to 0.13.0 | the entry points to ppov2_config, a file that is not there |
from trl.trainer import PPOv2Trainer | 0.13.0 to 0.13.0 | the entry points to ppov2_trainer, a file that is not there |
How was this read, and how was it checked?
From the source of each release tag, with Python's ast module; no release was installed or imported. peft and accelerate import eagerly, so a module's names are everything it binds at module level (classes, functions, assignments, imports). trl replaces its packages with a lazy module from 0.8.0 on; for those, the names are the entries of the lazy table, each followed to the file it names. Code under if TYPE_CHECKING: is skipped. Dates and yanked releases come from PyPI.
Checks, all by a second reading: (1) trl's lazy packages repeat their names as plain imports for type checkers; 214 of 231 package-and-release pairs match exactly, and the rest differ by 9 names that trl lists in only one of the two places (the lookup follows the table, which is what runs). (2) Each of the 369 top-level names is found as plain text in __init__.py of every release in its range (7,221 name-and-release pairs), and is not imported there in the release on either side (353 edges). (3) A regular expression finds 30,884 definitions in 4,557 file versions; all are among the names read. (4) 18 known facts hold, among them the releases in the public error reports under Sources.
Limits
- Nothing was installed or run. "Has it" means the import statement resolves in the source, with the optional packages installed.
- The ranges use the first release of each minor version (and the newest release); trl's 0.9 line is read at 0.9.3, as 0.9.2 has no git tag. Every release was also read once from the wheels on PyPI, with the same rules (peft 39, trl 105, accelerate 80 releases, trl 0.9.2 included): the lookup prints the patch releases whose names differ from the release read for their minor.
- The import can still fail for another reason: the file that defines the name imports something your transformers does not have. That shows up as a second
cannot import name ... from 'transformers'; see the related page below.
Questions
How do I fix "cannot import name 'DataCollatorForCompletionOnlyLM' from 'trl'"?
trl 0.20.0 (2025-07-29) removed it; 0.19.1 is the last release with it. Either pin pip install "trl<0.20.0", or drop the collator and set SFTConfig(completion_only_loss=True), which is what trl 0.19.0 told you to use.
Where did PPOTrainer, ORPOTrainer and the other trainers go in trl 0.29.0?
trl 0.29.0 (2026-02-25) removed 33 names from the top level. 30 of them were still importable from trl.experimental in 0.29.0, for example from trl.experimental.ppo import PPOTrainer; the full list is in the table on this page. Later releases removed some of the experimental modules as well, so the lookup also says whether each one is still there in 1.18.1.
How do I fix "cannot import name 'prepare_model_for_int8_training' from 'peft'"?
Use prepare_model_for_kbit_training, which peft has had since 0.4.0. peft 0.10.0 (2024-03-21) removed the int8 name; 0.9.0 is the last release with it.
I import from peft but the error says "cannot import name 'is_npu_available' from 'accelerate.utils'". Which package do I upgrade?
accelerate. The library in quotes after "from" is the one that lacks the name; the import that fails can sit inside another library. accelerate.utils has is_npu_available from 0.21.0 (2023-07-13), so pip install -U "accelerate>=0.21.0".
Does this page cover names below the top level, like trl.trainer.utils or accelerate.utils?
Yes. Every module of the three libraries is covered: 14,806 module-and-name pairs in all, read from peft 0.0.1 to 0.21.3 (23 releases); trl 0.2.0 to 1.18.1 (48 releases); accelerate 0.1.0 to 1.16.0 (51 releases).
Sources
- Release tags of huggingface/peft (src/peft), huggingface/trl (trl/) and huggingface/accelerate (src/accelerate); release dates from PyPI.
- Messages quoted: peft utils/other.py at 0.9.0, trl trainer/utils.py at 0.19.0, trl models/utils.py at 0.25.0, trl trainer/ppo_trainer.py at 0.28.0, trl commands/cli_utils.py at 0.12.0, accelerate utils/imports.py at 0.28.0.
- Reports of the errors this page answers: is_npu_available from accelerate.utils (raised by peft), is_safetensors_available from accelerate.utils, PartialState from accelerate (raised by transformers).
The same data as JSON: peft.json, trl.json, accelerate.json, licensed CC BY 4.0.
Related: "cannot import name ... from 'transformers'" · "cannot import name ... from 'huggingface_hub'" · "cannot import name ... from 'diffusers'" · "got an unexpected keyword argument": PEFT, TRL and TrainingArguments.