Skip to content

Conversation

@rdspring1
Copy link
Collaborator

  • Define HeuristicParams struct
  • Update manual_execute to take launch_params, compile_params, and scheduler_type from HeuristicParams
  • Add can_schedule, find_compatible_schedulers, and schedule operations to schedule submodule.
  • Create tests for pointwise, reduction, and inner persistent schedulers

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

github-actions bot commented Oct 11, 2025

Review updated until commit 8710824

Description

  • Add automatic scheduler support in direct bindings

  • Introduce HeuristicParams and derived scheduler parameter types

  • Implement schedule, can_schedule, and find_compatible_schedulers operations

  • Add comprehensive tests for pointwise, reduction, and persistent schedulers


Changes walkthrough 📝

Relevant files
Enhancement
heuristic_params.cpp
Bind HeuristicParams and scheduler-specific parameter types to Python

python/python_direct/heuristic_params.cpp

  • Define HeuristicParams class with lparams, cparams, and scheduler_type
  • Add __repr__ and __eq__ methods for string representation and
    comparison
  • Expose hash function and readonly scheduler_type field to Python
  • Define PointwiseParams and ReductionParams as subclasses of
    HeuristicParams
  • +33/-0   
    schedule.cpp
    Implement Python bindings for scheduler compatibility and execution

    python/python_direct/schedule.cpp

  • Add can_schedule to check scheduler compatibility with debug messages
  • Implement find_compatible_schedulers to detect valid schedulers
  • Add schedule function to apply a scheduler and return HeuristicParams
  • Include necessary headers for scheduler runtime and type support
  • +121/-0 
    __init__.py
    Extend manual_execute to support heuristic-based execution

    python/nvfuser_direct/init.py

  • Update manual_execute to accept optional heuristic_params
  • Pass heuristic parameters to compile and run when provided
  • Maintain backward compatibility when heuristic_params is None
  • +17/-2   
    heuristic.h
    Export HeuristicParams via NVF_API for external use           

    csrc/scheduler/heuristic.h

  • Add NVF_API macro to HeuristicParams class for symbol export
  • Enable external linkage of HeuristicParams in shared libraries
  • +1/-1     
    registry.h
    Export canSchedule function via NVF_API                                   

    csrc/scheduler/registry.h

  • Add NVF_API to canSchedule function for external access
  • Allow Python bindings to call canSchedule directly
  • +1/-1     
    runtime_info.h
    Export SchedulerRuntimeInfo constructor via NVF_API           

    csrc/scheduler/runtime_info.h

  • Add NVF_API to SchedulerRuntimeInfo constructor
  • Enable external instantiation of runtime info objects
  • +1/-1     
    Tests
    test_tutorial.py
    Add tests for automatic scheduler functionality                   

    tests/python/direct/test_tutorial.py

  • Add check_auto_schedule helper to validate scheduler selection
  • Test automatic scheduling for pointwise, reduction, and inner
    persistent cases
  • Verify correct scheduler rejection with error message checks
  • Compare NVFuser output with eager PyTorch results
  • +152/-1 
    Bug fix
    executor.h
    Fix scheduler parameter name typo in KernelExecutor           

    csrc/runtime/executor.h

  • Fix typo in SchedulerType parameter name (sceduler -> scheduler)
  • Maintain API consistency in KernelExecutor::compile method
  • +1/-1     

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🧪 PR contains tests
    ⚡ Recommended focus areas for review

    Debug Settings Persistence

    The can_schedule function modifies global debug dump options via DebugDumpOptionsGuard and sets FusionSegmenterLog, but it does not explicitly restore previous settings after use. This could lead to unintended side effects in other parts of the system if the guard does not properly reset the state.

    DebugDumpOptionsGuard debug_dump_options_guard;
    DebugDumpOptionsGuard::getCurOptions().set(
        DebugDumpOption::FusionSegmenterLog);
    
    // Send debug messages to stringstream
    std::stringstream ss;
    DebugStreamGuard dsg(ss);
    
    Default HeuristicParams Handling

    The manual_execute method accepts an optional heuristic_params argument, but when it is not provided, the code falls back to a default compile path without scheduler type. This may lead to inconsistent behavior between automatic and manual execution paths if the scheduler type is not properly inferred or handled in the fallback case.

    if heuristic_params is not None:
        self.ke.compile(
            self.fusion,
            inputs,
            heuristic_params.lparams,
            heuristic_params.cparams,
            heuristic_params.scheduler_type,
        )
    else:
        self.ke.compile(self.fusion, inputs)
    Incomplete Scheduler Enumeration

    The check_auto_schedule helper function filters out SchedulerType.none, but uses if not SchedulerType.none which is always true and does not correctly filter the enum value. This may result in incorrect filtering and unintended inclusion or exclusion of scheduler types during testing.

        if not SchedulerType.none
    ]

    @rdspring1
    Copy link
    Collaborator Author

    !test

    The hash of the heuristic parameters.
    )");

    py::class_<PointwiseParams, HeuristicParams> pointwise(
    Copy link
    Collaborator Author

    Choose a reason for hiding this comment

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

    I will added fields to PointwiseParams and ReductionParams later but the class definition was necessary to pass tests.

    * Define HeuristicParams struct
    * Update manual_execute to take launch_params, compile_params, and scheduler_type
    from HeuristicParams
    * Add can_schedule, find_compatible_schedulers, and schedule operations
    * Create tests for pointwise, reduction, and inner persistent schedulers
    @rdspring1
    Copy link
    Collaborator Author

    !test --pybench

    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.

    1 participant