/
usr
/
local
/
lib
/
python3.6
/
site-packages
/
transformers
/
/usr/local/lib/python3.6/site-packages/transformers
mkdir
upload
Name
Size
Mode
Actions
benchmark/
-
0755
rm
commands/
-
0755
rm
data/
-
0755
rm
models/
-
0755
rm
onnx/
-
0755
rm
pipelines/
-
0755
rm
sagemaker/
-
0755
rm
utils/
-
0755
rm
__pycache__/
-
0755
rm
activations.py
6612
0644
edit
dl
rm
activations_tf.py
4268
0644
edit
dl
rm
configuration_utils.py
46765
0644
edit
dl
rm
convert_graph_to_onnx.py
19575
0644
edit
dl
rm
convert_pytorch_checkpoint_to_tf2.py
16640
0644
edit
dl
rm
convert_slow_tokenizer.py
37626
0644
edit
dl
rm
convert_slow_tokenizers_checkpoints_to_fast.py
4954
0644
edit
dl
rm
convert_tf_hub_seq_to_seq_bert_to_pytorch.py
2899
0644
edit
dl
rm
debug_utils.py
12887
0644
edit
dl
rm
deepspeed.py
18883
0644
edit
dl
rm
dependency_versions_check.py
1767
0644
edit
dl
rm
dependency_versions_table.py
2390
0644
edit
dl
rm
dynamic_module_utils.py
19306
0644
edit
dl
rm
feature_extraction_sequence_utils.py
18074
0644
edit
dl
rm
feature_extraction_utils.py
26768
0644
edit
dl
rm
file_utils.py
3930
0644
edit
dl
rm
generation_beam_constraints.py
19078
0644
edit
dl
rm
generation_beam_search.py
40145
0644
edit
dl
rm
generation_flax_logits_process.py
10879
0644
edit
dl
rm
generation_flax_utils.py
38708
0644
edit
dl
rm
generation_logits_process.py
30336
0644
edit
dl
rm
generation_stopping_criteria.py
5509
0644
edit
dl
rm
generation_tf_logits_process.py
17503
0644
edit
dl
rm
generation_tf_utils.py
130671
0644
edit
dl
rm
generation_utils.py
177118
0644
edit
dl
rm
hf_argparser.py
11901
0644
edit
dl
rm
image_utils.py
12860
0644
edit
dl
rm
integrations.py
40203
0644
edit
dl
rm
keras_callbacks.py
18902
0644
edit
dl
rm
modelcard.py
35278
0644
edit
dl
rm
modeling_flax_outputs.py
35514
0644
edit
dl
rm
modeling_flax_pytorch_utils.py
12296
0644
edit
dl
rm
modeling_flax_utils.py
37661
0644
edit
dl
rm
modeling_outputs.py
60327
0644
edit
dl
rm
modeling_tf_outputs.py
46107
0644
edit
dl
rm
modeling_tf_pytorch_utils.py
19916
0644
edit
dl
rm
modeling_tf_utils.py
100832
0644
edit
dl
rm
modeling_utils.py
137800
0644
edit
dl
rm
optimization.py
27756
0644
edit
dl
rm
optimization_tf.py
15722
0644
edit
dl
rm
processing_utils.py
10559
0644
edit
dl
rm
py.typed
1
0644
edit
dl
rm
pytorch_utils.py
1649
0644
edit
dl
rm
testing_utils.py
48292
0644
edit
dl
rm
tf_utils.py
1568
0644
edit
dl
rm
tokenization_utils.py
39867
0644
edit
dl
rm
tokenization_utils_base.py
170159
0644
edit
dl
rm
tokenization_utils_fast.py
32909
0644
edit
dl
rm
trainer.py
143103
0644
edit
dl
rm
trainer_callback.py
23199
0644
edit
dl
rm
trainer_pt_utils.py
44764
0644
edit
dl
rm
trainer_seq2seq.py
10396
0644
edit
dl
rm
trainer_tf.py
34564
0644
edit
dl
rm
trainer_utils.py
18509
0644
edit
dl
rm
training_args.py
68042
0644
edit
dl
rm
training_args_seq2seq.py
2829
0644
edit
dl
rm
training_args_tf.py
14267
0644
edit
dl
rm
__init__.py
171952
0644
edit
dl
rm
Edit:
/usr/local/lib/python3.6/site-packages/transformers/generation_stopping_criteria.py
(5509B)
import time import warnings from abc import ABC from copy import deepcopy from typing import Optional import torch from .utils import add_start_docstrings STOPPING_CRITERIA_INPUTS_DOCSTRING = r""" Args: input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`): Indices of input sequence tokens in the vocabulary. Indices can be obtained using [`BertTokenizer`]. See [`PreTrainedTokenizer.encode`] and [`PreTrainedTokenizer.__call__`] for details. [What are input IDs?](../glossary#input-ids) scores (`torch.FloatTensor` of shape `(batch_size, config.vocab_size)`): Prediction scores of a language modeling head. These can be scores for each vocabulary token before SoftMax or scores for each vocabulary token after SoftMax. kwargs: Additional stopping criteria specific kwargs. Return: `bool`. `False` indicates we should continue, `True` indicates we should stop. """ class StoppingCriteria(ABC): """Abstract base class for all stopping criteria that can be applied during generation.""" @add_start_docstrings(STOPPING_CRITERIA_INPUTS_DOCSTRING) def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool: raise NotImplementedError("StoppingCriteria needs to be subclassed") class MaxLengthCriteria(StoppingCriteria): """ This class can be used to stop generation whenever the full generated number of tokens exceeds `max_length`. Keep in mind for decoder-only type of transformers, this will include the initial prompted tokens. Args: max_length (`int`): The maximum length that the output sequence can have in number of tokens. """ def __init__(self, max_length: int): self.max_length = max_length @add_start_docstrings(STOPPING_CRITERIA_INPUTS_DOCSTRING) def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool: return input_ids.shape[-1] >= self.max_length class MaxNewTokensCriteria(StoppingCriteria): """ This class can be used to stop generation whenever the generated number of tokens exceeds `max_new_tokens`. Keep in mind for decoder-only type of transformers, this will **not** include the initial prompted tokens. This is very close to `MaxLengthCriteria` but ignores the number of initial tokens. Args: start_length (`int`): The number of initial tokens. max_new_tokens (`int`): The maximum number of tokens to generate. """ def __init__(self, start_length: int, max_new_tokens: int): warnings.warn( "The class `MaxNewTokensCriteria` is deprecated. " f"Please use `MaxLengthCriteria(max_length={start_length + max_new_tokens})` " "with `max_length = start_length + max_new_tokens` instead.", FutureWarning, ) self.start_length = start_length self.max_new_tokens = max_new_tokens self.max_length = start_length + max_new_tokens @add_start_docstrings(STOPPING_CRITERIA_INPUTS_DOCSTRING) def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool: return input_ids.shape[-1] >= self.max_length class MaxTimeCriteria(StoppingCriteria): """ This class can be used to stop generation whenever the full generation exceeds some amount of time. By default, the time will start being counted when you initialize this function. You can override this by passing an `initial_time`. Args: max_time (`float`): The maximum allowed time in seconds for the generation. initial_time (`float`, *optional*, defaults to `time.time()`): The start of the generation allowed time. """ def __init__(self, max_time: float, initial_timestamp: Optional[float] = None): self.max_time = max_time self.initial_timestamp = time.time() if initial_timestamp is None else initial_timestamp @add_start_docstrings(STOPPING_CRITERIA_INPUTS_DOCSTRING) def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool: return time.time() - self.initial_timestamp > self.max_time class StoppingCriteriaList(list): @add_start_docstrings(STOPPING_CRITERIA_INPUTS_DOCSTRING) def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor, **kwargs) -> bool: return any(criteria(input_ids, scores) for criteria in self) @property def max_length(self) -> Optional[int]: for stopping_criterium in self: if isinstance(stopping_criterium, MaxLengthCriteria): return stopping_criterium.max_length elif isinstance(stopping_criterium, MaxNewTokensCriteria): return stopping_criterium.max_length return None def validate_stopping_criteria(stopping_criteria: StoppingCriteriaList, max_length: int) -> StoppingCriteriaList: stopping_max_length = stopping_criteria.max_length new_stopping_criteria = deepcopy(stopping_criteria) if stopping_max_length is not None and stopping_max_length != max_length: warnings.warn("You set different `max_length` for stopping criteria and `max_length` parameter", UserWarning) elif stopping_max_length is None: new_stopping_criteria.append(MaxLengthCriteria(max_length=max_length)) return new_stopping_criteria
Save
cmd:
run