Views
No views yet
| Attribute | Value |
|---|---|
| Original Model | Unbabel/Tower-Plus-72B |
| Quantization | W4A16_ASYM (4-bit weights, 16-bit activations) |
| Calibration Samples | 128 |
| Sequence Length | 2048 |
| Calibration Dataset | neuralmagic/LLM_compression_calibration |
1dependencies = [
2 "llmcompressor>=0.10.0.1",
3 "protobuf>=7.34.0",
4 "sentencepiece>=0.2.1",
5 "compressed-tensors>=0.12.2"
6]1from transformers import AutoModelForCausalLM, AutoTokenizer
2from llmcompressor.modifiers.awq import AWQModifier, AWQMapping
3from llmcompressor import oneshot
4
5from datasets import load_dataset
6
7# envs
8MODEL_PATH = "Tower-Plus-72B"
9OUTPUT_PATH = "Tower-Plus-72B-awq"
10DATASET_ID = "neuralmagic/LLM_compression_calibration"
11NUM_CALIBRATION_SAMPLES = 128
12MAX_SEQUENCE_LENGTH = 2048
13
14# Load model and tokenizer
15"""
16The model is first loaded onto the cpu, as indicated through the use of None for the device_map argument in the from_pretrained method when loading the model.
17uring oneshot, only one gpu is required which will be used to onload each layer for calibration in a sequential manner.
18"""
19model = AutoModelForCausalLM.from_pretrained(
20 MODEL_PATH,
21 device_map="cpu",
22 dtype="auto",
23)
24tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH)
25
26# Load and preprocess calibration dataset
27calib_dataset = load_dataset(DATASET_ID, split=f"train[:{NUM_CALIBRATION_SAMPLES}]")
28calib_dataset = calib_dataset.shuffle(seed=42)
29
30def preprocess(example):
31 return {
32 "text": tokenizer.apply_chat_template(
33 [{"role": "user", "content": example["text"]}],
34 tokenize=False,
35 )
36 }
37
38calib_dataset = calib_dataset.map(preprocess)
39
40# Tokenize calibration dataset
41def tokenize(example):
42 return tokenizer(
43 example["text"],
44 padding=False,
45 max_length=MAX_SEQUENCE_LENGTH,
46 truncation=True,
47 add_special_tokens=False,
48 )
49
50calib_dataset = calib_dataset.map(tokenize, remove_columns=calib_dataset.column_names)
51
52# Define AWQ quantization recipe
53recipe = [
54 AWQModifier(
55 ignore=["lm_head"],
56 scheme="W4A16_ASYM",
57 targets=["Linear"],
58 ),
59]
60
61# Run quantization with calibration
62oneshot(
63 model=model,
64 tokenizer=tokenizer,
65 dataset=calib_dataset,
66 recipe=recipe,
67 max_seq_length=MAX_SEQUENCE_LENGTH,
68 num_calibration_samples=NUM_CALIBRATION_SAMPLES,
69 output_dir=OUTPUT_PATH,
70 pipeline="sequential",
71)
1# pip install vllm
2from vllm import LLM, SamplingParams
3sampling_params = SamplingParams(
4 best_of=1,
5 temperature=0,
6 max_tokens=8192,
7)
8llm = LLM(model="Unbabel/Tower-Plus-72B", tensor_parallel_size=4)
9messages = [{"role": "user", "content": "Translate the following English source text to Portuguese (Portugal):\nEnglish: Hello world!\nPortuguese (Portugal): "}]
10outputs = llm.chat(messages, sampling_params)
11# Make sure your prompt_token_ids look like this
12print (outputs[0].outputs[0].text)
13# > Olá, mundo!1# pip install transformers
2# pip install accelerate
3import torch
4from transformers import pipeline
5pipe = pipeline("text-generation", model="Unbabel/Tower-Plus-72B", device_map="auto")
6# We use the tokenizer’s chat template to format each message - see https://huggingface.co/docs/transformers/main/en/chat_templating
7messages = [{"role": "user", "content": "Translate the following English source text to Portuguese (Portugal):\nEnglish: Hello world!\nPortuguese (Portugal): "}]
8input_ids = pipe.tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True)
9outputs = pipe(messages, max_new_tokens=256, do_sample=False)
10print(outputs[0]["generated_text"])@misc{rei2025towerplus,
title={Tower+: Bridging Generality and Translation Specialization in Multilingual LLMs},
author={Ricardo Rei and Nuno M. Guerreiro and José Pombal and João Alves and Pedro Teixeirinha and Amin Farajian and André F. T. Martins},
year={2025},
eprint={2506.17080},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2506.17080},
}