Files
Model-Optimizer/modelopt/torch/export/model_utils.py
T

70 lines
2.0 KiB
Python

# SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Utility functions for model type detection and classification."""
MODEL_NAME_TO_TYPE = {
"GPT2": "gpt",
"Mllama": "mllama",
"Llama4": "llama4",
"Llama": "llama",
"Mistral": "llama",
"GPTJ": "gptj",
"FalconForCausalLM": "falcon",
"RWForCausalLM": "falcon",
"baichuan": "baichuan",
"MPT": "mpt",
"Bloom": "bloom",
"ChatGLM": "chatglm",
"QWen": "qwen",
"RecurrentGemma": "recurrentgemma",
"Gemma3": "gemma3",
"Gemma2": "gemma2",
"Gemma": "gemma",
"phi3small": "phi3small",
"phi3": "phi3",
"PhiMoEForCausalLM": "phi3",
"phi": "phi",
"TLGv4ForCausalLM": "phi",
"MixtralForCausalLM": "llama",
"ArcticForCausalLM": "llama",
"StarCoder": "gpt",
"Dbrx": "dbrx",
"T5": "t5",
"Bart": "bart",
"GLM": "glm",
"InternLM2ForCausalLM": "internlm",
"ExaoneForCausalLM": "exaone",
"Nemotron": "gpt",
"Deepseek": "deepseek",
"Whisper": "whisper",
}
__doc__ = f"""Utility functions for model type detection and classification.
.. code-block:: python
{MODEL_NAME_TO_TYPE=}
"""
__all__ = ["get_model_type"]
def get_model_type(model):
"""Try get the model type from the model name. If not found, return None."""
for k, v in MODEL_NAME_TO_TYPE.items():
if k.lower() in type(model).__name__.lower():
return v
return None