soyrsoyr's picture
simplify model card to recipe and usage
e4f6a04 verified
|
Raw History Blame Contribute Delete
1.54 kB
metadata
library_name: transformers
license: mit
tags:
  - llm-compressor
  - tiny-model
  - mtp
  - pr-3225
  - test-fixture

GLM-4.7-Flash-0.82B-MTP

Small BF16 test model using zai-org/GLM-4.7-Flash, with a toy-trained backbone and synthetic MTP weights.

Quantization recipe

Uses Transformers 5.17.0 and LLM Compressor PR #3225.

import torch
from compressed_tensors.offload import set_onload_device
from compressed_tensors.quantization import preset_name_to_scheme
from transformers import AutoTokenizer, Glm4MoeLiteForCausalLM

from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.utils import load_context

MODEL_ID = "inference-optimization/GLM-4.7-Flash-0.82B-MTP"
SAVE_DIR = "GLM-4.7-Flash-0.82B-MTP-FP8-Dynamic"

with load_context(Glm4MoeLiteForCausalLM, load_mtp=True):
    model = Glm4MoeLiteForCausalLM.from_pretrained(
        MODEL_ID, dtype=torch.bfloat16, device_map="cpu",
    )
set_onload_device(model, "cuda")

recipe = QuantizationModifier(
    config_groups={
        "mtp": preset_name_to_scheme("FP8_DYNAMIC", targets=[r"re:^mtp\.layers\."]),
        "backbone": preset_name_to_scheme("FP8_DYNAMIC", targets=["Linear"]),
    },
    ignore=["lm_head", r"re:.*\.eh_proj$", r"re:.*\.indexer\..*"],
)

oneshot(model=model, recipe=recipe)
model.save_pretrained(SAVE_DIR)
AutoTokenizer.from_pretrained(MODEL_ID).save_pretrained(SAVE_DIR)