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_transition_scores_greedy_search_normalized(self):
"""
Test that `compute_transition_scores` is working as expected with gready search, with `normalize_logits=True`
"""
articles = ["Justin Timberlake", "Michael Phelps"]
tokenizer = AutoTokenizer.from_pretrained("distilber... |
Test that `compute_transition_scores` is working as expected with gready search, with `normalize_logits=True`
| test_transition_scores_greedy_search_normalized | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_transition_scores_beam_search_encoder_decoder(self):
"""
Test that `compute_transition_scores` is working as expected with beam search and encoder-decoder models
"""
articles = [
"Justin Timberlake and Jessica Biel, welcome to parenthood.",
"Michael Phelp... |
Test that `compute_transition_scores` is working as expected with beam search and encoder-decoder models
| test_transition_scores_beam_search_encoder_decoder | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_transition_scores_beam_search_encoder_decoder_with_eos(self):
"""
Test that `compute_transition_scores` is working as expected with beam search and encoder-decoder models, when
an EOS token is defined
"""
articles = [
"Justin Timberlake and Jessica Biel, welc... |
Test that `compute_transition_scores` is working as expected with beam search and encoder-decoder models, when
an EOS token is defined
| test_transition_scores_beam_search_encoder_decoder_with_eos | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_transition_scores_beam_search_decoder_only(self):
"""
Test that `compute_transition_scores` is working as expected with beam search and decoder-only models
"""
articles = [
"Justin Timberlake",
"Michael Phelps",
]
tokenizer = AutoTokenizer... |
Test that `compute_transition_scores` is working as expected with beam search and decoder-only models
| test_transition_scores_beam_search_decoder_only | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_transition_scores_early_stopping(self):
"""
Test that `compute_transition_scores` is working as expected with beam search and early stopping
This is an aggressive test that makes sure that `beam_search's`
transition scores are computed correctly for varying `num_return_sequence... |
Test that `compute_transition_scores` is working as expected with beam search and early stopping
This is an aggressive test that makes sure that `beam_search's`
transition scores are computed correctly for varying `num_return_sequences`, `num_beams` and `batch_size > 1`
2 x input_ids f... | test_transition_scores_early_stopping | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_encoder_decoder_generate_attention_mask(self):
"""
Test that `generate` automagically creates the correct `attention_mask` for encoder-decoder models (which
has a different keyword)
"""
articles = ["Timberlake", "Jessica Biel, welcome to parenthood among other things"]
... |
Test that `generate` automagically creates the correct `attention_mask` for encoder-decoder models (which
has a different keyword)
| test_encoder_decoder_generate_attention_mask | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_generate_input_ids_as_kwarg(self):
"""Test that `input_ids` work equally as a positional and keyword argument in decoder-only models"""
article = "I need input_ids to generate"
tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-gpt2")
model = AutoModelFor... | Test that `input_ids` work equally as a positional and keyword argument in decoder-only models | test_generate_input_ids_as_kwarg | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_generate_input_ids_as_encoder_kwarg(self):
"""Test that `input_ids` work equally as a positional and keyword argument in encoder-decoder models"""
article = "Justin Timberlake and Jessica Biel, welcome to parenthood."
tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-r... | Test that `input_ids` work equally as a positional and keyword argument in encoder-decoder models | test_generate_input_ids_as_encoder_kwarg | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_generate_inputs_and_encoder_kwargs(self):
"""
Test that an exception is thrown if the main tensor (`input_ids` in LLMs) is passed as both a positional and
keyword argument
"""
article = "I need input_ids to generate"
tokenizer = AutoTokenizer.from_pretrained("hf-... |
Test that an exception is thrown if the main tensor (`input_ids` in LLMs) is passed as both a positional and
keyword argument
| test_generate_inputs_and_encoder_kwargs | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_generate_too_many_encoder_kwargs(self):
"""Test that passing redundant inputs results in an exception (`input_ids` and `inputs_embeds` in LLMs)"""
article = "I need input_ids to generate"
tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-bart")
model = A... | Test that passing redundant inputs results in an exception (`input_ids` and `inputs_embeds` in LLMs) | test_generate_too_many_encoder_kwargs | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_generate_input_features_as_encoder_kwarg(self):
"""Test that non-`input_ids` main model inputs are correctly handled as positional arguments"""
input_features = floats_tensor((3, 80, 60))
model = AutoModelForSpeechSeq2Seq.from_pretrained(
"hf-internal-testing/tiny-random-Whi... | Test that non-`input_ids` main model inputs are correctly handled as positional arguments | test_generate_input_features_as_encoder_kwarg | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_generate_encoder_outputs_attention_mask(self):
"""Test that `generate` can handle attention masks when the encoder outputs are passed"""
input_features = floats_tensor((3, 80, 60))
attention_mask = torch.randint(0, 2, input_features.shape).to(torch_device)
model = AutoModelForSp... | Test that `generate` can handle attention masks when the encoder outputs are passed | test_generate_encoder_outputs_attention_mask | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_eos_token_id_int_and_list_greedy_search(self):
"""Test that `generate` can handle multiple EOS tokens"""
generation_kwargs = {
"do_sample": False,
"num_beams": 1,
}
expectation = 13
tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/t... | Test that `generate` can handle multiple EOS tokens | test_eos_token_id_int_and_list_greedy_search | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_generate_vision2text_conditioning(self):
"""Test that `decoder_input_ids` can be used to condition the generation in vision-to-text models"""
pixel_values = floats_tensor((2, 3, 30, 30))
conditioning_input = torch.tensor([[10], [10]]) # this should be the 2nd output token, after the BO... | Test that `decoder_input_ids` can be used to condition the generation in vision-to-text models | test_generate_vision2text_conditioning | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_cache_device_map_with_vision_layer_device_map(self):
"""
Test that the cache device map is correctly set when the vision layer has a device map. Regression test for
#36942
"""
# gemma 3 uses hybrid cache, which can be compiled -> needs a device map at allocation time
... |
Test that the cache device map is correctly set when the vision layer has a device map. Regression test for
#36942
| test_cache_device_map_with_vision_layer_device_map | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_cpu_offload_doesnt_compile(self):
"""Test that CPU offload doesn't trigger compilation"""
tokenizer = AutoTokenizer.from_pretrained("hf-internal-testing/tiny-random-MistralForCausalLM")
tokenized_inputs = tokenizer(["Hello world"], return_tensors="pt")
generate_kwargs = {"max_ne... | Test that CPU offload doesn't trigger compilation | test_cpu_offload_doesnt_compile | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_custom_generate_from_argument_in_generate(self):
"""Tests that the `custom_generate` argument is used when passed to `generate`"""
model = AutoModelForCausalLM.from_pretrained(
"hf-internal-testing/tiny-random-MistralForCausalLM", device_map="auto"
)
tokenizer = Auto... | Tests that the `custom_generate` argument is used when passed to `generate` | test_custom_generate_from_argument_in_generate | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_custom_generate_from_model_repo_with_custom_generate_code(self):
"""
Tests that models from model repos containing custom generation code override `generate` with the custom code
"""
model = AutoModelForCausalLM.from_pretrained(
"transformers-community/custom_generat... |
Tests that models from model repos containing custom generation code override `generate` with the custom code
| test_custom_generate_from_model_repo_with_custom_generate_code | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_custom_generate_bad_requirements(self):
"""Tests that we check the `requirements.txt` file from custom generation repos"""
model = AutoModelForCausalLM.from_pretrained(
"hf-internal-testing/tiny-random-MistralForCausalLM", device_map="auto"
)
tokenizer = AutoTokenize... | Tests that we check the `requirements.txt` file from custom generation repos | test_custom_generate_bad_requirements | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def test_custom_generate_requires_trust_remote_code(self):
"""Tests that `trust_remote_code` is required when using `custom_generate`"""
# Case 1: A model from a repo containing custom generation code must be loaded with `trust_remote_code`
with self.assertRaises(ValueError):
AutoMod... | Tests that `trust_remote_code` is required when using `custom_generate` | test_custom_generate_requires_trust_remote_code | python | huggingface/transformers | tests/generation/test_utils.py | https://github.com/huggingface/transformers/blob/master/tests/generation/test_utils.py | Apache-2.0 |
def prepare_image_inputs(
self,
batch_size=None,
min_resolution=None,
max_resolution=None,
num_channels=None,
num_images=None,
size_divisor=None,
equal_resolution=False,
numpify=False,
torchify=False,
):
"""This function prepare... | This function prepares a list of PIL images, or a list of numpy arrays if one specifies numpify=True,
or a list of PyTorch tensors if one specifies torchify=True.
One can specify whether the images are of the same resolution or not.
| prepare_image_inputs | python | huggingface/transformers | tests/models/aria/test_image_processing_aria.py | https://github.com/huggingface/transformers/blob/master/tests/models/aria/test_image_processing_aria.py | Apache-2.0 |
def test_special_mm_token_truncation(self):
"""Tests that special vision tokens do not get truncated when `truncation=True` is set."""
processor = self.get_processor()
input_str = self.prepare_text_inputs(batch_size=2, modality="image")
image_input = self.prepare_image_inputs(batch_siz... | Tests that special vision tokens do not get truncated when `truncation=True` is set. | test_special_mm_token_truncation | python | huggingface/transformers | tests/models/aria/test_processor_aria.py | https://github.com/huggingface/transformers/blob/master/tests/models/aria/test_processor_aria.py | Apache-2.0 |
def test_custom_model_patched_generation_inheritance(self):
"""
Tests that our inheritance patching for generate-compatible models works as expected. Without this feature,
old Hub models lose the ability to call `generate`.
"""
model = AutoModelForCausalLM.from_pretrained(
... |
Tests that our inheritance patching for generate-compatible models works as expected. Without this feature,
old Hub models lose the ability to call `generate`.
| test_custom_model_patched_generation_inheritance | python | huggingface/transformers | tests/models/auto/test_modeling_auto.py | https://github.com/huggingface/transformers/blob/master/tests/models/auto/test_modeling_auto.py | Apache-2.0 |
def _update_layer_configs(self):
"""Configures hidden layers and attn layer indices if they are not set."""
# Fix for SDPA tests, force at least 4 layers
if self.num_hidden_layers < 4:
self.num_hidden_layers = 4
if self.attn_layer_indices is None:
d = [x for x in... | Configures hidden layers and attn layer indices if they are not set. | _update_layer_configs | python | huggingface/transformers | tests/models/bamba/test_modeling_bamba.py | https://github.com/huggingface/transformers/blob/master/tests/models/bamba/test_modeling_bamba.py | Apache-2.0 |
def test_initialization(self):
r"""
Overriding the test_initialization test as the A_log and D params of the Bamba mixer are initialized differently
"""
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
configs_no_init = _config_zero_init(config)
... |
Overriding the test_initialization test as the A_log and D params of the Bamba mixer are initialized differently
| test_initialization | python | huggingface/transformers | tests/models/bamba/test_modeling_bamba.py | https://github.com/huggingface/transformers/blob/master/tests/models/bamba/test_modeling_bamba.py | Apache-2.0 |
def test_attention_outputs(self):
r"""
Overriding the test_attention_outputs test as the Bamba model outputs attention only for its attention layers
"""
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
config.return_dict = True
seq_len = get... |
Overriding the test_attention_outputs test as the Bamba model outputs attention only for its attention layers
| test_attention_outputs | python | huggingface/transformers | tests/models/bamba/test_modeling_bamba.py | https://github.com/huggingface/transformers/blob/master/tests/models/bamba/test_modeling_bamba.py | Apache-2.0 |
def test_mismatching_num_image_tokens(self):
"""
Tests that VLMs through an error with explicit message saying what is wrong
when number of images don't match number of image tokens in the text.
Also we need to test multi-image cases when one prompr has multiple image tokens.
"""... |
Tests that VLMs through an error with explicit message saying what is wrong
when number of images don't match number of image tokens in the text.
Also we need to test multi-image cases when one prompr has multiple image tokens.
| test_mismatching_num_image_tokens | python | huggingface/transformers | tests/models/chameleon/test_modeling_chameleon.py | https://github.com/huggingface/transformers/blob/master/tests/models/chameleon/test_modeling_chameleon.py | Apache-2.0 |
def test_generation_beyond_sliding_window(self, attn_implementation: str):
"""Test that we can correctly generate beyond the sliding window. This is non trivial as
we need to correctly slice the attention mask in all cases (because we use a HybridCache).
Outputs for every attention functions sho... | Test that we can correctly generate beyond the sliding window. This is non trivial as
we need to correctly slice the attention mask in all cases (because we use a HybridCache).
Outputs for every attention functions should be coherent and identical.
| test_generation_beyond_sliding_window | python | huggingface/transformers | tests/models/cohere2/test_modeling_cohere2.py | https://github.com/huggingface/transformers/blob/master/tests/models/cohere2/test_modeling_cohere2.py | Apache-2.0 |
def test_model_integration_test(self):
"""
Test if the model is able to retrieve the correct pages for a small and easy dataset.
"""
model = ColPaliForRetrieval.from_pretrained(
self.model_name,
torch_dtype=torch.bfloat16,
device_map=torch_device,
... |
Test if the model is able to retrieve the correct pages for a small and easy dataset.
| test_model_integration_test | python | huggingface/transformers | tests/models/colpali/test_modeling_colpali.py | https://github.com/huggingface/transformers/blob/master/tests/models/colpali/test_modeling_colpali.py | Apache-2.0 |
def _prepare_for_class(self, inputs_dict, model_class, return_labels=False):
"""
Overrides [ModelTesterMixin._prepare_for_class] to handle third input_ids dimension.
"""
inputs_dict = copy.deepcopy(inputs_dict)
if return_labels:
inputs_dict["labels"] = torch.zeros(
... |
Overrides [ModelTesterMixin._prepare_for_class] to handle third input_ids dimension.
| _prepare_for_class | python | huggingface/transformers | tests/models/csm/test_modeling_csm.py | https://github.com/huggingface/transformers/blob/master/tests/models/csm/test_modeling_csm.py | Apache-2.0 |
def _get_logits_processor_kwargs(self, do_sample=False, config=None):
"""
Overrides [GenerationTesterMixin._get_logits_processor_kwargs] to restrict to top_k, top_p, and temperature sampling.
"""
logits_processor_kwargs = {}
if do_sample:
logits_processor_kwargs.updat... |
Overrides [GenerationTesterMixin._get_logits_processor_kwargs] to restrict to top_k, top_p, and temperature sampling.
| _get_logits_processor_kwargs | python | huggingface/transformers | tests/models/csm/test_modeling_csm.py | https://github.com/huggingface/transformers/blob/master/tests/models/csm/test_modeling_csm.py | Apache-2.0 |
def test_initialization(self):
"""
Overrides [ModelTesterMixin.test_initialization] because of specificities of Mimi codec model.
See https://github.com/huggingface/transformers/blob/1077603410cd73ba71d64a522033574d66d64b55/tests/models/mimi/test_modeling_mimi.py#L384-L397
"""
co... |
Overrides [ModelTesterMixin.test_initialization] because of specificities of Mimi codec model.
See https://github.com/huggingface/transformers/blob/1077603410cd73ba71d64a522033574d66d64b55/tests/models/mimi/test_modeling_mimi.py#L384-L397
| test_initialization | python | huggingface/transformers | tests/models/csm/test_modeling_csm.py | https://github.com/huggingface/transformers/blob/master/tests/models/csm/test_modeling_csm.py | Apache-2.0 |
def _check_similar_generate_outputs(self, output_1, output_2, atol=1e-5, rtol=1e-5):
"""
Overrides [GenerationTesterMixin._check_similar_generate_outputs] to handle third input_ids dimension.
Here we only look a the first codebook (index 0 on last dimension of the generated sequences) since retu... |
Overrides [GenerationTesterMixin._check_similar_generate_outputs] to handle third input_ids dimension.
Here we only look a the first codebook (index 0 on last dimension of the generated sequences) since returned scores
are for this token.
| _check_similar_generate_outputs | python | huggingface/transformers | tests/models/csm/test_modeling_csm.py | https://github.com/huggingface/transformers/blob/master/tests/models/csm/test_modeling_csm.py | Apache-2.0 |
def test_tied_weights_keys(self):
"""
Overrides [ModelTesterMixin.test_tied_weights_keys] to not test for text config (not applicable to CSM).
"""
config, _ = self.model_tester.prepare_config_and_inputs_for_common()
for model_class in self.all_model_classes:
model_tie... |
Overrides [ModelTesterMixin.test_tied_weights_keys] to not test for text config (not applicable to CSM).
| test_tied_weights_keys | python | huggingface/transformers | tests/models/csm/test_modeling_csm.py | https://github.com/huggingface/transformers/blob/master/tests/models/csm/test_modeling_csm.py | Apache-2.0 |
def _get_custom_4d_mask_test_data(self):
"""
Overrides [ModelTesterMixin._get_custom_4d_mask_test_data] to handle third input_ids dimension.
"""
# Sequence in which all but the last token is the same
input_ids = torch.tensor([[0, 1, 2, 3], [0, 1, 2, 4], [0, 1, 2, 5]], device=torc... |
Overrides [ModelTesterMixin._get_custom_4d_mask_test_data] to handle third input_ids dimension.
| _get_custom_4d_mask_test_data | python | huggingface/transformers | tests/models/csm/test_modeling_csm.py | https://github.com/huggingface/transformers/blob/master/tests/models/csm/test_modeling_csm.py | Apache-2.0 |
def test_1b_model_integration_generate(self):
"""
Tests the generated tokens match the ones from the original model implementation.
Such tokens are to be retreived using https://gist.github.com/eustlb/d25577a357ddcf8f4a8cd0d00baca551, which is a script that infers the original model.
"""... |
Tests the generated tokens match the ones from the original model implementation.
Such tokens are to be retreived using https://gist.github.com/eustlb/d25577a357ddcf8f4a8cd0d00baca551, which is a script that infers the original model.
| test_1b_model_integration_generate | python | huggingface/transformers | tests/models/csm/test_modeling_csm.py | https://github.com/huggingface/transformers/blob/master/tests/models/csm/test_modeling_csm.py | Apache-2.0 |
def test_1b_model_integration_generate_no_audio(self):
"""
Tests the generated tokens match the ones from the original model implementation.
Such tokens are to be retreived using https://gist.github.com/eustlb/aed822f765e928b9612e01b0d8836d69, which is a script that infers the original model.
... |
Tests the generated tokens match the ones from the original model implementation.
Such tokens are to be retreived using https://gist.github.com/eustlb/aed822f765e928b9612e01b0d8836d69, which is a script that infers the original model.
| test_1b_model_integration_generate_no_audio | python | huggingface/transformers | tests/models/csm/test_modeling_csm.py | https://github.com/huggingface/transformers/blob/master/tests/models/csm/test_modeling_csm.py | Apache-2.0 |
def test_1b_model_integration_generate_multiple_audio(self):
"""
Test the generated tokens match the ones from the original model implementation.
Such tokens are to be retreived using https://gist.github.com/eustlb/0c94de002e1325abb61d32217f74c0f8, which is a script that infers the original mode... |
Test the generated tokens match the ones from the original model implementation.
Such tokens are to be retreived using https://gist.github.com/eustlb/0c94de002e1325abb61d32217f74c0f8, which is a script that infers the original model.
| test_1b_model_integration_generate_multiple_audio | python | huggingface/transformers | tests/models/csm/test_modeling_csm.py | https://github.com/huggingface/transformers/blob/master/tests/models/csm/test_modeling_csm.py | Apache-2.0 |
def test_1b_model_integration_generate_batched(self):
"""
Test the generated tokens match the ones from the original model implementation.
Such tokens are to be retreived using https://gist.github.com/eustlb/bcc532b53161bc31da3d66cb07ae193f, which is a script that infers the original model.
... |
Test the generated tokens match the ones from the original model implementation.
Such tokens are to be retreived using https://gist.github.com/eustlb/bcc532b53161bc31da3d66cb07ae193f, which is a script that infers the original model.
| test_1b_model_integration_generate_batched | python | huggingface/transformers | tests/models/csm/test_modeling_csm.py | https://github.com/huggingface/transformers/blob/master/tests/models/csm/test_modeling_csm.py | Apache-2.0 |
def test_create_position_ids_respects_padding_index(self):
"""This is a regression test for https://github.com/huggingface/transformers/issues/1761
The position ids should be masked with the embedding object's padding index. Therefore, the
first available non-padding position index is Data2VecT... | This is a regression test for https://github.com/huggingface/transformers/issues/1761
The position ids should be masked with the embedding object's padding index. Therefore, the
first available non-padding position index is Data2VecTextForTextEmbeddings.padding_idx + 1
| test_create_position_ids_respects_padding_index | python | huggingface/transformers | tests/models/data2vec/test_modeling_data2vec_text.py | https://github.com/huggingface/transformers/blob/master/tests/models/data2vec/test_modeling_data2vec_text.py | Apache-2.0 |
def test_past_key_values_format(self):
"""
Overwriting to pass the expected cache shapes (Deepseek-V3 uses MLA so the cache shapes are non-standard)
"""
config, inputs = self.model_tester.prepare_config_and_inputs_for_common()
batch_size, seq_length = inputs["input_ids"].shape
... |
Overwriting to pass the expected cache shapes (Deepseek-V3 uses MLA so the cache shapes are non-standard)
| test_past_key_values_format | python | huggingface/transformers | tests/models/deepseek_v3/test_modeling_deepseek_v3.py | https://github.com/huggingface/transformers/blob/master/tests/models/deepseek_v3/test_modeling_deepseek_v3.py | Apache-2.0 |
def test_eager_matches_sdpa_generate(self):
"""
Overwriting the common test as the test is flaky on tiny models
"""
max_new_tokens = 30
tokenizer = AutoTokenizer.from_pretrained("bzantium/tiny-deepseek-v3")
model_sdpa = DeepseekV3ForCausalLM.from_pretrained(
... |
Overwriting the common test as the test is flaky on tiny models
| test_eager_matches_sdpa_generate | python | huggingface/transformers | tests/models/deepseek_v3/test_modeling_deepseek_v3.py | https://github.com/huggingface/transformers/blob/master/tests/models/deepseek_v3/test_modeling_deepseek_v3.py | Apache-2.0 |
def test_flex_attention_with_grads(self):
"""
Overwriting as the namings/functionality on the attention part are different; for now it's more of a unique model.
Original issue is also due to dimensionalities, here specifically due to dims not being a multiple of 2.
"""
for model_... |
Overwriting as the namings/functionality on the attention part are different; for now it's more of a unique model.
Original issue is also due to dimensionalities, here specifically due to dims not being a multiple of 2.
| test_flex_attention_with_grads | python | huggingface/transformers | tests/models/deepseek_v3/test_modeling_deepseek_v3.py | https://github.com/huggingface/transformers/blob/master/tests/models/deepseek_v3/test_modeling_deepseek_v3.py | Apache-2.0 |
def test_use_flash_attention_2_true(self):
"""
NOTE: this is the only test testing that the legacy `use_flash_attention=2` argument still works as intended.
"""
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
for model_class in self.all_model_classe... |
NOTE: this is the only test testing that the legacy `use_flash_attention=2` argument still works as intended.
| test_use_flash_attention_2_true | python | huggingface/transformers | tests/models/diffllama/test_modeling_diffllama.py | https://github.com/huggingface/transformers/blob/master/tests/models/diffllama/test_modeling_diffllama.py | Apache-2.0 |
def test_stacked_causal_mask_static_cache(self):
"""same as above but with StaticCache"""
(
input_ids,
position_ids,
input_ids_shared_prefix,
mask_shared_prefix,
position_ids_shared_prefix,
) = self.get_test_data()
# regular ba... | same as above but with StaticCache | test_stacked_causal_mask_static_cache | python | huggingface/transformers | tests/models/diffllama/test_modeling_diffllama.py | https://github.com/huggingface/transformers/blob/master/tests/models/diffllama/test_modeling_diffllama.py | Apache-2.0 |
def test_create_position_ids_respects_padding_index(self):
"""This is a regression test for https://github.com/huggingface/transformers/issues/1761
The position ids should be masked with the embedding object's padding index. Therefore, the
first available non-padding position index is EsmEmbedd... | This is a regression test for https://github.com/huggingface/transformers/issues/1761
The position ids should be masked with the embedding object's padding index. Therefore, the
first available non-padding position index is EsmEmbeddings.padding_idx + 1
| test_create_position_ids_respects_padding_index | python | huggingface/transformers | tests/models/esm/test_modeling_esm.py | https://github.com/huggingface/transformers/blob/master/tests/models/esm/test_modeling_esm.py | Apache-2.0 |
def test_attention_outputs(self):
r"""
Overriding the test_attention_outputs test as the FalconH1 model outputs attention only for its attention layers
"""
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
config.return_dict = True
seq_len = ... |
Overriding the test_attention_outputs test as the FalconH1 model outputs attention only for its attention layers
| test_attention_outputs | python | huggingface/transformers | tests/models/falcon_h1/test_modeling_falcon_h1.py | https://github.com/huggingface/transformers/blob/master/tests/models/falcon_h1/test_modeling_falcon_h1.py | Apache-2.0 |
def test_attention_outputs(self):
"""
Custom `test_attention_outputs` since FastSpeech2Conformer does not output cross attentions, has variable
decoder attention shape, and uniquely outputs energy, pitch, and durations.
"""
config, inputs_dict = self.model_tester.prepare_config_a... |
Custom `test_attention_outputs` since FastSpeech2Conformer does not output cross attentions, has variable
decoder attention shape, and uniquely outputs energy, pitch, and durations.
| test_attention_outputs | python | huggingface/transformers | tests/models/fastspeech2_conformer/test_modeling_fastspeech2_conformer.py | https://github.com/huggingface/transformers/blob/master/tests/models/fastspeech2_conformer/test_modeling_fastspeech2_conformer.py | Apache-2.0 |
def _assert_tensors_equal(a, b, atol=1e-12, prefix=""):
"""If tensors not close, or a and b aren't both tensors, raise a nice Assertion error."""
if a is None and b is None:
return True
try:
if torch.allclose(a, b, atol=atol):
return True
raise
except Exception:
... | If tensors not close, or a and b aren't both tensors, raise a nice Assertion error. | _assert_tensors_equal | python | huggingface/transformers | tests/models/fsmt/test_modeling_fsmt.py | https://github.com/huggingface/transformers/blob/master/tests/models/fsmt/test_modeling_fsmt.py | Apache-2.0 |
def test_pan_and_scan(self):
"""
Enables Pan and Scan path by choosing the correct input image resolution. If you are changing
image processor attributes for PaS, please update this test.
"""
for image_processing_class in self.image_processor_list:
# Initialize image_... |
Enables Pan and Scan path by choosing the correct input image resolution. If you are changing
image processor attributes for PaS, please update this test.
| test_pan_and_scan | python | huggingface/transformers | tests/models/gemma3/test_image_processing_gemma3.py | https://github.com/huggingface/transformers/blob/master/tests/models/gemma3/test_image_processing_gemma3.py | Apache-2.0 |
def test_automodelforcausallm(self):
"""
Regression test for #36741/#36917 -- make sure `AutoModelForCausalLM` works with a Gemma3 config, i.e. that
`AutoModelForCausalLM.from_pretrained` pulls the text config before loading the model
"""
config = self.model_tester.get_config()
... |
Regression test for #36741/#36917 -- make sure `AutoModelForCausalLM` works with a Gemma3 config, i.e. that
`AutoModelForCausalLM.from_pretrained` pulls the text config before loading the model
| test_automodelforcausallm | python | huggingface/transformers | tests/models/gemma3/test_modeling_gemma3.py | https://github.com/huggingface/transformers/blob/master/tests/models/gemma3/test_modeling_gemma3.py | Apache-2.0 |
def test_lm_generate_distilgpt2_left_padding(self):
"""Tests that the generated text is the same, regardless of left padding"""
model = TFGPT2LMHeadModel.from_pretrained("distilbert/distilgpt2")
tokenizer = GPT2Tokenizer.from_pretrained("distilbert/distilgpt2")
tokenizer.pad_token = tok... | Tests that the generated text is the same, regardless of left padding | test_lm_generate_distilgpt2_left_padding | python | huggingface/transformers | tests/models/gpt2/test_modeling_tf_gpt2.py | https://github.com/huggingface/transformers/blob/master/tests/models/gpt2/test_modeling_tf_gpt2.py | Apache-2.0 |
def copy_cache(cache: DynamicCache):
"""Deep copy a DynamicCache to reuse the same one multiple times."""
new_cache = cache
for i in range(len(cache)):
new_cache.key_cache[i] = cache.key_cache[i].clone()
new_cache.value_cache[i] = cache.value_cache[i].... | Deep copy a DynamicCache to reuse the same one multiple times. | copy_cache | python | huggingface/transformers | tests/models/gpt_neox/test_modeling_gpt_neox.py | https://github.com/huggingface/transformers/blob/master/tests/models/gpt_neox/test_modeling_gpt_neox.py | Apache-2.0 |
def test_save_load_pretrained_default(self):
"""Ensure we can save / reload a processor correctly."""
tokenizer = self.get_tokenizer()
audio_processor = self.get_audio_processor()
processor = GraniteSpeechProcessor(
tokenizer=tokenizer,
audio_processor=audio_proce... | Ensure we can save / reload a processor correctly. | test_save_load_pretrained_default | python | huggingface/transformers | tests/models/granite_speech/test_processor_granite_speech.py | https://github.com/huggingface/transformers/blob/master/tests/models/granite_speech/test_processor_granite_speech.py | Apache-2.0 |
def test_bad_text_fails(self):
"""Ensure we gracefully fail if text is the wrong type."""
tokenizer = self.get_tokenizer()
audio_processor = self.get_audio_processor()
processor = GraniteSpeechProcessor(tokenizer=tokenizer, audio_processor=audio_processor)
with pytest.raises(Typ... | Ensure we gracefully fail if text is the wrong type. | test_bad_text_fails | python | huggingface/transformers | tests/models/granite_speech/test_processor_granite_speech.py | https://github.com/huggingface/transformers/blob/master/tests/models/granite_speech/test_processor_granite_speech.py | Apache-2.0 |
def test_bad_nested_text_fails(self):
"""Ensure we gracefully fail if text is the wrong nested type."""
tokenizer = self.get_tokenizer()
audio_processor = self.get_audio_processor()
processor = GraniteSpeechProcessor(
tokenizer=tokenizer,
audio_processor=audio_pro... | Ensure we gracefully fail if text is the wrong nested type. | test_bad_nested_text_fails | python | huggingface/transformers | tests/models/granite_speech/test_processor_granite_speech.py | https://github.com/huggingface/transformers/blob/master/tests/models/granite_speech/test_processor_granite_speech.py | Apache-2.0 |
def test_bad_audio_fails(self):
"""Ensure we gracefully fail if audio is the wrong type."""
tokenizer = self.get_tokenizer()
audio_processor = self.get_audio_processor()
processor = GraniteSpeechProcessor(
tokenizer=tokenizer,
audio_processor=audio_processor,
... | Ensure we gracefully fail if audio is the wrong type. | test_bad_audio_fails | python | huggingface/transformers | tests/models/granite_speech/test_processor_granite_speech.py | https://github.com/huggingface/transformers/blob/master/tests/models/granite_speech/test_processor_granite_speech.py | Apache-2.0 |
def test_nested_bad_audio_fails(self):
"""Ensure we gracefully fail if audio is the wrong nested type."""
tokenizer = self.get_tokenizer()
audio_processor = self.get_audio_processor()
processor = GraniteSpeechProcessor(
tokenizer=tokenizer,
audio_processor=audio_p... | Ensure we gracefully fail if audio is the wrong nested type. | test_nested_bad_audio_fails | python | huggingface/transformers | tests/models/granite_speech/test_processor_granite_speech.py | https://github.com/huggingface/transformers/blob/master/tests/models/granite_speech/test_processor_granite_speech.py | Apache-2.0 |
def test_audio_token_filling_same_len_feature_tensors(self, vec_dims, num_expected_features, random_func):
"""Ensure audio token filling is handled correctly when we have
one or more audio inputs whose features are all the same length
stacked into a tensor / numpy array.
NOTE: Currently... | Ensure audio token filling is handled correctly when we have
one or more audio inputs whose features are all the same length
stacked into a tensor / numpy array.
NOTE: Currently we enforce that each sample can only have one audio.
| test_audio_token_filling_same_len_feature_tensors | python | huggingface/transformers | tests/models/granite_speech/test_processor_granite_speech.py | https://github.com/huggingface/transformers/blob/master/tests/models/granite_speech/test_processor_granite_speech.py | Apache-2.0 |
def test_audio_token_filling_varying_len_feature_list(self):
"""Ensure audio token filling is handled correctly when we have
multiple varying len audio sequences passed as a list.
"""
tokenizer = self.get_tokenizer()
audio_processor = self.get_audio_processor()
processor ... | Ensure audio token filling is handled correctly when we have
multiple varying len audio sequences passed as a list.
| test_audio_token_filling_varying_len_feature_list | python | huggingface/transformers | tests/models/granite_speech/test_processor_granite_speech.py | https://github.com/huggingface/transformers/blob/master/tests/models/granite_speech/test_processor_granite_speech.py | Apache-2.0 |
def test_device_override(self):
"""Ensure that we regardless of the processing device, the tensors
produced are on the CPU.
"""
tokenizer = self.get_tokenizer()
audio_processor = self.get_audio_processor()
processor = GraniteSpeechProcessor(
tokenizer=tokenize... | Ensure that we regardless of the processing device, the tensors
produced are on the CPU.
| test_device_override | python | huggingface/transformers | tests/models/granite_speech/test_processor_granite_speech.py | https://github.com/huggingface/transformers/blob/master/tests/models/granite_speech/test_processor_granite_speech.py | Apache-2.0 |
def get_expected_values(self, image_inputs, batched=False):
"""
This function computes the expected height and width when providing images to GroundingDinoImageProcessor,
assuming do_resize is set to True with a scalar size.
"""
if not batched:
image = image_inputs[0]... |
This function computes the expected height and width when providing images to GroundingDinoImageProcessor,
assuming do_resize is set to True with a scalar size.
| get_expected_values | python | huggingface/transformers | tests/models/grounding_dino/test_image_processing_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/tests/models/grounding_dino/test_image_processing_grounding_dino.py | Apache-2.0 |
def generate_fake_bounding_boxes(n_boxes):
"""Generate bounding boxes in the format (center_x, center_y, width, height)"""
# Validate the input
if not isinstance(n_boxes, int):
raise ValueError("n_boxes must be an integer")
if n_boxes <= 0:
raise ValueError("n_boxes must be a positive in... | Generate bounding boxes in the format (center_x, center_y, width, height) | generate_fake_bounding_boxes | python | huggingface/transformers | tests/models/grounding_dino/test_modeling_grounding_dino.py | https://github.com/huggingface/transformers/blob/master/tests/models/grounding_dino/test_modeling_grounding_dino.py | Apache-2.0 |
def test_create_position_ids_respects_padding_index(self):
"""This is a regression test for https://github.com/huggingface/transformers/issues/1761
The position ids should be masked with the embedding object's padding index. Therefore, the
first available non-padding position index is IBertEmbe... | This is a regression test for https://github.com/huggingface/transformers/issues/1761
The position ids should be masked with the embedding object's padding index. Therefore, the
first available non-padding position index is IBertEmbeddings.padding_idx + 1
| test_create_position_ids_respects_padding_index | python | huggingface/transformers | tests/models/ibert/test_modeling_ibert.py | https://github.com/huggingface/transformers/blob/master/tests/models/ibert/test_modeling_ibert.py | Apache-2.0 |
def test_create_position_ids_from_inputs_embeds(self):
"""This is a regression test for https://github.com/huggingface/transformers/issues/1761
The position ids should be masked with the embedding object's padding index. Therefore, the
first available non-padding position index is IBertEmbedding... | This is a regression test for https://github.com/huggingface/transformers/issues/1761
The position ids should be masked with the embedding object's padding index. Therefore, the
first available non-padding position index is IBertEmbeddings.padding_idx + 1
| test_create_position_ids_from_inputs_embeds | python | huggingface/transformers | tests/models/ibert/test_modeling_ibert.py | https://github.com/huggingface/transformers/blob/master/tests/models/ibert/test_modeling_ibert.py | Apache-2.0 |
def test_left_padding_compatibility(self):
"""Overwrite because IDEFICS needs image attention mask to be also padded"""
# NOTE: left-padding results in small numerical differences. This is expected.
# See https://github.com/huggingface/transformers/issues/25420#issuecomment-1775317535
d... | Overwrite because IDEFICS needs image attention mask to be also padded | test_left_padding_compatibility | python | huggingface/transformers | tests/models/idefics/test_modeling_idefics.py | https://github.com/huggingface/transformers/blob/master/tests/models/idefics/test_modeling_idefics.py | Apache-2.0 |
def test_generate_continue_from_past_key_values(self):
"""Overwrite because IDEFICS needs image attention mask to be also processed"""
# Tests that we can continue generating from past key values, returned from a previous `generate` call
for model_class in self.all_generative_model_classes:
... | Overwrite because IDEFICS needs image attention mask to be also processed | test_generate_continue_from_past_key_values | python | huggingface/transformers | tests/models/idefics/test_modeling_idefics.py | https://github.com/huggingface/transformers/blob/master/tests/models/idefics/test_modeling_idefics.py | Apache-2.0 |
def test_generate_without_input_ids(self):
"""Overwrite because IDEFICS needs image attention mask to be also processed and requires image at input always."""
config, input_dict = self.prepare_config_and_inputs_for_generate()
pixel_values = input_dict["pixel_values"]
image_attention_mas... | Overwrite because IDEFICS needs image attention mask to be also processed and requires image at input always. | test_generate_without_input_ids | python | huggingface/transformers | tests/models/idefics/test_modeling_idefics.py | https://github.com/huggingface/transformers/blob/master/tests/models/idefics/test_modeling_idefics.py | Apache-2.0 |
def test_generate_continue_from_inputs_embeds(self):
"""Overwrite for IDEFICS: Ensure image attention mask is processed while continuing from `inputs_embeds`."""
for model_class in self.all_generative_model_classes:
config, inputs = self.model_tester.prepare_config_and_inputs_for_common()
... | Overwrite for IDEFICS: Ensure image attention mask is processed while continuing from `inputs_embeds`. | test_generate_continue_from_inputs_embeds | python | huggingface/transformers | tests/models/idefics/test_modeling_idefics.py | https://github.com/huggingface/transformers/blob/master/tests/models/idefics/test_modeling_idefics.py | Apache-2.0 |
def _check_attentions_for_generate(
self, batch_size, attentions, prompt_length, output_length, config, decoder_past_key_values
):
"""
Overwrite from generation tests because Idefics has only SDPA layers.
Do not skip because we still want generation tests to run. Rather we can remove... |
Overwrite from generation tests because Idefics has only SDPA layers.
Do not skip because we still want generation tests to run. Rather we can remove checks for shape.
| _check_attentions_for_generate | python | huggingface/transformers | tests/models/idefics/test_modeling_idefics.py | https://github.com/huggingface/transformers/blob/master/tests/models/idefics/test_modeling_idefics.py | Apache-2.0 |
def test_tokenizer_left_padding(self):
"""Identical to test_tokenizer_padding, but with padding_side not explicitly set."""
image_processor = self.get_image_processor()
tokenizer = self.get_tokenizer()
processor = IdeficsProcessor(tokenizer=tokenizer, image_processor=image_processor)
... | Identical to test_tokenizer_padding, but with padding_side not explicitly set. | test_tokenizer_left_padding | python | huggingface/transformers | tests/models/idefics/test_processor_idefics.py | https://github.com/huggingface/transformers/blob/master/tests/models/idefics/test_processor_idefics.py | Apache-2.0 |
def test_text_only_inference(self):
"""Test that the processor works correctly with text-only input."""
processor = self.get_processor()
text = "This is a simple text without images."
inputs = processor(text=text)
tokenized_sentence = processor.tokenizer(text, add_special_token... | Test that the processor works correctly with text-only input. | test_text_only_inference | python | huggingface/transformers | tests/models/idefics3/test_processor_idefics3.py | https://github.com/huggingface/transformers/blob/master/tests/models/idefics3/test_processor_idefics3.py | Apache-2.0 |
def test_missing_images_error(self):
"""Test that appropriate error is raised when images are referenced but not provided."""
processor = self.get_processor()
# Test single text with image token but no image
text = "Let me show you this image: <image> What do you think?"
with se... | Test that appropriate error is raised when images are referenced but not provided. | test_missing_images_error | python | huggingface/transformers | tests/models/idefics3/test_processor_idefics3.py | https://github.com/huggingface/transformers/blob/master/tests/models/idefics3/test_processor_idefics3.py | Apache-2.0 |
def test_sdpa_can_dispatch_composite_models(self):
"""
Tests if composite models dispatch correctly on SDPA/eager when requested so when loading the model.
This tests only by looking at layer names, as usually SDPA layers are calles "SDPAAttention".
In contrast to the above test, this on... |
Tests if composite models dispatch correctly on SDPA/eager when requested so when loading the model.
This tests only by looking at layer names, as usually SDPA layers are calles "SDPAAttention".
In contrast to the above test, this one checks if the "config._attn_implamentation" is a dict after ... | test_sdpa_can_dispatch_composite_models | python | huggingface/transformers | tests/models/instructblipvideo/test_modeling_instructblipvideo.py | https://github.com/huggingface/transformers/blob/master/tests/models/instructblipvideo/test_modeling_instructblipvideo.py | Apache-2.0 |
def test_chat_template_accepts_processing_kwargs(self):
"""Tests that the chat template correctly handles additional processing arguments."""
# Get processor and skip if it doesn't have a chat template
processor = self.get_processor()
if processor.chat_template is None:
self.... | Tests that the chat template correctly handles additional processing arguments. | test_chat_template_accepts_processing_kwargs | python | huggingface/transformers | tests/models/janus/test_processor_janus.py | https://github.com/huggingface/transformers/blob/master/tests/models/janus/test_processor_janus.py | Apache-2.0 |
def test_llama_3_1_hard(self):
"""
An integration test for llama 3.1. It tests against a long output to ensure the subtle numerical differences
from llama 3.1.'s RoPE can be detected
"""
# diff on `EXPECTED_TEXT`:
# 2024-08-26: updating from torch 2.3.1 to 2.4.0 slightly ... |
An integration test for llama 3.1. It tests against a long output to ensure the subtle numerical differences
from llama 3.1.'s RoPE can be detected
| test_llama_3_1_hard | python | huggingface/transformers | tests/models/llama/test_modeling_llama.py | https://github.com/huggingface/transformers/blob/master/tests/models/llama/test_modeling_llama.py | Apache-2.0 |
def test_llava_reload(self):
"""
Simple test for reloading default llava configs
"""
with tempfile.TemporaryDirectory() as tmp_dir:
config = LlavaConfig()
config.save_pretrained(tmp_dir)
reloaded = LlavaConfig.from_pretrained(tmp_dir)
asse... |
Simple test for reloading default llava configs
| test_llava_reload | python | huggingface/transformers | tests/models/llava/test_configuration_llava.py | https://github.com/huggingface/transformers/blob/master/tests/models/llava/test_configuration_llava.py | Apache-2.0 |
def test_pixtral_reload(self):
"""
Simple test for reloading pixtral configs
"""
vision_config = {
"model_type": "pixtral",
"head_dim": 64,
"hidden_act": "silu",
"image_size": 1024,
"is_composition": True,
"patch_siz... |
Simple test for reloading pixtral configs
| test_pixtral_reload | python | huggingface/transformers | tests/models/llava/test_configuration_llava.py | https://github.com/huggingface/transformers/blob/master/tests/models/llava/test_configuration_llava.py | Apache-2.0 |
def test_arbitrary_reload(self):
"""
Simple test for reloading arbitrarily composed subconfigs
"""
default_values = LlavaConfig().to_diff_dict()
default_values["vision_config"]["model_type"] = "pixtral"
default_values["text_config"]["model_type"] = "opt"
self.maxD... |
Simple test for reloading arbitrarily composed subconfigs
| test_arbitrary_reload | python | huggingface/transformers | tests/models/llava/test_configuration_llava.py | https://github.com/huggingface/transformers/blob/master/tests/models/llava/test_configuration_llava.py | Apache-2.0 |
def test_padding(self):
"""
LLaVA needs to pad images to square size before processing as per orig implementation.
Checks that image processor pads images correctly given different background colors.
"""
# taken from original implementation: https://github.com/haotian-liu/LLaVA/... |
LLaVA needs to pad images to square size before processing as per orig implementation.
Checks that image processor pads images correctly given different background colors.
| test_padding | python | huggingface/transformers | tests/models/llava/test_image_processing_llava.py | https://github.com/huggingface/transformers/blob/master/tests/models/llava/test_image_processing_llava.py | Apache-2.0 |
def test_mismatching_num_image_tokens(self):
"""
Tests that VLMs through an error with explicit message saying what is wrong
when number of images doesn't match number of image tokens in the text.
Also we need to test multi-image cases when one prompr has multiple image tokens.
"... |
Tests that VLMs through an error with explicit message saying what is wrong
when number of images doesn't match number of image tokens in the text.
Also we need to test multi-image cases when one prompr has multiple image tokens.
| test_mismatching_num_image_tokens | python | huggingface/transformers | tests/models/llava/test_modeling_llava.py | https://github.com/huggingface/transformers/blob/master/tests/models/llava/test_modeling_llava.py | Apache-2.0 |
def test_vision_feature_layers(self, vision_feature_layer):
"""
Test that we can use either one vision feature layer, or a list of
vision feature layers.
"""
config, input_dict = self.model_tester.prepare_config_and_inputs_for_common()
config.vision_feature_layer = vision... |
Test that we can use either one vision feature layer, or a list of
vision feature layers.
| test_vision_feature_layers | python | huggingface/transformers | tests/models/llava/test_modeling_llava.py | https://github.com/huggingface/transformers/blob/master/tests/models/llava/test_modeling_llava.py | Apache-2.0 |
def test_granite_vision(self):
"""
Check the expected output of a granite vision model, which leverages
multiple vision feature layers and a visual encoder with no CLS (siglip).
"""
granite_model_path = "ibm-granite/granite-vision-3.1-2b-preview"
model = LlavaNextForCondi... |
Check the expected output of a granite vision model, which leverages
multiple vision feature layers and a visual encoder with no CLS (siglip).
| test_granite_vision | python | huggingface/transformers | tests/models/llava_next/test_modeling_llava_next.py | https://github.com/huggingface/transformers/blob/master/tests/models/llava_next/test_modeling_llava_next.py | Apache-2.0 |
def test_simple_generate(self):
"""
Simple generate test to avoid regressions.
Note: state-spaces (cuda) implementation and pure torch implementation
have irreconciliable differences as of now, which will cause this test to fail
in an environment with state-spaces installed.
... |
Simple generate test to avoid regressions.
Note: state-spaces (cuda) implementation and pure torch implementation
have irreconciliable differences as of now, which will cause this test to fail
in an environment with state-spaces installed.
| test_simple_generate | python | huggingface/transformers | tests/models/mamba2/test_modeling_mamba2.py | https://github.com/huggingface/transformers/blob/master/tests/models/mamba2/test_modeling_mamba2.py | Apache-2.0 |
def test_batched_equivalence_with_cache(self):
"""
Verifies that batched generation matches individual generation.
Important because of the specific caching mechanism + statefulness of mamba model.
Depending on precision and devices, differences can be observed from generation to generat... |
Verifies that batched generation matches individual generation.
Important because of the specific caching mechanism + statefulness of mamba model.
Depending on precision and devices, differences can be observed from generation to generation.
| test_batched_equivalence_with_cache | python | huggingface/transformers | tests/models/mamba2/test_modeling_mamba2.py | https://github.com/huggingface/transformers/blob/master/tests/models/mamba2/test_modeling_mamba2.py | Apache-2.0 |
def test_batched_equivalence_without_cache(self):
"""
Verifies that batched generation matches individual generation without cache.
Important because of the specific caching mechanism + statefulness of mamba model.
Depending on precision and devices, differences can be observed from gene... |
Verifies that batched generation matches individual generation without cache.
Important because of the specific caching mechanism + statefulness of mamba model.
Depending on precision and devices, differences can be observed from generation to generation.
| test_batched_equivalence_without_cache | python | huggingface/transformers | tests/models/mamba2/test_modeling_mamba2.py | https://github.com/huggingface/transformers/blob/master/tests/models/mamba2/test_modeling_mamba2.py | Apache-2.0 |
def test_past_key_values_format(self, custom_all_cache_shapes=None):
"""
Test that the KV cache is formatted correctly.
"""
for model_class in self.all_generative_model_classes:
config, inputs = self.model_tester.prepare_config_and_inputs_for_common()
model = mod... |
Test that the KV cache is formatted correctly.
| test_past_key_values_format | python | huggingface/transformers | tests/models/minimax/test_modeling_minimax.py | https://github.com/huggingface/transformers/blob/master/tests/models/minimax/test_modeling_minimax.py | Apache-2.0 |
def test_generate_text_only_with_cache(self):
"""
Tests that our cached generation with text-only inputs works. When mllama was introduced, this feature
required cache modifications (because layers are skipped in practice). This test should prevent regressions.
"""
config, inputs... |
Tests that our cached generation with text-only inputs works. When mllama was introduced, this feature
required cache modifications (because layers are skipped in practice). This test should prevent regressions.
| test_generate_text_only_with_cache | python | huggingface/transformers | tests/models/mllama/test_modeling_mllama.py | https://github.com/huggingface/transformers/blob/master/tests/models/mllama/test_modeling_mllama.py | Apache-2.0 |
def test_eager_matches_sdpa_generate(self):
"""Overwritten -- mochi has custom inputs and custom output checks"""
max_new_tokens = 5
for model_class in self.all_generative_model_classes:
if not model_class._supports_sdpa:
self.skipTest(f"{model_class.__name__} does ... | Overwritten -- mochi has custom inputs and custom output checks | test_eager_matches_sdpa_generate | python | huggingface/transformers | tests/models/moshi/test_modeling_moshi.py | https://github.com/huggingface/transformers/blob/master/tests/models/moshi/test_modeling_moshi.py | Apache-2.0 |
def test_small_integration_test(self):
"""
For comparison run:
>>> import t5 # pip install t5==0.7.1
>>> from t5.data.sentencepiece_vocabulary import SentencePieceVocabulary
>>> path_to_mtf_small_mt5_checkpoint = '<fill_in>'
>>> path_to_mtf_small_mt5_spm_model_path = '<... |
For comparison run:
>>> import t5 # pip install t5==0.7.1
>>> from t5.data.sentencepiece_vocabulary import SentencePieceVocabulary
>>> path_to_mtf_small_mt5_checkpoint = '<fill_in>'
>>> path_to_mtf_small_mt5_spm_model_path = '<fill_in>'
>>> t5_model = t5.models.MtfMode... | test_small_integration_test | python | huggingface/transformers | tests/models/mt5/test_modeling_flax_mt5.py | https://github.com/huggingface/transformers/blob/master/tests/models/mt5/test_modeling_flax_mt5.py | Apache-2.0 |
def test_small_integration_test(self):
"""
For comparison run:
>>> import t5 # pip install t5==0.7.1
>>> from t5.data.sentencepiece_vocabulary import SentencePieceVocabulary
>>> path_to_mtf_small_mt5_checkpoint = '<fill_in>'
>>> path_to_mtf_small_mt5_spm_model_path = '<... |
For comparison run:
>>> import t5 # pip install t5==0.7.1
>>> from t5.data.sentencepiece_vocabulary import SentencePieceVocabulary
>>> path_to_mtf_small_mt5_checkpoint = '<fill_in>'
>>> path_to_mtf_small_mt5_spm_model_path = '<fill_in>'
>>> t5_model = t5.models.MtfMode... | test_small_integration_test | python | huggingface/transformers | tests/models/mt5/test_modeling_tf_mt5.py | https://github.com/huggingface/transformers/blob/master/tests/models/mt5/test_modeling_tf_mt5.py | Apache-2.0 |
def test_batching_equivalence(self):
"""
Tests that the model supports batching and that the output is nearly the same for the same input in
different batch sizes.
(Why "nearly the same" not "exactly the same"? Batching uses different matmul shapes, which often leads to
different... |
Tests that the model supports batching and that the output is nearly the same for the same input in
different batch sizes.
(Why "nearly the same" not "exactly the same"? Batching uses different matmul shapes, which often leads to
different results: https://github.com/huggingface/transfo... | test_batching_equivalence | python | huggingface/transformers | tests/models/omdet_turbo/test_modeling_omdet_turbo.py | https://github.com/huggingface/transformers/blob/master/tests/models/omdet_turbo/test_modeling_omdet_turbo.py | Apache-2.0 |
def test_attention_mask_with_token_types(self):
"""Test that attention masking works correctly both with and without token type IDs."""
config, inputs_dict = self.model_tester.prepare_config_and_inputs_for_common()
for model_class in self.all_model_classes:
model = model_class._from... | Test that attention masking works correctly both with and without token type IDs. | test_attention_mask_with_token_types | python | huggingface/transformers | tests/models/paligemma/test_modeling_paligemma.py | https://github.com/huggingface/transformers/blob/master/tests/models/paligemma/test_modeling_paligemma.py | Apache-2.0 |
def setUpClass(cls):
"""Setup method: Called once before test-cases execution"""
cls.params = {}
cls.params.update(
context_length=32,
patch_length=8,
num_input_channels=3,
patch_stride=8,
d_model=4,
expansion_factor=2,
... | Setup method: Called once before test-cases execution | setUpClass | python | huggingface/transformers | tests/models/patchtsmixer/test_modeling_patchtsmixer.py | https://github.com/huggingface/transformers/blob/master/tests/models/patchtsmixer/test_modeling_patchtsmixer.py | Apache-2.0 |
def test_mismatching_num_image_tokens(self):
"""
Tests that VLMs through an error with explicit message saying what is wrong
when number of images don't match number of image tokens in the text.
Also we need to test multi-image cases when one prompt has multiple image tokens.
"""... |
Tests that VLMs through an error with explicit message saying what is wrong
when number of images don't match number of image tokens in the text.
Also we need to test multi-image cases when one prompt has multiple image tokens.
| test_mismatching_num_image_tokens | python | huggingface/transformers | tests/models/qwen2_vl/test_modeling_qwen2_vl.py | https://github.com/huggingface/transformers/blob/master/tests/models/qwen2_vl/test_modeling_qwen2_vl.py | Apache-2.0 |
def test_forward_with_rope_deltas_cached(self):
"""
Tests that Qwen2-VL computes new rope deltas every forward pass with new set of inputs.
Rope deltas are cached when we generate and re-used for decoding phase, byt are not reset
automatically after generation ends. See https://github.co... |
Tests that Qwen2-VL computes new rope deltas every forward pass with new set of inputs.
Rope deltas are cached when we generate and re-used for decoding phase, byt are not reset
automatically after generation ends. See https://github.com/huggingface/transformers/pull/36013 for more
| test_forward_with_rope_deltas_cached | python | huggingface/transformers | tests/models/qwen2_vl/test_modeling_qwen2_vl.py | https://github.com/huggingface/transformers/blob/master/tests/models/qwen2_vl/test_modeling_qwen2_vl.py | Apache-2.0 |
def test_create_position_ids_respects_padding_index(self):
"""This is a regression test for https://github.com/huggingface/transformers/issues/1761
The position ids should be masked with the embedding object's padding index. Therefore, the
first available non-padding position index is RobertaEm... | This is a regression test for https://github.com/huggingface/transformers/issues/1761
The position ids should be masked with the embedding object's padding index. Therefore, the
first available non-padding position index is RobertaEmbeddings.padding_idx + 1
| test_create_position_ids_respects_padding_index | python | huggingface/transformers | tests/models/roberta/test_modeling_roberta.py | https://github.com/huggingface/transformers/blob/master/tests/models/roberta/test_modeling_roberta.py | Apache-2.0 |
def test_create_position_ids_respects_padding_index(self):
"""This is a regression test for https://github.com/huggingface/transformers/issues/1761
The position ids should be masked with the embedding object's padding index. Therefore, the
first available non-padding position index is RobertaPr... | This is a regression test for https://github.com/huggingface/transformers/issues/1761
The position ids should be masked with the embedding object's padding index. Therefore, the
first available non-padding position index is RobertaPreLayerNormEmbeddings.padding_idx + 1
| test_create_position_ids_respects_padding_index | python | huggingface/transformers | tests/models/roberta_prelayernorm/test_modeling_roberta_prelayernorm.py | https://github.com/huggingface/transformers/blob/master/tests/models/roberta_prelayernorm/test_modeling_roberta_prelayernorm.py | Apache-2.0 |
def test_rle_encoding(self):
"""
Test the run-length encoding function.
"""
# Test that a mask of all zeros returns a single run [height * width].
input_mask = torch.zeros((1, 2, 2), dtype=torch.long) # shape: 1 x 2 x 2
rle = _mask_to_rle_pytorch(input_mask)
sel... |
Test the run-length encoding function.
| test_rle_encoding | python | huggingface/transformers | tests/models/sam/test_processor_sam.py | https://github.com/huggingface/transformers/blob/master/tests/models/sam/test_processor_sam.py | Apache-2.0 |
def test_batching_equivalence(self):
"""
Overwriting ModelTesterMixin.test_batching_equivalence since SuperGlue returns `matching_scores` tensors full of
zeros which causes the test to fail, because cosine_similarity of two zero tensors is 0.
Discussed here : https://github.com/huggingfa... |
Overwriting ModelTesterMixin.test_batching_equivalence since SuperGlue returns `matching_scores` tensors full of
zeros which causes the test to fail, because cosine_similarity of two zero tensors is 0.
Discussed here : https://github.com/huggingface/transformers/pull/29886#issuecomment-24815394... | test_batching_equivalence | python | huggingface/transformers | tests/models/superglue/test_modeling_superglue.py | https://github.com/huggingface/transformers/blob/master/tests/models/superglue/test_modeling_superglue.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.