fix config saving compatibility issue for transformers 4.45+
Browse filesconfig = AutoConfig.from_pretrained("OpenGVLab/InternVL2-1B", trust_remote_code=True)
config.save_pretrained("internvl2-1b")
raises error:
if llm_config['architectures'][0] == 'LlamaForCausalLM':
KeyError: 'architectures'
the root cause that transformers added validation of non-default parameters for generation during config saving it requires initialize configuration class without parameters and as the result llm_config comes as None (and according to code above it become {})
configuration_internvl_chat.py
CHANGED
@@ -46,9 +46,9 @@ class InternVLChatConfig(PretrainedConfig):
|
|
46 |
logger.info('llm_config is None. Initializing the LlamaConfig config with default values (`LlamaConfig`).')
|
47 |
|
48 |
self.vision_config = InternVisionConfig(**vision_config)
|
49 |
-
if llm_config
|
50 |
self.llm_config = LlamaConfig(**llm_config)
|
51 |
-
elif llm_config
|
52 |
self.llm_config = Qwen2Config(**llm_config)
|
53 |
else:
|
54 |
raise ValueError('Unsupported architecture: {}'.format(llm_config['architectures'][0]))
|
|
|
46 |
logger.info('llm_config is None. Initializing the LlamaConfig config with default values (`LlamaConfig`).')
|
47 |
|
48 |
self.vision_config = InternVisionConfig(**vision_config)
|
49 |
+
if llm_config.get('architectures', ["Qwen2ForCausalLM"])[0] == 'LlamaForCausalLM':
|
50 |
self.llm_config = LlamaConfig(**llm_config)
|
51 |
+
elif llm_config.get('architectures', ["Qwen2ForCausalLM"])[0] == 'Qwen2ForCausalLM':
|
52 |
self.llm_config = Qwen2Config(**llm_config)
|
53 |
else:
|
54 |
raise ValueError('Unsupported architecture: {}'.format(llm_config['architectures'][0]))
|