Co-authored-by: sglang-bot <232288953+sglang-bot@users.noreply.github.com> Co-authored-by: Brayden Zhong <brayden.zhong@radixark.ai> Co-authored-by: Jimmy Shong <69131491+Jiminator@users.noreply.github.com> Co-authored-by: hnyls2002 <lsyincs@gmail.com> Co-authored-by: Alex Nails <alex.nails@radixark.ai> Co-authored-by: Liangsheng Yin <hnyls2002@gmail.com>
73 lines
2.8 KiB
Python
73 lines
2.8 KiB
Python
# Copyright 2023-2026 SGLang Team
|
|
# 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.
|
|
# ==============================================================================
|
|
"""Per-architecture GGUF -> HF tensor name maps.
|
|
|
|
``GGUFModelLoader`` normally derives this map from ``gguf.get_tensor_name_map``,
|
|
which only covers architectures upstream gguf-py knows, and from a meta-device
|
|
``AutoModelForCausalLM.from_config`` to enumerate the HF parameter names. Neither
|
|
works for an architecture that lives outside transformers, so those are supplied
|
|
here instead.
|
|
|
|
A builder returns the complete ``{gguf_tensor_name: hf_param_name}`` map. Any
|
|
GGUF tensor left out of the map is skipped by ``gguf_quant_weights_iterator``,
|
|
which is how dummy tensors are dropped.
|
|
"""
|
|
|
|
from typing import Callable, Dict
|
|
|
|
from transformers import PretrainedConfig
|
|
|
|
# Sandwich naming: ffn_norm is the pre-FFN norm.
|
|
_MUSE_GLIMMER_LAYER_TENSORS = {
|
|
"attn_norm": "input_layernorm",
|
|
"post_attention_norm": "post_attn_norm",
|
|
"ffn_norm": "post_attention_layernorm",
|
|
"post_ffw_norm": "post_ffn_norm",
|
|
"attn_q": "self_attn.q_proj",
|
|
"attn_k": "self_attn.k_proj",
|
|
"attn_v": "self_attn.v_proj",
|
|
"attn_output": "self_attn.o_proj",
|
|
"attn_gate": "self_attn.output_gate_proj",
|
|
"ffn_gate": "mlp.gate_proj",
|
|
"ffn_up": "mlp.up_proj",
|
|
"ffn_down": "mlp.down_proj",
|
|
}
|
|
|
|
_MUSE_GLIMMER_GLOBAL_TENSORS = {
|
|
"token_embd": "model.embed_tokens",
|
|
"output_norm": "model.norm",
|
|
"output": "lm_head",
|
|
}
|
|
|
|
# attn_q_norm/attn_k_norm omitted: Muse Glimmer's QK-norm is non-parametric.
|
|
|
|
|
|
def build_muse_glimmer_name_map(config: PretrainedConfig) -> Dict[str, str]:
|
|
name_map = {
|
|
f"{gguf}.weight": f"{hf}.weight"
|
|
for gguf, hf in _MUSE_GLIMMER_GLOBAL_TENSORS.items()
|
|
}
|
|
for layer in range(config.num_hidden_layers):
|
|
for gguf, hf in _MUSE_GLIMMER_LAYER_TENSORS.items():
|
|
name_map[f"blk.{layer}.{gguf}.weight"] = f"model.layers.{layer}.{hf}.weight"
|
|
return name_map
|
|
|
|
|
|
# Keyed by HF ``config.model_type`` (loader.py looks it up with that), which is
|
|
# not the GGUF ``general.architecture`` that GGUF_NATIVE_CONFIG_BUILDERS uses:
|
|
# llama.cpp spells the arch "muse-glimmer" while the HF config says "muse_glimmer".
|
|
GGUF_HF_NAME_MAP_BUILDERS: Dict[str, Callable[[PretrainedConfig], Dict[str, str]]] = {
|
|
"muse_glimmer": build_muse_glimmer_name_map,
|
|
}
|