1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//! Grammar DFA operations for constrained generation.
//!
//! Masks logits on-device using a compiled DFA, avoiding CPU↔GPU roundtrips.
use crateResult;
use Runtime;
use Tensor;
/// Device-resident DFA for grammar-constrained generation.
///
/// The transition table is flattened for device-friendly access:
/// - `transition_table[state * 256 + byte]` = next_state (or INVALID_STATE if no transition)
/// - `accepting_mask[state]` = 1 if accepting, 0 otherwise
///
/// `vocab_bytes` stores the token byte representations as a flat buffer with offsets.
/// Sentinel value for invalid transitions.
pub const INVALID_STATE: i32 = -1;
/// Operations for grammar-constrained logit masking on device.