Skip to content
Merged
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
19 changes: 13 additions & 6 deletions cpp/grammar_matcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ int32_t* CheckAndGetBitmaskPtr(const DLTensor& token_bitmask, int vocab_size, in
<< "The provided index is out of bounds";
}

XGRAMMAR_CHECK(token_bitmask.device.device_type == kDLCPU)
<< "The provided bitmask's device is not valid: should be CPU";
XGRAMMAR_CHECK(
token_bitmask.device.device_type == kDLCPU ||
token_bitmask.device.device_type == kDLCUDAHost ||
token_bitmask.device.device_type == kDLROCMHost
) << "The provided bitmask's device is not valid: should be CPU";

return reinterpret_cast<int32_t*>(token_bitmask.data) + index * buffer_size;
}
Expand All @@ -67,10 +70,14 @@ void ApplyTokenBitmaskInplaceCPU(
DLTensor* logits, const DLTensor& bitmask, std::optional<std::vector<int>> indices
) {
// Check device and dim
XGRAMMAR_CHECK(logits->device.device_type == kDLCPU)
<< "The provided logits's device is not valid: should be CPU";
XGRAMMAR_CHECK(bitmask.device.device_type == kDLCPU)
<< "The provided bitmask's device is not valid: should be CPU";
XGRAMMAR_CHECK(
logits->device.device_type == kDLCPU || logits->device.device_type == kDLCUDAHost ||
logits->device.device_type == kDLROCMHost
) << "The provided logits's device is not valid: should be CPU";
XGRAMMAR_CHECK(
bitmask.device.device_type == kDLCPU || bitmask.device.device_type == kDLCUDAHost ||
bitmask.device.device_type == kDLROCMHost
) << "The provided bitmask's device is not valid: should be CPU";
XGRAMMAR_CHECK(logits->ndim == 2 || logits->ndim == 1)
<< "The provided logits's shape is not valid: should be 2D or 1D";
XGRAMMAR_CHECK(bitmask.ndim == 2 || bitmask.ndim == 1)
Expand Down
Loading