General Utilities

This page lists all of Transformers general utility functions that are found in the file `utils.py`.

Most of those are only useful if you are studying the general code in the library.

## [](#transformers.utils.ExplicitEnum)Enums and namedtuples

### class transformers.utils.ExplicitEnum

[](#transformers.utils.ExplicitEnum)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/generic.py#L341)

( valuenames = Nonemodule = Nonequalname = Nonetype = Nonestart = 1 )

Enum with more explicit error message for missing values.

### class transformers.utils.PaddingStrategy

[](#transformers.utils.PaddingStrategy)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/generic.py#L353)

( valuenames = Nonemodule = Nonequalname = Nonetype = Nonestart = 1 )

Possible values for the `padding` argument in [PreTrainedTokenizerBase.**call**()](/docs/transformers/v4.30.0/en/model_doc/speecht5#transformers.SpeechT5Tokenizer.__call__). Useful for tab-completion in an IDE.

### class transformers.TensorType

[](#transformers.TensorType)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/generic.py#L364)

( valuenames = Nonemodule = Nonequalname = Nonetype = Nonestart = 1 )

Possible values for the `return_tensors` argument in [PreTrainedTokenizerBase.**call**()](/docs/transformers/v4.30.0/en/model_doc/speecht5#transformers.SpeechT5Tokenizer.__call__). Useful for tab-completion in an IDE.

## [](#transformers.add_start_docstrings)Special Decorators

#### transformers.add\_start\_docstrings

[](#transformers.add_start_docstrings)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/doc.py#L23)

( \*docstr )

#### transformers.utils.add\_start\_docstrings\_to\_model\_forward

[](#transformers.utils.add_start_docstrings_to_model_forward)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/doc.py#L31)

( \*docstr )

#### transformers.add\_end\_docstrings

[](#transformers.add_end_docstrings)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/doc.py#L53)

( \*docstr )

#### transformers.utils.add\_code\_sample\_docstrings

[](#transformers.utils.add_code_sample_docstrings)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/doc.py#L1059)

( \*docstrprocessor\_class = Nonecheckpoint = Noneoutput\_type = Noneconfig\_class = Nonemask = '\[MASK\]'qa\_target\_start\_index = 14qa\_target\_end\_index = 15model\_cls = Nonemodality = Noneexpected\_output = Noneexpected\_loss = Nonereal\_checkpoint = None )

#### transformers.utils.replace\_return\_docstrings

[](#transformers.utils.replace_return_docstrings)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/doc.py#L1147)

( output\_type = Noneconfig\_class = None )

## [](#transformers.utils.cached_property)Special Properties

### class transformers.utils.cached\_property

[](#transformers.utils.cached_property)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/generic.py#L36)

( fget = Nonefset = Nonefdel = Nonedoc = None )

Descriptor that mimics @property but caches output in member variable.

From tensorflow\_datasets

Built-in in functools from Python 3.8.

## [](#transformers.utils._LazyModule)Other Utilities

### class transformers.utils.\_LazyModule

[](#transformers.utils._LazyModule)[< source \>](https://github.com/huggingface/transformers/blob/v4.30.0/src/transformers/utils/import_utils.py#L1035)

( namemodule\_fileimport\_structuremodule\_spec = Noneextra\_objects = None )

Module class that surfaces all objects but only performs associated imports when the objects are requested.