A REAP-pruned version of
zai/glm-4.7
(GLM-4.7), reducing the model from 358B to ~251B parameters by pruning 30% of MoE experts while preserving model quality.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = "0xSero/GLM-4.7-REAP-30"
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_path,
torch_dtype=torch.bfloat16,
device_map="auto",
trust_remote_code=True
)
messages = [{"role": "user", "content": "Write a Python function to check if a number is prime."}]
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt", add_generation_prompt=True)
inputs = inputs.to(model.device)
outputs = model.generate(
inputs,
max_new_tokens=512,
temperature=0.7,
do_sample=True,
pad_token_id=tokenizer.eos_token_id
)
response = tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True)
print(response)
With vLLM (Recommended for Production)
from vllm import LLM, SamplingParams
llm = LLM(
model="0xSero/GLM-4.7-REAP-30",
tensor_parallel_size=8, # Use all 8 GPUs
trust_remote_code=True,
dtype="bfloat16"
)
sampling_params = SamplingParams(temperature=0.7, max_tokens=512)
outputs = llm.generate(["Write a Python function to check if a number is prime."], sampling_params)
print(outputs[0].outputs[0].text)
REAP Methodology
REAP (Router-Experts Activation Pruning)
is a state-of-the-art MoE pruning technique developed by Cerebras that identifies and removes the least important experts based on their activation patterns.
# Clone REAP repository
git clone https://github.com/Cerebras/reap
cd reap
pip install -e .
# Or use our fork with GLM-4.7 support
git clone https://github.com/0xSero/reap
Run REAP Pruning
# Full calibration run (~5 hours on 8x H200)
python src/reap/prune.py \
--model-name zai/glm-4.7 \
--dataset-name 0xSero/glm47-reap-calibration-v2 \
--compression-ratio 0.30 \
--prune-method reap \
--seed 42 \
--samples_per_category 1360 \
--model_max_length 2048 \
--distance_measure angular \
--record_pruning_metrics_only true \
--output_file_name observations_1360_angular-seed_42.pt
# With observation reuse (instant, <5 minutes)# If you already have the observations file from a previous run:
python src/reap/prune.py \
--model-name zai/glm-4.7 \
--compression-ratio 0.30 \
--load_observations observations_1360_angular-seed_42.pt \
--prune-method reap \
--seed 42
Observation Reuse
The key insight: REAP's calibration phase computes per-expert saliency scores that are
independent of the compression ratio
. Once computed, you can instantly generate models at any pruning level:
# observations_1360_angular-seed_42.pt contains:# - Expert activation statistics per layer# - Router weight distributions# - Angular distance matrices# Size: ~19MB for GLM-4.7# Generate multiple variants instantly:for ratio in [0.30, 0.35, 0.40, 0.50]:
run_reap(compression_ratio=ratio, load_observations="observations.pt")
GLM-4.7-REAP-30 huggingface.co is an AI model on huggingface.co that provides GLM-4.7-REAP-30's model effect (), which can be used instantly with this 0xSero GLM-4.7-REAP-30 model. huggingface.co supports a free trial of the GLM-4.7-REAP-30 model, and also provides paid use of the GLM-4.7-REAP-30. Support call GLM-4.7-REAP-30 model through api, including Node.js, Python, http.
GLM-4.7-REAP-30 huggingface.co is an online trial and call api platform, which integrates GLM-4.7-REAP-30's modeling effects, including api services, and provides a free online trial of GLM-4.7-REAP-30, you can try GLM-4.7-REAP-30 online for free by clicking the link below.
0xSero GLM-4.7-REAP-30 online free url in huggingface.co:
GLM-4.7-REAP-30 is an open source model from GitHub that offers a free installation service, and any user can find GLM-4.7-REAP-30 on GitHub to install. At the same time, huggingface.co provides the effect of GLM-4.7-REAP-30 install, users can directly use GLM-4.7-REAP-30 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.