code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def test_peft_save_quantized(self):
"""
Simple test that tests the basic usage of PEFT model save_pretrained with quantized base models
"""
# 4bit
for model_id in self.peft_test_model_ids:
for transformers_class in self.transformers_test_model_classes:
... |
Simple test that tests the basic usage of PEFT model save_pretrained with quantized base models
| test_peft_save_quantized | python | huggingface/transformers | tests/peft_integration/test_peft_integration.py | https://github.com/huggingface/transformers/blob/master/tests/peft_integration/test_peft_integration.py | Apache-2.0 |
def test_peft_save_quantized_regression(self):
"""
Simple test that tests the basic usage of PEFT model save_pretrained with quantized base models
Regression test to make sure everything works as expected before the safetensors integration.
"""
# 4bit
for model_id in self... |
Simple test that tests the basic usage of PEFT model save_pretrained with quantized base models
Regression test to make sure everything works as expected before the safetensors integration.
| test_peft_save_quantized_regression | python | huggingface/transformers | tests/peft_integration/test_peft_integration.py | https://github.com/huggingface/transformers/blob/master/tests/peft_integration/test_peft_integration.py | Apache-2.0 |
def test_peft_pipeline(self):
"""
Simple test that tests the basic usage of PEFT model + pipeline
"""
from transformers import pipeline
for adapter_id, base_model_id in zip(self.peft_test_model_ids, self.transformers_test_model_ids):
peft_pipe = pipeline("text-genera... |
Simple test that tests the basic usage of PEFT model + pipeline
| test_peft_pipeline | python | huggingface/transformers | tests/peft_integration/test_peft_integration.py | https://github.com/huggingface/transformers/blob/master/tests/peft_integration/test_peft_integration.py | Apache-2.0 |
def test_peft_add_adapter_with_state_dict(self):
"""
Simple test that tests the basic usage of PEFT model through `from_pretrained`. This test tests if
add_adapter works as expected with a state_dict being passed.
"""
from peft import LoraConfig
dummy_input = torch.LongT... |
Simple test that tests the basic usage of PEFT model through `from_pretrained`. This test tests if
add_adapter works as expected with a state_dict being passed.
| test_peft_add_adapter_with_state_dict | python | huggingface/transformers | tests/peft_integration/test_peft_integration.py | https://github.com/huggingface/transformers/blob/master/tests/peft_integration/test_peft_integration.py | Apache-2.0 |
def test_peft_add_adapter_with_state_dict_low_cpu_mem_usage(self):
"""
Check the usage of low_cpu_mem_usage, which is supported in PEFT >= 0.13.0
"""
from peft import LoraConfig
min_version_lcmu = "0.13.0"
is_lcmu_supported = version.parse(importlib.metadata.version("pef... |
Check the usage of low_cpu_mem_usage, which is supported in PEFT >= 0.13.0
| test_peft_add_adapter_with_state_dict_low_cpu_mem_usage | python | huggingface/transformers | tests/peft_integration/test_peft_integration.py | https://github.com/huggingface/transformers/blob/master/tests/peft_integration/test_peft_integration.py | Apache-2.0 |
def test_peft_from_pretrained_hub_kwargs(self):
"""
Tests different combinations of PEFT model + from_pretrained + hub kwargs
"""
peft_model_id = "peft-internal-testing/tiny-opt-lora-revision"
# This should not work
with self.assertRaises(OSError):
_ = AutoMo... |
Tests different combinations of PEFT model + from_pretrained + hub kwargs
| test_peft_from_pretrained_hub_kwargs | python | huggingface/transformers | tests/peft_integration/test_peft_integration.py | https://github.com/huggingface/transformers/blob/master/tests/peft_integration/test_peft_integration.py | Apache-2.0 |
def test_peft_from_pretrained_unexpected_keys_warning(self):
"""
Test for warning when loading a PEFT checkpoint with unexpected keys.
"""
from peft import LoraConfig
logger = logging.get_logger("transformers.integrations.peft")
for model_id, peft_model_id in zip(self.t... |
Test for warning when loading a PEFT checkpoint with unexpected keys.
| test_peft_from_pretrained_unexpected_keys_warning | python | huggingface/transformers | tests/peft_integration/test_peft_integration.py | https://github.com/huggingface/transformers/blob/master/tests/peft_integration/test_peft_integration.py | Apache-2.0 |
def test_peft_from_pretrained_missing_keys_warning(self):
"""
Test for warning when loading a PEFT checkpoint with missing keys.
"""
from peft import LoraConfig
logger = logging.get_logger("transformers.integrations.peft")
for model_id, peft_model_id in zip(self.transfo... |
Test for warning when loading a PEFT checkpoint with missing keys.
| test_peft_from_pretrained_missing_keys_warning | python | huggingface/transformers | tests/peft_integration/test_peft_integration.py | https://github.com/huggingface/transformers/blob/master/tests/peft_integration/test_peft_integration.py | Apache-2.0 |
def test_peft_load_adapter_training_inference_mode_true(self):
"""
By default, when loading an adapter, the whole model should be in eval mode and no parameter should have
requires_grad=False.
"""
for model_id in self.peft_test_model_ids:
for transformers_class in sel... |
By default, when loading an adapter, the whole model should be in eval mode and no parameter should have
requires_grad=False.
| test_peft_load_adapter_training_inference_mode_true | python | huggingface/transformers | tests/peft_integration/test_peft_integration.py | https://github.com/huggingface/transformers/blob/master/tests/peft_integration/test_peft_integration.py | Apache-2.0 |
def test_peft_load_adapter_training_inference_mode_false(self):
"""
When passing is_trainable=True, the LoRA modules should be in training mode and their parameters should have
requires_grad=True.
"""
for model_id in self.peft_test_model_ids:
for transformers_class in... |
When passing is_trainable=True, the LoRA modules should be in training mode and their parameters should have
requires_grad=True.
| test_peft_load_adapter_training_inference_mode_false | python | huggingface/transformers | tests/peft_integration/test_peft_integration.py | https://github.com/huggingface/transformers/blob/master/tests/peft_integration/test_peft_integration.py | Apache-2.0 |
def test_peft_pipeline_no_warning(self):
"""
Test to verify that the warning message "The model 'PeftModel' is not supported for text-generation"
does not appear when using PeftModel with text-generation pipeline.
"""
from peft import PeftModel
from transformers import p... |
Test to verify that the warning message "The model 'PeftModel' is not supported for text-generation"
does not appear when using PeftModel with text-generation pipeline.
| test_peft_pipeline_no_warning | python | huggingface/transformers | tests/peft_integration/test_peft_integration.py | https://github.com/huggingface/transformers/blob/master/tests/peft_integration/test_peft_integration.py | Apache-2.0 |
def test_input_parameter_passthrough(self):
"""Test that chunked vs non chunked versions of ASR pipelines returns the same structure for the same inputs."""
speech_recognizer = pipeline(
task="automatic-speech-recognition",
model="hf-internal-testing/tiny-random-wav2vec2",
... | Test that chunked vs non chunked versions of ASR pipelines returns the same structure for the same inputs. | test_input_parameter_passthrough | python | huggingface/transformers | tests/pipelines/test_pipelines_automatic_speech_recognition.py | https://github.com/huggingface/transformers/blob/master/tests/pipelines/test_pipelines_automatic_speech_recognition.py | Apache-2.0 |
def test_pipeline_assisted_generation(self):
"""Tests that we can run assisted generation in the pipeline"""
model = "openai/whisper-tiny"
pipe = pipeline("automatic-speech-recognition", model=model, assistant_model=model)
# We can run the pipeline
prompt = load_dataset("hf-inte... | Tests that we can run assisted generation in the pipeline | test_pipeline_assisted_generation | python | huggingface/transformers | tests/pipelines/test_pipelines_automatic_speech_recognition.py | https://github.com/huggingface/transformers/blob/master/tests/pipelines/test_pipelines_automatic_speech_recognition.py | Apache-2.0 |
def require_ffmpeg(test_case):
"""
Decorator marking a test that requires FFmpeg.
These tests are skipped when FFmpeg isn't installed.
"""
import subprocess
try:
subprocess.check_output(["ffmpeg", "-h"], stderr=subprocess.DEVNULL)
return test_case
except Exception:
... |
Decorator marking a test that requires FFmpeg.
These tests are skipped when FFmpeg isn't installed.
| require_ffmpeg | python | huggingface/transformers | tests/pipelines/test_pipelines_automatic_speech_recognition.py | https://github.com/huggingface/transformers/blob/master/tests/pipelines/test_pipelines_automatic_speech_recognition.py | Apache-2.0 |
def test_pipeline_with_task_parameters_no_side_effects(self):
"""
Regression test: certain pipeline flags, like `task`, modified the model configuration, causing unexpected
side-effects
"""
# This checkpoint has task-specific parameters that will modify the behavior of the pipeli... |
Regression test: certain pipeline flags, like `task`, modified the model configuration, causing unexpected
side-effects
| test_pipeline_with_task_parameters_no_side_effects | python | huggingface/transformers | tests/pipelines/test_pipelines_common.py | https://github.com/huggingface/transformers/blob/master/tests/pipelines/test_pipelines_common.py | Apache-2.0 |
def test_pipeline_assisted_generation(self):
"""Tests that we can run assisted generation in the pipeline"""
model = "hf-internal-testing/tiny-random-MistralForCausalLM"
pipe = pipeline("text-generation", model=model, assistant_model=model, max_new_tokens=2)
# We can run the pipeline
... | Tests that we can run assisted generation in the pipeline | test_pipeline_assisted_generation | python | huggingface/transformers | tests/pipelines/test_pipelines_text_generation.py | https://github.com/huggingface/transformers/blob/master/tests/pipelines/test_pipelines_text_generation.py | Apache-2.0 |
def test_to_dict(self):
"""
Simple test that checks if one uses a config and converts it to a dict, the dict is the same as the config object
"""
quantization_config = AqlmConfig()
config_to_dict = quantization_config.to_dict()
for key in config_to_dict:
self... |
Simple test that checks if one uses a config and converts it to a dict, the dict is the same as the config object
| test_to_dict | python | huggingface/transformers | tests/quantization/aqlm_integration/test_aqlm.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/aqlm_integration/test_aqlm.py | Apache-2.0 |
def test_from_dict(self):
"""
Simple test that checks if one uses a dict and converts it to a config object, the config object is the same as the dict
"""
dict = {
"in_group_size": 32,
"num_codebooks": 8,
"nbits_per_codebook": 8,
"linear_we... |
Simple test that checks if one uses a dict and converts it to a config object, the config object is the same as the dict
| test_from_dict | python | huggingface/transformers | tests/quantization/aqlm_integration/test_aqlm.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/aqlm_integration/test_aqlm.py | Apache-2.0 |
def test_quantized_model_conversion(self):
"""
Simple test that checks if the quantized model has been converted properly
"""
from aqlm import QuantizedLinear
from transformers.integrations import replace_with_aqlm_linear
model_id = "facebook/opt-350m"
config = ... |
Simple test that checks if the quantized model has been converted properly
| test_quantized_model_conversion | python | huggingface/transformers | tests/quantization/aqlm_integration/test_aqlm.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/aqlm_integration/test_aqlm.py | Apache-2.0 |
def test_quantized_model(self):
"""
Simple test that checks if the quantized model is working properly
"""
input_ids = self.tokenizer(self.input_text, return_tensors="pt").to(torch_device)
output = self.quantized_model.generate(**input_ids, max_new_tokens=self.max_new_tokens)
... |
Simple test that checks if the quantized model is working properly
| test_quantized_model | python | huggingface/transformers | tests/quantization/aqlm_integration/test_aqlm.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/aqlm_integration/test_aqlm.py | Apache-2.0 |
def test_save_pretrained(self):
"""
Simple test that checks if the quantized model is working properly after being saved and loaded
"""
with tempfile.TemporaryDirectory() as tmpdirname:
self.quantized_model.save_pretrained(tmpdirname)
model = AutoModelForCausalLM.... |
Simple test that checks if the quantized model is working properly after being saved and loaded
| test_save_pretrained | python | huggingface/transformers | tests/quantization/aqlm_integration/test_aqlm.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/aqlm_integration/test_aqlm.py | Apache-2.0 |
def test_quantized_model_multi_gpu(self):
"""
Simple test that checks if the quantized model is working properly with multiple GPUs
"""
input_ids = self.tokenizer(self.input_text, return_tensors="pt").to(torch_device)
quantized_model = AutoModelForCausalLM.from_pretrained(self.m... |
Simple test that checks if the quantized model is working properly with multiple GPUs
| test_quantized_model_multi_gpu | python | huggingface/transformers | tests/quantization/aqlm_integration/test_aqlm.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/aqlm_integration/test_aqlm.py | Apache-2.0 |
def test_quantized_model_compile(self):
"""
Simple test that checks if the quantized model is working properly
"""
# Sample tokens greedily
def decode_one_tokens(model, cur_token, input_pos, cache_position, past_key_values):
logits = model(
cur_token,... |
Simple test that checks if the quantized model is working properly
| test_quantized_model_compile | python | huggingface/transformers | tests/quantization/aqlm_integration/test_aqlm.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/aqlm_integration/test_aqlm.py | Apache-2.0 |
def test_wrong_backend(self):
"""
Simple test that checks if a user passes a wrong backend an error is raised
"""
# This should work fine
_ = AwqConfig(bits=4)
with self.assertRaises(ValueError):
AwqConfig(bits=4, backend="")
# These should work fine... |
Simple test that checks if a user passes a wrong backend an error is raised
| test_wrong_backend | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_to_dict(self):
"""
Simple test that checks if one uses a config and converts it to a dict, the dict is the same as the config object
"""
quantization_config = AwqConfig(bits=4)
config_to_dict = quantization_config.to_dict()
for key in config_to_dict:
... |
Simple test that checks if one uses a config and converts it to a dict, the dict is the same as the config object
| test_to_dict | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_from_dict(self):
"""
Simple test that checks if one uses a dict and converts it to a config object, the config object is the same as the dict
"""
dict = {"bits": 2, "zero_point": False, "backend": "autoawq"}
quantization_config = AwqConfig.from_dict(dict)
self.a... |
Simple test that checks if one uses a dict and converts it to a config object, the config object is the same as the dict
| test_from_dict | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_quantized_model_conversion(self):
"""
Simple test that checks if the quantized model has been converted properly
"""
from awq.modules.linear import WQLinear_GEMM, WQLinear_GEMV
from transformers.integrations.awq import replace_with_awq_linear
model_id = "facebo... |
Simple test that checks if the quantized model has been converted properly
| test_quantized_model_conversion | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_quantized_model(self):
"""
Simple test that checks if the quantized model is working properly
"""
input_ids = self.tokenizer(self.input_text, return_tensors="pt").to(torch_device)
output = self.quantized_model.generate(**input_ids, max_new_tokens=40)
self.assert... |
Simple test that checks if the quantized model is working properly
| test_quantized_model | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_quantized_model_bf16(self):
"""
Simple test that checks if the quantized model is working properly with bf16
"""
input_ids = self.tokenizer(self.input_text, return_tensors="pt").to(torch_device)
quantized_model = AutoModelForCausalLM.from_pretrained(self.model_name, tor... |
Simple test that checks if the quantized model is working properly with bf16
| test_quantized_model_bf16 | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_quantized_model_exllama(self):
"""
Simple test that checks if the quantized model is working properly with exllama backend
"""
input_ids = self.tokenizer(self.input_text, return_tensors="pt").to(torch_device)
quantization_config = AwqConfig(version="exllama")
qu... |
Simple test that checks if the quantized model is working properly with exllama backend
| test_quantized_model_exllama | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_quantized_model_no_device_map(self):
"""
Simple test that checks if the quantized model is working properly
"""
input_ids = self.tokenizer(self.input_text, return_tensors="pt").to(torch_device)
quantized_model = AutoModelForCausalLM.from_pretrained(self.model_name).to(t... |
Simple test that checks if the quantized model is working properly
| test_quantized_model_no_device_map | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_save_pretrained(self):
"""
Simple test that checks if the quantized model is working properly after being saved and loaded
"""
with tempfile.TemporaryDirectory() as tmpdirname:
self.quantized_model.save_pretrained(tmpdirname)
model = AutoModelForCausalLM.... |
Simple test that checks if the quantized model is working properly after being saved and loaded
| test_save_pretrained | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_quantized_model_multi_accelerator(self):
"""
Simple test that checks if the quantized model is working properly with multiple GPUs
"""
input_ids = self.tokenizer(self.input_text, return_tensors="pt").to(torch_device)
quantized_model = AutoModelForCausalLM.from_pretraine... |
Simple test that checks if the quantized model is working properly with multiple GPUs
| test_quantized_model_multi_accelerator | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_quantized_model_no_k_proj_quantized(self):
"""
Simple test that checks if the quantized model is working properly with multiple GPUs
"""
dummy_input = torch.LongTensor([[0, 1, 0]]).to(torch_device)
quantized_model = AutoModelForCausalLM.from_pretrained(self.model_with_n... |
Simple test that checks if the quantized model is working properly with multiple GPUs
| test_quantized_model_no_k_proj_quantized | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_raise_save_pretrained(self):
"""
Test that `save_pretrained` is effectively blocked for fused models
"""
quantization_config = AwqConfig(bits=4, fuse_max_seq_len=128, do_fuse=True)
model = AutoModelForCausalLM.from_pretrained(
self.model_name,
qu... |
Test that `save_pretrained` is effectively blocked for fused models
| test_raise_save_pretrained | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_fused_modules_to_not_convert(self):
"""
Test if fused + modules to_not_covnert work as expected
"""
model_id = "hf-internal-testing/Mixtral-tiny-AWQ"
quantization_config = AwqConfig(bits=4, fuse_max_seq_len=128, do_fuse=True)
model = AutoModelForCausalLM.from_pr... |
Test if fused + modules to_not_covnert work as expected
| test_fused_modules_to_not_convert | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_generation_fused(self):
"""
Test generation quality for fused models - single batch case
"""
quantization_config = AwqConfig(bits=4, fuse_max_seq_len=128, do_fuse=True)
model = AutoModelForCausalLM.from_pretrained(
self.model_name,
quantization_c... |
Test generation quality for fused models - single batch case
| test_generation_fused | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_generation_fused_batched(self):
"""
Test generation quality for fused models - multi batch case
"""
quantization_config = AwqConfig(bits=4, fuse_max_seq_len=128, do_fuse=True)
model = AutoModelForCausalLM.from_pretrained(
self.model_name,
quantiz... |
Test generation quality for fused models - multi batch case
| test_generation_fused_batched | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_generation_custom_model(self):
"""
Test generation quality for fused models using custom fused map.
"""
quantization_config = AwqConfig(
bits=4,
fuse_max_seq_len=512,
modules_to_fuse={
"attention": ["q_proj", "k_proj", "v_proj"... |
Test generation quality for fused models using custom fused map.
| test_generation_custom_model | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_generation_mixtral_fused(self):
"""
Text generation test for Mixtral + AWQ + fused
"""
quantization_config = AwqConfig(bits=4, fuse_max_seq_len=1024, do_fuse=True)
model = AutoModelForCausalLM.from_pretrained(
self.mixtral_model_name,
quantization... |
Text generation test for Mixtral + AWQ + fused
| test_generation_mixtral_fused | python | huggingface/transformers | tests/quantization/autoawq/test_awq.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoawq/test_awq.py | Apache-2.0 |
def test_quantized_model(self):
"""
Simple test that checks if the quantized model is working properly
"""
input_ids = self.tokenizer(self.input_text, return_tensors="pt").to(torch_device)
output = self.quantized_model.generate(**input_ids, max_new_tokens=40, do_sample=False)
... |
Simple test that checks if the quantized model is working properly
| test_quantized_model | python | huggingface/transformers | tests/quantization/autoround/test_auto_round.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoround/test_auto_round.py | Apache-2.0 |
def test_quantized_model_bf16(self):
"""
Simple test that checks if the quantized model is working properly with bf16
"""
input_ids = self.tokenizer(self.input_text, return_tensors="pt").to(torch_device)
quantization_config = AutoRoundConfig(backend="triton")
quantized_mo... |
Simple test that checks if the quantized model is working properly with bf16
| test_quantized_model_bf16 | python | huggingface/transformers | tests/quantization/autoround/test_auto_round.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoround/test_auto_round.py | Apache-2.0 |
def test_quantized_model_on_cpu(self):
"""
Simple test that checks if the quantized model is working properly
"""
input_ids = self.tokenizer(self.input_text, return_tensors="pt")
quantized_model = AutoModelForCausalLM.from_pretrained(self.model_name, torch_dtype="auto")
... |
Simple test that checks if the quantized model is working properly
| test_quantized_model_on_cpu | python | huggingface/transformers | tests/quantization/autoround/test_auto_round.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoround/test_auto_round.py | Apache-2.0 |
def test_save_pretrained(self):
"""
Simple test that checks if the quantized model is working properly after being saved and loaded
"""
## some backends like marlin/ipex will repack the weight that caused the weight shape changed
with tempfile.TemporaryDirectory() as tmpdirname:... |
Simple test that checks if the quantized model is working properly after being saved and loaded
| test_save_pretrained | python | huggingface/transformers | tests/quantization/autoround/test_auto_round.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoround/test_auto_round.py | Apache-2.0 |
def test_quantized_model_multi_accelerator(self):
"""
Simple test that checks if the quantized model is working properly with multiple accelerators
"""
input_ids = self.tokenizer(self.input_text, return_tensors="pt").to(torch_device)
quantization_config = AutoRoundConfig(backend=... |
Simple test that checks if the quantized model is working properly with multiple accelerators
| test_quantized_model_multi_accelerator | python | huggingface/transformers | tests/quantization/autoround/test_auto_round.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoround/test_auto_round.py | Apache-2.0 |
def test_convert_from_gptq(self):
"""
Simple test that checks if auto-round work properly with gptq format
"""
model_name = "ybelkada/opt-125m-gptq-4bit"
quantization_config = AutoRoundConfig()
model = AutoModelForCausalLM.from_pretrained(
model_name, device... |
Simple test that checks if auto-round work properly with gptq format
| test_convert_from_gptq | python | huggingface/transformers | tests/quantization/autoround/test_auto_round.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoround/test_auto_round.py | Apache-2.0 |
def test_convert_from_awq_cpu(self):
"""
Simple test that checks if auto-round work properly with awq format
"""
model_name = "casperhansen/opt-125m-awq"
quantization_config = AutoRoundConfig()
model = AutoModelForCausalLM.from_pretrained(
model_name, device... |
Simple test that checks if auto-round work properly with awq format
| test_convert_from_awq_cpu | python | huggingface/transformers | tests/quantization/autoround/test_auto_round.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoround/test_auto_round.py | Apache-2.0 |
def test_mixed_bits(self):
"""
Simple test that checks if auto-round work properly with mixed bits
"""
model_name = "facebook/opt-125m"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype="auto")
tokenizer = AutoTokenizer.from_pretrained(model_name)
... |
Simple test that checks if auto-round work properly with mixed bits
| test_mixed_bits | python | huggingface/transformers | tests/quantization/autoround/test_auto_round.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/autoround/test_auto_round.py | Apache-2.0 |
def test_to_dict(self):
"""
Simple test that checks if one uses a config and converts it to a dict, the dict is the same as the config object
"""
quantization_config = BitNetQuantConfig()
config_to_dict = quantization_config.to_dict()
for key in config_to_dict:
... |
Simple test that checks if one uses a config and converts it to a dict, the dict is the same as the config object
| test_to_dict | python | huggingface/transformers | tests/quantization/bitnet_integration/test_bitnet.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bitnet_integration/test_bitnet.py | Apache-2.0 |
def test_quantized_model(self):
"""
Simple test that checks if the quantized model is working properly
"""
input_text = "What are we having for dinner?"
expected_output = "What are we having for dinner? What are we going to do for fun this weekend?"
input_ids = self.token... |
Simple test that checks if the quantized model is working properly
| test_quantized_model | python | huggingface/transformers | tests/quantization/bitnet_integration/test_bitnet.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bitnet_integration/test_bitnet.py | Apache-2.0 |
def test_packing_unpacking(self):
"""
Simple test the packing and unpacking logic
"""
from transformers.integrations import pack_weights, unpack_weights
u = torch.randint(0, 255, (256, 256), dtype=torch.uint8)
unpacked_u = unpack_weights(u, dtype=torch.bfloat16)
... |
Simple test the packing and unpacking logic
| test_packing_unpacking | python | huggingface/transformers | tests/quantization/bitnet_integration/test_bitnet.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bitnet_integration/test_bitnet.py | Apache-2.0 |
def test_weights_dtype(self):
"""
test the weights dtype after loading
"""
self_attn_q = self.quantized_model.model.layers[0].self_attn.q_proj.weight
self_attn_k = self.quantized_model.model.layers[0].self_attn.k_proj.weight
self_attn_v = self.quantized_model.model.layer... |
test the weights dtype after loading
| test_weights_dtype | python | huggingface/transformers | tests/quantization/bitnet_integration/test_bitnet.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bitnet_integration/test_bitnet.py | Apache-2.0 |
def test_replace_with_bitlinear_shape(self):
"""
test that the BitNet layer weight shapes are correct, and the weight_scale is correctly initialized to 1
"""
from transformers.integrations import replace_with_bitnet_linear
out_features = 1024
in_features = 512
... |
test that the BitNet layer weight shapes are correct, and the weight_scale is correctly initialized to 1
| test_replace_with_bitlinear_shape | python | huggingface/transformers | tests/quantization/bitnet_integration/test_bitnet.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bitnet_integration/test_bitnet.py | Apache-2.0 |
def tearDown(self):
r"""
TearDown function needs to be called at the end of each test to free the GPU memory and cache, also to
avoid unexpected behaviors. Please see: https://discuss.pytorch.org/t/how-can-we-release-gpu-memory-cache/14530/27
"""
del self.model_fp16
del s... |
TearDown function needs to be called at the end of each test to free the GPU memory and cache, also to
avoid unexpected behaviors. Please see: https://discuss.pytorch.org/t/how-can-we-release-gpu-memory-cache/14530/27
| tearDown | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_quantization_num_parameters(self):
r"""
Test if the number of returned parameters is correct
See: https://github.com/huggingface/transformers/issues/25978
"""
num_params_4bit = self.model_4bit.num_parameters()
num_params_fp16 = self.model_fp16.num_parameters()
... |
Test if the number of returned parameters is correct
See: https://github.com/huggingface/transformers/issues/25978
| test_quantization_num_parameters | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_quantization_config_json_serialization(self):
r"""
A simple test to check if the quantization config is correctly serialized and deserialized
"""
config = self.model_4bit.config
self.assertTrue(hasattr(config, "quantization_config"))
_ = config.to_dict()
... |
A simple test to check if the quantization config is correctly serialized and deserialized
| test_quantization_config_json_serialization | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_memory_footprint(self):
r"""
A simple test to check if the model conversion has been done correctly by checking on the
memory footprint of the converted model and the class type of the linear layers of the converted models
"""
from bitsandbytes.nn import Params4bit
... |
A simple test to check if the model conversion has been done correctly by checking on the
memory footprint of the converted model and the class type of the linear layers of the converted models
| test_memory_footprint | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_original_dtype(self):
r"""
A simple test to check if the model successfully stores the original dtype
"""
self.assertTrue(hasattr(self.model_4bit.config, "_pre_quantization_dtype"))
self.assertFalse(hasattr(self.model_fp16.config, "_pre_quantization_dtype"))
self... |
A simple test to check if the model successfully stores the original dtype
| test_original_dtype | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_linear_are_4bit(self):
r"""
A simple test to check if the model conversion has been done correctly by checking on the
memory footprint of the converted model and the class type of the linear layers of the converted models
"""
from transformers import T5PreTrainedModel
... |
A simple test to check if the model conversion has been done correctly by checking on the
memory footprint of the converted model and the class type of the linear layers of the converted models
| test_linear_are_4bit | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_rwkv_4bit(self):
r"""
A simple test to check if 4-bit RWKV inference works as expected.
"""
model_id = "RWKV/rwkv-4-169m-pile"
quantization_config = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_use_double_quant=True)
model = AutoModelForCausalLM.from_pretrain... |
A simple test to check if 4-bit RWKV inference works as expected.
| test_rwkv_4bit | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_generate_quality(self):
r"""
Test the generation quality of the quantized model and see that we are matching the expected output.
Given that we are operating on small numbers + the testing model is relatively small, we might not get
the same output across GPUs. So we'll generate... |
Test the generation quality of the quantized model and see that we are matching the expected output.
Given that we are operating on small numbers + the testing model is relatively small, we might not get
the same output across GPUs. So we'll generate few tokens (5-10) and check their output.
... | test_generate_quality | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_generate_quality_config(self):
r"""
Test that loading the model with the config is equivalent
"""
bnb_config = BitsAndBytesConfig()
bnb_config.load_in_4bit = True
model_4bit_from_config = AutoModelForCausalLM.from_pretrained(
self.model_name, quantiz... |
Test that loading the model with the config is equivalent
| test_generate_quality_config | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_generate_quality_dequantize(self):
r"""
Test that loading the model and unquantize it produce correct results
"""
bnb_config = BitsAndBytesConfig(load_in_4bit=True)
model_4bit = AutoModelForCausalLM.from_pretrained(
self.model_name, quantization_config=bnb_c... |
Test that loading the model and unquantize it produce correct results
| test_generate_quality_dequantize | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_device_and_dtype_assignment(self):
r"""
Test whether attempting to change the device or cast the dtype of a model
after converting it to 4-bit precision will raise an appropriate error.
The test ensures that such operations are prohibited on 4-bit models
to prevent inval... |
Test whether attempting to change the device or cast the dtype of a model
after converting it to 4-bit precision will raise an appropriate error.
The test ensures that such operations are prohibited on 4-bit models
to prevent invalid conversions.
| test_device_and_dtype_assignment | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_fp32_4bit_conversion(self):
r"""
Test whether it is possible to mix both `4bit` and `fp32` weights when using `keep_in_fp32_modules` correctly.
"""
model = AutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-small", load_in_4bit=True, device_map="auto")
self.assertTrue(m... |
Test whether it is possible to mix both `4bit` and `fp32` weights when using `keep_in_fp32_modules` correctly.
| test_fp32_4bit_conversion | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_bnb_4bit_wrong_config(self):
r"""
Test whether creating a bnb config with unsupported values leads to errors.
"""
with self.assertRaises(ValueError):
_ = BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_storage="add") |
Test whether creating a bnb config with unsupported values leads to errors.
| test_bnb_4bit_wrong_config | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_inference_without_keep_in_fp32(self):
r"""
Test whether it is possible to mix both `4bit` and `fp32` weights when using `keep_in_fp32_modules` correctly.
`flan-t5-small` uses `T5DenseGatedActDense` whereas `google-t5/t5-small` uses `T5DenseReluDense`. We need to test
both cases.... |
Test whether it is possible to mix both `4bit` and `fp32` weights when using `keep_in_fp32_modules` correctly.
`flan-t5-small` uses `T5DenseGatedActDense` whereas `google-t5/t5-small` uses `T5DenseReluDense`. We need to test
both cases.
| test_inference_without_keep_in_fp32 | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_inference_with_keep_in_fp32(self):
r"""
Test whether it is possible to mix both `4bit` and `fp32` weights when using `keep_in_fp32_modules` correctly.
`flan-t5-small` uses `T5DenseGatedActDense` whereas `google-t5/t5-small` uses `T5DenseReluDense`. We need to test
both cases.
... |
Test whether it is possible to mix both `4bit` and `fp32` weights when using `keep_in_fp32_modules` correctly.
`flan-t5-small` uses `T5DenseGatedActDense` whereas `google-t5/t5-small` uses `T5DenseReluDense`. We need to test
both cases.
| test_inference_with_keep_in_fp32 | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def tearDown(self):
r"""
TearDown function needs to be called at the end of each test to free the GPU memory and cache, also to
avoid unexpected behaviors. Please see: https://discuss.pytorch.org/t/how-can-we-release-gpu-memory-cache/14530/27
"""
del self.base_model
del s... |
TearDown function needs to be called at the end of each test to free the GPU memory and cache, also to
avoid unexpected behaviors. Please see: https://discuss.pytorch.org/t/how-can-we-release-gpu-memory-cache/14530/27
| tearDown | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_correct_head_class(self):
r"""
A simple test to check if the last modules for some classes (AutoModelForCausalLM or SequenceClassification)
are kept in their native class.
"""
from bitsandbytes.nn import Params4bit
self.assertTrue(self.base_model.h[-1].mlp.dense... |
A simple test to check if the last modules for some classes (AutoModelForCausalLM or SequenceClassification)
are kept in their native class.
| test_correct_head_class | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def tearDown(self):
r"""
TearDown function needs to be called at the end of each test to free the GPU memory and cache, also to
avoid unexpected behaviors. Please see: https://discuss.pytorch.org/t/how-can-we-release-gpu-memory-cache/14530/27
"""
if hasattr(self, "pipe"):
... |
TearDown function needs to be called at the end of each test to free the GPU memory and cache, also to
avoid unexpected behaviors. Please see: https://discuss.pytorch.org/t/how-can-we-release-gpu-memory-cache/14530/27
| tearDown | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_pipeline(self):
r"""
The aim of this test is to verify that the mixed 4bit is compatible with `pipeline` from transformers. Since
we used pipeline for inference speed benchmarking we want to make sure that this feature does not break anything
on pipeline.
"""
# s... |
The aim of this test is to verify that the mixed 4bit is compatible with `pipeline` from transformers. Since
we used pipeline for inference speed benchmarking we want to make sure that this feature does not break anything
on pipeline.
| test_pipeline | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_multi_gpu_loading(self):
r"""
This tests that the model has been loaded and can be used correctly on a multi-GPU setup.
Let's just try to load a model on 2 GPUs and see if it works. The model we test has ~2GB of total, 3GB should suffice
"""
device_map = {
"t... |
This tests that the model has been loaded and can be used correctly on a multi-GPU setup.
Let's just try to load a model on 2 GPUs and see if it works. The model we test has ~2GB of total, 3GB should suffice
| test_multi_gpu_loading | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def test_serialization(self, quant_type="nf4", double_quant=True, safe_serialization=True):
r"""
Test whether it is possible to serialize a model in 4-bit. Uses most typical params as default.
See ExtendedSerializationTest class for more params combinations.
"""
tokenizer = Auto... |
Test whether it is possible to serialize a model in 4-bit. Uses most typical params as default.
See ExtendedSerializationTest class for more params combinations.
| test_serialization | python | huggingface/transformers | tests/quantization/bnb/test_4bit.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_4bit.py | Apache-2.0 |
def tearDown(self):
r"""
TearDown function needs to be called at the end of each test to free the GPU memory and cache, also to
avoid unexpected behaviors. Please see: https://discuss.pytorch.org/t/how-can-we-release-gpu-memory-cache/14530/27
"""
del self.model_fp16
del s... |
TearDown function needs to be called at the end of each test to free the GPU memory and cache, also to
avoid unexpected behaviors. Please see: https://discuss.pytorch.org/t/how-can-we-release-gpu-memory-cache/14530/27
| tearDown | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_quantization_config_json_serialization(self):
r"""
A simple test to check if the quantization config is correctly serialized and deserialized
"""
config = self.model_8bit.config
self.assertTrue(hasattr(config, "quantization_config"))
_ = config.to_dict()
... |
A simple test to check if the quantization config is correctly serialized and deserialized
| test_quantization_config_json_serialization | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_original_dtype(self):
r"""
A simple test to check if the model successfully stores the original dtype
"""
self.assertTrue(hasattr(self.model_8bit.config, "_pre_quantization_dtype"))
self.assertFalse(hasattr(self.model_fp16.config, "_pre_quantization_dtype"))
self... |
A simple test to check if the model successfully stores the original dtype
| test_original_dtype | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_memory_footprint(self):
r"""
A simple test to check if the model conversion has been done correctly by checking on the
memory footprint of the converted model and the class type of the linear layers of the converted models
"""
from bitsandbytes.nn import Int8Params
... |
A simple test to check if the model conversion has been done correctly by checking on the
memory footprint of the converted model and the class type of the linear layers of the converted models
| test_memory_footprint | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_linear_are_8bit(self):
r"""
A simple test to check if the model conversion has been done correctly by checking on the
memory footprint of the converted model and the class type of the linear layers of the converted models
"""
from transformers import T5PreTrainedModel
... |
A simple test to check if the model conversion has been done correctly by checking on the
memory footprint of the converted model and the class type of the linear layers of the converted models
| test_linear_are_8bit | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_llm_skip(self):
r"""
A simple test to check if `llm_int8_skip_modules` works as expected
"""
quantization_config = BitsAndBytesConfig(load_in_8bit=True, llm_int8_skip_modules=["classifier"])
seq_classification_model = AutoModelForSequenceClassification.from_pretrained(
... |
A simple test to check if `llm_int8_skip_modules` works as expected
| test_llm_skip | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_generate_quality(self):
r"""
Test the generation quality of the quantized model and see that we are matching the expected output.
Given that we are operating on small numbers + the testing model is relatively small, we might not get
the same output across GPUs. So we'll generate... |
Test the generation quality of the quantized model and see that we are matching the expected output.
Given that we are operating on small numbers + the testing model is relatively small, we might not get
the same output across GPUs. So we'll generate few tokens (5-10) and check their output.
... | test_generate_quality | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_generate_quality_config(self):
r"""
Test that loading the model with the config is equivalent
"""
bnb_config = BitsAndBytesConfig()
bnb_config.load_in_8bit = True
model_8bit_from_config = AutoModelForCausalLM.from_pretrained(
self.model_name, quantiz... |
Test that loading the model with the config is equivalent
| test_generate_quality_config | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_generate_quality_dequantize(self):
r"""
Test that loading the model and dequantizing it produce correct results
"""
bnb_config = BitsAndBytesConfig(load_in_8bit=True)
model_8bit = AutoModelForCausalLM.from_pretrained(
self.model_name, quantization_config=bnb... |
Test that loading the model and dequantizing it produce correct results
| test_generate_quality_dequantize | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_raise_if_config_and_load_in_8bit(self):
r"""
Test that loading the model with the config and `load_in_8bit` raises an error
"""
bnb_config = BitsAndBytesConfig()
with self.assertRaises(ValueError):
_ = AutoModelForCausalLM.from_pretrained(
se... |
Test that loading the model with the config and `load_in_8bit` raises an error
| test_raise_if_config_and_load_in_8bit | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_device_and_dtype_assignment(self):
r"""
Test whether attempting to change the device or cast the dtype of a model
after converting it to 8-bit precision will raise an appropriate error.
The test ensures that such operations are prohibited on 8-bit models
to prevent inval... |
Test whether attempting to change the device or cast the dtype of a model
after converting it to 8-bit precision will raise an appropriate error.
The test ensures that such operations are prohibited on 8-bit models
to prevent invalid conversions.
| test_device_and_dtype_assignment | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_fp32_int8_conversion(self):
r"""
Test whether it is possible to mix both `int8` and `fp32` weights when using `keep_in_fp32_modules` correctly.
"""
model = AutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-small", load_in_8bit=True, device_map="auto")
self.assertTrue(m... |
Test whether it is possible to mix both `int8` and `fp32` weights when using `keep_in_fp32_modules` correctly.
| test_fp32_int8_conversion | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_int8_serialization(self):
r"""
Test whether it is possible to serialize a model in 8-bit.
"""
from bitsandbytes.nn import Int8Params
with tempfile.TemporaryDirectory() as tmpdirname:
self.model_8bit.save_pretrained(tmpdirname)
# check that the f... |
Test whether it is possible to serialize a model in 8-bit.
| test_int8_serialization | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_int8_serialization_regression(self):
r"""
Test whether it is possible to serialize a model in 8-bit - using not safetensors
"""
from bitsandbytes.nn import Int8Params
with tempfile.TemporaryDirectory() as tmpdirname:
self.model_8bit.save_pretrained(tmpdirnam... |
Test whether it is possible to serialize a model in 8-bit - using not safetensors
| test_int8_serialization_regression | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_int8_serialization_sharded(self):
r"""
Test whether it is possible to serialize a model in 8-bit - sharded version.
"""
from bitsandbytes.nn import Int8Params
with tempfile.TemporaryDirectory() as tmpdirname:
self.model_8bit.save_pretrained(tmpdirname, max_s... |
Test whether it is possible to serialize a model in 8-bit - sharded version.
| test_int8_serialization_sharded | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_int8_from_pretrained(self):
r"""
Test whether loading a 8bit model from the Hub works as expected
"""
from bitsandbytes.nn import Int8Params
model_id = "ybelkada/bloom-1b7-8bit"
model = AutoModelForCausalLM.from_pretrained(model_id)
linear = get_some_l... |
Test whether loading a 8bit model from the Hub works as expected
| test_int8_from_pretrained | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_inference_without_keep_in_fp32(self):
r"""
Test whether it is possible to mix both `int8` and `fp32` weights when using `keep_in_fp32_modules` correctly.
`flan-t5-small` uses `T5DenseGatedActDense` whereas `google-t5/t5-small` uses `T5DenseReluDense`. We need to test
both cases.... |
Test whether it is possible to mix both `int8` and `fp32` weights when using `keep_in_fp32_modules` correctly.
`flan-t5-small` uses `T5DenseGatedActDense` whereas `google-t5/t5-small` uses `T5DenseReluDense`. We need to test
both cases.
| test_inference_without_keep_in_fp32 | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_inference_with_keep_in_fp32(self):
r"""
Test whether it is possible to mix both `int8` and `fp32` weights when using `keep_in_fp32_modules` correctly.
`flan-t5-small` uses `T5DenseGatedActDense` whereas `google-t5/t5-small` uses `T5DenseReluDense`. We need to test
both cases.
... |
Test whether it is possible to mix both `int8` and `fp32` weights when using `keep_in_fp32_modules` correctly.
`flan-t5-small` uses `T5DenseGatedActDense` whereas `google-t5/t5-small` uses `T5DenseReluDense`. We need to test
both cases.
| test_inference_with_keep_in_fp32 | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_inference_with_keep_in_fp32_serialized(self):
r"""
Test whether it is possible to mix both `int8` and `fp32` weights when using `keep_in_fp32_modules` correctly on
a serialized model.
`flan-t5-small` uses `T5DenseGatedActDense` whereas `google-t5/t5-small` uses `T5DenseReluDense... |
Test whether it is possible to mix both `int8` and `fp32` weights when using `keep_in_fp32_modules` correctly on
a serialized model.
`flan-t5-small` uses `T5DenseGatedActDense` whereas `google-t5/t5-small` uses `T5DenseReluDense`. We need to test
both cases.
| test_inference_with_keep_in_fp32_serialized | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def tearDown(self):
r"""
TearDown function needs to be called at the end of each test to free the GPU memory and cache, also to
avoid unexpected behaviors. Please see: https://discuss.pytorch.org/t/how-can-we-release-gpu-memory-cache/14530/27
"""
del self.base_model
del s... |
TearDown function needs to be called at the end of each test to free the GPU memory and cache, also to
avoid unexpected behaviors. Please see: https://discuss.pytorch.org/t/how-can-we-release-gpu-memory-cache/14530/27
| tearDown | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_correct_head_class(self):
r"""
A simple test to check if the last modules for some classes (AutoModelForCausalLM or SequenceClassification)
are kept in their native class.
"""
from bitsandbytes.nn import Int8Params
# last param of a base model should be a linear... |
A simple test to check if the last modules for some classes (AutoModelForCausalLM or SequenceClassification)
are kept in their native class.
| test_correct_head_class | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def tearDown(self):
r"""
TearDown function needs to be called at the end of each test to free the GPU memory and cache, also to
avoid unexpected behaviors. Please see: https://discuss.pytorch.org/t/how-can-we-release-gpu-memory-cache/14530/27
"""
if hasattr(self, "pipe"):
... |
TearDown function needs to be called at the end of each test to free the GPU memory and cache, also to
avoid unexpected behaviors. Please see: https://discuss.pytorch.org/t/how-can-we-release-gpu-memory-cache/14530/27
| tearDown | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_pipeline(self):
r"""
The aim of this test is to verify that the mixed int8 is compatible with `pipeline` from transformers. Since
we used pipeline for inference speed benchmarking we want to make sure that this feature does not break anything
on pipeline.
"""
# s... |
The aim of this test is to verify that the mixed int8 is compatible with `pipeline` from transformers. Since
we used pipeline for inference speed benchmarking we want to make sure that this feature does not break anything
on pipeline.
| test_pipeline | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_multi_gpu_loading(self):
r"""
This tests that the model has been loaded and can be used correctly on a multi-GPU setup.
Let's just try to load a model on 2 GPUs and see if it works. The model we test has ~2GB of total, 3GB should suffice
"""
device_map = {
"t... |
This tests that the model has been loaded and can be used correctly on a multi-GPU setup.
Let's just try to load a model on 2 GPUs and see if it works. The model we test has ~2GB of total, 3GB should suffice
| test_multi_gpu_loading | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_cpu_accelerator_loading_random_device_map(self):
r"""
A test to check is dispatching a model on cpu & gpu works correctly using a random `device_map`.
"""
device_map = {
"transformer.word_embeddings": 0,
"transformer.word_embeddings_layernorm": 0,
... |
A test to check is dispatching a model on cpu & gpu works correctly using a random `device_map`.
| test_cpu_accelerator_loading_random_device_map | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
def test_cpu_accelerator_loading_custom_device_map(self):
r"""
A test to check is dispatching a model on cpu & gpu works correctly using a custom `device_map`.
This time the device map is more organized than the test above and uses the abstraction
`transformer.h` to encapsulate all the d... |
A test to check is dispatching a model on cpu & gpu works correctly using a custom `device_map`.
This time the device map is more organized than the test above and uses the abstraction
`transformer.h` to encapsulate all the decoder layers.
| test_cpu_accelerator_loading_custom_device_map | python | huggingface/transformers | tests/quantization/bnb/test_mixed_int8.py | https://github.com/huggingface/transformers/blob/master/tests/quantization/bnb/test_mixed_int8.py | Apache-2.0 |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.