Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ Note that the model can be swapped for a local or remote HF-compatible checkpoin
Quantization is applied by selecting an algorithm and calling the `oneshot` API.

```python
from compressed_tensors.offload import dispatch_model
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.utils import dispatch_for_generation

MODEL_ID = "Qwen/Qwen3-30B-A3B"

Expand All @@ -134,7 +134,7 @@ oneshot(model=model, recipe=recipe)

# Confirm generations of the quantized model look sane.
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
model.device
)
Expand Down
4 changes: 2 additions & 2 deletions docs/getting-started/compress.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.utils import dispatch_for_generation
from compressed_tensors.offload import dispatch_model

MODEL_ID = "Qwen/Qwen3-30B-A3B"

Expand All @@ -47,7 +47,7 @@ oneshot(model=model, recipe=recipe)

# Confirm generations of the quantized model look sane.
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
model.device
)
Expand Down
4 changes: 2 additions & 2 deletions docs/key-models/llama4/fp8-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ Let's walk through the main steps of the quantization process:
Load the model using `AutoModelForCausalLM`:

```python
from compressed_tensors.offload import dispatch_model
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.utils import dispatch_for_generation

MODEL_ID = "meta-llama/Llama-4-Scout-17B-16E-Instruct"

Expand Down Expand Up @@ -53,7 +53,7 @@ oneshot(model=model, recipe=recipe)

