55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
# Copyright 2022 The HuggingFace Team. All rights reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
"""
|
|
Doc utilities: Utilities related to documentation
|
|
"""
|
|
|
|
|
|
def add_start_docstrings(*docstr):
|
|
def docstring_decorator(fn):
|
|
fn.__doc__ = "".join(docstr) + (fn.__doc__ if fn.__doc__ is not None else "")
|
|
return fn
|
|
|
|
return docstring_decorator
|
|
|
|
|
|
def add_start_docstrings_to_model_forward(*docstr):
|
|
def docstring_decorator(fn):
|
|
docstring = "".join(docstr) + (fn.__doc__ if fn.__doc__ is not None else "")
|
|
class_name = f"[`{fn.__qualname__.split('.')[0]}`]"
|
|
intro = f" The {class_name} forward method, overrides the `__call__` special method."
|
|
note = r"""
|
|
|
|
<Tip>
|
|
|
|
Although the recipe for forward pass needs to be defined within this function, one should call the [`Layer`]
|
|
instance afterwards instead of this since the former takes care of running the pre and post processing steps while
|
|
the latter silently ignores them.
|
|
|
|
</Tip>
|
|
"""
|
|
|
|
fn.__doc__ = intro + note + docstring
|
|
return fn
|
|
|
|
return docstring_decorator
|
|
|
|
|
|
def add_end_docstrings(*docstr):
|
|
def docstring_decorator(fn):
|
|
fn.__doc__ = (fn.__doc__ if fn.__doc__ is not None else "") + "".join(docstr)
|
|
return fn
|
|
|
|
return docstring_decorator
|