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
2 changes: 1 addition & 1 deletion experimental/attention/llama3_attention.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from compressed_tensors.quantization import QuantizationArgs, QuantizationScheme
from datasets import load_dataset
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.quantization import QuantizationScheme, QuantizationArgs

# Select model and load it.
model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
Expand Down
4 changes: 2 additions & 2 deletions experimental/attention/llama3_attention_r3_nvfp4.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from compressed_tensors.quantization import QuantizationScheme
from compressed_tensors.quantization.quant_scheme import NVFP4
from datasets import load_dataset
from transformers import AutoModelForCausalLM, AutoTokenizer

from llmcompressor import oneshot
from llmcompressor.modifiers.quantization import QuantizationModifier
from llmcompressor.modifiers.transform import SpinQuantModifier
from llmcompressor.utils import dispatch_for_generation
from compressed_tensors.quantization import QuantizationScheme
from compressed_tensors.quantization.quant_scheme import NVFP4

# Select model and load it.
model_id = "meta-llama/Meta-Llama-3-8B-Instruct"
Expand Down
16 changes: 16 additions & 0 deletions src/llmcompressor/entrypoints/oneshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
from datasets import Dataset, DatasetDict


TOKENIZERS_PARALLELISM_ENV = "TOKENIZERS_PARALLELISM"


class Oneshot:
"""
Class responsible for carrying out one-shot calibration on a pretrained model.
Expand Down Expand Up @@ -121,6 +124,19 @@ def __init__(
:param log_dir: Path to save logs during oneshot run.
Nothing is logged to file if None.
"""
# Disable tokenizer parallelism to prevent warning when using
# multiprocessing for dataset preprocessing. The warning occurs because
# FastTokenizer's internal threading conflicts with dataset.map's num_proc.
# See: https://github.com/vllm-project/llm-compressor/issues/2007
if TOKENIZERS_PARALLELISM_ENV not in os.environ:
os.environ[TOKENIZERS_PARALLELISM_ENV] = "false"
logger.warning(
"Disabling tokenizer parallelism due to threading conflict between "
"FastTokenizer and Datasets. Set "
f"{TOKENIZERS_PARALLELISM_ENV}=false to "
"suppress this warning."
)

# Set up file logging (no default files):
# 1) If LLM_COMPRESSOR_LOG_FILE is set, log to that file.
# 2) Else, if an explicit log_dir is provided, create a timestamped file there.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os

import pytest

from llmcompressor.entrypoints.oneshot import (
TOKENIZERS_PARALLELISM_ENV as _TOKENIZERS_PARALLELISM_ENV,
)


class TestTokenizerParallelism:
"""Tests for tokenizer parallelism warning suppression (issue #2007)."""

def test_oneshot_sets_tokenizers_parallelism_when_not_set(self, monkeypatch):
"""
Test that Oneshot sets TOKENIZERS_PARALLELISM=false when not already set.

This prevents the warning:
"huggingface/tokenizers: The current process just got forked, after
parallelism has already been used. Disabling parallelism to avoid deadlocks..."

See: https://github.com/vllm-project/llm-compressor/issues/2007
"""
monkeypatch.delenv(_TOKENIZERS_PARALLELISM_ENV, raising=False)

from llmcompressor.entrypoints.oneshot import Oneshot

# Create a minimal Oneshot instance to trigger __init__
# We expect it to fail due to missing model, but the env var should be set
with pytest.raises(Exception):
Oneshot(model="nonexistent-model")

assert os.environ[_TOKENIZERS_PARALLELISM_ENV] == "false"

def test_oneshot_respects_existing_tokenizers_parallelism(self, monkeypatch):
"""
Test that Oneshot respects user's existing TOKENIZERS_PARALLELISM setting.

If a user has explicitly set TOKENIZERS_PARALLELISM, we should not override it.
"""
monkeypatch.setenv(_TOKENIZERS_PARALLELISM_ENV, "true")

from llmcompressor.entrypoints.oneshot import Oneshot

with pytest.raises(Exception):
Oneshot(model="nonexistent-model")

assert os.environ[_TOKENIZERS_PARALLELISM_ENV] == "true"
2 changes: 1 addition & 1 deletion tools/collect_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
creating bug reports. See `.github/ISSUE_TEMPLATE/bug_report.md`
"""

import importlib
import platform
import sys
import importlib


def get_version(pkg_name):
Expand Down