Skip to content

cv-utils: add several Triton kernels - #1182

Merged
drbh merged 20 commits into
huggingface:mainfrom
molbap:more_cv_utils
Nov 10, 2026
Merged

drbh merged 20 commits into
huggingface:mainfrom
molbap:more_cv_utils

Conversation

@molbap

@molbap molbap commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

This adds Triton functions to cv-utils for pre- and post-processing in transformers.

  • resize_normalize: antialiased resize, center crop, rescale and normalize of uint8 images of different sizes, in one call.
  • resize_normalize_patchify: the same, written directly in the Qwen2-VL patch layout, for images and videos.
  • upsample_argmax: segmentation class map from low-resolution logits, without storing the upsampled logits.
  • connected_component_areas: cc_2d for masks of any height and width.

The transformers side is github.com/huggingface/transformers/pull/46771, where image processors call these kernels with use_kernels=True.

This bumps cv-utils to v2. Tests compare against torch.nn.functional.interpolate and are in the kernels_ci subset.

@github-actions github-actions Bot added the chore Version bumps, releases, misc maintenance label Sep 25, 2026
@vasqu

vasqu commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

We also have #1181 cc @danieldk I don't think it exactly interferes with this PR?

@danieldk

Copy link
Copy Markdown
Member

We also have #1181 cc @danieldk I don't think it exactly interferes with this PR?

Indeed, shouldn't interfere, since these are pure Python changes.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

This PR changes source code for the following kernel(s): cv-utils.

If you have the kernel-bot build permissions, then trigger /kernel-bot build cv-utils yourself. Otherwise, a maintainer will review the PR and will take an appropriate action. Thanks for your patience.

@molbap
molbap marked this pull request as ready for review October 9, 2026 13:11
@molbap

molbap commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

/kernel-bot build-and-stage cv-utils

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Build request processed.

Command: /kernel-bot build-and-stage cv-utils
Mode: build and stage
Target branch: pr-1182
PR head SHA: e0acdfd53b66755eb89b137d509572b40433109a
Workflows: build.yaml, build-mac.yaml, build-windows.yaml

Dispatched (1):

Hub uploads:

@vasqu

vasqu commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Lmk when I should review @molbap 🫡

@molbap

molbap commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

I think you can review now @vasqu !

@molbap

molbap commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

/kernel-bot build-and-stage cv-utils

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Build request processed.

Command: /kernel-bot build-and-stage cv-utils
Mode: build and stage
Target branch: pr-1182
PR head SHA: 41aa57e340f0c0fda238d67df0357e7ab2d6f19f
Workflows: build.yaml, build-mac.yaml, build-windows.yaml

Dispatched (1):

Hub uploads:

@molbap

molbap commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

/kernel-bot build-and-stage cv-utils

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Build request processed.

Command: /kernel-bot build-and-stage cv-utils
Mode: build and stage
Target branch: pr-1182
PR head SHA: d7a34185afe32c1b47afbf0a0c42eb1aaa91b133
Workflows: build.yaml, build-mac.yaml, build-windows.yaml

Dispatched (1):

Hub uploads:

@github-actions github-actions Bot added the needs-rebase Has merge conflicts with the base branch label Oct 21, 2026
@github-actions github-actions Bot removed the needs-rebase Has merge conflicts with the base branch label Oct 29, 2026
@molbap molbap changed the title cv-utils: add resize_normalize and resize_normalize_patchify Triton kernels cv-utils: add several Triton kernels Oct 29, 2026
@molbap

molbap commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

/kernel-bot build-and-stage cv-utils

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Build request processed.

Command: /kernel-bot build-and-stage cv-utils
Mode: build and stage
Target branch: pr-1182
PR head SHA: fd940b8ba3c87eecb925700fd1061848faa74859
Workflows: build.yaml, build-mac.yaml, build-windows.yaml

Dispatched (1):

Hub uploads:

@molbap

molbap commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

/kernel-bot build-and-stage cv-utils

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Build request processed.

Command: /kernel-bot build-and-stage cv-utils
Mode: build and stage
Target branch: pr-1182
PR head SHA: f60a95475afee5de3ed385dfe8c1c3e395f6072e
Workflows: build.yaml, build-mac.yaml, build-windows.yaml

Dispatched (1):

Hub uploads:

@drbh drbh left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

planning to optimistically merge this PR after a small CI fix that is causing the min torch version ci job seen here https://github.com/huggingface/kernels-community/actions/runs/41133285042/job/124352993673#step:9:30

**update: pr to resolve opened here

