Doc styling (#8067)
* Important files * Styling them all * Revert "Styling them all" This reverts commit 7d029395fdae8513b8281cbc2a6c239f8093503e. * Syling them for realsies * Fix syntax error * Fix benchmark_utils * More fixes * Fix modeling auto and script * Remove new line * Fixes * More fixes * Fix more files * Style * Add FSMT * More fixes * More fixes * More fixes * More fixes * Fixes * More fixes * More fixes * Last fixes * Make sphinx happy
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
"""
|
||||
Utilities for working with the local dataset cache.
|
||||
This file is adapted from the AllenNLP library at https://github.com/allenai/allennlp
|
||||
Copyright by the AllenNLP authors.
|
||||
Utilities for working with the local dataset cache. This file is adapted from the AllenNLP library at
|
||||
https://github.com/allenai/allennlp Copyright by the AllenNLP authors.
|
||||
"""
|
||||
|
||||
import fnmatch
|
||||
@@ -433,10 +432,9 @@ def add_start_docstrings_to_callable(*docstr):
|
||||
note = r"""
|
||||
|
||||
.. note::
|
||||
Although the recipe for forward pass needs to be defined within
|
||||
this function, one should call the :class:`Module` instance afterwards
|
||||
instead of this since the former takes care of running the
|
||||
pre and post processing steps while the latter silently ignores them.
|
||||
Although the recipe for forward pass needs to be defined within this function, one should call the
|
||||
:class:`Module` instance afterwards instead of this since the former takes care of running the pre and post
|
||||
processing steps while the latter silently ignores them.
|
||||
"""
|
||||
fn.__doc__ = intro + note + "".join(docstr) + (fn.__doc__ if fn.__doc__ is not None else "")
|
||||
return fn
|
||||
@@ -454,20 +452,18 @@ def add_end_docstrings(*docstr):
|
||||
|
||||
PT_RETURN_INTRODUCTION = r"""
|
||||
Returns:
|
||||
:class:`~{full_output_type}` or :obj:`tuple(torch.FloatTensor)`:
|
||||
A :class:`~{full_output_type}` (if ``return_dict=True`` is passed or when ``config.return_dict=True``) or a
|
||||
tuple of :obj:`torch.FloatTensor` comprising various elements depending on the configuration
|
||||
(:class:`~transformers.{config_class}`) and inputs.
|
||||
:class:`~{full_output_type}` or :obj:`tuple(torch.FloatTensor)`: A :class:`~{full_output_type}` (if
|
||||
``return_dict=True`` is passed or when ``config.return_dict=True``) or a tuple of :obj:`torch.FloatTensor`
|
||||
comprising various elements depending on the configuration (:class:`~transformers.{config_class}`) and inputs.
|
||||
|
||||
"""
|
||||
|
||||
|
||||
TF_RETURN_INTRODUCTION = r"""
|
||||
Returns:
|
||||
:class:`~{full_output_type}` or :obj:`tuple(tf.Tensor)`:
|
||||
A :class:`~{full_output_type}` (if ``return_dict=True`` is passed or when ``config.return_dict=True``) or a
|
||||
tuple of :obj:`tf.Tensor` comprising various elements depending on the configuration
|
||||
(:class:`~transformers.{config_class}`) and inputs.
|
||||
:class:`~{full_output_type}` or :obj:`tuple(tf.Tensor)`: A :class:`~{full_output_type}` (if
|
||||
``return_dict=True`` is passed or when ``config.return_dict=True``) or a tuple of :obj:`tf.Tensor` comprising
|
||||
various elements depending on the configuration (:class:`~transformers.{config_class}`) and inputs.
|
||||
|
||||
"""
|
||||
|
||||
@@ -831,19 +827,16 @@ def is_remote_url(url_or_filename):
|
||||
|
||||
def hf_bucket_url(model_id: str, filename: str, use_cdn=True, mirror=None) -> str:
|
||||
"""
|
||||
Resolve a model identifier, and a file name, to a HF-hosted url
|
||||
on either S3 or Cloudfront (a Content Delivery Network, or CDN).
|
||||
Resolve a model identifier, and a file name, to a HF-hosted url on either S3 or Cloudfront (a Content Delivery
|
||||
Network, or CDN).
|
||||
|
||||
Cloudfront is replicated over the globe so downloads are way faster
|
||||
for the end user (and it also lowers our bandwidth costs). However, it
|
||||
is more aggressively cached by default, so may not always reflect the
|
||||
latest changes to the underlying file (default TTL is 24 hours).
|
||||
Cloudfront is replicated over the globe so downloads are way faster for the end user (and it also lowers our
|
||||
bandwidth costs). However, it is more aggressively cached by default, so may not always reflect the latest changes
|
||||
to the underlying file (default TTL is 24 hours).
|
||||
|
||||
In terms of client-side caching from this library, even though
|
||||
Cloudfront relays the ETags from S3, using one or the other
|
||||
(or switching from one to the other) will affect caching: cached files
|
||||
are not shared between the two because the cached file's name contains
|
||||
a hash of the url.
|
||||
In terms of client-side caching from this library, even though Cloudfront relays the ETags from S3, using one or
|
||||
the other (or switching from one to the other) will affect caching: cached files are not shared between the two
|
||||
because the cached file's name contains a hash of the url.
|
||||
"""
|
||||
endpoint = (
|
||||
PRESET_MIRROR_DICT.get(mirror, mirror)
|
||||
@@ -861,12 +854,10 @@ def hf_bucket_url(model_id: str, filename: str, use_cdn=True, mirror=None) -> st
|
||||
|
||||
def url_to_filename(url, etag=None):
|
||||
"""
|
||||
Convert `url` into a hashed filename in a repeatable way.
|
||||
If `etag` is specified, append its hash to the url's, delimited
|
||||
by a period.
|
||||
If the url ends with .h5 (Keras HDF5 weights) adds '.h5' to the name
|
||||
so that TF 2.0 can identify it as a HDF5 file
|
||||
(see https://github.com/tensorflow/tensorflow/blob/00fad90125b18b80fe054de1055770cfb8fe4ba3/tensorflow/python/keras/engine/network.py#L1380)
|
||||
Convert `url` into a hashed filename in a repeatable way. If `etag` is specified, append its hash to the url's,
|
||||
delimited by a period. If the url ends with .h5 (Keras HDF5 weights) adds '.h5' to the name so that TF 2.0 can
|
||||
identify it as a HDF5 file (see
|
||||
https://github.com/tensorflow/tensorflow/blob/00fad90125b18b80fe054de1055770cfb8fe4ba3/tensorflow/python/keras/engine/network.py#L1380)
|
||||
"""
|
||||
url_bytes = url.encode("utf-8")
|
||||
url_hash = sha256(url_bytes)
|
||||
@@ -885,8 +876,8 @@ def url_to_filename(url, etag=None):
|
||||
|
||||
def filename_to_url(filename, cache_dir=None):
|
||||
"""
|
||||
Return the url and etag (which may be ``None``) stored for `filename`.
|
||||
Raise ``EnvironmentError`` if `filename` or its stored metadata do not exist.
|
||||
Return the url and etag (which may be ``None``) stored for `filename`. Raise ``EnvironmentError`` if `filename` or
|
||||
its stored metadata do not exist.
|
||||
"""
|
||||
if cache_dir is None:
|
||||
cache_dir = TRANSFORMERS_CACHE
|
||||
@@ -921,10 +912,10 @@ def cached_path(
|
||||
local_files_only=False,
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
Given something that might be a URL (or might be a local path),
|
||||
determine which. If it's a URL, download the file and cache it, and
|
||||
return the path to the cached file. If it's already a local path,
|
||||
make sure the file exists and then return the path.
|
||||
Given something that might be a URL (or might be a local path), determine which. If it's a URL, download the file
|
||||
and cache it, and return the path to the cached file. If it's already a local path, make sure the file exists and
|
||||
then return the path
|
||||
|
||||
Args:
|
||||
cache_dir: specify a cache directory to save the file to (overwrite the default cache dir).
|
||||
force_download: if True, re-dowload the file even if it's already cached in the cache dir.
|
||||
@@ -936,8 +927,8 @@ def cached_path(
|
||||
re-extract the archive and overide the folder where it was extracted.
|
||||
|
||||
Return:
|
||||
None in case of non-recoverable file (non-existent or inaccessible url + no cache on disk).
|
||||
Local path (string) otherwise
|
||||
None in case of non-recoverable file (non-existent or inaccessible url + no cache on disk). Local path (string)
|
||||
otherwise
|
||||
"""
|
||||
if cache_dir is None:
|
||||
cache_dir = TRANSFORMERS_CACHE
|
||||
@@ -1045,12 +1036,12 @@ def get_from_cache(
|
||||
local_files_only=False,
|
||||
) -> Optional[str]:
|
||||
"""
|
||||
Given a URL, look for the corresponding file in the local cache.
|
||||
If it's not there, download it. Then return the path to the cached file.
|
||||
Given a URL, look for the corresponding file in the local cache. If it's not there, download it. Then return the
|
||||
path to the cached file.
|
||||
|
||||
Return:
|
||||
None in case of non-recoverable file (non-existent or inaccessible url + no cache on disk).
|
||||
Local path (string) otherwise
|
||||
None in case of non-recoverable file (non-existent or inaccessible url + no cache on disk). Local path (string)
|
||||
otherwise
|
||||
"""
|
||||
if cache_dir is None:
|
||||
cache_dir = TRANSFORMERS_CACHE
|
||||
@@ -1213,8 +1204,8 @@ def is_tensor(x):
|
||||
class ModelOutput(OrderedDict):
|
||||
"""
|
||||
Base class for all model outputs as dataclass. Has a ``__getitem__`` that allows indexing by integer or slice (like
|
||||
a tuple) or strings (like a dictionary) that will ignore the ``None`` attributes. Otherwise behaves like a
|
||||
regular python dictionary.
|
||||
a tuple) or strings (like a dictionary) that will ignore the ``None`` attributes. Otherwise behaves like a regular
|
||||
python dictionary.
|
||||
|
||||
.. warning::
|
||||
You can't unpack a :obj:`ModelOutput` directly. Use the :meth:`~transformers.file_utils.ModelOutput.to_tuple`
|
||||
|
||||
Reference in New Issue
Block a user