I tried creating an 8bit quant for Qwen/Qwen-AgentWorld-35B-A3B · Hugging Face but it always bugs out at 35/40, assuming OOM.
I have a second spark coming in tomorrow with the cable, and once I get setup, can I expect it to work at that point?
Here’s my script (genAi’d, maybe I/it missed something) based on Background - LLM Compressor Docs
import os
import shutil
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from llmcompressor import oneshot
from llmcompressor.modeling.moe.linearize import load_quantizable_moe
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.utils import load_context
# Model identifiers and output targets
model_id = "Qwen/Qwen-AgentWorld-35B-A3B"
output_dir = "./Qwen-AgentWorld-35B-A3B-FP8"
print(f"Loading tokenizer and model: {model_id}")
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
# Wrap the model load to linearize MoE experts efficiently during load
with load_context():
# Load the base model in BF16 across available GPUs
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
dtype=torch.bfloat16,
trust_remote_code=True
)
# Configure the recipe matching standard Qwen official profiles
# Targets all dense compute layers, strictly protecting the logit head
recipe = QuantizationModifier(
targets="Linear",
scheme="FP8_DYNAMIC",
ignore=["lm_head"]
)
print("Starting one-shot FP8 quantization...")
oneshot(model=model, recipe=recipe)
print(f"Saving quantized weights and config blocks to {output_dir}...")
model.save_pretrained(output_dir)
tokenizer.save_pretrained(output_dir)
# Save a copy of this script inside the artifact directory for HF reproducibility
os.makedirs(output_dir, exist_ok=True)
shutil.copy(__file__, os.path.join(output_dir, "quant-qwen.py"))
print("Quantization complete!")