Skip to content

Commit

Permalink
Merge branch 'main' into sdpa_decomposition
Browse files Browse the repository at this point in the history
  • Loading branch information
HolyWu committed Dec 7, 2024
2 parents aa624a1 + 5f1d12f commit a8849bb
Show file tree
Hide file tree
Showing 13 changed files with 912 additions and 66 deletions.
701 changes: 701 additions & 0 deletions .github/scripts/generate_binary_build_matrix.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/build-test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

jobs:
generate-matrix:
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
uses: ./.github/workflows/generate_binary_build_matrix.yml
with:
package-type: wheel
os: linux
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test-tensorrt-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:

jobs:
generate-matrix:
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
uses: ./.github/workflows/generate_binary_build_matrix.yml
with:
package-type: wheel
os: linux
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test-tensorrt-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:

jobs:
generate-matrix:
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
uses: ./.github/workflows/generate_binary_build_matrix.yml
with:
package-type: wheel
os: windows
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ on:

jobs:
generate-matrix:
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
uses: ./.github/workflows/generate_binary_build_matrix.yml
with:
package-type: wheel
os: windows
Expand Down
113 changes: 59 additions & 54 deletions .github/workflows/docgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,67 @@ name: Generate Docs
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ main ]
push:
branches: [main]

jobs:
build-docs:
runs-on: linux.g5.4xlarge.nvidia.gpu
if: ${{ ! contains(github.actor, 'pytorchbot') }}
environment: pytorchbot-env
container:
image: docker.io/pytorch/manylinux-builder:cuda12.4
options: --gpus all
env:
CUDA_HOME: /usr/local/cuda-12.4
VERSION_SUFFIX: cu124
CU_VERSION: cu124
CHANNEL: nightly
CI_BUILD: 1
steps:
- uses: actions/checkout@v3
with:
ref: ${{github.head_ref}}
token: ${{ secrets.GH_PYTORCHBOT_TOKEN }}
- name: Select Python / CUDA
run: |
git config --global --add safe.directory /__w/TensorRT/TensorRT
echo "/opt/python/cp311-cp311/bin/" >> $GITHUB_PATH
build-docs:
runs-on: linux.g5.4xlarge.nvidia.gpu
if: ${{ ! contains(github.actor, 'pytorchbot') }}
environment: pytorchbot-env
container:
image: docker.io/pytorch/manylinux2_28-builder:cuda12.6
options: --gpus all
env:
CUDA_HOME: /usr/local/cuda-12.6
VERSION_SUFFIX: cu126
CU_VERSION: cu126
CHANNEL: nightly
CI_BUILD: 1
steps:
- uses: actions/checkout@v3
with:
ref: ${{github.head_ref}}
token: ${{ secrets.GH_PYTORCHBOT_TOKEN }}
- name: Select Python / CUDA
run: |
git config --global --add safe.directory /__w/TensorRT/TensorRT
echo "/opt/python/cp311-cp311/bin/" >> $GITHUB_PATH
- name: Install base deps
run: |
python3 -m pip install pip --upgrade
python3 -m pip install pyyaml numpy torch --pre --extra-index-url https://download.pytorch.org/whl/nightly/cu124
./packaging/pre_build_script.sh
- name: Get HEAD SHA
id: vars
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build Python Package
run: |
python3 -m pip install --pre . --extra-index-url https://download.pytorch.org/whl/nightly/cu124
- name: Generate New Docs
run: |
cd docsrc
yum install -y doxygen pandoc
python3 -m pip install -r requirements.txt
python3 -c "import torch_tensorrt; print(torch_tensorrt.__version__)"
make html
cd ..
- uses: stefanzweifel/git-auto-commit-action@v4
with:
# Required
commit_message: "docs: [Automated] Regenerating documenation for ${{ steps.vars.outputs.sha }}"
commit_options: "--no-verify --signoff"
file_pattern: docs/
commit_user_name: Torch-TensorRT Github Bot
commit_user_email: [email protected]
commit_author: Torch-TensorRT Github Bot <[email protected]>
- name: Install base deps
run: |
python3 -m pip install pip --upgrade
python3 -m pip install pyyaml numpy torch --pre --extra-index-url https://download.pytorch.org/whl/nightly/cu124
./packaging/pre_build_script.sh
- name: Get HEAD SHA
id: vars
run: echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build Python Package
run: |
python3 -m pip install --pre . --extra-index-url https://download.pytorch.org/whl/nightly/cu124
- name: Generate New Docs
run: |
cd docsrc
dnf clean all
dnf makecache --refresh
dnf install yum-utils -y
dnf config-manager --set-enabled powertools
dnf update --skip-broken --nobest -y
dnf install -y doxygen pandoc
python3 -m pip install -r requirements.txt
python3 -c "import torch_tensorrt; print(torch_tensorrt.__version__)"
make html
cd ..
- uses: stefanzweifel/git-auto-commit-action@v4
with:
# Required
commit_message: "docs: [Automated] Regenerating documenation for ${{ steps.vars.outputs.sha }}"
commit_options: "--no-verify --signoff"
file_pattern: docs/
commit_user_name: Torch-TensorRT Github Bot
commit_user_email: [email protected]
commit_author: Torch-TensorRT Github Bot <[email protected]>

