BugFix: AttributeError: 'InternVLChatConfig' object has no attribute 'llm_config'
#29
by
snowleopard-mllm
- opened
When loading InternVideo2_5_Chat_8B model or InternVL2_5 series models:
It raises AttributeError: 'InternVLChatConfig' object has no attribute 'llm_config'
Please refer: https://huggingface.co/OpenGVLab/InternVideo2_5_Chat_8B/discussions/14
Simple Solution for InternVL Configuration Issue
(Tested with transformers v4.52.4)
Required Modifications
Add Initialization (configuration_internvl_chat.py:49)
self.vision_config = InternVisionConfig(**vision_config) self.llm_config = None # Initialize llm_config to prevent AttributeError
Add Null Check (configuration_internvl_chat.py:85)
output['llm_config'] = self.llm_config.to_dict() if self.llm_config is not None else {}
Root Cause Analysis
When executing:
model = AutoModel.from_pretrained(model_path, trust_remote_code=True).half().cuda().to(torch.bfloat16)
The following occurs:
- The Hugging Face framework downloads and parses
configuration_internvl_chat.py
- During config initialization (
transformers/configuration_utils.py:816-822
):config_dict = self.to_dict() # Get the default config dict (from a fresh PreTrainedConfig instance) default_config_dict = PretrainedConfig().to_dict() # get class specific config dict class_config_dict = self.__class__().to_dict() if not self.has_no_defaults_at_init else {}
- Key Issue:
self.llm_config
isNone
duringclass_config_dict
generation becausellm_config
is None- Without explicit initialization, this triggers an
AttributeError
when.to_dict()
is called
Why the Fix Works
- The initialization ensures
self.llm_config
always exists (even asNone
) - The null check prevents method calls on
None
while maintaining expected dictionary structure