---
title: Qwen3.5-2B-FP8-Dynamic-LLMCompressor
canonical_url: "https://www.modelscope.cn/models/kfcVme50/Qwen3.5-2B-FP8-Dynamic-LLMCompressor"
md_url: "https://www.modelscope.cn/models/kfcVme50/Qwen3.5-2B-FP8-Dynamic-LLMCompressor.md"
repository: kfcVme50/Qwen3.5-2B-FP8-Dynamic-LLMCompressor
chinese_name: Qwen3.5-2B-FP8-Dynamic-LLMCompressor
last_updated: 2026-11-04
license: apache-2.0
pipeline_tag: image-text-to-text
tasks:
  - image-text-to-text
model_type:
  - qwen3_5
architectures:
  - Qwen3_5ForConditionalGeneration
base_model:
  - Qwen/Qwen3.5-2B
base_model_relation: quantized
parameters: 2.2B
tensor_type:
  - F16
  - F8_E4M3
  - BF16
library_name:
  - safetensors
downloads: 15
stars: 0
tags:
  - qwen3_5
  - fp8
  - fp8-dynamic
  - quantization
  - llm-compressor
  - compressed-tensors
---

# Qwen3.5-2B-FP8-Dynamic-LLMCompressor

> Qwen3.5-2B-FP8-Dynamic-LLMCompressor - kfcVme50 在 ModelScope 开源的模型。Qwen3.5-2B-FP8-Dynamic-LLMCompressor

kfcVme50/Qwen3.5-2B-FP8-Dynamic-LLMCompressor 是 ModelScope 魔搭社区上的 2.2B 参数image-text-to-text模型，采用 apache-2.0 许可，基于 Qwen/Qwen3.5-2B 构建。

- **Repository**: kfcVme50/Qwen3.5-2B-FP8-Dynamic-LLMCompressor
- **License**: apache-2.0
- **Tasks**: image-text-to-text
- **Parameters**: 2.2B
- **Base model**: Qwen/Qwen3.5-2B
- **Tags**: qwen3_5, fp8, fp8-dynamic, quantization, llm-compressor, compressed-tensors
- **Downloads**: 15
- **Stars**: 0
- **Last updated**: 2026-11-04

Source: https://www.modelscope.cn/models/kfcVme50/Qwen3.5-2B-FP8-Dynamic-LLMCompressor

---

# Qwen3.5-2B-FP8-Dynamic-LLMCompressor

基于 Qwen3.5-2B 制作的 动态 FP8 量化模型，使用 llm-compressor 0.14.0 制作，以 compressed-tensors 0.19.0 格式保存。

## 量化配置

采用 `FP8_DYNAMIC` 对 96 个语言线性层做量化。权重按输出通道使用静态尺度，激活按 token 动态缩放，制作时无需校准数据。权重共 3.311 GiB。 `visual`、`linear_attn`、`lm_head` 及其他非目标层保留浮点精度，KV cache 沿用推理引擎的默认设置。

制作所用的上游提交号未记录。

## 文本推理

完整下载仓库后，在支持 compressed-tensors 的 vLLM 0.32.0 环境运行。模型目录应包含权重、索引、配置和 tokenizer。示例使用文本输入。

