Skip to content

[BUG] visit_IfExp would execute both if and else statements #2880

@henrylhtsang

Description

@henrylhtsang

Which component has the problem?

CuTe DSL

Bug Report

Describe the bug
If you run

ans = [cute.printf("if statement\n"), 1][1] if row_idx < self.seqlen_q else [cute.printf("else statement\n"), 1][1]

then you would see both executed

if statement

else statement

From @v0i0, this is due to https://github.com/NVIDIA/cutlass/blob/main/python/CuTeDSL/cutlass/base_dsl/ast_preprocessor.py#L1637, which transforms the if else into select so it computes both sides.

This can be a bit unexpected, since this differs from the usual behavior:

if A:
  XXX
else:
  YYY

Steps/Code to reproduce bug
Include this code.

ans = [cute.printf("if statement\n"), 1][1] if row_idx < self.seqlen_q else [cute.printf("else statement\n"), 1][1]

Expected behavior
Same behavior as normal if else blocks.

Environment details (please complete the following information):
Linux, python 3.12, GB200, nvidia-cutlass-dsl 4.3.3

Additional context
NA

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions