trl
trl copied to clipboard
create_model_from_path crashes when config lacks architecture metadata
Reproduction
PretrainedConfig.architectures is optional and defaults to None. The following isolates the model-loader selection without downloading a model:
from unittest.mock import patch
from transformers import PretrainedConfig
from trl.trainer.utils import create_model_from_path
config = PretrainedConfig()
with (
patch("trl.trainer.utils.AutoConfig.from_pretrained", return_value=config),
patch("trl.trainer.utils.AutoModelForCausalLM.from_pretrained"),
):
create_model_from_path("model-id")
Output:
Traceback (most recent call last):
File "repro.py", line 13, in <module>
create_model_from_path("model-id")
File "trl/trainer/utils.py", line 1183, in create_model_from_path
architecture = getattr(transformers, config.architectures[0], None)
~~~~~~~~~~~~~~~~~~~~^^^
TypeError: 'NoneType' object is not subscriptable
Setting config.architectures = [] instead produces IndexError: list index out of range at the same line.
Expected behavior
create_model_from_path documents a best-effort architecture inference followed by a fallback to AutoModelForCausalLM. A config with no usable architecture metadata should take that fallback rather than failing while inspecting the optional field. The same fallback should also tolerate an absent auto_map, which is not defined by the base PretrainedConfig.
System Info
- Platform: macOS-26.5.2-arm64-arm-64bit-Mach-O
- Python version: 3.13.5
- TRL version: 1.13.0.dev0+1f47de9
- PyTorch version: 2.13.0
- accelerator(s): cpu
- Transformers version: 5.16.1
- Accelerate version: 1.14.0
- Datasets version: 5.0.1
Checklist
- [x] I have checked that my issue isn't already filed.
- [x] I have included my system information.
- [x] Any code provided is minimal, complete, and reproducible.
- [x] Any code provided is properly formatted in code blocks.
- [x] Any traceback provided is complete.