MCPcopy
hub / github.com/InternLM/lmdeploy / get_model_arch

Function get_model_arch

lmdeploy/archs.py:151–177  ·  view source on GitHub ↗

Get a model's architecture and configuration. Args: model_path(str): the model path

(model_path: str, trust_remote_code: bool = False)

Source from the content-addressed store, hash-verified

149
150
151def get_model_arch(model_path: str, trust_remote_code: bool = False):
152 """Get a model's architecture and configuration.
153
154 Args:
155 model_path(str): the model path
156 """
157 try:
158 cfg = AutoConfig.from_pretrained(model_path, trust_remote_code=trust_remote_code)
159 except Exception as e: # noqa
160 from transformers import PretrainedConfig
161 cfg = PretrainedConfig.from_pretrained(model_path, trust_remote_code=trust_remote_code)
162
163 _cfg = cfg.to_dict()
164 if _cfg.get('architectures', None):
165 arch = _cfg['architectures'][0]
166 if _cfg.get('auto_map'):
167 for _, v in _cfg['auto_map'].items():
168 if 'InternLMXComposer2ForCausalLM' in v:
169 arch = 'InternLMXComposer2ForCausalLM'
170 elif _cfg.get('auto_map', None) and 'AutoModelForCausalLM' in _cfg['auto_map']:
171 arch = _cfg['auto_map']['AutoModelForCausalLM'].split('.')[-1]
172 elif _cfg.get('language_config', None) and _cfg['language_config'].get(
173 'auto_map', None) and 'AutoModelForCausalLM' in _cfg['language_config']['auto_map']:
174 arch = _cfg['language_config']['auto_map']['AutoModelForCausalLM'].split('.')[-1]
175 else:
176 raise RuntimeError(f'Could not find model architecture from config: {_cfg}')
177 return arch, cfg
178
179
180def search_nested_config(config, key):

Callers 13

__init__Method · 0.90
__init__Method · 0.90
load_vl_modelFunction · 0.90
is_supportedFunction · 0.90
get_registered_nameFunction · 0.90
get_tm_configFunction · 0.90
load_model_configFunction · 0.90
__init__Method · 0.90
get_taskFunction · 0.90
load_model_and_tokenizerFunction · 0.90

Calls 4

to_dictMethod · 0.80
itemsMethod · 0.80
from_pretrainedMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected