Skip to content

Conversation

@rdspring1 rdspring1 added Python API Issues related to the Python API Direct Bindings Python extension with direct mapping to NvFuser CPP objects. labels Jul 28, 2025
@github-actions
Copy link

github-actions bot commented Jul 28, 2025

Review updated until commit 730be69

Description

  • Added threshold and clamp operations to direct bindings

  • Introduced new macro for threshold-like operations

  • Defined clamp and threshold operations with documentation


Changes walkthrough 📝

Relevant files
Enhancement
ops.cpp
Add threshold and clamp operations                                             

python/python_direct/ops.cpp

  • Introduced NVFUSER_DIRECT_BINDING_THRESHOLD_LIKE_OP macro
  • Added clamp and threshold operations using the new macro
  • Included documentation for clamp and threshold operations
  • +47/-0   

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🧪 No relevant tests
    ⚡ Recommended focus areas for review

    Possible Issue

    The macro NVFUSER_DIRECT_BINDING_THRESHOLD_LIKE_OP defines two bindings for the same operation name (NAME), which might lead to conflicts or unexpected behavior. Ensure that the operation names are unique or that the bindings are correctly handled.

    #define NVFUSER_DIRECT_BINDING_THRESHOLD_LIKE_OP(NAME, OP_NAME, DOCSTRING)     \
      ops.def(                                                                     \
          NAME,                                                                    \
          [](Val* arg1, Val* arg2, Val* arg3) -> Val* {                            \
            return static_cast<Val* (*)(Val*, Val*, Val*)>(OP_NAME)(               \
                arg1, arg2, arg3);                                                 \
          },                                                                       \
          py::return_value_policy::reference);                                     \
      ops.def(                                                                     \
          NAME,                                                                    \
          [](TensorView* arg1, Val* arg2, Val* arg3) -> TensorView* {              \
            return static_cast<TensorView* (*)(TensorView*, Val*, Val*)>(OP_NAME)( \
                arg1, arg2, arg3);                                                 \
          },                                                                       \
          DOCSTRING,                                                               \
          py::return_value_policy::reference);
    Documentation

    The documentation for the clamp and threshold operations should specify the types of min, max, threshold, and value parameters more clearly. For example, whether they can be scalars or only tensors.

      NVFUSER_DIRECT_BINDING_THRESHOLD_LIKE_OP("clamp", clamp, R"(
    Clamps all elements in input into the range [ min, max ]
    
    Parameters
    ----------
    input : Val or TensorView
    min : Val or TensorView
    max : Val or TensorView
    
    Returns
    -------
    Val or TensorView
        Clamped values.
    )")
    
      NVFUSER_DIRECT_BINDING_THRESHOLD_LIKE_OP("threshold", threshold, R"(
    Thresholds each element of the input Tensor.
    
    Parameters
    ----------
    input : Val or TensorView
    threshold : Val or TensorView
    value : Val or TensorView
    
    Returns
    -------
    Val or TensorView
        Thresholded values.
    )")

    @rdspring1 rdspring1 force-pushed the direct_tp12 branch 2 times, most recently from ec04d7c to 5340d8b Compare July 28, 2025 23:19
    @rdspring1
    Copy link
    Collaborator Author

    !test

    Copy link
    Collaborator

    @jjsjann123 jjsjann123 left a comment

    Choose a reason for hiding this comment

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

    nitpick: tests~~

    @rdspring1
    Copy link
    Collaborator Author

    Reference #432 to add opinfo tests for threshold and clamp

    @rdspring1 rdspring1 merged commit 6fe634a into main Jul 30, 2025
    50 of 52 checks passed
    @rdspring1 rdspring1 deleted the direct_tp12 branch July 30, 2025 16:29
    rdspring1 added a commit that referenced this pull request Jul 30, 2025
    rdspring1 added a commit that referenced this pull request Jul 31, 2025
    rdspring1 added a commit that referenced this pull request Aug 3, 2025
    rdspring1 added a commit that referenced this pull request Aug 3, 2025
    rdspring1 added a commit that referenced this pull request Aug 3, 2025
    rdspring1 added a commit that referenced this pull request Aug 3, 2025
    rdspring1 added a commit that referenced this pull request Aug 4, 2025
    rdspring1 added a commit that referenced this pull request Aug 4, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    Direct Bindings Python extension with direct mapping to NvFuser CPP objects. Python API Issues related to the Python API

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants