text
stringlengths
1
1.02k
class_index
int64
0
10.8k
source
stringlengths
85
188
else: text = text_or_text_and_label added_labels.add(label) examples.append(InputExample(guid=guid, text_a=text, text_b=None, label=label))
10,649
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/data/processors/utils.py
# Update examples if overwrite_examples: self.examples = examples else: self.examples.extend(examples) # Update labels if overwrite_labels: self.labels = list(added_labels) else: self.labels = list(set(self.labels).union(added_labe...
10,649
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/data/processors/utils.py
Args: tokenizer: Instance of a tokenizer that will tokenize the examples max_length: Maximum example length pad_on_left: If set to `True`, the examples will be padded on the left rather than on the right (default) pad_token: Padding token mask_padding_with_zer...
10,649
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/data/processors/utils.py
all_input_ids = [] for ex_index, example in enumerate(self.examples): if ex_index % 10000 == 0: logger.info(f"Tokenizing example {ex_index}") input_ids = tokenizer.encode( example.text_a, add_special_tokens=True, max_length...
10,649
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/data/processors/utils.py
# Zero-pad up to the sequence length. padding_length = batch_length - len(input_ids) if pad_on_left: input_ids = ([pad_token] * padding_length) + input_ids attention_mask = ([0 if mask_padding_with_zero else 1] * padding_length) + attention_mask else: ...
10,649
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/data/processors/utils.py
if self.mode == "classification": label = label_map[example.label] elif self.mode == "regression": label = float(example.label) else: raise ValueError(self.mode) if ex_index < 5 and self.verbose: logger.info("*** Exampl...
10,649
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/data/processors/utils.py
if return_tensors is None: return features elif return_tensors == "tf": if not is_tf_available(): raise RuntimeError("return_tensors set to 'tf' but TensorFlow 2.0 can't be imported") import tensorflow as tf def gen(): for ex in fe...
10,649
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/data/processors/utils.py
all_input_ids = torch.tensor([f.input_ids for f in features], dtype=torch.long) all_attention_mask = torch.tensor([f.attention_mask for f in features], dtype=torch.long) if self.mode == "classification": all_labels = torch.tensor([f.label for f in features], dtype=torch.long) ...
10,649
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/data/processors/utils.py
class GenerationMode(ExplicitEnum): """ Possible generation modes, downstream of the [`~generation.GenerationMixin.generate`] method. """ # Non-beam methods CONTRASTIVE_SEARCH = "contrastive_search" GREEDY_SEARCH = "greedy_search" SAMPLE = "sample" ASSISTED_GENERATION = "assisted_genera...
10,650
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
class GenerationConfig(PushToHubMixin): # no-format """ Class that holds a configuration for a generation task. A `generate` call supports the following generation methods for text-decoder, text-to-text, speech-to-text, and vision-to-text models: - *greedy decoding* if `num_beams=1` and `do_sam...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
To learn more about decoding strategies refer to the [text generation strategies guide](../generation_strategies). <Tip> A large number of these flags control the logits or the stopping criteria of the generation. Make sure you check the [generate-related classes](https://huggingface.co/docs/transformers/...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
max_length (`int`, *optional*, defaults to 20): The maximum length the generated tokens can have. Corresponds to the length of the input prompt + `max_new_tokens`. Its effect is overridden by `max_new_tokens`, if also set. max_new_tokens (`int`, *optional*): The maximum numbe...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
`True`, where the generation stops as soon as there are `num_beams` complete candidates; `False`, where an heuristic is applied and the generation stops when is it very unlikely to find better candidates; `"never"`, where the beam search procedure only stops when there cannot be better candidate...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
> Parameters that control the generation strategy used
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
do_sample (`bool`, *optional*, defaults to `False`): Whether or not to use sampling ; use greedy decoding otherwise. num_beams (`int`, *optional*, defaults to 1): Number of beams for beam search. 1 means no beam search. num_beam_groups (`int`, *optional*, defaults to 1): ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
"low" means the first half of the layers up to the first 20 layers, and "high" means the last half of the layers up to the last 20 layers. If a list of integers, it must contain the indices of the layers to use for candidate premature layers in DoLa. The 0-th layer is the word embedd...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
> Parameters that control the cache use_cache (`bool`, *optional*, defaults to `True`): Whether or not the model should use the past last key/values attentions (if applicable to the model) to speed up decoding. cache_implementation (`str`, *optional*, default to `None`): ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
We support other cache types, but they must be manually instantiated and passed to `generate` through the `past_key_values` argument. See our [cache documentation](https://huggingface.co/docs/transformers/en/kv_cache) for further information. cache_config (`CacheConfig` or `dict`, *optio...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
temperature (`float`, *optional*, defaults to 1.0): The value used to module the next token probabilities. This value is set in a model's `generation_config.json` file. If it isn't set, the default value is 1.0 top_k (`int`, *optional*, defaults to 50): The number of highest probability ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
value between 0 and 1. Typical values are in the 0.01-0.2 range, comparably selective as setting `top_p` in the 0.99-0.8 range (use the opposite of normal `top_p` values). typical_p (`float`, *optional*, defaults to 1.0): Local typicality measures how similar the conditional probability ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
`epsilon_cutoff` will be sampled. In the paper, suggested values range from 3e-4 to 9e-4, depending on the size of the model. See [Truncation Sampling as Language Model Desmoothing](https://arxiv.org/abs/2210.15191) for more details. eta_cutoff (`float`, *optional*, defaults to 0.0): ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
This value is subtracted from a beam's score if it generates a token same as any beam from other group at a particular time. Note that `diversity_penalty` is only effective if `group beam search` is enabled. repetition_penalty (`float`, *optional*, defaults to 1.0): The parameter for rep...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
likelihood of the sequence (i.e. negative), `length_penalty` > 0.0 promotes longer sequences, while `length_penalty` < 0.0 encourages shorter sequences. no_repeat_ngram_size (`int`, *optional*, defaults to 0): If set to int > 0, all ngrams of that size can only occur once. bad_wo...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
can allow different forms of each word. renormalize_logits (`bool`, *optional*, defaults to `False`): Whether to renormalize the logits after applying all the logits processors (including the custom ones). It's highly recommended to set this flag to `True` as the search algorithms suppos...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
multilingual models like [mBART](../model_doc/mbart) where the first generated token needs to be the target language token. forced_eos_token_id (`int` or List[int]`, *optional*, defaults to `model.config.forced_eos_token_id`): The id of the token to force as the last generated token when...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
generated. The tuple shall consist of: `(start_index, decay_factor)` where `start_index` indicates where penalty starts and `decay_factor` represents the factor of exponential decay suppress_tokens (`List[int]`, *optional*): A list of tokens that will be suppressed at generation. The `Su...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
of index 123. sequence_bias (`Dict[Tuple[int], float]`, *optional*)): Dictionary that maps a sequence of tokens to its bias term. Positive biases increase the odds of the sequence being selected, while negative biases do the opposite. Check [`~generation.SequenceBiasLogitsPro...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Switch to sequential beam search and sequential topk for contrastive search to reduce peak memory. Used with beam search and contrastive search. watermarking_config (`BaseWatermarkingConfig` or `dict`, *optional*): Arguments used to watermark the model outputs by adding a small bias to r...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
> Parameters that define the output variables of generate
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
num_return_sequences (`int`, *optional*, defaults to 1): The number of independently computed returned sequences for each element in the batch. output_attentions (`bool`, *optional*, defaults to `False`): Whether or not to return the attentions tensors of all attention layers. See `atten...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
return_dict_in_generate (`bool`, *optional*, defaults to `False`): Whether or not to return a [`~utils.ModelOutput`], as opposed to returning exclusively the generated sequence. This flag must be set to `True` to return the generation cache (when `use_cache` is `True`) or optional ou...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
> Special tokens that can be used at generation time pad_token_id (`int`, *optional*): The id of the *padding* token. bos_token_id (`int`, *optional*): The id of the *beginning-of-sequence* token. eos_token_id (`Union[int, List[int]]`, *optional*): The id of ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
encoder_no_repeat_ngram_size (`int`, *optional*, defaults to 0): If set to int > 0, all ngrams of that size that occur in the `encoder_input_ids` cannot occur in the `decoder_input_ids`. decoder_start_token_id (`int` or `List[int]`, *optional*): If an encoder-decoder model st...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
> Generation parameters exclusive to assistant generation is_assistant (`bool`, *optional*, defaults to `False`): Whether the model is an assistant (draft) model. num_assistant_tokens (`int`, *optional*, defaults to 20): Defines the number of _speculative tokens_ that shall be ge...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
reduce by 1. `num_assistant_tokens` value is persistent over multiple generation calls with the same assistant model. - `"heuristic_transient"`: Same as `"heuristic"` but `num_assistant_tokens` is reset to its initial value after each generation call. - `"constant"`: `num_assistant_tokens` stays...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
`assistant_confidence_threshold` value is persistent over multiple generation calls with the same assistant model. It is an unsupervised version of the dynamic speculation lookahead from Dynamic Speculation Lookahead Accelerates Speculative Decoding of Large Language Models <https://arxiv.org/ab...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
If set to a positive integer, the re-encodeing process will additionally consider the last `assistant_lookbehind` assistant tokens to correctly align tokens. Can only be used with different tokenizers in speculative decoding. See this [blog](https://huggingface.co/blog/universal_assisted_generat...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
> Parameters related to performances and compilation compile_config (CompileConfig, *optional*): If using a static cache, this controls how `generate` will `compile` the forward pass for performance gains. > Wild card generation_kwargs: Additional generatio...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
def __init__(self, **kwargs): # Parameters that control the length of the output self.max_length = kwargs.pop("max_length", 20) self.max_new_tokens = kwargs.pop("max_new_tokens", None) self.min_length = kwargs.pop("min_length", 0) self.min_new_tokens = kwargs.pop("min_new_tokens"...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# Parameters that control the cache self.use_cache = kwargs.pop("use_cache", True) self.cache_implementation = kwargs.pop("cache_implementation", None) self.cache_config = kwargs.pop("cache_config", None) if self.cache_implementation is not None and self.cache_implementation in CACHE_CON...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# Parameters for manipulation of the model output logits self.temperature = kwargs.pop("temperature", 1.0) self.top_k = kwargs.pop("top_k", 50) self.top_p = kwargs.pop("top_p", 1.0) self.min_p = kwargs.pop("min_p", None) self.typical_p = kwargs.pop("typical_p", 1.0) self....
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
self.constraints = kwargs.pop("constraints", None) self.forced_bos_token_id = kwargs.pop("forced_bos_token_id", None) self.forced_eos_token_id = kwargs.pop("forced_eos_token_id", None) self.remove_invalid_values = kwargs.pop("remove_invalid_values", False) self.exponential_decay_length_p...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
elif isinstance(watermarking_config, BaseWatermarkingConfig): self.watermarking_config = watermarking_config else: self.watermarking_config = WatermarkingConfig.from_dict(watermarking_config)
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# Parameters that define the output variables of `generate` self.num_return_sequences = kwargs.pop("num_return_sequences", 1) self.output_attentions = kwargs.pop("output_attentions", False) self.output_hidden_states = kwargs.pop("output_hidden_states", False) self.output_scores = kwargs....
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# Assistant generation self.is_assistant = False self.num_assistant_tokens = kwargs.pop("num_assistant_tokens", 20) self.num_assistant_tokens_schedule = kwargs.pop("num_assistant_tokens_schedule", "constant") self.assistant_confidence_threshold = kwargs.pop("assistant_confidence_threshol...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# The remaining attributes do not parametrize `.generate()`, but are informative and/or used by the hub # interface. self._from_model_config = kwargs.pop("_from_model_config", False) self._commit_hash = kwargs.pop("_commit_hash", None) self.transformers_version = kwargs.pop("transformers...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
def __hash__(self): return hash(self.to_json_string(ignore_metadata=True)) def __eq__(self, other): if not isinstance(other, GenerationConfig): return False self_without_metadata = self.to_json_string(use_diff=False, ignore_metadata=True) other_without_metadata = other....
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Returns: `GenerationMode`: The generation mode triggered by the instance. """ # TODO joao: find out a way of not depending on external fields (e.g. `assistant_model`), then make this a # property and part of the `__repr__` if self.constraints is not None or self.force_words_i...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
generation_mode = GenerationMode.GROUP_BEAM_SEARCH elif self.do_sample is True: generation_mode = GenerationMode.BEAM_SAMPLE else: generation_mode = GenerationMode.BEAM_SEARCH
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# Assisted generation may extend some generation modes if ( assistant_model is not None or self.prompt_lookup_num_tokens is not None or self.assistant_early_exit is not None ): if generation_mode in ("greedy_search", "sample"): generation_m...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# DoLa generation may extend some generation modes if self.dola_layers is not None: if generation_mode in ("greedy_search", "sample"): generation_mode = GenerationMode.DOLA_GENERATION else: raise ValueError( "You've set `dola_layers`, w...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Arg: is_init (`bool`, *optional*, defaults to `False`): Whether the validation is performed during the initialization of the instance. """ # Validation of individual attributes if self.early_stopping not in {True, False, "never"}: raise ValueError(f"`earl...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# Validation of attribute relations: fix_location = "" if is_init: fix_location = ( " This was detected when initializing the generation config instance, which means the corresponding " "file may hold incorrect parameterization and should be fixed." ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# 1. detect sampling-only parameterization when not in sampling mode if self.do_sample is False: greedy_wrong_parameter_msg = ( "`do_sample` is set to `False`. However, `{flag_name}` is set to `{flag_value}` -- this flag is only " "used in sample-based generation mode...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
greedy_wrong_parameter_msg.format(flag_name="min_p", flag_value=self.min_p), UserWarning, ) if self.typical_p is not None and self.typical_p != 1.0: warnings.warn( greedy_wrong_parameter_msg.format(flag_name="typical_p", flag_value=self...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
if self.eta_cutoff is not None and self.eta_cutoff != 0.0: warnings.warn( greedy_wrong_parameter_msg.format(flag_name="eta_cutoff", flag_value=self.eta_cutoff), UserWarning, )
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# 2. detect beam-only parameterization when not in beam mode if self.num_beams is None: warnings.warn("`num_beams` is set to None - defaulting to 1.", UserWarning) self.num_beams = 1
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
if self.num_beams == 1: single_beam_wrong_parameter_msg = ( "`num_beams` is set to 1. However, `{flag_name}` is set to `{flag_value}` -- this flag is only used " "in beam-based generation modes. You should set `num_beams>1` or unset `{flag_name}`." + fix_location ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
warnings.warn( single_beam_wrong_parameter_msg.format( flag_name="diversity_penalty", flag_value=self.diversity_penalty ), UserWarning, ) if self.length_penalty is not None and self.length_penalty != 1.0: ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# 3. detect incorrect paramaterization specific to advanced beam modes else: # constrained beam search if self.constraints is not None or self.force_words_ids is not None: constrained_wrong_parameter_msg = ( "one of `constraints`, `force_words_ids` is ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
constrained_wrong_parameter_msg.format( flag_name="num_beam_groups", flag_value=self.num_beam_groups ) ) # group beam search if self.diversity_penalty != 0.0 or self.num_beam_groups != 1: group_error_prefix =...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
+ "`diversity_penalty` should be greater than `0.0`, otherwise your groups will be identical." ) # DoLa generation if self.dola_layers is not None and (self.repetition_penalty is None or self.repetition_penalty < 1.2): warnings.warn( "`dola...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# 4. check `num_return_sequences` if self.num_return_sequences != 1: if self.num_beams == 1: if self.do_sample is False: raise ValueError( "Greedy methods without beam search do not support `num_return_sequences` different than 1 " ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# 5. check cache-related arguments if self.cache_implementation is not None and self.cache_implementation not in ALL_CACHE_IMPLEMENTATIONS: raise ValueError( f"Invalid `cache_implementation` ({self.cache_implementation}). Choose one of: " f"{ALL_CACHE_IMPLEMENTATIONS}...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
if self.use_cache is False: # In this case, all cache-related arguments should be unset. However, since `use_cache=False` is often used # passed to `generate` directly to hot-fix cache issues, let's raise a warning instead of an error # (otherwise a user might need to overwrite sever...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# 6. check watermarking arguments if self.watermarking_config is not None: if not ( isinstance(self.watermarking_config, WatermarkingConfig) or isinstance(self.watermarking_config, SynthIDTextWatermarkingConfig) ): warnings.warn( ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# 8. other incorrect combinations if self.return_dict_in_generate is not True: for extra_output_flag in self.extra_output_flags: if getattr(self, extra_output_flag) is True: warnings.warn( f"`return_dict_in_generate` is NOT set to `True`, b...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# 8. check common issue: passing `generate` arguments inside the generation config generate_arguments = ( "logits_processor", "stopping_criteria", "prefix_allowed_tokens_fn", "synced_gpus", "assistant_model", "streamer", "negati...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
def save_pretrained( self, save_directory: Union[str, os.PathLike], config_file_name: Optional[Union[str, os.PathLike]] = None, push_to_hub: bool = False, **kwargs, ): r""" Save a generation configuration object to the directory `save_directory`, so that it ca...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Args: save_directory (`str` or `os.PathLike`): Directory where the configuration JSON file will be saved (will be created if it does not exist). config_file_name (`str` or `os.PathLike`, *optional*, defaults to `"generation_config.json"`): Name of the generation c...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# At save time, validate the instance -- if any warning/exception is thrown, we refuse to save the instance. # This strictness is enforced to prevent bad configurations from being saved and re-used. try: with warnings.catch_warnings(record=True) as caught_warnings: self.valid...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
if use_auth_token is not None: warnings.warn( "The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. " "Please use `token` instead.", FutureWarning, ) if kwargs.get("token", None) is not None: ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
if push_to_hub: commit_message = kwargs.pop("commit_message", None) repo_id = kwargs.pop("repo_id", save_directory.split(os.path.sep)[-1]) repo_id = self._create_repo(repo_id, **kwargs) files_timestamps = self._get_files_timestamps(save_directory) output_config_f...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
@classmethod def from_pretrained( cls, pretrained_model_name: Union[str, os.PathLike], config_file_name: Optional[Union[str, os.PathLike]] = None, cache_dir: Optional[Union[str, os.PathLike]] = None, force_download: bool = False, local_files_only: bool = False, ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
- a string, the *model id* of a pretrained model configuration hosted inside a model repo on huggingface.co. - a path to a *directory* containing a configuration file saved using the [`~GenerationConfig.save_pretrained`] method, e.g., `./my_model_directory/`. ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Deprecated and ignored. All downloads are now resumed by default when possible. Will be removed in v5 of Transformers. proxies (`Dict[str, str]`, *optional*): A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128', 'http:/...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
<Tip> To test a pull request you made on the Hub, you can pass `revision="refs/pr/<pr_number>"`. </Tip> return_unused_kwargs (`bool`, *optional*, defaults to `False`): If `False`, then this function returns just the final configuration object.
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
If `True`, then this functions returns a `Tuple(config, unused_kwargs)` where *unused_kwargs* is a dictionary consisting of the key/value pairs whose keys are not configuration attributes: i.e., the part of `kwargs` which has not been used to update `config` and is otherwise ignored. ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Returns: [`GenerationConfig`]: The configuration object instantiated from this pretrained model. Examples: ```python >>> from transformers import GenerationConfig >>> # Download configuration from huggingface.co and cache. >>> generation_config = GenerationConfig.f...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
>>> # If you'd like to try a minor variation to an existing configuration, you can also pass generation >>> # arguments to `.from_pretrained()`. Be mindful that typos and unused arguments will be ignored >>> generation_config, unused_kwargs = GenerationConfig.from_pretrained( ... "openai-com...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
if use_auth_token is not None: warnings.warn( "The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.", FutureWarning, ) if token is not None: raise ValueError( ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
is_local = os.path.exists(config_path) if os.path.isfile(os.path.join(subfolder, config_path)): # Special case when config_path is a local file resolved_config_file = config_path is_local = True elif is_remote_url(config_path): configuration_file = config_...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
revision=revision, subfolder=subfolder, _commit_hash=commit_hash, ) commit_hash = extract_commit_hash(resolved_config_file, commit_hash) except EnvironmentError: # Raise any environment error raise by `cached_file`. It w...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
try: # Load config dict config_dict = cls._dict_from_json_file(resolved_config_file) config_dict["_commit_hash"] = commit_hash except (json.JSONDecodeError, UnicodeDecodeError): raise EnvironmentError( f"It looks like the config file at '{resolved_...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
if kwargs.get("return_unused_kwargs") is True: config, unused_kwargs = cls.from_dict(config_dict, **kwargs) config._original_object_hash = hash(config) # Hash to detect whether the instance was modified return config, unused_kwargs else: config = cls.from_dict(co...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Args: config_dict (`Dict[str, Any]`): Dictionary that will be used to instantiate the configuration object. kwargs (`Dict[str, Any]`): Additional parameters from which to initialize the configuration object. Returns: [`GenerationConfig`]: The ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# The line below allows model-specific config to be loaded as well through kwargs, with safety checks. # See https://github.com/huggingface/transformers/pull/21269 config = cls(**{**config_dict, **kwargs}) unused_kwargs = config.update(**kwargs) logger.info(f"Generate config {config}") ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
def dict_torch_dtype_to_str(self, d: Dict[str, Any]) -> None: """ Checks whether the passed dictionary and its nested dicts have a *torch_dtype* key and if it's not None, converts torch.dtype to a string of just the type. For example, `torch.float32` get converted into *"float32"* string...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Returns: `Dict[str, Any]`: Dictionary of all the attributes that make up this configuration instance, """ config_dict = self.to_dict() # get the default config dict default_config_dict = GenerationConfig().to_dict() serializable_config_dict = {} # only seri...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# Fields to ignore at serialization time if "_commit_hash" in output: del output["_commit_hash"] if "_original_object_hash" in output: del output["_original_object_hash"] if "compile_config" in output: del output["compile_config"] # Transformers versi...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Args: use_diff (`bool`, *optional*, defaults to `True`): If set to `True`, only the difference between the config instance and the default `GenerationConfig()` is serialized to JSON string. ignore_metadata (`bool`, *optional*, defaults to `False`): ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
def convert_keys_to_string(obj): if isinstance(obj, dict): return {str(key): convert_keys_to_string(value) for key, value in obj.items()} elif isinstance(obj, list): return [convert_keys_to_string(item) for item in obj] else: return obj...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Args: json_file_path (`str` or `os.PathLike`): Path to the JSON file in which this configuration instance's parameters will be saved. use_diff (`bool`, *optional*, defaults to `True`): If set to `True`, only the difference between the config instance and the defau...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Args: model_config (`PretrainedConfig`): The model config that will be used to instantiate the generation config. Returns: [`GenerationConfig`]: The configuration object instantiated from those parameters. """ config_dict = model_config.to_dict() ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# Special case: some models have generation attributes set in the decoder. Use them if still unset in the # generation config (which in turn is defined from the outer attributes of model config). decoder_config = model_config.get_text_config(decoder=True) if decoder_config is not model_config: ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
# If any `output_...` flag is set to `True`, we ensure `return_dict_in_generate` is set to `True`. if generation_config.return_dict_in_generate is False: if any( getattr(generation_config, extra_output_flag, False) for extra_output_flag in generation_config.extra_outp...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Returns: `Dict[str, Any]`: Dictionary containing all the key-value pairs that were not used to update the instance. """ to_remove = [] for key, value in kwargs.items(): if hasattr(self, key): setattr(self, key, value) to_remove.append(key) ...
10,651
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
class BaseWatermarkingConfig(ABC): """Generic watermarking config""" @classmethod def from_dict(cls, config_dict, **kwargs): """ Constructs a BaseWatermarkingConfig instance from a dictionary of parameters. Args: config_dict (Dict[str, Any]): Dictionary containing confi...
10,652
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
Args: json_file_path (Union[str, os.PathLike]): Path to the JSON file in which this configuration instance's parameters will be saved. """ with open(json_file_path, "w", encoding="utf-8") as writer: config_dict = self.to_dict() json_string = json.dumps(config_dict, in...
10,652
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py
def to_json_string(self): """ Serializes this instance to a JSON formatted string. Returns: str: JSON formatted string representing the configuration instance. """ return json.dumps(self.__dict__, indent=2) + "\n" def update(self, **kwargs): """ ...
10,652
/Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/generation/configuration_utils.py