lbourdois/fineweb-2-trimming
Preview • Updated • 1.97M • 1.69k • 1
How to use alphaedge-ai/granite-4.0-h-1b-spa-32768 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="alphaedge-ai/granite-4.0-h-1b-spa-32768")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("alphaedge-ai/granite-4.0-h-1b-spa-32768")
model = AutoModelForCausalLM.from_pretrained("alphaedge-ai/granite-4.0-h-1b-spa-32768")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use alphaedge-ai/granite-4.0-h-1b-spa-32768 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "alphaedge-ai/granite-4.0-h-1b-spa-32768"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "alphaedge-ai/granite-4.0-h-1b-spa-32768",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/alphaedge-ai/granite-4.0-h-1b-spa-32768
How to use alphaedge-ai/granite-4.0-h-1b-spa-32768 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "alphaedge-ai/granite-4.0-h-1b-spa-32768" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "alphaedge-ai/granite-4.0-h-1b-spa-32768",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "alphaedge-ai/granite-4.0-h-1b-spa-32768" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "alphaedge-ai/granite-4.0-h-1b-spa-32768",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use alphaedge-ai/granite-4.0-h-1b-spa-32768 with Docker Model Runner:
docker model run hf.co/alphaedge-ai/granite-4.0-h-1b-spa-32768
This model is a 7.10% smaller version of ibm-granite/granite-4.0-h-1b optimized for Spanish language via vocabulary size reduction using the trimming method.
This trimmed model should perform similarly to the original model with only 32,768 tokens and a much smaller memory footprint. However, it may not perform well for other languages as tokens not commonly used in the selected languages were removed from the vocabulary.
| Metric | Original | Trimmed | Reduction |
|---|---|---|---|
| Vocabulary size | 100,352 tokens | 32,768 tokens | 67.35% |
| Model size | 1,461,538,368 params | 1,357,729,344 params | 7.10% |
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda"
model_path = "alphaedge-ai/granite-4.0-h-1b-spa-32768"
tokenizer = AutoTokenizer.from_pretrained(model_path)
# drop device_map if running on CPU
model = AutoModelForCausalLM.from_pretrained(model_path, device_map=device)
model.eval()
# change input text as desired
chat = [
{"role": "user", "content": "Your prompt in Spanish."},
]
chat = tokenizer.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
# tokenize the text
input_tokens = tokenizer(chat, return_tensors="pt").to(device)
# generate output tokens
output = model.generate(**input_tokens, max_new_tokens=100)
# decode output tokens into text
output = tokenizer.batch_decode(output)
print(output[0])
@misc{granite2025,
author = {IBM Research},
title = {Granite 4.0 Language Models},
year = {2025},
howpublished = {https://github.com/ibm-granite/granite-4.0-language-models},
}
@misc{hf_blogpost_trimming,
title={Introduction to Trimming},
author={Loïck BOURDOIS and Tom AARSEN and Bram VANROY and Christopher AKIKI and Woojun JUNG and Manuel ROMERO and Prithiv SAKTHI},
year={2026},
url={https://huggingface.co/blog/lbourdois/introduction-to-trimming},
}
Base model
ibm-granite/granite-4.0-h-1b-base