concurrency:
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
group: ${{ github.workflow }}-${{ github.ref_name }}
cancel-in-progress: true
112 changes: 112 additions & 0 deletions .github/workflows/generate_binary_build_matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Generates the binary build matrix

on:
workflow_call:
inputs:
package-type:
description: "Package type to build from (wheel, conda, libtorch)"
default: "wheel"
type: string
os:
description: "Operating system to generate for (linux, windows, macos, macos-arm64)"
default: "linux"
type: string
channel:
description: "Channel to use (nightly, test, release, all)"
default: ""
type: string
test-infra-repository:
description: "Test infra repository to use"
default: "pytorch/test-infra"
type: string
test-infra-ref:
description: "Test infra reference to use"
default: "main"
type: string
with-cuda:
description: "Build with Cuda?"
default: "enable"
type: string
with-rocm:
description: "Build with Rocm?"
default: "enable"
type: string
with-cpu:
description: "Build with CPU?"
default: "enable"
type: string
with-xpu:
description: "Build with XPU?"
default: "disable"
type: string
use-only-dl-pytorch-org:
description: "Use only download.pytorch.org when generating wheel install command?"
default: "false"
type: string
build-python-only:
description: "Generate binary build matrix for a python only package (i.e. only one python version)"
default: "disable"
type: string
python-versions:
description: "A JSON-encoded list of python versions to build. An empty list means building all supported versions"
default: "[]"
type: string
use_split_build:
description: |
[Experimental] Build a libtorch only wheel and build pytorch such that
are built from the libtorch wheel.
required: false
type: boolean
default: false

outputs:
matrix:
description: "Generated build matrix"
value: ${{ jobs.generate.outputs.matrix }}

jobs:
generate:
outputs:
matrix: ${{ steps.generate.outputs.matrix }}
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Checkout test-infra repository
uses: actions/checkout@v4
with:
repository: ${{ inputs.test-infra-repository }}
ref: ${{ inputs.test-infra-ref }}
- uses: ./.github/actions/set-channel
- uses: actions/checkout@v4
with:
repository: pytorch/tensorrt
- name: Generate test matrix
id: generate
env:
PACKAGE_TYPE: ${{ inputs.package-type }}
OS: ${{ inputs.os }}
CHANNEL: ${{ inputs.channel != '' && inputs.channel || env.CHANNEL }}
WITH_CUDA: ${{ inputs.with-cuda }}
WITH_ROCM: ${{ inputs.with-rocm }}
WITH_CPU: ${{ inputs.with-cpu }}
WITH_XPU: ${{ inputs.with-xpu }}
# limit pull request builds to one version of python unless ciflow/binaries/all is applied to the workflow
# should not affect builds that are from events that are not the pull_request event
LIMIT_PR_BUILDS: ${{ github.event_name == 'pull_request' && !contains( github.event.pull_request.labels.*.name, 'ciflow/binaries/all') }}
# This is used when testing release binaries only from download.pytorch.org.
# In cases when pipy binaries are not published yet.
USE_ONLY_DL_PYTORCH_ORG: ${{ inputs.use-only-dl-pytorch-org }}
BUILD_PYTHON_ONLY: ${{ inputs.build-python-only }}
USE_SPLIT_BUILD: ${{ inputs.use_split_build }}
PYTHON_VERSIONS: ${{ inputs.python-versions }}
run: |
set -eou pipefail
MATRIX_BLOB="$(python3 .github/scripts/generate_binary_build_matrix.py)"
echo "${MATRIX_BLOB}"
echo "matrix=${MATRIX_BLOB}" >> "${GITHUB_OUTPUT}"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ inputs.package-type }}-${{ inputs.os }}-${{ inputs.test-infra-repository }}-${{ inputs.test-infra-ref }}
cancel-in-progress: true
2 changes: 1 addition & 1 deletion .github/workflows/release-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions:

