Skip to content

fix(plugins): lower floor division in generated plugin output shapes - #4876

Open
narendasan wants to merge 1 commit into
mainfrom
narendasan/plugin-shape-floordiv
Open

narendasan wants to merge 1 commit into
mainfrom
narendasan/plugin-shape-floordiv

Conversation

@narendasan

@narendasan narendasan commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • A custom op whose fake kernel sizes an output from a dynamic input dimension with // -- e.g. x.new_empty((*x.shape[:-1], x.shape[-1] // 2)) -- could not be turned into an automatically generated plugin. Torch writes the size as its own sympy FloorDiv, sympy.lambdify prints unknown functions by name, and the generated shape function raised NameError: name 'FloorDiv' is not defined inside get_output_data_types(), which TensorRT reports as a failed addPluginV3.
  • Lambdify the output shapes against a namespace that implements FloorDiv as operator.floordiv, which tensorrt.plugin.ShapeExpr supports (as do plain ints, for static sizes).

Tests

  • New tests/py/dynamo/automatic_plugin/test_automatic_plugin_shape_exprs.py: compiles an op returning the sum of the two halves of a dynamic last dim and checks shapes and values at the min/opt/max sizes (odd sizes included). It fails without the change, with the NameError above.
  • pytest tests/py/dynamo/automatic_plugin: 34 passed, 2 skipped.
  • Independent of perf(kernels): let triton_op kernels assume TensorRT's tensor alignment #4875 and fix(kernels): reject triton_op kernels needing more than 48 KiB of shared memory #4877 (the other fixes from the same work) and landable in any order: with all three merged onto main, pytest tests/py/kernels tests/py/dynamo/automatic_plugin/test_automatic_plugin_shape_exprs.py gives 250 passed, 34 skipped.
  • Run on an RTX 5090 with TensorRT 11.3: main's Python against a locally built runtime.

🤖 Generated with Claude Code

@meta-cla meta-cla Bot added the cla signed label Oct 19, 2026
@github-actions github-actions Bot added component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Oct 19, 2026
@github-actions
github-actions Bot requested a review from zewenli98 October 19, 2026 16:15
A custom op whose fake kernel sizes an output as a fraction of an input
dimension -- `x.new_empty(..., x.shape[-1] // 2)` -- could not be turned into
a plugin when that dimension is dynamic. Torch writes the size as its own
sympy `FloorDiv`, `sympy.lambdify` prints unknown functions by name, and the
generated shape function raised `NameError: name 'FloorDiv' is not defined`
inside `get_output_data_types()`, which TensorRT reports as a failed
`addPluginV3`.

Lambdify the output shapes against a namespace that implements `FloorDiv` as
`operator.floordiv`, which `tensorrt.plugin.ShapeExpr` supports (and plain
ints, for static sizes).

Tests: `tests/py/dynamo/automatic_plugin/test_automatic_plugin_shape_exprs.py`
compiles an op returning the sum of the two halves of a dynamic last dim and
checks shapes and values at the min/opt/max sizes (odd sizes included); it
fails without the change. `pytest tests/py/dynamo/automatic_plugin`: 34
passed, 2 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@narendasan
narendasan force-pushed the narendasan/plugin-shape-floordiv branch from 06d08e2 to dfe7174 Compare November 23, 2026 23:06
@narendasan
narendasan requested a review from bowang007 November 23, 2026 23:25
@narendasan narendasan added this to the v2.16.0 milestone Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant