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 assert_tensors_close(a, b, atol=1e-12, prefix=""):
"""If tensors have different shapes, different values or a and b are not 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
rais... | If tensors have different shapes, different values or a and b are not both tensors, raise a nice Assertion error. | assert_tensors_close | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/bart/test_modeling_bart.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/bart/test_modeling_bart.py | Apache-2.0 |
def test_block_sparse_attention_probs(self):
"""
Asserting if outputted attention matrix is similar to hard coded attention matrix
"""
if not self.test_attention_probs:
return
model = BigBirdModel.from_pretrained(
"google/bigbird-roberta-base", attention... |
Asserting if outputted attention matrix is similar to hard coded attention matrix
| test_block_sparse_attention_probs | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/big_bird/test_modeling_big_bird.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/big_bird/test_modeling_big_bird.py | Apache-2.0 |
def test_special_tokens(self):
"""
To reproduce:
$ wget https://github.com/google-research/bigbird/blob/master/bigbird/vocab/gpt2.model?raw=true
$ mv gpt2.model?raw=true gpt2.model
```
import tensorflow_text as tft
import tensorflow as tf
vocab_model_fi... |
To reproduce:
$ wget https://github.com/google-research/bigbird/blob/master/bigbird/vocab/gpt2.model?raw=true
$ mv gpt2.model?raw=true gpt2.model
```
import tensorflow_text as tft
import tensorflow as tf
vocab_model_file = "./gpt2.model"
tokenizer = tf... | test_special_tokens | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/big_bird/test_tokenization_big_bird.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/big_bird/test_tokenization_big_bird.py | Apache-2.0 |
def test_encodings_from_sample_data(self):
"""
Assert that the created tokens are the same than the hard-coded ones
"""
tokenizer = self.get_rust_tokenizer()
INPUT_SENTENCES = ["The quick brown fox</s>", "jumps over the lazy dog</s>"]
TARGET_TOKENS = [[2175, 23714, 73173... |
Assert that the created tokens are the same than the hard-coded ones
| test_encodings_from_sample_data | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/bloom/test_tokenization_bloom.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/bloom/test_tokenization_bloom.py | Apache-2.0 |
def test_encodings_from_xnli_dataset(self):
"""
Tests the tokenizer downloaded from here:
- https://huggingface.co/bigscience/tokenizer/
"""
tokenizer = self.get_rust_tokenizer()
ds = load_dataset("xnli", "all_languages", split="test", streaming=True)
sample_... |
Tests the tokenizer downloaded from here:
- https://huggingface.co/bigscience/tokenizer/
| test_encodings_from_xnli_dataset | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/bloom/test_tokenization_bloom.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/bloom/test_tokenization_bloom.py | Apache-2.0 |
def prepare_inputs(self, equal_resolution=False, numpify=False, torchify=False):
"""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.
"""
assert not (numpify and torchify), "... | 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.
| prepare_inputs | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/clip/test_feature_extraction_clip.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/clip/test_feature_extraction_clip.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 ConditionalDetrFeatureExtractor,
assuming do_resize is set to True with a scalar size.
"""
if not batched:
image = image_input... |
This function computes the expected height and width when providing images to ConditionalDetrFeatureExtractor,
assuming do_resize is set to True with a scalar size.
| get_expected_values | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/conditional_detr/test_feature_extraction_conditional_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/conditional_detr/test_feature_extraction_conditional_detr.py | Apache-2.0 |
def test_create_position_ids_respects_padding_index(self):
"""Ensure that the default position ids only assign a sequential . 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. Theref... | Ensure that the default position ids only assign a sequential . 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 Data2Ve... | test_create_position_ids_respects_padding_index | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/data2vec/test_modeling_data2vec_text.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/data2vec/test_modeling_data2vec_text.py | Apache-2.0 |
def test_autoregressive_prediction(self):
"""
An integration test that performs autoregressive prediction of state, action and return
from a sequence of state, actions and returns. Test is performed over two timesteps.
"""
NUM_STEPS = 2 # number of steps of autoregressive pred... |
An integration test that performs autoregressive prediction of state, action and return
from a sequence of state, actions and returns. Test is performed over two timesteps.
| test_autoregressive_prediction | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/decision_transformer/test_modeling_decision_transformer.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/decision_transformer/test_modeling_decision_transformer.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 DeformableDetrFeatureExtractor,
assuming do_resize is set to True with a scalar size.
"""
if not batched:
image = image_inputs... |
This function computes the expected height and width when providing images to DeformableDetrFeatureExtractor,
assuming do_resize is set to True with a scalar size.
| get_expected_values | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/deformable_detr/test_feature_extraction_deformable_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/deformable_detr/test_feature_extraction_deformable_detr.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 DetrFeatureExtractor,
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 DetrFeatureExtractor,
assuming do_resize is set to True with a scalar size.
| get_expected_values | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/detr/test_feature_extraction_detr.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/detr/test_feature_extraction_detr.py | Apache-2.0 |
def check_pt_tf_equivalence(self, tf_model, pt_model, tf_inputs_dict):
"""Wrap `check_pt_tf_models` to further check PT -> TF again"""
self.check_pt_tf_models(tf_model, pt_model, tf_inputs_dict)
# PT -> TF
with tempfile.TemporaryDirectory() as tmpdirname:
pt_model.save_pret... | Wrap `check_pt_tf_models` to further check PT -> TF again | check_pt_tf_equivalence | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py | Apache-2.0 |
def check_pt_to_tf_equivalence(self, config, decoder_config, tf_inputs_dict):
"""EncoderDecoderModel requires special way to cross load (PT -> TF)"""
encoder_decoder_config = EncoderDecoderConfig.from_encoder_decoder_configs(config, decoder_config)
# Output all for aggressive testing
en... | EncoderDecoderModel requires special way to cross load (PT -> TF) | check_pt_to_tf_equivalence | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py | Apache-2.0 |
def check_tf_to_pt_equivalence(self, config, decoder_config, tf_inputs_dict):
"""EncoderDecoderModel requires special way to cross load (TF -> PT)"""
encoder_decoder_config = EncoderDecoderConfig.from_encoder_decoder_configs(config, decoder_config)
# Output all for aggressive testing
en... | EncoderDecoderModel requires special way to cross load (TF -> PT) | check_tf_to_pt_equivalence | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/encoder_decoder/test_modeling_tf_encoder_decoder.py | Apache-2.0 |
def test_create_position_ids_respects_padding_index(self):
"""Ensure that the default position ids only assign a sequential . 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. Theref... | Ensure that the default position ids only assign a sequential . 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 EsmEmbe... | test_create_position_ids_respects_padding_index | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/esm/test_modeling_esm.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/esm/test_modeling_esm.py | Apache-2.0 |
def test_inference_for_masked_lm(self):
"""
For comparison:
1. Modify the pre-training model `__call__` to skip computing metrics and return masked_lm_output like so:
```
...
sequence_output, pooled_output = EncoderModel(
self.config, random_seed=s... |
For comparison:
1. Modify the pre-training model `__call__` to skip computing metrics and return masked_lm_output like so:
```
...
sequence_output, pooled_output = EncoderModel(
self.config, random_seed=self.random_seed, name="encoder")(
i... | test_inference_for_masked_lm | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/fnet/test_modeling_fnet.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/fnet/test_modeling_fnet.py | Apache-2.0 |
def test_online_tokenizer_config(self):
"""this just tests that the online tokenizer files get correctly fetched and
loaded via its tokenizer_config.json and it's not slow so it's run by normal CI
"""
tokenizer = FSMTTokenizer.from_pretrained(FSMT_TINY2)
self.assertListEqual([tok... | this just tests that the online tokenizer files get correctly fetched and
loaded via its tokenizer_config.json and it's not slow so it's run by normal CI
| test_online_tokenizer_config | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/fsmt/test_tokenization_fsmt.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/fsmt/test_tokenization_fsmt.py | Apache-2.0 |
def test_full_tokenizer(self):
"""Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt"""
tokenizer = FSMTTokenizer(self.langs, self.src_vocab_file, self.tgt_vocab_file, self.merges_file)
text = "lower"
bpe_tokens = ["low", "er</w>"]
tokens = tokenizer.... | Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt | test_full_tokenizer | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/fsmt/test_tokenization_fsmt.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/fsmt/test_tokenization_fsmt.py | Apache-2.0 |
def test_lm_generate_distilgpt2_left_padding(self):
"""Tests that the generated text is the same, regarless of left padding"""
model = TFGPT2LMHeadModel.from_pretrained("distilgpt2")
tokenizer = GPT2Tokenizer.from_pretrained("distilgpt2")
tokenizer.pad_token = tokenizer.eos_token
... | Tests that the generated text is the same, regarless of left padding | test_lm_generate_distilgpt2_left_padding | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/gpt2/test_modeling_tf_gpt2.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/gpt2/test_modeling_tf_gpt2.py | Apache-2.0 |
def test_create_position_ids_respects_padding_index(self):
"""Ensure that the default position ids only assign a sequential . 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. Theref... | Ensure that the default position ids only assign a sequential . 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 IBertEm... | test_create_position_ids_respects_padding_index | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/ibert/test_modeling_ibert.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/ibert/test_modeling_ibert.py | Apache-2.0 |
def test_padding_to_max_length(self):
"""We keep this test for backward compatibility but it should be removed when `pad_to_max_length` will be deprecated"""
tokenizers = self.get_tokenizers(do_lower_case=False)
for tokenizer in tokenizers:
with self.subTest(f"{tokenizer.__class__.__... | We keep this test for backward compatibility but it should be removed when `pad_to_max_length` will be deprecated | test_padding_to_max_length | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/layoutlmv2/test_tokenization_layoutlmv2.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/layoutlmv2/test_tokenization_layoutlmv2.py | Apache-2.0 |
def test_batch_encode_dynamic_overflowing(self):
"""
When calling batch_encode with multiple sequences, it can return different number of
overflowing encoding for each sequence:
[
Sequence 1: [Encoding 1, Encoding 2],
Sequence 2: [Encoding 1],
Sequence 3: [E... |
When calling batch_encode with multiple sequences, it can return different number of
overflowing encoding for each sequence:
[
Sequence 1: [Encoding 1, Encoding 2],
Sequence 2: [Encoding 1],
Sequence 3: [Encoding 1, Encoding 2, ... Encoding N]
]
Thi... | test_batch_encode_dynamic_overflowing | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/layoutlmv2/test_tokenization_layoutlmv2.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/layoutlmv2/test_tokenization_layoutlmv2.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 MaskFormerFeatureExtractor,
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 MaskFormerFeatureExtractor,
assuming do_resize is set to True with a scalar size.
| get_expected_values | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/maskformer/test_feature_extraction_maskformer.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/maskformer/test_feature_extraction_maskformer.py | Apache-2.0 |
def model(self):
"""Only load the model if needed."""
model = MBartForConditionalGeneration.from_pretrained(self.checkpoint_name).to(torch_device)
if "cuda" in torch_device:
model = model.half()
return model | Only load the model if needed. | model | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/mbart/test_modeling_mbart.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/mbart/test_modeling_mbart.py | Apache-2.0 |
def test_small_integration_test(self):
"""
For comparision 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 comparision 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.MtfMod... | test_small_integration_test | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/mt5/test_modeling_flax_mt5.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/mt5/test_modeling_flax_mt5.py | Apache-2.0 |
def test_small_integration_test(self):
"""
For comparision 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 comparision 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.MtfMod... | test_small_integration_test | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/mt5/test_modeling_tf_mt5.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/mt5/test_modeling_tf_mt5.py | Apache-2.0 |
def test_equivalence_to_orig_tokenizer(self):
"""
To run with original TF tokenizer:
!wget https://github.com/google-research/bigbird/raw/master/bigbird/vocab/pegasus.model
!pip install tensorflow-text
import tensorflow.compat.v2 as tf
import tensorflow_text as tft
... |
To run with original TF tokenizer:
!wget https://github.com/google-research/bigbird/raw/master/bigbird/vocab/pegasus.model
!pip install tensorflow-text
import tensorflow.compat.v2 as tf
import tensorflow_text as tft
VOCAB_FILE = "./pegasus.model"
tf.enable_v2... | test_equivalence_to_orig_tokenizer | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/pegasus/test_tokenization_pegasus.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/pegasus/test_tokenization_pegasus.py | Apache-2.0 |
def require_retrieval(test_case):
"""
Decorator marking a test that requires a set of dependencies necessary for pefrorm retrieval with
[`RagRetriever`].
These tests are skipped when respective libraries are not installed.
"""
if not (is_torch_available() and is_datasets_available() and is_fai... |
Decorator marking a test that requires a set of dependencies necessary for pefrorm retrieval with
[`RagRetriever`].
These tests are skipped when respective libraries are not installed.
| require_retrieval | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/rag/test_modeling_rag.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/rag/test_modeling_rag.py | Apache-2.0 |
def test_create_position_ids_respects_padding_index(self):
"""Ensure that the default position ids only assign a sequential . 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. Theref... | Ensure that the default position ids only assign a sequential . 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 Roberta... | test_create_position_ids_respects_padding_index | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/roberta/test_modeling_roberta.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/roberta/test_modeling_roberta.py | Apache-2.0 |
def test_small_integration_test(self):
"""
For comparision run:
>>> import t5 # pip install t5==0.7.1
>>> from t5.data.sentencepiece_vocabulary import SentencePieceVocabulary
>>> path_to_mtf_small_t5_checkpoint = '<fill_in>'
>>> path_to_mtf_small_spm_model_path = '<fill... |
For comparision run:
>>> import t5 # pip install t5==0.7.1
>>> from t5.data.sentencepiece_vocabulary import SentencePieceVocabulary
>>> path_to_mtf_small_t5_checkpoint = '<fill_in>'
>>> path_to_mtf_small_spm_model_path = '<fill_in>'
>>> t5_model = t5.models.MtfModel(mo... | test_small_integration_test | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/t5/test_modeling_flax_t5.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/t5/test_modeling_flax_t5.py | Apache-2.0 |
def test_small_v1_1_integration_test(self):
"""
For comparision run:
>>> import t5 # pip install t5==0.7.1
>>> from t5.data.sentencepiece_vocabulary import SentencePieceVocabulary
>>> path_to_mtf_small_t5_v1_1_checkpoint = '<fill_in>'
>>> path_to_mtf_small_spm_model_pat... |
For comparision run:
>>> import t5 # pip install t5==0.7.1
>>> from t5.data.sentencepiece_vocabulary import SentencePieceVocabulary
>>> path_to_mtf_small_t5_v1_1_checkpoint = '<fill_in>'
>>> path_to_mtf_small_spm_model_path = '<fill_in>'
>>> t5_model = t5.models.MtfMod... | test_small_v1_1_integration_test | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/t5/test_modeling_flax_t5.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/t5/test_modeling_flax_t5.py | Apache-2.0 |
def test_small_byt5_integration_test(self):
"""
For comparision run:
>>> import t5 # pip install t5==0.9.1
>>> path_to_byt5_small_checkpoint = '<fill_in>'
>>> t5_model = t5.models.MtfModel(model_dir=path_to_tf_checkpoint, batch_size=1, tpu=None)
>>> vocab = t5.data.Byte... |
For comparision run:
>>> import t5 # pip install t5==0.9.1
>>> path_to_byt5_small_checkpoint = '<fill_in>'
>>> t5_model = t5.models.MtfModel(model_dir=path_to_tf_checkpoint, batch_size=1, tpu=None)
>>> vocab = t5.data.ByteVocabulary()
>>> score = t5_model.score(inputs=... | test_small_byt5_integration_test | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/t5/test_modeling_flax_t5.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/t5/test_modeling_flax_t5.py | Apache-2.0 |
def test_small_v1_1_integration_test(self):
"""
For comparision run:
>>> import t5 # pip install t5==0.7.1
>>> from t5.data.sentencepiece_vocabulary import SentencePieceVocabulary
>>> path_to_mtf_small_t5_v1.1_checkpoint = '<fill_in>'
>>> path_to_mtf_small_spm_model_pat... |
For comparision run:
>>> import t5 # pip install t5==0.7.1
>>> from t5.data.sentencepiece_vocabulary import SentencePieceVocabulary
>>> path_to_mtf_small_t5_v1.1_checkpoint = '<fill_in>'
>>> path_to_mtf_small_spm_model_path = '<fill_in>'
>>> t5_model = t5.models.MtfMod... | test_small_v1_1_integration_test | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/t5/test_modeling_tf_t5.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/t5/test_modeling_tf_t5.py | Apache-2.0 |
def _prepare_tables(self):
"""Prepares two tables, both with three distinct rows.
The first table has two columns:
1.0, 2.0 | 3.0
2.0, 0.0 | 1.0
1.0, 3.0 | 4.0
The second table has three columns:
1.0 | 2.0 | 3.0
2.0 | 0.0 | 1.0
1.0 | 3.0 | 4.0
... | Prepares two tables, both with three distinct rows.
The first table has two columns:
1.0, 2.0 | 3.0
2.0, 0.0 | 1.0
1.0, 3.0 | 4.0
The second table has three columns:
1.0 | 2.0 | 3.0
2.0 | 0.0 | 1.0
1.0 | 3.0 | 4.0
Returns:
SegmentedTensors ... | _prepare_tables | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/tapas/test_modeling_tapas.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/tapas/test_modeling_tapas.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 ViltFeatureExtractor,
assuming do_resize is set to True with a scalar size and size_divisor.
"""
if not batched:
image = image... |
This function computes the expected height and width when providing images to ViltFeatureExtractor,
assuming do_resize is set to True with a scalar size and size_divisor.
| get_expected_values | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/vilt/test_feature_extraction_vilt.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/vilt/test_feature_extraction_vilt.py | Apache-2.0 |
def test_create_position_ids_respects_padding_index(self):
"""Ensure that the default position ids only assign a sequential . 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. Theref... | Ensure that the default position ids only assign a sequential . 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 XLMRobe... | test_create_position_ids_respects_padding_index | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.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 YolosFeatureExtractor,
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 YolosFeatureExtractor,
assuming do_resize is set to True with a scalar size.
| get_expected_values | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/models/yolos/test_feature_extraction_yolos.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/models/yolos/test_feature_extraction_yolos.py | Apache-2.0 |
def test_framework_provided(self):
"""
Ensure the that the provided framework is returned.
"""
mock_framework = "mock_framework"
# Framework provided - return whatever the user provides
result = FeaturesManager.determine_framework(self.test_model, mock_framework)
... |
Ensure the that the provided framework is returned.
| test_framework_provided | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/onnx/test_features.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/onnx/test_features.py | Apache-2.0 |
def test_checkpoint_provided(self):
"""
Ensure that the determined framework is the one used for the local checkpoint.
For the functionality to execute, local checkpoints are provided but framework is not.
"""
# PyTorch checkpoint
with TemporaryDirectory() as local_pt_ck... |
Ensure that the determined framework is the one used for the local checkpoint.
For the functionality to execute, local checkpoints are provided but framework is not.
| test_checkpoint_provided | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/onnx/test_features.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/onnx/test_features.py | Apache-2.0 |
def test_from_environment(self):
"""
Ensure that the determined framework is the one available in the environment.
For the functionality to execute, framework and local checkpoints are not provided.
"""
# Framework not provided, hub model is used (no local checkpoint directory)
... |
Ensure that the determined framework is the one available in the environment.
For the functionality to execute, framework and local checkpoints are not provided.
| test_from_environment | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/onnx/test_features.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/onnx/test_features.py | Apache-2.0 |
def test_infer_dynamic_axis_pytorch(self):
"""
Validate the dynamic axis generated for each parameters are correct
"""
from transformers import BertModel
model = BertModel(BertConfig.from_pretrained("lysandre/tiny-bert-random"))
tokenizer = BertTokenizerFast.from_pretrai... |
Validate the dynamic axis generated for each parameters are correct
| test_infer_dynamic_axis_pytorch | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/onnx/test_onnx.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/onnx/test_onnx.py | Apache-2.0 |
def test_ensure_valid_input(self):
"""
Validate parameters are correctly exported
GPT2 has "past" parameter in the middle of input_ids, token_type_ids and attention_mask.
ONNX doesn't support export with a dictionary, only a tuple. Thus we need to ensure we remove
token_type_ids ... |
Validate parameters are correctly exported
GPT2 has "past" parameter in the middle of input_ids, token_type_ids and attention_mask.
ONNX doesn't support export with a dictionary, only a tuple. Thus we need to ensure we remove
token_type_ids and attention_mask for now to not having a Non... | test_ensure_valid_input | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/onnx/test_onnx.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/onnx/test_onnx.py | Apache-2.0 |
def test_compute_effective_axis_dimension(self):
"""
When exporting ONNX model with dynamic axis (batch or sequence) we set batch_size and/or sequence_length = -1.
We cannot generate an effective tensor with axis dim == -1, so we trick by using some "fixed" values
(> 1 to avoid ONNX sque... |
When exporting ONNX model with dynamic axis (batch or sequence) we set batch_size and/or sequence_length = -1.
We cannot generate an effective tensor with axis dim == -1, so we trick by using some "fixed" values
(> 1 to avoid ONNX squeezing the axis).
This test ensure we are correctly ... | test_compute_effective_axis_dimension | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/onnx/test_onnx_v2.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/onnx/test_onnx_v2.py | Apache-2.0 |
def test_flatten_output_collection_property(self):
"""
This test ensures we correctly flatten nested collection such as the one we use when returning past_keys.
past_keys = Tuple[Tuple]
ONNX exporter will export nested collections as ${collection_name}.${level_idx_0}.${level_idx_1}...${... |
This test ensures we correctly flatten nested collection such as the one we use when returning past_keys.
past_keys = Tuple[Tuple]
ONNX exporter will export nested collections as ${collection_name}.${level_idx_0}.${level_idx_1}...${idx_n}
| test_flatten_output_collection_property | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/onnx/test_onnx_v2.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/onnx/test_onnx_v2.py | Apache-2.0 |
def test_use_external_data_format(self):
"""
External data format is required only if the serialized size of the parameters if bigger than 2Gb
"""
TWO_GB_LIMIT = EXTERNAL_DATA_FORMAT_SIZE_LIMIT
# No parameters
self.assertFalse(OnnxConfig.use_external_data_format(0))
... |
External data format is required only if the serialized size of the parameters if bigger than 2Gb
| test_use_external_data_format | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/onnx/test_onnx_v2.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/onnx/test_onnx_v2.py | Apache-2.0 |
def test_use_past(self):
"""
Ensure the use_past variable is correctly being set
"""
for name, config in OnnxConfigWithPastTestCaseV2.SUPPORTED_WITH_PAST_CONFIGS:
with self.subTest(name):
self.assertFalse(
OnnxConfigWithPast.from_model_conf... |
Ensure the use_past variable is correctly being set
| test_use_past | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/onnx/test_onnx_v2.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/onnx/test_onnx_v2.py | Apache-2.0 |
def test_values_override(self):
"""
Ensure the use_past variable correctly set the `use_cache` value in model's configuration
"""
for name, config in OnnxConfigWithPastTestCaseV2.SUPPORTED_WITH_PAST_CONFIGS:
with self.subTest(name):
# without past
... |
Ensure the use_past variable correctly set the `use_cache` value in model's configuration
| test_values_override | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/onnx/test_onnx_v2.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/onnx/test_onnx_v2.py | Apache-2.0 |
def test_training(self):
"""Tests export of StableDropout in training mode."""
devnull = open(os.devnull, "wb")
# drop_prob must be > 0 for the test to be meaningful
sd = modeling_deberta.StableDropout(0.1)
# Avoid warnings in training mode
do_constant_folding = False
... | Tests export of StableDropout in training mode. | test_training | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/onnx/test_onnx_v2.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/onnx/test_onnx_v2.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 | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/pipelines/test_pipelines_automatic_speech_recognition.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/pipelines/test_pipelines_automatic_speech_recognition.py | Apache-2.0 |
def analyze_directory(
self,
directory: Path,
identifier: Union[str, None] = None,
ignore_files: Union[List[str], None] = None,
n_identifier: Union[str, List[str], None] = None,
only_modules: bool = True,
):
"""
Runs through the specific directory, loo... |
Runs through the specific directory, looking for the files identified with `identifier`. Executes
the doctests in those files
Args:
directory (`Path`): Directory containing the files
identifier (`str`): Will parse files containing this
ignore_files (`List[st... | analyze_directory | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/tests/utils/test_doc_samples.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/tests/utils/test_doc_samples.py | Apache-2.0 |
def find_code_in_transformers(object_name):
"""Find and return the code source code of `object_name`."""
parts = object_name.split(".")
i = 0
# First let's find the module where our object lives.
module = parts[i]
while i < len(parts) and not os.path.isfile(os.path.join(TRANSFORMERS_PATH, f"{mo... | Find and return the code source code of `object_name`. | find_code_in_transformers | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_copies.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_copies.py | Apache-2.0 |
def blackify(code):
"""
Applies the black part of our `make style` command to `code`.
"""
has_indent = len(get_indent(code)) > 0
if has_indent:
code = f"class Bla:\n{code}"
mode = black.Mode(target_versions={black.TargetVersion.PY35}, line_length=119, preview=True)
result = black.for... |
Applies the black part of our `make style` command to `code`.
| blackify | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_copies.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_copies.py | Apache-2.0 |
def is_copy_consistent(filename, overwrite=False):
"""
Check if the code commented as a copy in `filename` matches the original.
Return the differences or overwrites the content depending on `overwrite`.
"""
with open(filename, "r", encoding="utf-8", newline="\n") as f:
lines = f.readlines(... |
Check if the code commented as a copy in `filename` matches the original.
Return the differences or overwrites the content depending on `overwrite`.
| is_copy_consistent | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_copies.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_copies.py | Apache-2.0 |
def get_model_list(filename, start_prompt, end_prompt):
"""Extracts the model list from the README."""
with open(os.path.join(REPO_PATH, filename), "r", encoding="utf-8", newline="\n") as f:
lines = f.readlines()
# Find the start of the list.
start_index = 0
while not lines[start_index].star... | Extracts the model list from the README. | get_model_list | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_copies.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_copies.py | Apache-2.0 |
def _find_text_in_file(filename, start_prompt, end_prompt):
"""
Find the text in `filename` between a line beginning with `start_prompt` and before `end_prompt`, removing empty
lines.
"""
with open(filename, "r", encoding="utf-8", newline="\n") as f:
lines = f.readlines()
# Find the star... |
Find the text in `filename` between a line beginning with `start_prompt` and before `end_prompt`, removing empty
lines.
| _find_text_in_file | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_copies.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_copies.py | Apache-2.0 |
def check_model_list_copy(overwrite=False, max_per_line=119):
"""Check the model lists in the README and index.rst are consistent and maybe `overwrite`."""
# Fix potential doc links in the README
with open(os.path.join(REPO_PATH, "README.md"), "r", encoding="utf-8", newline="\n") as f:
readme = f.re... | Check the model lists in the README and index.rst are consistent and maybe `overwrite`. | check_model_list_copy | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_copies.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_copies.py | Apache-2.0 |
def clean_model_doc_toc(model_doc):
"""
Cleans the table of content of the model documentation by removing duplicates and sorting models alphabetically.
"""
counts = defaultdict(int)
for doc in model_doc:
counts[doc["local"]] += 1
duplicates = [key for key, value in counts.items() if val... |
Cleans the table of content of the model documentation by removing duplicates and sorting models alphabetically.
| clean_model_doc_toc | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_doc_toc.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_doc_toc.py | Apache-2.0 |
def find_backend(line):
"""Find one (or multiple) backend in a code line of the init."""
if _re_test_backend.search(line) is None:
return None
backends = [b[0] for b in _re_backend.findall(line)]
backends.sort()
return "_and_".join(backends) | Find one (or multiple) backend in a code line of the init. | find_backend | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_dummies.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_dummies.py | Apache-2.0 |
def read_init():
"""Read the init and extracts PyTorch, TensorFlow, SentencePiece and Tokenizers objects."""
with open(os.path.join(PATH_TO_TRANSFORMERS, "__init__.py"), "r", encoding="utf-8", newline="\n") as f:
lines = f.readlines()
# Get to the point we do the actual imports for type checking
... | Read the init and extracts PyTorch, TensorFlow, SentencePiece and Tokenizers objects. | read_init | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_dummies.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_dummies.py | Apache-2.0 |
def create_dummy_object(name, backend_name):
"""Create the code for the dummy object corresponding to `name`."""
if name.isupper():
return DUMMY_CONSTANT.format(name)
elif name.islower():
return DUMMY_FUNCTION.format(name, backend_name)
else:
return DUMMY_CLASS.format(name, backe... | Create the code for the dummy object corresponding to `name`. | create_dummy_object | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_dummies.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_dummies.py | Apache-2.0 |
def create_dummy_files(backend_specific_objects=None):
"""Create the content of the dummy files."""
if backend_specific_objects is None:
backend_specific_objects = read_init()
# For special correspondence backend to module name as used in the function requires_modulename
dummy_files = {}
fo... | Create the content of the dummy files. | create_dummy_files | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_dummies.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_dummies.py | Apache-2.0 |
def check_dummies(overwrite=False):
"""Check if the dummy files are up to date and maybe `overwrite` with the right content."""
dummy_files = create_dummy_files()
# For special correspondence backend to shortcut as used in utils/dummy_xxx_objects.py
short_names = {"torch": "pt"}
# Locate actual dum... | Check if the dummy files are up to date and maybe `overwrite` with the right content. | check_dummies | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_dummies.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_dummies.py | Apache-2.0 |
def parse_init(init_file):
"""
Read an init_file and parse (per backend) the _import_structure objects defined and the TYPE_CHECKING objects
defined
"""
with open(init_file, "r", encoding="utf-8", newline="\n") as f:
lines = f.readlines()
line_index = 0
while line_index < len(lines)... |
Read an init_file and parse (per backend) the _import_structure objects defined and the TYPE_CHECKING objects
defined
| parse_init | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_inits.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_inits.py | Apache-2.0 |
def analyze_results(import_dict_objects, type_hint_objects):
"""
Analyze the differences between _import_structure objects and TYPE_CHECKING objects found in an init.
"""
def find_duplicates(seq):
return [k for k, v in collections.Counter(seq).items() if v > 1]
if list(import_dict_objects.... |
Analyze the differences between _import_structure objects and TYPE_CHECKING objects found in an init.
| analyze_results | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_inits.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_inits.py | Apache-2.0 |
def check_all_inits():
"""
Check all inits in the transformers repo and raise an error if at least one does not define the same objects in
both halves.
"""
failures = []
for root, _, files in os.walk(PATH_TO_TRANSFORMERS):
if "__init__.py" in files:
fname = os.path.join(root,... |
Check all inits in the transformers repo and raise an error if at least one does not define the same objects in
both halves.
| check_all_inits | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_inits.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_inits.py | Apache-2.0 |
def get_transformers_submodules():
"""
Returns the list of Transformers submodules.
"""
submodules = []
for path, directories, files in os.walk(PATH_TO_TRANSFORMERS):
for folder in directories:
# Ignore private modules
if folder.startswith("_"):
direct... |
Returns the list of Transformers submodules.
| get_transformers_submodules | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_inits.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_inits.py | Apache-2.0 |
def check_model_list():
"""Check the model list inside the transformers library."""
# Get the models from the directory structure of `src/transformers/models/`
models_dir = os.path.join(PATH_TO_TRANSFORMERS, "models")
_models = []
for model in os.listdir(models_dir):
model_dir = os.path.join... | Check the model list inside the transformers library. | check_model_list | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def get_model_modules():
"""Get the model modules inside the transformers library."""
_ignore_modules = [
"modeling_auto",
"modeling_encoder_decoder",
"modeling_marian",
"modeling_mmbt",
"modeling_outputs",
"modeling_retribert",
"modeling_utils",
"... | Get the model modules inside the transformers library. | get_model_modules | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def get_models(module, include_pretrained=False):
"""Get the objects in module that are models."""
models = []
model_classes = (transformers.PreTrainedModel, transformers.TFPreTrainedModel, transformers.FlaxPreTrainedModel)
for attr_name in dir(module):
if not include_pretrained and ("Pretrained... | Get the objects in module that are models. | get_models | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def is_a_private_model(model):
"""Returns True if the model should not be in the main init."""
if model in PRIVATE_MODELS:
return True
# Wrapper, Encoder and Decoder are all privates
if model.endswith("Wrapper"):
return True
if model.endswith("Encoder"):
return True
if m... | Returns True if the model should not be in the main init. | is_a_private_model | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def check_models_are_in_init():
"""Checks all models defined in the library are in the main init."""
models_not_in_init = []
dir_transformers = dir(transformers)
for module in get_model_modules():
models_not_in_init += [
model[0] for model in get_models(module, include_pretrained=Tru... | Checks all models defined in the library are in the main init. | check_models_are_in_init | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def get_model_test_files():
"""Get the model test files.
The returned files should NOT contain the `tests` (i.e. `PATH_TO_TESTS` defined in this script). They will be
considered as paths relative to `tests`. A caller has to use `os.path.join(PATH_TO_TESTS, ...)` to access the files.
"""
_ignore_fi... | Get the model test files.
The returned files should NOT contain the `tests` (i.e. `PATH_TO_TESTS` defined in this script). They will be
considered as paths relative to `tests`. A caller has to use `os.path.join(PATH_TO_TESTS, ...)` to access the files.
| get_model_test_files | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def find_tested_models(test_file):
"""Parse the content of test_file to detect what's in all_model_classes"""
# This is a bit hacky but I didn't find a way to import the test_file as a module and read inside the class
with open(os.path.join(PATH_TO_TESTS, test_file), "r", encoding="utf-8", newline="\n") as ... | Parse the content of test_file to detect what's in all_model_classes | find_tested_models | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def check_models_are_tested(module, test_file):
"""Check models defined in module are tested in test_file."""
# XxxPreTrainedModel are not tested
defined_models = get_models(module)
tested_models = find_tested_models(test_file)
if tested_models is None:
if test_file.replace(os.path.sep, "/")... | Check models defined in module are tested in test_file. | check_models_are_tested | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def check_all_models_are_tested():
"""Check all models are properly tested."""
modules = get_model_modules()
test_files = get_model_test_files()
failures = []
for module in modules:
test_file = [file for file in test_files if f"test_{module.__name__.split('.')[-1]}.py" in file]
if le... | Check all models are properly tested. | check_all_models_are_tested | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def get_all_auto_configured_models():
"""Return the list of all models in at least one auto class."""
result = set() # To avoid duplicates we concatenate all model classes in a set.
if is_torch_available():
for attr_name in dir(transformers.models.auto.modeling_auto):
if attr_name.start... | Return the list of all models in at least one auto class. | get_all_auto_configured_models | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def ignore_unautoclassed(model_name):
"""Rules to determine if `name` should be in an auto class."""
# Special white list
if model_name in IGNORE_NON_AUTO_CONFIGURED:
return True
# Encoder and Decoder should be ignored
if "Encoder" in model_name or "Decoder" in model_name:
return Tru... | Rules to determine if `name` should be in an auto class. | ignore_unautoclassed | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def check_models_are_auto_configured(module, all_auto_models):
"""Check models defined in module are each in an auto class."""
defined_models = get_models(module)
failures = []
for model_name, _ in defined_models:
if model_name not in all_auto_models and not ignore_unautoclassed(model_name):
... | Check models defined in module are each in an auto class. | check_models_are_auto_configured | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def check_all_models_are_auto_configured():
"""Check all models are each in an auto class."""
missing_backends = []
if not is_torch_available():
missing_backends.append("PyTorch")
if not is_tf_available():
missing_backends.append("TensorFlow")
if not is_flax_available():
miss... | Check all models are each in an auto class. | check_all_models_are_auto_configured | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def check_decorator_order(filename):
"""Check that in the test file `filename` the slow decorator is always last."""
with open(filename, "r", encoding="utf-8", newline="\n") as f:
lines = f.readlines()
decorator_before = None
errors = []
for i, line in enumerate(lines):
search = _re_... | Check that in the test file `filename` the slow decorator is always last. | check_decorator_order | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def check_all_decorator_order():
"""Check that in all test files, the slow decorator is always last."""
errors = []
for fname in os.listdir(PATH_TO_TESTS):
if fname.endswith(".py"):
filename = os.path.join(PATH_TO_TESTS, fname)
new_errors = check_decorator_order(filename)
... | Check that in all test files, the slow decorator is always last. | check_all_decorator_order | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def find_all_documented_objects():
"""Parse the content of all doc files to detect which classes and functions it documents"""
documented_obj = []
for doc_file in Path(PATH_TO_DOC).glob("**/*.rst"):
with open(doc_file, "r", encoding="utf-8", newline="\n") as f:
content = f.read()
... | Parse the content of all doc files to detect which classes and functions it documents | find_all_documented_objects | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def ignore_undocumented(name):
"""Rules to determine if `name` should be undocumented."""
# NOT DOCUMENTED ON PURPOSE.
# Constants uppercase are not documented.
if name.isupper():
return True
# PreTrainedModels / Encoders / Decoders / Layers / Embeddings / Attention are not documented.
i... | Rules to determine if `name` should be undocumented. | ignore_undocumented | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def check_all_objects_are_documented():
"""Check all models are properly documented."""
documented_objs = find_all_documented_objects()
modules = transformers._modules
objects = [c for c in dir(transformers) if c not in modules and not c.startswith("_")]
undocumented_objs = [c for c in objects if c ... | Check all models are properly documented. | check_all_objects_are_documented | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def check_model_type_doc_match():
"""Check all doc pages have a corresponding model type."""
model_doc_folder = Path(PATH_TO_DOC) / "model_doc"
model_docs = [m.stem for m in model_doc_folder.glob("*.mdx")]
model_types = list(transformers.models.auto.configuration_auto.MODEL_NAMES_MAPPING.keys())
mo... | Check all doc pages have a corresponding model type. | check_model_type_doc_match | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def is_rst_docstring(docstring):
"""
Returns `True` if `docstring` is written in rst.
"""
if _re_rst_special_words.search(docstring) is not None:
return True
if _re_double_backquotes.search(docstring) is not None:
return True
if _re_rst_example.search(docstring) is not None:
... |
Returns `True` if `docstring` is written in rst.
| is_rst_docstring | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def check_docstrings_are_in_md():
"""Check all docstrings are in md"""
files_with_rst = []
for file in Path(PATH_TO_TRANSFORMERS).glob("**/*.py"):
with open(file, encoding="utf-8") as f:
code = f.read()
docstrings = code.split('"""')
for idx, docstring in enumerate(docst... | Check all docstrings are in md | check_docstrings_are_in_md | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def check_repo_quality():
"""Check all models are properly tested and documented."""
print("Checking all models are included.")
check_model_list()
print("Checking all models are public.")
check_models_are_in_init()
print("Checking all models are properly tested.")
check_all_decorator_order()... | Check all models are properly tested and documented. | check_repo_quality | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_repo.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_repo.py | Apache-2.0 |
def check_model_table(overwrite=False):
"""Check the model table in the index.rst is consistent with the state of the lib and maybe `overwrite`."""
current_table, start_index, end_index, lines = _find_text_in_file(
filename=os.path.join(PATH_TO_DOCS, "index.mdx"),
start_prompt="<!--This table is... | Check the model table in the index.rst is consistent with the state of the lib and maybe `overwrite`. | check_model_table | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_table.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_table.py | Apache-2.0 |
def has_onnx(model_type):
"""
Returns whether `model_type` is supported by ONNX (by checking if there is an ONNX config) or not.
"""
config_mapping = transformers_module.models.auto.configuration_auto.CONFIG_MAPPING
if model_type not in config_mapping:
return False
config = config_mappin... |
Returns whether `model_type` is supported by ONNX (by checking if there is an ONNX config) or not.
| has_onnx | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_table.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_table.py | Apache-2.0 |
def get_onnx_model_list():
"""
Return the list of models supporting ONNX.
"""
config_mapping = transformers_module.models.auto.configuration_auto.CONFIG_MAPPING
model_names = config_mapping = transformers_module.models.auto.configuration_auto.MODEL_NAMES_MAPPING
onnx_model_types = [model_type fo... |
Return the list of models supporting ONNX.
| get_onnx_model_list | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_table.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_table.py | Apache-2.0 |
def check_onnx_model_list(overwrite=False):
"""Check the model list in the serialization.mdx is consistent with the state of the lib and maybe `overwrite`."""
current_list, start_index, end_index, lines = _find_text_in_file(
filename=os.path.join(PATH_TO_DOCS, "serialization.mdx"),
start_prompt=... | Check the model list in the serialization.mdx is consistent with the state of the lib and maybe `overwrite`. | check_onnx_model_list | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/check_table.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/check_table.py | Apache-2.0 |
def get_processor_types_from_config_class(config_class, allowed_mappings=None):
"""Return a tuple of processors for `config_class`.
We use `tuple` here to include (potentially) both slow & fast tokenizers.
"""
if allowed_mappings is None:
allowed_mappings = ["processor", "tokenizer", "feature_e... | Return a tuple of processors for `config_class`.
We use `tuple` here to include (potentially) both slow & fast tokenizers.
| get_processor_types_from_config_class | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/create_dummy_models.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/create_dummy_models.py | Apache-2.0 |
def get_architectures_from_config_class(config_class, arch_mappings):
"""Return a tuple of all possible architectures attributed to a configuration class `config_class`.
For example, BertConfig -> [BertModel, BertForMaskedLM, ..., BertForQuestionAnswering].
"""
# A model architecture could appear in se... | Return a tuple of all possible architectures attributed to a configuration class `config_class`.
For example, BertConfig -> [BertModel, BertForMaskedLM, ..., BertForQuestionAnswering].
| get_architectures_from_config_class | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/create_dummy_models.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/create_dummy_models.py | Apache-2.0 |
def get_config_class_from_processor_class(processor_class):
"""Get the config class from a processor class.
Some config/model classes use tokenizers/feature_extractors from other models. For example, `GPT-J` uses
`GPT2Tokenizer`. If no checkpoint is found for a config class, or a checkpoint is found withou... | Get the config class from a processor class.
Some config/model classes use tokenizers/feature_extractors from other models. For example, `GPT-J` uses
`GPT2Tokenizer`. If no checkpoint is found for a config class, or a checkpoint is found without necessary file(s) to
create the processor for `processor_clas... | get_config_class_from_processor_class | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/create_dummy_models.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/create_dummy_models.py | Apache-2.0 |
def build_processor(config_class, processor_class):
"""Create a processor for `processor_class`.
If a processor is not able to be built with the original arguments, this method tries to change the arguments and
call itself recursively, by inferring a new `config_class` or a new `processor_class` from anoth... | Create a processor for `processor_class`.
If a processor is not able to be built with the original arguments, this method tries to change the arguments and
call itself recursively, by inferring a new `config_class` or a new `processor_class` from another one, in order to
find a checkpoint containing the ne... | build_processor | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/create_dummy_models.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/create_dummy_models.py | Apache-2.0 |
def get_tiny_config(config_class):
"""Retrieve a tiny configuration from `config_class` using each model's `ModelTester`.
Args:
config_class: Subclass of `PreTrainedConfig`.
Returns:
An instance of `config_class` with tiny hyperparameters
"""
model_type = config_class.model_type
... | Retrieve a tiny configuration from `config_class` using each model's `ModelTester`.
Args:
config_class: Subclass of `PreTrainedConfig`.
Returns:
An instance of `config_class` with tiny hyperparameters
| get_tiny_config | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/create_dummy_models.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/create_dummy_models.py | Apache-2.0 |
def convert_processors(processors, tiny_config, output_folder, result):
"""Change a processor to work with smaller inputs.
For tokenizers, we try to reduce their vocabulary size.
For feature extractor, we use smaller image size or change
other attributes using the values from `tiny_config`. See `conve... | Change a processor to work with smaller inputs.
For tokenizers, we try to reduce their vocabulary size.
For feature extractor, we use smaller image size or change
other attributes using the values from `tiny_config`. See `convert_feature_extractor`.
This method should not fail: we catch the errors an... | convert_processors | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/create_dummy_models.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/create_dummy_models.py | Apache-2.0 |
def get_checkpoint_dir(output_dir, model_arch):
"""Get framework-agnostic architecture name. Used to save all PT/TF/Flax models into the same directory."""
arch_name = model_arch.__name__
if arch_name.startswith("TF"):
arch_name = arch_name[2:]
elif arch_name.startswith("Flax"):
arch_na... | Get framework-agnostic architecture name. Used to save all PT/TF/Flax models into the same directory. | get_checkpoint_dir | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/create_dummy_models.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/create_dummy_models.py | Apache-2.0 |
def build_model(model_arch, tiny_config, output_dir):
"""Create and save a model for `model_arch`.
Also copy the set of processors to each model (under the same model type) output folder.
"""
checkpoint_dir = get_checkpoint_dir(output_dir, model_arch)
processor_output_dir = os.path.join(output_di... | Create and save a model for `model_arch`.
Also copy the set of processors to each model (under the same model type) output folder.
| build_model | python | FMInference/FlexLLMGen | benchmark/third_party/transformers/utils/create_dummy_models.py | https://github.com/FMInference/FlexLLMGen/blob/master/benchmark/third_party/transformers/utils/create_dummy_models.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.