```python
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
model.device
)
Expand Down
4 changes: 2 additions & 2 deletions examples/autoround/quantization_kv_cache/llama3_example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from auto_round.calib_dataset import get_dataset
from compressed_tensors.offload import dispatch_model
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
Expand Down Expand Up @@ -54,7 +54,7 @@
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
sample = tokenizer("Hello my name is", return_tensors="pt")
sample = {key: value.to(model.device) for key, value in sample.items()}
output = model.generate(**sample, max_new_tokens=100)
Expand Down
4 changes: 2 additions & 2 deletions examples/autoround/quantization_w4a16/llama3_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from auto_round.calib_dataset import get_dataset
from compressed_tensors.offload import dispatch_model
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.autoround import AutoRoundModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
Expand Down Expand Up @@ -41,7 +41,7 @@
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
sample = tokenizer("Hello my name is", return_tensors="pt")
sample = {key: value.to(model.device) for key, value in sample.items()}
output = model.generate(**sample, max_new_tokens=100)
Expand Down
4 changes: 2 additions & 2 deletions examples/autoround/quantization_w4a16/qwen3_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from auto_round.calib_dataset import get_dataset
from compressed_tensors.offload import dispatch_model
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.autoround import AutoRoundModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
model_id = "Qwen/Qwen3-235B-A22B"
Expand Down Expand Up @@ -53,7 +53,7 @@
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
sample = tokenizer("Hello my name is", return_tensors="pt")
sample = {key: value.to(model.device) for key, value in sample.items()}
output = model.generate(**sample, max_new_tokens=100)
Expand Down
4 changes: 2 additions & 2 deletions examples/autoround/quantization_w4a4_fp4/llama3.1_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from auto_round.calib_dataset import get_dataset
from compressed_tensors.offload import dispatch_model
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.autoround import AutoRoundModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
MODEL_ID = "meta-llama/Meta-Llama-3.1-8B-Instruct"
Expand Down Expand Up @@ -41,7 +41,7 @@

print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
model.device
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from auto_round.calib_dataset import get_dataset
from compressed_tensors.offload import dispatch_model
from transformers import AutoProcessor, Llama4ForConditionalGeneration

from llmcompressor import oneshot
from llmcompressor.modifiers.autoround import AutoRoundModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
model_id = "meta-llama/Llama-4-Scout-17B-16E-Instruct"
Expand Down Expand Up @@ -51,7 +51,7 @@
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
sample = processor(text="Hello my name is", return_tensors="pt")
sample = {key: value.to(model.device) for key, value in sample.items()}
output = model.generate(**sample, max_new_tokens=1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from auto_round.calib_dataset import get_dataset
from compressed_tensors.offload import dispatch_model
from transformers import AutoProcessor, Llama4ForConditionalGeneration

from llmcompressor import oneshot
from llmcompressor.modifiers.autoround import AutoRoundModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
model_id = "meta-llama/Llama-4-Scout-17B-16E-Instruct"
Expand Down Expand Up @@ -51,7 +51,7 @@
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
sample = processor(text="Hello my name is", return_tensors="pt")
sample = {key: value.to(model.device) for key, value in sample.items()}
output = model.generate(**sample, max_new_tokens=1)
Expand Down
4 changes: 2 additions & 2 deletions examples/awq/fp8_block_llama_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from compressed_tensors.offload import dispatch_model
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.awq import AWQModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
MODEL_ID = "meta-llama/Meta-Llama-3-8B-Instruct"
Expand Down Expand Up @@ -67,7 +67,7 @@ def tokenize(sample):
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
model.device
)
Expand Down
4 changes: 2 additions & 2 deletions examples/awq/fp8_dynamic_llama_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from compressed_tensors.offload import dispatch_model
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.awq import AWQModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
MODEL_ID = "meta-llama/Meta-Llama-3-8B-Instruct"
Expand Down Expand Up @@ -67,7 +67,7 @@ def tokenize(sample):
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
model.device
)
Expand Down
4 changes: 2 additions & 2 deletions examples/awq/llama_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from compressed_tensors.offload import dispatch_model
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.awq import AWQModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
MODEL_ID = "meta-llama/Meta-Llama-3-8B-Instruct"
Expand Down Expand Up @@ -67,7 +67,7 @@ def tokenize(sample):
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
model.device
)
Expand Down
4 changes: 2 additions & 2 deletions examples/awq/llama_example_with_masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"""

import torch
from compressed_tensors.offload import dispatch_model
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.awq import AWQModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
MODEL_ID = "meta-llama/Meta-Llama-3-8B-Instruct"
Expand Down Expand Up @@ -126,7 +126,7 @@ def tokenize(sample):
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
model.device
)
Expand Down
4 changes: 2 additions & 2 deletions examples/awq/qwen3-vl-30b-a3b-Instruct-example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import torch
from compressed_tensors.offload import dispatch_model
from datasets import load_dataset
from transformers import AutoProcessor, Qwen3VLMoeForConditionalGeneration

from llmcompressor import oneshot
from llmcompressor.modifiers.awq import AWQModifier
from llmcompressor.utils import dispatch_for_generation

MODEL_ID = "Qwen/Qwen3-VL-30B-A3B-Instruct"

Expand Down Expand Up @@ -104,7 +104,7 @@ def data_collator(batch):
)

print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = processor(text="Hello my name is", return_tensors="pt").input_ids.to("cuda")
output = model.generate(input_ids, max_new_tokens=20)
print(processor.decode(output[0]))
Expand Down
4 changes: 2 additions & 2 deletions examples/awq/qwen3_coder_moe_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from compressed_tensors.offload import dispatch_model
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.awq import AWQModifier
from llmcompressor.utils import dispatch_for_generation

MODEL_ID = "Qwen/Qwen3-Coder-30B-A3B-Instruct"
SAVE_DIR = MODEL_ID.split("/")[-1] + "-W4A16-awq"
Expand Down Expand Up @@ -68,7 +68,7 @@ def preprocess(example):

# Confirm generations of the quantized model look sane.
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = tokenizer(
"Write a binary search function", return_tensors="pt"
).input_ids.to(model.device)
Expand Down
4 changes: 2 additions & 2 deletions examples/awq/qwen3_moe_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from compressed_tensors.offload import dispatch_model
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.awq import AWQModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
MODEL_ID = "Qwen/Qwen3-30B-A3B"
Expand Down Expand Up @@ -70,7 +70,7 @@ def tokenize(sample):
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
model.device
)
Expand Down
4 changes: 2 additions & 2 deletions examples/awq/qwen3_next_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from compressed_tensors.offload import dispatch_model
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.awq import AWQModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
MODEL_ID = "Qwen/Qwen3-Next-80B-A3B-Thinking"
Expand Down Expand Up @@ -70,7 +70,7 @@ def tokenize(sample):
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
model.device
)
Expand Down
4 changes: 2 additions & 2 deletions examples/awq/w4a8_fp8_llama_example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from compressed_tensors.offload import dispatch_model
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.awq import AWQModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
MODEL_ID = "meta-llama/Meta-Llama-3-8B-Instruct"
Expand Down Expand Up @@ -60,7 +60,7 @@ def preprocess(example):
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
input_ids = tokenizer("Hello my name is", return_tensors="pt").input_ids.to(
model.device
)
Expand Down
4 changes: 2 additions & 2 deletions examples/big_models_with_sequential_onloading/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ oneshot(
During `oneshot`, only one gpu is required which will be used to onload each layer for calibration in a sequential manner.

```python
dispatch_for_generation(model)
dispatch_model(model)
sample = tokenizer("Hello my name is", return_tensors="pt")
sample = {key: value.to(model.device) for key, value in sample.items()}
output = model.generate(**sample, max_new_tokens=100)
print(tokenizer.decode(output[0]))
```

Finally, we call `dispatch_for_generation` to evenly load the model across available devices (potentially offloading the model if required) and run sample generations on the newly quantized model.
Finally, we call `dispatch_model` to evenly load the model across available devices (potentially offloading the model if required) and run sample generations on the newly quantized model.
4 changes: 2 additions & 2 deletions examples/big_models_with_sequential_onloading/llama3.3_70b.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from compressed_tensors.offload import dispatch_model
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import GPTQModifier
from llmcompressor.modifiers.smoothquant import SmoothQuantModifier
from llmcompressor.utils import dispatch_for_generation

# Select model and load it.
model_id = "meta-llama/Llama-3.3-70B-Instruct"
Expand Down Expand Up @@ -74,7 +74,7 @@ def tokenize(sample):
# Confirm generations of the quantized model look sane.
print("\n\n")
print("========== SAMPLE GENERATION ==============")
dispatch_for_generation(model)
dispatch_model(model)
sample = tokenizer("Hello my name is", return_tensors="pt")
sample = {key: value.to(model.device) for key, value in sample.items()}
output = model.generate(**sample, max_new_tokens=100)
Expand Down
Loading
Loading