rational for merging - build and tests look good, this pr adds functionality and has been open for >1 month. happy to hold off for any reason

drbh added a commit that referenced this pull request Nov 10, 2026
this pr fixes the `test-kernel-minimum-torch` job for stable abi kernels
that run triton in their tests (first hit on #1182
https://github.com/huggingface/kernels-community/actions/runs/41133285042/job/124352993673)

tldr; `uv venv` picks the runner's system python which has no headers,
so triton fails to compile its launcher with `Python.h: No such file or
directory`. the venv now uses `--managed-python`, which ships with
headers

repro in an ubuntu 24.04 container with the system python and no
`python3.12-dev`, running the #1182 tests

before

    44 failed, 92 passed, 4 skipped

after

    136 passed, 4 skipped

note: the repro ran on rocm (mi300x) so triton compiles `hip_utils.c`
instead of `cuda_utils.c`, same `Python.h` include. #1182 needs a
rebuild after this is merged since the workflow runs from main
@drbh

drbh commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

/kernel-bot merge-and-upload cv-utils

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Build request failed.

Command: /kernel-bot merge-and-upload cv-utils
Mode: merge, build and upload
Target branch: ``
PR head SHA: f60a95475afee5de3ed385dfe8c1c3e395f6072e
Workflows: `build.yaml, build-mac.yaml, build-windows.yaml`

Failure: Failed to merge PR before build/upload. Check mergeability and required checks.

@drbh

drbh commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

/kernel-bot merge-and-upload cv-utils

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Build request failed.

Command: /kernel-bot merge-and-upload cv-utils
Mode: merge, build and upload
Target branch: ``
PR head SHA: f60a95475afee5de3ed385dfe8c1c3e395f6072e
Workflows: `build.yaml, build-mac.yaml, build-windows.yaml`

Failure: Failed to merge PR before build/upload. Check mergeability and required checks.

@drbh
drbh merged commit c5c58b6 into huggingface:main Nov 10, 2026
8 of 9 checks passed
@drbh

drbh commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

/kernel-bot merge-and-upload cv-utils

@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Build request processed.

Command: /kernel-bot merge-and-upload cv-utils
Mode: merge, build and upload
Target branch: ``
PR head SHA: f60a95475afee5de3ed385dfe8c1c3e395f6072e
Workflows: `build.yaml, build-mac.yaml, build-windows.yaml`

Merge result: PR is already merged. Continuing with build/upload.

Dispatched (1):

Hub uploads:

drbh added a commit that referenced this pull request Nov 13, 2026
this pr fixes the `test-kernel-rocm` job for kernels that run triton in
their tests (first hit on #1320
https://github.com/huggingface/kernels-community/actions/runs/43476728896/job/132069439103)

tldr; the job runs in a bare `ubuntu:24.04` container with no compiler,
so triton fails to build its launcher with `RuntimeError: Failed to find
C compiler`. the base packages step now also installs `gcc` and
`libc6-dev` (`--no-install-recommends` skips the libc headers otherwise)

same #1182 cv-utils tests as #1318, `44 failed, 92 passed, 4 skipped`,
but a missing compiler instead of missing `Python.h` (the nix ci-test
python has headers). the cuda runners have a host gcc so
`test-kernel-gpu` passes

note: #1320 and #1329 need a rebuild after this is merged since the
workflow runs from main
github-actions Bot pushed a commit that referenced this pull request Nov 19, 2026
this pr adds a rocm build for `cv-utils`

same change as causal-conv1d in #1319: the `rocm` backend, `rocm =
"2.10"` stable abi and a `cpp-rocm` kernel with the same sources and
`activation` archs, and `stable_utils.h` picks the hip runtime under
`USE_ROCM`. the kernels have no warp intrinsics and nms already uses 64
bit masks, so no kernel changes. the triton functions from #1182 run on
rocm as is

built all rocm variants (`rocm70`, `rocm71`, `rocm714`, `rocm72`,
`rocm100`) and ran the tests on mi300x (gfx942) with torch
`2.10.0+rocm7.0`, `2.12.1+rocm7.1` and `2.14.1+rocm7.2`, 136 pass on
each (4 skipped, they need two gpus). `generic_nms` keeps the same boxes
as `torchvision.ops.nms` on rocm at 1k, 5k and 20k boxes and is within
4% of its speed

note: this lands in v2, sam3 video still loads `version=1` so
transformers needs to bump that before it picks up the rocm build. no
version bump here since this only adds a backend


*keeping as draft until ci support rocm 
- #1313

---------

Signed-off-by: David Holtz <david.richard.holtz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Version bumps, releases, misc maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants