Text Generation
Transformers
PyTorch
constrained-decoding
reachability
logit-processor
structured-generation
grammar-masking
dfa
fsm
Instructions to use uuugi/gclm-constrained-decoding with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use uuugi/gclm-constrained-decoding with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="uuugi/gclm-constrained-decoding")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("uuugi/gclm-constrained-decoding", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use uuugi/gclm-constrained-decoding with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "uuugi/gclm-constrained-decoding" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "uuugi/gclm-constrained-decoding", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/uuugi/gclm-constrained-decoding
- SGLang
How to use uuugi/gclm-constrained-decoding with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "uuugi/gclm-constrained-decoding" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "uuugi/gclm-constrained-decoding", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "uuugi/gclm-constrained-decoding" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "uuugi/gclm-constrained-decoding", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use uuugi/gclm-constrained-decoding with Docker Model Runner:
docker model run hf.co/uuugi/gclm-constrained-decoding
Replace fragile math with clean pseudocode and clean inline text
Browse files
README.md
CHANGED
|
@@ -20,8 +20,8 @@ pipeline_tag: text-generation
|
|
| 20 |
[](https://huggingface.co/docs/transformers)
|
| 21 |
[](LICENSE)
|
| 22 |
|
| 23 |
-
An ultra-fast, strictly
|
| 24 |
-
GCLM mathematically guarantees that an LLM will strictly reach designated goal/accepting states within a fixed token budget (
|
| 25 |
|
| 26 |
---
|
| 27 |
|
|
@@ -51,28 +51,26 @@ GCLM mathematically guarantees that an LLM will strictly reach designated goal/a
|
|
| 51 |
## 📐 Mathematical Formulation
|
| 52 |
|
| 53 |
### 1. Offline Backward BFS Table Builder
|
| 54 |
-
Given an FSM
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
For \(t = 1, \dots, T_{\max}\):
|
| 61 |
|
| 62 |
-
|
| 63 |
-
R[t, s] = R[t-1, s]
|
| 64 |
-
|
| 65 |
|
| 66 |
-
### 2. Strict
|
| 67 |
-
At decoding step
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
|
| 77 |
---
|
| 78 |
|
|
|
|
| 20 |
[](https://huggingface.co/docs/transformers)
|
| 21 |
[](LICENSE)
|
| 22 |
|
| 23 |
+
An ultra-fast, strictly **O(1)** runtime **Goal-Conditioned Reachability Logit Masking Engine** for Large Language Models.
|
| 24 |
+
GCLM mathematically guarantees that an LLM will strictly reach designated goal/accepting states within a fixed token budget (`T_max`), **fundamentally preventing dead-end traps and truncated syntax failures**.
|
| 25 |
|
| 26 |
---
|
| 27 |
|
|
|
|
| 51 |
## 📐 Mathematical Formulation
|
| 52 |
|
| 53 |
### 1. Offline Backward BFS Table Builder
|
| 54 |
+
Given an FSM $(S, \Sigma, \delta, s_0, S_{\text{goal}})$ and maximum token budget $T_{\max}$, we precompute a reachability tensor $R \in \{0, 1\}^{(T_{\max} + 1) \times |S|}$ via vectorized backward BFS:
|
| 55 |
|
| 56 |
+
```python
|
| 57 |
+
# Base Step (t = 0):
|
| 58 |
+
R[0, s] = 1 if (s in S_goal) else 0
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
# Vectorized Backward BFS (for t = 1 ... T_max):
|
| 61 |
+
R[t, s] = R[t-1, s] OR (∃ v ∈ V such that δ(s, v) >= 0 and R[t-1, δ(s, v)] == 1)
|
| 62 |
+
```
|
| 63 |
|
| 64 |
+
### 2. Strict O(1) Runtime Logits Masking
|
| 65 |
+
At decoding step $k$ with remaining token budget $T_{\text{rem}} = T_{\max} - k$:
|
| 66 |
|
| 67 |
+
```python
|
| 68 |
+
# Step 1: Vectorized check for valid transitions within remaining budget
|
| 69 |
+
ValidTokens(v) = (δ(s_curr, v) >= 0) AND R[min(T_rem - 1, T_max), clamp(δ(s_curr, v), 0)]
|
| 70 |
|
| 71 |
+
# Step 2: In-place O(1) logit masking
|
| 72 |
+
Logits[v] = Logits[v] if ValidTokens(v) == 1 else -inf
|
| 73 |
+
```
|
| 74 |
|
| 75 |
---
|
| 76 |
|