Commit 7ea9c2f
committed
Add Rust port of V-JEPA 2 model using mlx-rs
This commit adds a comprehensive Rust implementation of the V-JEPA 2 model
using mlx-rs (Rust bindings for Apple's MLX framework).
## Rust Implementation (vjepa2-rs/)
### Completed Components:
- ✅ Core transformer modules (src/modules.rs):
- MLP with GELU/SiLU activation
- SwiGLU FFN (Swish-Gated Linear Unit)
- Standard multi-head Attention
- RoPEAttention (Rotary Position Embeddings for 3D video inputs)
- Transformer Block with residual connections and drop path
- rotate_queries_or_keys function for RoPE
- ✅ Patch embedding layers (src/patch_embed.rs):
- PatchEmbed: 2D Conv-based patch embedding for images
- PatchEmbed3D: 3D Conv-based patch embedding for videos
- ✅ Positional embeddings (src/pos_embs.rs):
- 1D and 2D sinusoidal positional embeddings
- ✅ Vision Transformer structure (src/vision_transformer.rs):
- Basic VisionTransformer with patch embedding and blocks
- ✅ Error handling (src/error.rs):
- Custom error types with thiserror
- ✅ Documentation:
- Comprehensive README.md with usage instructions
- Inline documentation for all modules
- Design decisions documented (e.g., RoPE bug replication)
### Key Features:
- Faithful port of Python MLX implementation
- Replicates PyTorch RoPE behavior for pretrained weight compatibility
- LayerNorm eps=1e-6 to match PyTorch exactly
- 3D position separation for video inputs (depth, height, width)
- Type-safe error handling
### Apple Silicon Requirement:
1 parent 71e6389 commit 7ea9c2f
File tree
12 files changed
+1915
-3
lines changed- .github/workflows
- tests
- vjepa2-rs
- src
12 files changed
+1915
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
132 | 132 | | |
133 | 133 | | |
134 | 134 | | |
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
141 | 150 | | |
142 | 151 | | |
143 | 152 | | |
144 | 153 | | |
145 | 154 | | |
146 | 155 | | |
147 | | - | |
| 156 | + | |
148 | 157 | | |
149 | 158 | | |
150 | 159 | | |
| |||
153 | 162 | | |
154 | 163 | | |
155 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
156 | 217 | | |
157 | 218 | | |
158 | 219 | | |
| |||
0 commit comments