```python
import json
import os
from collections.abc import Mapping
from pathlib import Path

# 在导入推理库之前启用离线模式，不下载任何模型文件。
os.environ["HF_HUB_OFFLINE"] = "1"
os.environ["TRANSFORMERS_OFFLINE"] = "1"

MODEL_DIR = Path(".").resolve()  # 从下载后的完整模型目录运行


def token_ids_from_template(encoded):
    # Transformers 5 可能返回 BatchEncoding/UserDict，而不一定是普通 dict。
    if isinstance(encoded, Mapping):
        if "input_ids" not in encoded:
            raise ValueError("Chat template 未返回 input_ids")
        encoded = encoded["input_ids"]
    if hasattr(encoded, "tolist"):
        encoded = encoded.tolist()
    if (isinstance(encoded, (list, tuple)) and len(encoded) == 1
            and isinstance(encoded[0], (list, tuple))):
        encoded = encoded[0]
    if not isinstance(encoded, (list, tuple)) or not encoded:
        raise TypeError("Chat template 必须返回非空 token ID 序列")
    if any(isinstance(token, bool) or not isinstance(token, int) or token < 0
           for token in encoded):
        raise TypeError("Token ID 必须为非负整数")
    return list(encoded)


def main():
    from vllm import LLM, SamplingParams

    if not MODEL_DIR.is_dir() or not (MODEL_DIR / "config.json").is_file():
        raise FileNotFoundError("请将 MODEL_DIR 改为完整的本地模型目录")
    if not list(MODEL_DIR.glob("*.safetensors")):
        raise FileNotFoundError("模型权重缺失，不能使用本地占位目录")

    config = json.loads((MODEL_DIR / "config.json").read_text(encoding="utf-8"))
    if config.get("quantization_config", {}).get("quant_method") != "compressed-tensors":
        raise ValueError("该示例要求本模型的 compressed-tensors checkpoint")
    generation_path = MODEL_DIR / "generation_config.json"
    generation = json.loads(generation_path.read_text(encoding="utf-8")) if generation_path.exists() else {}
    eos = generation.get("eos_token_id")
    if eos is None:
        eos = config.get("eos_token_id")
    if eos is None:
        eos = config.get("text_config", {}).get("eos_token_id")
    stop_ids = eos if isinstance(eos, list) else ([eos] if eos is not None else [])

    llm = LLM(
        model=str(MODEL_DIR),
        tokenizer=str(MODEL_DIR),
        dtype="float16",
        tensor_parallel_size=1,
        max_model_len=4096,
        gpu_memory_utilization=0.75,
        enforce_eager=True,
        max_num_seqs=1,
        enable_prefix_caching=False,
        limit_mm_per_prompt={"image": 0, "video": 0},
        generation_config="vllm",
        trust_remote_code=False,
        seed=42,
    )
    tokenizer = llm.get_tokenizer()
    messages = [{"role": "user", "content": "小明有 2 个苹果，又得到 3 个，现在一共有几个？\n请在最后一行用 #### 数字 给出答案。"}]
    encoded = tokenizer.apply_chat_template(
        messages, tokenize=True, add_generation_prompt=True,
    )
    # 不传 enable_thinking，保留 checkpoint 聊天模板的默认行为。
    token_ids = token_ids_from_template(encoded)
    max_new_tokens = 1024
    if len(token_ids) + max_new_tokens > 4096:
        raise ValueError("提示长度加生成预算超过 4096；本示例不自动截断输入")
    sampling = SamplingParams(
        temperature=0.0,
        top_p=1.0,
        top_k=-1,
        n=1,
        max_tokens=max_new_tokens,
        seed=42,
        ignore_eos=False,
        stop_token_ids=stop_ids,
        repetition_penalty=generation.get("repetition_penalty", 1.0),
        min_tokens=generation.get("min_new_tokens") or 0,
        presence_penalty=0.0,
        frequency_penalty=0.0,
        skip_special_tokens=True,
    )
    outputs = llm.generate(
        [{"prompt_token_ids": token_ids}],
        sampling_params=sampling,
        use_tqdm=False,
    )
    print(tokenizer.decode(outputs[0].outputs[0].token_ids, skip_special_tokens=True))


if __name__ == "__main__":
    main()
```

## 验证结果

在 RTX 4090 D 上使用 vLLM 0.32.0，加载日志记录的内核为 CUTLASS FP8。下表为 GSM8K 测试集前 100 题，贪心生成，每题最多 1024 个新 token，单请求顺序执行。 FP8 Block128 为同批对照。

| 模型 | 正确/题数 | 准确率 | 可解析率 | 触顶率 | 串行 token/s | worker peak allocated GiB | worker peak reserved GiB | 权重文件 GiB | 加载文件合计 GiB |
|---|---:|---:|---:|---:|---:|---:|---:|---:|---:|
| FP16 | 71/100 | 71.00% | 92.00% | 7.00% | 55.823 | 17.268 | 17.324 | 4.236 | 4.257 |
| FP8 Dynamic | 70/100 | 70.00% | 97.00% | 2.00% | 47.499 | 17.113 | 17.121 | 3.311 | 3.330 |
| FP8 Block128 | 72/100 | 72.00% | 95.00% | 4.00% | 44.134 | 17.283 | 17.334 | 3.310 | 3.329 |

## 复现与许可

以下命令在配套量化代码项目中运行。

```bash
python run.py quantize --tool llmcompressor --method fp8 --stage full
```

量化参数见 [config.json](config.json) 和 [recipe.yaml](recipe.yaml)，文件校验值见 [SHA256SUMS](SHA256SUMS)。模型沿用基座的 [Apache-2.0 许可](LICENSE)。
