Quantized layers:
routed MoE experts only (attention, router/gate, and
lm_head
are kept in the original precision)
This is a
tiny, randomly-initialized
Qwen3-MoE model quantized to W4A8, used
purely as
vLLM CI coverage
for the Quark W4A8 fused-MoE path
(
QuarkW4A8Fp8MoEMethod
), which dispatches through the ROCm AITER fused MoE
kernel. It is not intended to produce meaningful text — it exists so CI can load
a real W4A8 checkpoint and run a forward pass on GPU.
The dimensions (hidden
2048
, MoE intermediate
1024
,
8
experts, top-
2
) are
multiples of 256 so the AITER W4A8 shuffle/GEMM tile constraints hold. The
vocab_size
matches the tokenizer so token ids stay within the embedding table.
Note: Quark quantizes
nn.Linear
modules. MoE experts are stored as individual
nn.Linear
layers in
transformers
~4.57; quantize with that version so the
routed experts are captured.
import argparse
import torch
from datasets import load_dataset
from torch.utils.data import DataLoader
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
from quark.torch import ModelQuantizer, export_safetensors
from quark.torch.quantization.config.config import (
FP8E4M3PerTensorSpec,
Int4PerChannelSpec,
ProgressiveSpec,
QConfig,
QLayerConfig,
)
defget_config() -> QConfig:
# Quantize the routed experts only.
exclude_layers = ["*self_attn*", "*mlp.gate", "*lm_head"]
input_spec = FP8E4M3PerTensorSpec(
observer_method="min_max", scale_type="float", is_dynamic=True
).to_quantization_spec()
# Progressive FP8 -> INT4 weight spec (Kimi-K2.5-W4A8 recipe).
weight_spec = ProgressiveSpec(
first_stage=FP8E4M3PerTensorSpec(
observer_method="min_max", scale_type="float", is_dynamic=False
),
second_stage=Int4PerChannelSpec(
symmetric=True,
scale_type="float",
round_method="half_even",
is_dynamic=False,
ch_axis=0,
),
).to_quantization_spec()
return QConfig(
global_quant_config=QLayerConfig(input_tensors=input_spec, weight=weight_spec),
exclude=exclude_layers,
)
defmain() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--export-path", required=True)
parser.add_argument("--tokenizer", default="Qwen/Qwen1.5-MoE-A2.7B-Chat")
parser.add_argument("--hidden", type=int, default=2048)
parser.add_argument("--moe-intermediate", type=int, default=1024)
parser.add_argument("--experts", type=int, default=8)
parser.add_argument("--topk", type=int, default=2)
parser.add_argument("--layers", type=int, default=2)
parser.add_argument("--seed", type=int, default=0)
args = parser.parse_args()
torch.manual_seed(args.seed)
tokenizer = AutoTokenizer.from_pretrained(args.tokenizer)
# vocab_size MUST cover the tokenizer, else real prompts produce token ids# beyond the embedding table -> out-of-bounds embedding lookup (GPU fault).
cfg = AutoConfig.for_model(
"qwen3_moe",
hidden_size=args.hidden,
intermediate_size=args.hidden,
moe_intermediate_size=args.moe_intermediate,
num_hidden_layers=args.layers,
num_attention_heads=16,
num_key_value_heads=2,
head_dim=128,
num_experts=args.experts,
num_experts_per_tok=args.topk,
vocab_size=len(tokenizer),
max_position_embeddings=2048,
)
model = AutoModelForCausalLM.from_config(cfg).to("cuda").eval().to(torch.bfloat16)
ds = load_dataset("mit-han-lab/pile-val-backup", split="validation")
samples = [
tokenizer(ds[i]["text"], return_tensors="pt", truncation=True,
max_length=64).input_ids.to("cuda")
for i inrange(8)
]
dataloader = DataLoader(samples, batch_size=1)
quantizer = ModelQuantizer(get_config())
with torch.no_grad():
model = quantizer.quantize_model(model, dataloader)
export_safetensors(
model, args.export_path, custom_mode="quark",
weight_format="real_quantized", pack_method="reorder",
)
tokenizer.save_pretrained(args.export_path)
# Symmetric INT4 export emits all-zero `*_zero_point_2` tensors that vLLM's# W4A8 loader does not expect; drop them so the checkpoint loads directly.if __name__ == "__main__":
main()
Usage in vLLM
W4A8 dispatches through the ROCm AITER fused MoE kernel, so run on gfx942/gfx950
with AITER enabled:
tiny-qwen3-moe-w4a8 huggingface.co is an AI model on huggingface.co that provides tiny-qwen3-moe-w4a8's model effect (), which can be used instantly with this amd tiny-qwen3-moe-w4a8 model. huggingface.co supports a free trial of the tiny-qwen3-moe-w4a8 model, and also provides paid use of the tiny-qwen3-moe-w4a8. Support call tiny-qwen3-moe-w4a8 model through api, including Node.js, Python, http.
tiny-qwen3-moe-w4a8 huggingface.co is an online trial and call api platform, which integrates tiny-qwen3-moe-w4a8's modeling effects, including api services, and provides a free online trial of tiny-qwen3-moe-w4a8, you can try tiny-qwen3-moe-w4a8 online for free by clicking the link below.
amd tiny-qwen3-moe-w4a8 online free url in huggingface.co:
tiny-qwen3-moe-w4a8 is an open source model from GitHub that offers a free installation service, and any user can find tiny-qwen3-moe-w4a8 on GitHub to install. At the same time, huggingface.co provides the effect of tiny-qwen3-moe-w4a8 install, users can directly use tiny-qwen3-moe-w4a8 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
tiny-qwen3-moe-w4a8 install url in huggingface.co: