Angshul commited on
Commit
37c4d1b
·
verified ·
1 Parent(s): 5973eb4

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +106 -52
README.md CHANGED
@@ -1,93 +1,147 @@
1
  ---
 
 
 
2
  license: other
3
- license_name: falcon-llm-license
4
- license_link: https://falconllm.tii.ae/falcon-terms-and-conditions.html
5
  base_model: tiiuae/Falcon-H1-0.5B-Instruct
6
  tags:
 
 
7
  - rust
8
- - cuda
9
  - candle
 
10
  - mamba2
11
- - falcon-h1
12
  - text-generation
 
13
  ---
14
 
15
- # Falcon-H1-0.5B — Rust CUDA Transformer
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- A Rust implementation of the pretrained Falcon-H1-0.5B-Instruct model.
18
 
19
- ## Architecture
20
 
21
- The implementation reproduces Falcon-H1's hybrid architecture:
22
 
23
- - Parallel Mamba-2 and attention
24
- - Grouped-query attention
25
- - Rotary positional embeddings
26
- - RMSNorm
27
- - SwiGLU feed-forward networks
28
- - Original model dimensions and parameters
29
 
30
- Implemented using Rust and Hugging Face Candle.
31
 
32
- ## Pretrained Weights
 
 
 
 
 
33
 
34
- The checkpoint contains converted FP32 weights from:
35
 
36
- https://huggingface.co/tiiuae/Falcon-H1-0.5B-Instruct
 
 
37
 
38
- No additional training or fine-tuning was performed.
39
 
40
- The checkpoint uses a custom .f32pack format.
41
- It is not directly loadable using Transformers.from_pretrained.
 
 
 
42
 
43
- ## GPU Validation
44
 
45
- Tested on NVIDIA Tesla T4 using Google Colab.
46
 
47
- Compared against the original Hugging Face implementation.
48
 
49
- - Maximum absolute logit error: 7.0522e-5
50
- - Mean absolute logit error: 1.4631e-5
51
- - Identical top-5 token predictions
52
 
53
- Validation used the three-token input [1, 2, 3].
 
 
 
 
54
 
55
- ## Build
56
 
57
- Install Rust and CUDA, then execute:
58
 
59
- cargo build --release --features cuda
60
 
61
- ## Start HTTP API
 
 
 
62
 
63
- ./target/release/falcon-h1-api --checkpoint falcon-h1.f32pack --device cuda
 
 
 
 
 
64
 
65
- ## API Endpoints
66
 
67
- - GET /health
68
- - GET /v1/model
69
- - POST /v1/logits
70
- - POST /v1/generate
71
 
72
- The current API accepts token IDs.
73
 
74
- ## CPU Support
75
 
76
- The architecture also supports CPU execution.
77
 
78
- ## Attribution
79
 
80
- Original pretrained model: Technology Innovation Institute (TII).
 
 
 
 
 
 
81
 
82
- Original model weights are governed by the Falcon-LLM License.
83
 
84
- See the original model repository for licensing conditions.
85
 
86
- ## Implementation Status
87
 
88
- - Rust implementation: completed
89
- - CUDA inference: validated on T4
90
- - Numerical agreement: verified for a three-token input
91
- - HTTP inference API: implemented
92
- - Knowledge distillation: not yet implemented
93
- - GPU training optimization: pending
 
1
  ---
2
+ language:
3
+ - en
4
+ pipeline_tag: text-generation
5
  license: other
 
 
6
  base_model: tiiuae/Falcon-H1-0.5B-Instruct
7
  tags:
8
+ - falcon_h1
9
+ - falcon-h1
10
  - rust
 
11
  - candle
12
+ - cuda
13
  - mamba2
14
+ - inference
15
  - text-generation
16
+ - conversational
17
  ---
18
 
19
+ # Falcon-H1-0.5B-Instruct — Rust CUDA Inference API (v0.4)
20
+
21
+ This repository hosts the **original Falcon-H1-0.5B-Instruct pretrained weights converted to an FP32 `.f32pack` checkpoint** for inference using a native **Rust/Candle implementation with NVIDIA CUDA support**.
22
+
23
+ The implementation preserves the model's **hybrid Mamba-2 and grouped-query attention architecture**. It is an inference port, **not a newly trained, fine-tuned, distilled, or quantized model**.
24
+
25
+ - **Rust source code and HTTP API:** https://github.com/AngshulMajumdar/Falcon-H1-Rust-Transformer-API
26
+ - **This converted checkpoint:** https://huggingface.co/Angshul/Falcon-H1-0.5B-Rust
27
+ - **Original pretrained model (Technology Innovation Institute):** https://huggingface.co/tiiuae/Falcon-H1-0.5B-Instruct
28
+
29
+ ## Implementation
30
+
31
+ The Rust v0.4 backend includes:
32
+
33
+ - Native inference with Rust and Candle, supporting CPU and NVIDIA CUDA.
34
+ - Custom fused CUDA kernels for Mamba-2 state recurrence.
35
+ - Cached incremental decoding, retaining Mamba recurrent states, convolution history, and attention key/value states.
36
+ - Batched grouped-query attention (GQA).
37
+ - FP32 inference using the converted `.f32pack` weights.
38
+ - Fixed-length greedy generation of up to **512 new tokens**, subject to a **2,048-token combined input/output limit** on the CUDA backend.
39
+ - A lightweight HTTP API for inference and timing measurements.
40
+
41
+ The provided `.f32pack` file is intended for this Rust backend. It is **not** a native Hugging Face `safetensors` checkpoint and cannot be opened directly using `transformers.from_pretrained()`. Use the upstream repository for standard Transformers inference.
42
+
43
+ ## HTTP API
44
+
45
+ | Endpoint | Purpose |
46
+ | --- | --- |
47
+ | `GET /health` | Check service and execution backend |
48
+ | `GET /v1/model` | Retrieve model configuration |
49
+ | `POST /v1/logits` | Calculate next-token logits |
50
+ | `POST /v1/generate` | Generate tokens with greedy decoding |
51
+ | `POST /v1/generate_profile` | Generate tokens and report prefill/decode timing |
52
 
53
+ **The API uses token IDs, not raw text strings.** Use the original Falcon-H1 tokenizer to encode input and decode results. The server runs locally or on an externally managed deployment; this Hugging Face model repository does not itself provide a hosted endpoint.
54
 
55
+ ### Build and run
56
 
57
+ Install Rust and, for GPU execution, a compatible NVIDIA CUDA toolkit. Clone the source repository:
58
 
59
+ ```bash
60
+ git clone https://github.com/AngshulMajumdar/Falcon-H1-Rust-Transformer-API.git
61
+ cd Falcon-H1-Rust-Transformer-API
62
+ cargo build --release --features cuda
63
+ ```
 
64
 
65
+ Download `falcon-h1.f32pack` from this Hugging Face repository and put it in the directory where you launch the server. Then start the CUDA API:
66
 
67
+ ```bash
68
+ ./target/release/falcon-h1-api \
69
+ --checkpoint falcon-h1.f32pack \
70
+ --device cuda \
71
+ --bind 127.0.0.1:8083
72
+ ```
73
 
74
+ Check that it is running:
75
 
76
+ ```bash
77
+ curl http://127.0.0.1:8083/health
78
+ ```
79
 
80
+ Send a token-ID request:
81
 
82
+ ```bash
83
+ curl -X POST http://127.0.0.1:8083/v1/generate \
84
+ -H "Content-Type: application/json" \
85
+ -d '{"input_ids":[1,2,3],"max_new_tokens":16}'
86
+ ```
87
 
88
+ The response contains `output_ids`, including the supplied prompt tokens and newly generated tokens. The example IDs above are only a smoke test, not a meaningful natural-language prompt.
89
 
90
+ For a natural-language request, obtain the tokenizer from `tiiuae/Falcon-H1-0.5B-Instruct` and use it to encode the prompt before calling the API.
91
 
92
+ ### Reproducibility checks
93
 
94
+ The GitHub repository includes kernel tests, cached-generation parity checks, and benchmarking scripts.
 
 
95
 
96
+ ```bash
97
+ cargo test --release --features cuda --lib fused_cuda_matches_reference_demo -- --nocapture
98
+ cargo test --release --features cuda --lib cached_cuda_generation_equals_full_prefix -- --nocapture
99
+ cargo test --release --features cuda --lib cached_cpu_generation_equals_full_prefix -- --nocapture
100
+ ```
101
 
102
+ For benchmark options and dependencies, see the [GitHub README](https://github.com/AngshulMajumdar/Falcon-H1-Rust-Transformer-API#benchmark).
103
 
104
+ ## Validation against the official Transformers model
105
 
106
+ The Rust CUDA backend was validated on an **NVIDIA Tesla T4** in November 2026 against the official Hugging Face Transformers implementation of Falcon-H1-0.5B-Instruct.
107
 
108
+ - The CUDA build and fused kernel correctness test passed.
109
+ - Cached generation parity tests passed on CPU and CUDA.
110
+ - FP32 logits agreed with the reference implementation, with a maximum absolute difference of approximately **5.6 × 10⁻⁴** over the tested prompts.
111
+ - Final long-generation checks matched the official implementation **exactly at every generated-token position**.
112
 
113
+ | Prompt tokens | Generated tokens | Exact matching tokens |
114
+ | ---: | ---: | ---: |
115
+ | 16 | 128 | 128/128 |
116
+ | 64 | 512 | 512/512 |
117
+ | 128 | 256 | 256/256 |
118
+ | 128 | 512 | 512/512 |
119
 
120
+ To compare the same number of tokens, early EOS stopping was disabled in the PyTorch reference. Rust v0.4 currently performs fixed-length generation and does not stop automatically at an EOS token.
121
 
122
+ These checks validate the tested configurations; they do not constitute a formal equivalence proof across all inputs or devices.
 
 
 
123
 
124
+ ## Performance
125
 
126
+ On a Tesla T4, across **12 tested prompt/output-length configurations**, Rust CUDA end-to-end HTTP generation was **2.00×–2.77× faster** than the official Hugging Face Transformers implementation running with **eager attention and reference/fallback Mamba kernels** in FP32.
127
 
128
+ **Important benchmark scope:** These results are **not** a comparison against optimized PyTorch Mamba kernels (`mamba_ssm` or `causal_conv1d`), FlashAttention, vLLM, or other production inference stacks. They should not be interpreted as evidence that this Rust implementation is universally faster.
129
 
130
+ ## Current limitations
131
 
132
+ - Inference only: no training, fine-tuning, or distillation.
133
+ - Token-ID API: no built-in tokenizer or text-to-text endpoint.
134
+ - Fixed-length greedy generation; no automatic EOS stopping.
135
+ - Fused sequential Mamba prefill, rather than a fully parallel SSD prefill implementation.
136
+ - Attention KV caches use on-device concatenation, not preallocated buffers.
137
+ - No CUDA Graphs, optimized FlashAttention, or production-grade serving features.
138
+ - Benchmark results are specific to the reported hardware, software configuration, and batch-size-one workload.
139
 
140
+ ## Attribution and license
141
 
142
+ **Falcon-H1-0.5B-Instruct, its architecture, and its original pretrained parameters were developed by the Technology Innovation Institute (TII).** This repository redistributes converted weights for use with the Rust inference implementation; it does not claim authorship of the underlying pretrained model.
143
 
144
+ The original Falcon-H1 model is distributed under the **Falcon-LLM License**. Review the [upstream model page and its license terms](https://huggingface.co/tiiuae/Falcon-H1-0.5B-Instruct) before using or redistributing the checkpoint. The separate Rust source repository has its own code license.
145
 
146
+ - **Upstream model:** https://huggingface.co/tiiuae/Falcon-H1-0.5B-Instruct
147
+ - **Rust/CUDA API and reproducibility code:** https://github.com/AngshulMajumdar/Falcon-H1-Rust-Transformer-API