Skip to content

Avoid deprecated nvcv_image conversion#1978

Open
nightcityblade wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
nightcityblade:fix/issue-1512
Open

Avoid deprecated nvcv_image conversion#1978
nightcityblade wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
nightcityblade:fix/issue-1512

Conversation

@nightcityblade
Copy link
Copy Markdown
Contributor

Description

Replace the deprecated DecodedFrame.nvcv_image() conversion in NvVideoDecoder.generate_decoded_frames with direct CV-CUDA tensor wrapping of the decoded frame.

Closes #1512.

Usage

# PyNvVideoCodec decoded frames are wrapped directly as CV-CUDA tensors.
cvcuda_tensor = cvcuda.as_tensor(decoded_frame, "NCHW")

Checklist

  • I am familiar with the Contributing Guide.
  • New or Existing tests cover these changes.
  • The documentation is up to date with these changes.

Signed-off-by: nightcityblade <nightcityblade@gmail.com>
@nightcityblade nightcityblade requested a review from a team as a code owner May 13, 2026 15:30
@nightcityblade nightcityblade requested review from praateekmahajan and removed request for a team May 13, 2026 15:30
@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented May 13, 2026

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 13, 2026

Greptile Summary

This PR replaces the deprecated DecodedFrame.nvcv_image() + cvcuda.as_image() pipeline with a direct cvcuda.as_tensor(decoded_frame, "NCHW") call, which is the recommended CV-CUDA approach for wrapping PyNvVideoCodec frames. Because the new call explicitly fixes the layout to NCHW, the previously necessary runtime layout check and its ValueError branch are correctly removed.

  • nvcodec_utils.py: The decoding loop now calls cvcuda.as_tensor once to wrap the raw frame as an NCHW tensor, then proceeds to reformat into NHWC — removing two intermediate objects (nvcv_image, as_image) and the conditional guard.
  • test_nvcodec_utils.py: Drops test_generate_decoded_frames_unexpected_layout (the error path no longer exists) and updates as_tensor_side_effect to use identity-based dispatch on the mock decoded frame, accurately reflecting the new single-argument wrapping call.

Confidence Score: 5/5

Safe to merge — the change is a targeted removal of a deprecated API with no new logic paths introduced.

The diff swaps a deprecated two-step conversion (nvcv_image → as_image → as_tensor) for the single recommended call. No new branching, no altered data flow, and the removed error branch was genuinely unreachable after the change. Tests are updated in parallel to match the new call signature.

No files require special attention.

Important Files Changed

Filename Overview
nemo_curator/utils/nvcodec_utils.py Removes deprecated nvcv_image() call and replaces it with direct cvcuda.as_tensor(decoded_frame, "NCHW"), eliminating the now-unreachable NCHW layout check and its associated error branch.
tests/utils/test_nvcodec_utils.py Removes the test for the now-deleted unexpected-layout error path, drops nvcv_image/as_image mock setup, and adds identity-based dispatch in as_tensor_side_effect to handle the new single-call wrapping convention.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[decoded_frame from nvDec.Decode] --> B["cvcuda.as_tensor(decoded_frame, 'NCHW')"]
    B --> C[cvcuda_tensor with NCHW shape]
    C --> D["Compute nhwc_shape from nchw_shape"]
    D --> E["torch.empty(nhwc_shape, dtype=uint8, device=cuda:N)"]
    E --> F["cvcuda.as_tensor(torch_nhwc, 'NHWC')"]
    F --> G["cvcuda.reformat_into(cvcuda_nhwc, cvcuda_tensor)"]
    G --> H["input_frame_list.put(torch_nhwc)"]
Loading

Reviews (2): Last reviewed commit: "Remove redundant decoded frame layout gu..." | Re-trigger Greptile

@nightcityblade
Copy link
Copy Markdown
Contributor Author

Thanks Greptile — I agree the post-conversion NCHW layout guard became redundant after requesting NCHW directly via cvcuda.as_tensor(decoded_frame, "NCHW"). I pushed a follow-up commit that removes that dead branch and drops the stale unit test that only exercised the removed guard.\n\nValidation:\n- ruff check nemo_curator/utils/nvcodec_utils.py tests/utils/test_nvcodec_utils.py: passed\n- ruff format --check nemo_curator/utils/nvcodec_utils.py tests/utils/test_nvcodec_utils.py: passed\n- pytest tests/utils/test_nvcodec_utils.py: blocked locally on macOS because NeMo-Curator currently raises on non-Linux systems during import

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request waiting-on-maintainers Waiting on maintainers to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alternateive to nvcv_image

2 participants