Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,40 @@ TEST_F(ApplyTokenBitmaskWrapperTest, MatchesReferenceAcrossDtypesAndPatterns) {
}
}

TEST_F(ApplyTokenBitmaskWrapperTest,
PreservesAllowedLogitsAndMasksWithInfinity) {
const torch::Device device("npu:0");
const std::vector<torch::ScalarType> dtypes = {
torch::kFloat16, torch::kBFloat16, torch::kFloat32};
for (const torch::ScalarType dtype : dtypes) {
SCOPED_TRACE(static_cast<int32_t>(dtype));
const auto options = torch::TensorOptions().dtype(dtype).device(device);
torch::Tensor input = torch::arange(64, options).view({2, 32}) - 32;
input.select(/*dim=*/1, /*index=*/0)
.fill_(-std::numeric_limits<float>::infinity());
const torch::Tensor bitmask = make_mask(2, 32, "boundaries").to(device);
torch::Tensor actual = input.clone();

ASSERT_TRUE(can_apply_token_bitmask_inplace(actual, bitmask));
apply_token_bitmask_inplace(actual, bitmask);
ASSERT_EQ(aclrtSynchronizeStream(
c10_npu::getCurrentNPUStream(device.index()).stream()),
ACL_SUCCESS);

const torch::Tensor result = actual.to(torch::kCPU);
const torch::Tensor original = input.to(torch::kCPU);
EXPECT_TRUE(torch::equal(result.select(/*dim=*/1, /*index=*/0),
original.select(/*dim=*/1, /*index=*/0)));
EXPECT_TRUE(torch::equal(result.select(/*dim=*/1, /*index=*/31),
original.select(/*dim=*/1, /*index=*/31)));
EXPECT_TRUE(
torch::isneginf(result.slice(/*dim=*/1, /*start=*/1, /*end=*/31))
.all()
.item<bool>());
EXPECT_FALSE(torch::isnan(result).any().item<bool>());
}
}

TEST_F(ApplyTokenBitmaskWrapperTest, RejectsInputsThatRequireFallback) {
const auto device = torch::Device("npu:0");
const auto options =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ def generate_source(dtype: str) -> str:
)
with tilelang.tvm.transform.PassContext(opt_level=3, config=DEFAULT_ASCEND_PASS_CONFIGS):
kernel = tilelang.engine.lower(tilelang_kernel)
return kernel.kernel_source
# TileLang can emit CUDA's infinity macro for Ascend float constants.
# Keep the mask at -inf without requiring CUDA headers or build flags.
compat_header = "#ifndef CUDART_INF\n#define CUDART_INF (__builtin_inff())\n#endif\n"
return compat_header + kernel.kernel_source
Loading