diff --git a/.github/workflows/tripy-l0.yml b/.github/workflows/tripy-l0.yml index 406a77544..d8fa8b38c 100644 --- a/.github/workflows/tripy-l0.yml +++ b/.github/workflows/tripy-l0.yml @@ -61,7 +61,7 @@ jobs: options: --gpus all -v ${{ github.workspace }}/tripy:/tripy run: | python3 docs/generate_rsts.py - sphinx-build build/doc_sources build/docs -c docs/ -j 4 -W + sphinx-build build/doc_sources build/docs -c docs/ -j 4 -W -n - name: run-test uses: addnab/docker-run-action@v3 diff --git a/.github/workflows/tripy-l1.yml b/.github/workflows/tripy-l1.yml index f85321f13..84c87ce05 100644 --- a/.github/workflows/tripy-l1.yml +++ b/.github/workflows/tripy-l1.yml @@ -40,7 +40,7 @@ jobs: run: | cd /tripy/ python3 docs/generate_rsts.py - sphinx-build build/doc_sources build/docs -c docs/ -j 4 -W + sphinx-build build/doc_sources build/docs -c docs/ -j 4 -W -n cp docs/packages.html build/docs/ - uses: actions/upload-pages-artifact@v3 diff --git a/tripy/docs/README.md b/tripy/docs/README.md index 2fac8d95a..7015b925b 100644 --- a/tripy/docs/README.md +++ b/tripy/docs/README.md @@ -7,7 +7,7 @@ This directory includes all the source files for the public API documentation. You can build the documentation locally in the development container by running: ```bash python3 docs/generate_rsts.py -sphinx-build build/doc_sources build/docs -c docs/ -j 4 -W +sphinx-build build/doc_sources build/docs -c docs/ -j 4 -W -n ``` To view the documentation, you can open `build/docs/index.html` in a browser. diff --git a/tripy/docs/conf.py b/tripy/docs/conf.py index e48f1f3d9..2e11dec2c 100644 --- a/tripy/docs/conf.py +++ b/tripy/docs/conf.py @@ -51,6 +51,18 @@ autodoc_typehints_format = "short" python_use_unqualified_type_names = True +nitpick_ignore = { + ("py:class", "tripy.types.ShapeLike"), + ("py:class", "tripy.types.TensorLike"), + ("py:class", "tripy.types.NestedNumberSequence"), + ("py:class", "Tensor"), + ("py:class", "Shape"), +} +nitpick_ignore_regex = { + ("py:class", r"numbers\.Number"), + ("py:class", r"collections\..*"), +} + autodoc_default_options = { "members": True, "no-undoc-members": True, diff --git a/tripy/tests/integration/test_convolution.py b/tripy/tests/integration/test_conv.py similarity index 100% rename from tripy/tests/integration/test_convolution.py rename to tripy/tests/integration/test_conv.py diff --git a/tripy/tripy/backend/api/executable.py b/tripy/tripy/backend/api/executable.py index be9e8b117..c50f01712 100644 --- a/tripy/tripy/backend/api/executable.py +++ b/tripy/tripy/backend/api/executable.py @@ -162,9 +162,7 @@ def add(a, b): ) raise - from tripy.utils.stack_info import StackInfo - - output_tensors = [Tensor(output, stack_info=StackInfo([])) for output in executor_outputs] + output_tensors = [Tensor(output, fetch_stack_info=False) for output in executor_outputs] if len(output_tensors) == 1: output_tensors = output_tensors[0] return output_tensors diff --git a/tripy/tripy/frontend/module/convolution.py b/tripy/tripy/frontend/module/conv.py similarity index 99% rename from tripy/tripy/frontend/module/convolution.py rename to tripy/tripy/frontend/module/conv.py index 09b439694..c194fc256 100644 --- a/tripy/tripy/frontend/module/convolution.py +++ b/tripy/tripy/frontend/module/conv.py @@ -83,7 +83,7 @@ def __init__( self.dtype = dtype -@export.public_api(document_under="operations/modules") +@export.public_api(document_under="operations/modules", autodoc_options=[":no-show-inheritance:"]) @dataclass class Conv(ConvBase): r""" diff --git a/tripy/tripy/frontend/module/conv_transpose.py b/tripy/tripy/frontend/module/conv_transpose.py index 1640379b4..ec9da8687 100644 --- a/tripy/tripy/frontend/module/conv_transpose.py +++ b/tripy/tripy/frontend/module/conv_transpose.py @@ -21,11 +21,11 @@ from tripy import export from tripy.common import datatype -from tripy.frontend.module.convolution import ConvBase +from tripy.frontend.module.conv import ConvBase from tripy.frontend.module.parameter import DefaultParameter, Parameter -@export.public_api(document_under="operations/modules") +@export.public_api(document_under="operations/modules", autodoc_options=[":no-show-inheritance:"]) @dataclass class ConvTranspose(ConvBase): r""" diff --git a/tripy/tripy/frontend/shape.py b/tripy/tripy/frontend/shape.py index 11670e667..56b94bf80 100644 --- a/tripy/tripy/frontend/shape.py +++ b/tripy/tripy/frontend/shape.py @@ -15,7 +15,7 @@ # limitations under the License. # -from typing import Optional, Sequence, Union +from typing import Any, Optional, Sequence, Union from tripy import export, utils from tripy.common.datatype import int32 @@ -41,7 +41,7 @@ class Shape(Tensor): def __init__( self, - data: Union[Sequence, Tensor, "np.ndarray", "cp.ndarray", "torch.Tensor", "jnp.ndarray"], + data: Any, name: Optional[str] = None, ) -> None: r""" @@ -297,7 +297,7 @@ class ShapeScalar(Tensor): def __init__( self, - data: Union[Sequence, Tensor, "np.ndarray", "cp.ndarray", "torch.Tensor", "jnp.ndarray"], + data: Any, name: Optional[str] = None, ) -> None: r""" diff --git a/tripy/tripy/frontend/tensor.py b/tripy/tripy/frontend/tensor.py index a20d03ed2..e46d886ed 100644 --- a/tripy/tripy/frontend/tensor.py +++ b/tripy/tripy/frontend/tensor.py @@ -16,7 +16,9 @@ # from textwrap import indent -from typing import Any, List, Optional, Sequence, Union +from typing import Any, Optional + +import mlir_tensorrt.runtime.api as runtime # Import ops to populate the registry before we define our Tensor class import tripy.frontend.ops @@ -27,8 +29,7 @@ from tripy.common.exception import raise_error from tripy.frontend.ops.registry import TENSOR_METHOD_REGISTRY from tripy.frontend.trace.ops import Storage - -import mlir_tensorrt.runtime.api as runtime +from tripy.utils.stack_info import StackInfo class TensorMeta(type): @@ -73,11 +74,11 @@ def _get_unique_name(cls): def __init__( self, - data: Union[List, "np.ndarray", "cp.ndarray", "torch.Tensor", "jnp.ndarray"], + data: Any, dtype: Optional["tripy.dtype"] = None, device: Optional["tripy.device"] = None, name: Optional[str] = None, - stack_info: Optional["StackInfo"] = None, + fetch_stack_info: bool = True, ) -> None: """ Args: @@ -85,7 +86,9 @@ def __init__( dtype: The data type of the tensor. device: The device on which to allocate the tensor. name: The name of the tensor. If provided, this must be a unique string. - stack_info: The stack infomation of the tensor. + fetch_stack_info: Whether to fetch stack information for the tensor. + Stack information allows Tripy to generate much higher quality error + messages at the cost of a small overhead when initializing the tensor. .. code-block:: python :linenos: @@ -95,13 +98,12 @@ def __init__( """ from tripy.frontend.trace.tensor import TraceTensor - # We include code for everything above the `BaseTraceOp.build` function, which is called at most - # this many stack frames above the constructor. - STACK_DEPTH_OF_BUILD = 4 - # not using utils.default() because it always evaluates the `default` argument. - stack_info = ( - stack_info if stack_info is not None else utils.get_stack_info(include_code_index=STACK_DEPTH_OF_BUILD) - ) + stack_info = StackInfo([]) + if fetch_stack_info: + # We include code for everything above the `BaseTraceOp.build` function, which is called at most + # this many stack frames above the constructor. + STACK_DEPTH_OF_BUILD = 4 + stack_info = utils.get_stack_info(include_code_index=STACK_DEPTH_OF_BUILD) name = name if name is not None else Tensor._get_unique_name() diff --git a/tripy/tripy/types.py b/tripy/tripy/types.py index f7145e243..76f07767c 100644 --- a/tripy/tripy/types.py +++ b/tripy/tripy/types.py @@ -21,7 +21,7 @@ import numbers import sys -from typing import Union, Sequence +from typing import Sequence, Union from tripy import export @@ -29,32 +29,28 @@ NestedNumberSequence = export.public_api( document_under="types.rst", - autodoc_options=[":no-index:"], module=sys.modules[__name__], symbol="NestedNumberSequence", doc=""" Denotes the recursive type annotation for sequences of Python numbers, possibly nested to an arbitrary depth. - Tripy often automatically converts these sequences to `tp.Tensor`. + Tripy often automatically converts these sequences to :class:`Tensor`. """, )(Union[numbers.Number, Sequence["tripy.types.NestedNumberSequence"]]) TensorLike = export.public_api( document_under="types.rst", - autodoc_options=[":no-index:"], module=sys.modules[__name__], symbol="TensorLike", doc=""" - Type annotation for a parameter that is either a Tripy `Tensor` or a Python sequence that can be automatically converted into one. + Type annotation for a parameter that is either a Tripy :class:`Tensor` or a Python sequence that can be automatically converted into one. """, )(Union["tripy.Tensor", "tripy.types.NestedNumberSequence"]) - ShapeLike = export.public_api( document_under="types.rst", - autodoc_options=[":no-index:"], module=sys.modules[__name__], symbol="ShapeLike", doc=""" - Type annotation for a parameter that is either a Tripy `Shape` or Python sequence that can be automatically converted into one. + Type annotation for a parameter that is either a Tripy :class:`Shape` or Python sequence that can be automatically converted into one. """, )(Union["tripy.Shape", Sequence[Union[int, "tripy.ShapeScalar"]]])