jobs:
generate-matrix:
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
uses: ./.github/workflows/generate_binary_build_matrix.yml
if: ${{ contains(github.event.pull_request.labels.*.name, 'build-release-artifacts') || startsWith(github.event.ref, 'refs/tags/v') }}
with:
package-type: wheel
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions:

jobs:
generate-matrix:
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
uses: ./.github/workflows/generate_binary_build_matrix.yml
if: ${{ contains(github.event.pull_request.labels.*.name, 'build-release-artifacts') || startsWith(github.event.ref, 'refs/tags/v') }}
with:
package-type: wheel
Expand Down
2 changes: 1 addition & 1 deletion docsrc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
sphinx_gallery_conf = {
"examples_dirs": "../examples",
"gallery_dirs": "tutorials/_rendered_examples/",
"ignore_pattern": "utils.py",
"ignore_pattern": r"(triton/\w*.py)|(utils.py)",
}

# Setup the breathe extension
Expand Down
2 changes: 1 addition & 1 deletion py/torch_tensorrt/dynamo/conversion/impl/slice/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def cumsum(
)
else:
new_dims = tuple(data.shape)
zeros = np.zeros(new_dims)
zeros = np.zeros(new_dims, dtype=np.float32)
zero_trttensor = get_trt_tensor(ctx, zeros, f"{name}_initial_value")

running_sum = loop.add_recurrence(zero_trttensor)
Expand Down
10 changes: 8 additions & 2 deletions py/torch_tensorrt/dynamo/lowering/_decompositions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

import torch
from torch._decomp import register_decomposition
from torch._export.utils import (
_collect_all_valid_cia_ops_for_aten_namespace,
_get_decomp_for_cia,
)
from torch._ops import OpOverload
from torch.export import default_decompositions
from torch_tensorrt.dynamo._defaults import default_device
from torch_tensorrt.dynamo.conversion.converter_utils import get_positive_dim
from torch_tensorrt.dynamo.utils import to_torch_device
Expand Down Expand Up @@ -558,7 +561,10 @@ def get_decompositions(
return {**CORE_ATEN_DECOMPOSITIONS_FILTERED, **TORCH_TRT_DECOMPOSITIONS}
else:
# changes made here due to torch2.6 changes https://github.com/pytorch/pytorch/pull/135080
decomp_table = default_decompositions()
decomp_table = {}
for op in _collect_all_valid_cia_ops_for_aten_namespace():
decomp_table[op] = _get_decomp_for_cia(op)

DECOMP_TABLE_FILTERED: Dict[OpOverload, Callable[[Any], Any]] = {
decomp: decomp_table[decomp]
for decomp in decomp_table
Expand Down
26 changes: 24 additions & 2 deletions py/torch_tensorrt/dynamo/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import warnings
from dataclasses import fields, replace
from enum import Enum
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
Expand All @@ -10,6 +11,8 @@
import tensorrt as trt
import torch
from torch._subclasses.fake_tensor import FakeTensor

from packaging import version
from torch_tensorrt._Device import Device
from torch_tensorrt._enums import dtype
from torch_tensorrt._features import ENABLED_FEATURES
Expand All @@ -19,8 +22,6 @@
from torch_tensorrt.dynamo._engine_cache import BaseEngineCache
from torch_tensorrt.dynamo._settings import CompilationSettings

from packaging import version

from .types import TRTDataType

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -494,6 +495,27 @@ def parse_dynamo_kwargs(
if "options" in kwargs and len(kwargs) == 1:
kwargs = kwargs["options"]

if "truncate_long_and_double" in kwargs:
if (
"truncate_double" in kwargs
and kwargs["truncate_double"] is not _defaults.TRUNCATE_DOUBLE
):
raise ValueError(
'Provided configuration for "truncate_double" and deprecated API "truncate_long_and_double". '
'Please only use "truncate_double".'
)
else:
kwargs["truncate_double"] = kwargs["truncate_long_and_double"]
warnings.warn(
'Compiler option "truncate_long_and_double" is deprecated in favor of "truncate_double" as int64 is now natively supported. '
"This option will be removed in the next version.",
DeprecationWarning,
stacklevel=2,
)
del kwargs[
"truncate_long_and_double"
] # Remove deprecated key after handling

valid_attrs = {attr.name for attr in fields(settings)}
valid_kwargs = {k: v for k, v in kwargs.items() if k in valid_attrs}
settings = replace(settings, **valid_kwargs)
Expand Down

0 comments on commit a8849bb

Please sign in to comment.