GLM-4.6-quantized.w4a16
19
—
by
RedHatAI
Language Model
OTHER
4.6B params
New
19 downloads
Early-stage
Edge AI:
Mobile
Laptop
Server
11GB+ RAM
Mobile
Laptop
Server
Quick Summary
AI model with specialized capabilities.
Device Compatibility
Mobile
4-6GB RAM
Laptop
16GB RAM
Server
GPU
Minimum Recommended
5GB+ RAM
Code Examples
Deploymentpythontransformers
from vllm import LLM, SamplingParams
from transformers import AutoTokenizer
model_id = "RedHatAI/GLM-4.6-quantized.w4a16"
number_gpus = 4
sampling_params = SamplingParams(temperature=0.6, top_p=0.9, max_tokens=256)
tokenizer = AutoTokenizer.from_pretrained(model_id)
messages = [
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
{"role": "user", "content": "Who are you?"},
]
prompts = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
llm = LLM(model=model_id, tensor_parallel_size=number_gpus)
outputs = llm.generate(prompts, sampling_params)
generated_text = outputs[0].outputs[0].text
print(generated_text)Load model.pythontransformers
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer
from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import GPTQModifier
from llmcompressor.utils import dispatch_for_generation
MODEL_ID = "zai-org/GLM-4.6"
# Load model.
model = AutoModelForCausalLM.from_pretrained(
MODEL_ID, torch_dtype="auto"
)
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
# Select calibration dataset.
DATASET_ID = "HuggingFaceH4/ultrachat_200k"
DATASET_SPLIT = "train_sft"
# Select number of samples.
# Increasing the number of samples can improve accuracy.
NUM_CALIBRATION_SAMPLES = 512
MAX_SEQUENCE_LENGTH = 2048
# Load dataset and preprocess.
ds = load_dataset(DATASET_ID, split=f"{DATASET_SPLIT}[:{NUM_CALIBRATION_SAMPLES}]")
ds = ds.shuffle(seed=42)
def preprocess(example):
return {
"text": tokenizer.apply_chat_template(
example["messages"],
tokenize=False,
)
}
ds = ds.map(preprocess)
# Tokenize inputs.
def tokenize(sample):
return tokenizer(
sample["text"],
padding=False,
max_length=MAX_SEQUENCE_LENGTH,
truncation=True,
add_special_tokens=False,
)
ds = ds.map(tokenize, remove_columns=ds.column_names)
# Configure the quantization algorithm and scheme with explicit parameters.
recipe = GPTQModifier(
targets="Linear",
scheme="W4A16",
ignore=[
"lm_head",
"re:.*mlp.gate$"
],
)
# Apply quantization.
oneshot(
model=model,
dataset=ds,
recipe=recipe,
max_seq_length=MAX_SEQUENCE_LENGTH,
num_calibration_samples=NUM_CALIBRATION_SAMPLES,
pipeline="sequential",
sequential_targets=["Glm4MoeDecoderLayer"],
trust_remote_code_model=True,
)
SAVE_DIR = "./" + MODEL_ID.rstrip("/").split("/")[-1] + "-quantized.w4a16"
model.save_pretrained(SAVE_DIR, save_compressed=True)
tokenizer.save_pretrained(SAVE_DIR)Reproductiontext
lm_eval --model local-chat-completions \
--tasks mmlu_pro \
--model_args "model=RedHatAI/GLM-4.6-quantized.w4a16,max_length=90000,base_url=http://0.0.0.0:3758/v1/chat/completions,num_concurrent=128,max_retries=3,tokenized_requests=False,tokenizer_backend=None,timeout=1200" \
--num_fewshot 5 \
--apply_chat_template \
--fewshot_as_multiturn \
--output_path ./ \
--seed 42 \
--gen_kwargs "do_sample=True,temperature=1.0,top_p=0.95,max_gen_toks=64000"
lm_eval --model local-chat-completions \
--tasks leaderboard_ifeval \
--model_args "model=RedHatAI/GLM-4.6-quantized.w4a16,max_length=90000,base_url=http://0.0.0.0:3758/v1/chat/completions,num_concurrent=128,max_retries=3,tokenized_requests=False,tokenizer_backend=None,timeout=1200" \
--num_fewshot 5 \
--apply_chat_template \
--fewshot_as_multiturn \
--output_path ./ \
--seed 42 \
--gen_kwargs "do_sample=True,temperature=1.0,top_p=0.95,max_gen_toks=64000"Deploy This Model
Production-ready deployment in minutes
Together.ai
Instant API access to this model
Production-ready inference API. Start free, scale to millions.
Try Free APIReplicate
One-click model deployment
Run models in the cloud with simple API. No DevOps required.
Deploy NowDisclosure: We may earn a commission from these partners. This helps keep LLMYourWay free.