swizzle-ai 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- swizzle_ai-0.2.0/PKG-INFO +252 -0
- swizzle_ai-0.2.0/README.md +225 -0
- swizzle_ai-0.2.0/pyproject.toml +44 -0
- swizzle_ai-0.2.0/setup.cfg +4 -0
- swizzle_ai-0.2.0/swizzle/__init__.py +47 -0
- swizzle_ai-0.2.0/swizzle/cli.py +252 -0
- swizzle_ai-0.2.0/swizzle/client.py +135 -0
- swizzle_ai-0.2.0/swizzle/completions.py +183 -0
- swizzle_ai-0.2.0/swizzle/exceptions.py +26 -0
- swizzle_ai-0.2.0/swizzle/robotics.py +479 -0
- swizzle_ai-0.2.0/swizzle/types.py +75 -0
- swizzle_ai-0.2.0/swizzle/world.py +164 -0
- swizzle_ai-0.2.0/swizzle_ai.egg-info/PKG-INFO +252 -0
- swizzle_ai-0.2.0/swizzle_ai.egg-info/SOURCES.txt +19 -0
- swizzle_ai-0.2.0/swizzle_ai.egg-info/dependency_links.txt +1 -0
- swizzle_ai-0.2.0/swizzle_ai.egg-info/entry_points.txt +3 -0
- swizzle_ai-0.2.0/swizzle_ai.egg-info/requires.txt +6 -0
- swizzle_ai-0.2.0/swizzle_ai.egg-info/top_level.txt +1 -0
- swizzle_ai-0.2.0/tests/test_benchmark_streaming.py +12 -0
- swizzle_ai-0.2.0/tests/test_client.py +88 -0
- swizzle_ai-0.2.0/tests/test_robotics.py +155 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swizzle-ai
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Official Python SDK & Student CLI for Swizzle: Sub-40ms LLM TTFT, 60Hz Robotics VLA (PatchCache, SpecAct, Teleop), and Batched Latent World-Model MPC.
|
|
5
|
+
Author-email: Paramveer Singh <param15.veer.singh@gmail.com>
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://swizzle-ten.vercel.app
|
|
8
|
+
Project-URL: Repository, https://github.com/Swizzle-AI/swizzle-python-sdk
|
|
9
|
+
Project-URL: Documentation, https://github.com/Swizzle-AI/swizzle-python-sdk#readme
|
|
10
|
+
Keywords: llm,inference,speculative-decoding,prefix-caching,vllm,agents,swizzle
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
Requires-Dist: httpx>=0.24.0
|
|
23
|
+
Requires-Dist: pydantic>=2.0.0
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: pytest>=7.0.0; extra == "test"
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == "test"
|
|
27
|
+
|
|
28
|
+
# Swizzle Python SDK (`swizzle-ai`)
|
|
29
|
+
|
|
30
|
+
<div align="center">
|
|
31
|
+
|
|
32
|
+
### Official High-Performance Python Client for Swizzle AI
|
|
33
|
+
|
|
34
|
+
**Speculative Decoding Streaming · Dual-Wire Compatibility · 80.5 Hz Robotics Visual Servoing · Latent World Models**
|
|
35
|
+
|
|
36
|
+
[](https://pypi.org/project/swizzle-ai/)
|
|
37
|
+
[](https://pypi.org/project/swizzle-ai/)
|
|
38
|
+
[](https://github.com/Swizzle-AI/swizzle-python-sdk)
|
|
39
|
+
[](LICENSE)
|
|
40
|
+
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## ⚡ Architecture Overview
|
|
46
|
+
|
|
47
|
+
```mermaid
|
|
48
|
+
flowchart TD
|
|
49
|
+
subgraph Client["swizzle-ai Python SDK (Client Layer)"]
|
|
50
|
+
direction TB
|
|
51
|
+
Init["swizzle.Swizzle(api_key, base_url)"]
|
|
52
|
+
|
|
53
|
+
subgraph SubClients["Client Modules"]
|
|
54
|
+
C1["client.chat.completions<br/>• Sync & Async Streaming<br/>• Speculative Burst Token Unpacking<br/>• Hardware Telemetry Header Parsing"]
|
|
55
|
+
C2["client.robotics (VLAPolicy)<br/>• 80.5 Hz Real-Time Control Loop<br/>• ViT Patch Delta Cache (97.1% Hit)<br/>• 7-DoF 2nd-Order Kinematic SpecAct<br/>• Quintic Spline Temporal Ensembling"]
|
|
56
|
+
C3["client.world (WorldPlanner)<br/>• Latent Transition Dynamics<br/>• 128-Rollout Batched CEM Planning<br/>• Horizon Cost Optimization"]
|
|
57
|
+
C4["swizzle CLI<br/>• swizzle-ai chat<br/>• swizzle-ai robot<br/>• swizzle-ai bench"]
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
Init --> C1
|
|
61
|
+
Init --> C2
|
|
62
|
+
Init --> C3
|
|
63
|
+
Init --> C4
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
subgraph Transport["Dual-Wire Transport"]
|
|
67
|
+
HTTP["HTTP/2 & Server-Sent Events (SSE)"]
|
|
68
|
+
WS["Sub-15ms WebSocket Stream"]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
subgraph Backend["Swizzle Distributed Cluster"]
|
|
72
|
+
GW["Swizzle Gateway (Go 1.22+)<br/>Dual Wire Protocol & AST-Diff Trie"]
|
|
73
|
+
ENG["Swizzle Engine & Kernels<br/>Speculative Tree Verification & Paged XOR Attention"]
|
|
74
|
+
ROBOT["Swizzle Robotics Edge/Cloud Worker<br/>Cosmos, SmolVLA, OpenVLA, Pi0, V-JEPA 2"]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
C1 -->|OpenAI / Anthropic Spec| HTTP
|
|
78
|
+
C2 -->|Real-Time Frame & Motor Telemetry| WS
|
|
79
|
+
C3 -->|Latent Goal / Rollout Queries| HTTP
|
|
80
|
+
HTTP --> GW
|
|
81
|
+
WS --> GW
|
|
82
|
+
GW --> ENG
|
|
83
|
+
GW --> ROBOT
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## 📦 Installation
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install swizzle-ai
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Or install in editable mode for local development:
|
|
95
|
+
```bash
|
|
96
|
+
git clone https://github.com/Swizzle-AI/swizzle-python-sdk.git
|
|
97
|
+
cd swizzle-python-sdk
|
|
98
|
+
pip install -e .[test]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
---
|
|
102
|
+
|
|
103
|
+
## 🚀 Quickstart & Usage
|
|
104
|
+
|
|
105
|
+
### 1. Speculative Decoding Chat Completions with Hardware Telemetry
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from swizzle import Swizzle
|
|
109
|
+
|
|
110
|
+
client = Swizzle(api_key="swz_live_free_tier")
|
|
111
|
+
|
|
112
|
+
response = client.chat.completions.create(
|
|
113
|
+
model="Qwen/Qwen2.5-Coder-7B-Instruct",
|
|
114
|
+
messages=[
|
|
115
|
+
{"role": "system", "content": "You are a performance systems engineer."},
|
|
116
|
+
{"role": "user", "content": "Explain shared-memory bank conflicts in CUDA."}
|
|
117
|
+
],
|
|
118
|
+
temperature=0.2,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
print(response.choices[0].message.content)
|
|
122
|
+
|
|
123
|
+
# Access hardware-roofline telemetry returned by Swizzle
|
|
124
|
+
print(f"TTFT: {response.telemetry.ttft_ms} ms")
|
|
125
|
+
print(f"Prefix Cache Hit: {response.telemetry.cache_hit_tokens} tokens")
|
|
126
|
+
print(f"Speculative Speedup: {response.telemetry.speculative_speedup}")
|
|
127
|
+
print(f"AST-Tree Reuse: {response.telemetry.ast_reuse_pct}")
|
|
128
|
+
print(f"PD Disaggregation: {response.telemetry.pd_mode}")
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
### 2. Low-Latency Streaming with Speculative Burst Unpacking
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from swizzle import Swizzle
|
|
137
|
+
|
|
138
|
+
client = Swizzle(api_key="swz_live_free_tier")
|
|
139
|
+
|
|
140
|
+
stream = client.chat.completions.create(
|
|
141
|
+
model="Qwen/Qwen2.5-Coder-7B-Instruct",
|
|
142
|
+
messages=[{"role": "user", "content": "Refactor this HTTP handler into Go"}],
|
|
143
|
+
stream=True
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
for chunk in stream:
|
|
147
|
+
if chunk.choices and chunk.choices[0].delta.content:
|
|
148
|
+
print(chunk.choices[0].delta.content, end="", flush=True)
|
|
149
|
+
|
|
150
|
+
print(f"\nSpeculative Engine: {chunk.telemetry.speculative_engine}")
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
### 3. Asynchronous Client (`AsyncSwizzle`)
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
import asyncio
|
|
159
|
+
from swizzle import AsyncSwizzle
|
|
160
|
+
|
|
161
|
+
async def main():
|
|
162
|
+
async with AsyncSwizzle(api_key="swz_live_free_tier") as client:
|
|
163
|
+
response = await client.chat.completions.create(
|
|
164
|
+
model="Qwen/Qwen2.5-Coder-7B-Instruct",
|
|
165
|
+
messages=[{"role": "user", "content": "Benchmark matrix multiplication in Python"}]
|
|
166
|
+
)
|
|
167
|
+
print(response.choices[0].message.content)
|
|
168
|
+
|
|
169
|
+
asyncio.run(main())
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
### 4. Robotics VLAs & Latent World Models (`swizzle.robotics` & `swizzle.world`)
|
|
175
|
+
|
|
176
|
+
Execute high-frequency (80.5 Hz) Vision-Language-Action policies (`SmolVLA`, `OpenVLA`, $\pi_0$-FAST) and Latent World Models (`NVIDIA Cosmos`, `Meta V-JEPA 2`) across 2 GB–8 GB student laptops:
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
from swizzle import VLAPolicy, WorldPlanner, HardwareDetector
|
|
180
|
+
|
|
181
|
+
# 1. Auto-detect student laptop VRAM and recommended quantized stack
|
|
182
|
+
hw = HardwareDetector.detect()
|
|
183
|
+
print(f"Recommended VLA: {hw.recommended_vla} | World Model: {hw.recommended_world_model}")
|
|
184
|
+
|
|
185
|
+
# 2. 80.5 Hz VLA Control with 97.1% ViT Patch Reuse + 7-DoF Kinematic SpecAct + 50Hz Spline
|
|
186
|
+
policy = VLAPolicy(
|
|
187
|
+
model=hw.recommended_vla,
|
|
188
|
+
patch_cache=True,
|
|
189
|
+
speculative_kinematics=True,
|
|
190
|
+
temporal_ensemble_hz=50,
|
|
191
|
+
)
|
|
192
|
+
step = policy.act(camera_patches, instruction="pick up the red block")
|
|
193
|
+
print(f"7-DoF Action: {step.action} | Patch Hit Ratio: {step.patch_hit_ratio:.1%}")
|
|
194
|
+
|
|
195
|
+
# 3. Batched 128-Rollout Cross-Entropy Method (CEM) World-Model Planning (25.0 ms)
|
|
196
|
+
planner = WorldPlanner(model=hw.recommended_world_model, num_trajectories=128, horizon=5)
|
|
197
|
+
plan = planner.plan(current_latent=[0.1, 0.2, 0.0, 0.0], goal_latent=[0.8, 0.7, 0.0, 0.0])
|
|
198
|
+
print(f"Optimal First Action: {plan.optimal_actions[0]} (Cost: {plan.final_cost:.4f})")
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
### 5. CLI Tooling
|
|
204
|
+
|
|
205
|
+
`swizzle-ai` ships with an interactive command-line interface:
|
|
206
|
+
|
|
207
|
+
```bash
|
|
208
|
+
# Authenticate or inspect active endpoint
|
|
209
|
+
swizzle-ai login --key swz_live_free_tier
|
|
210
|
+
|
|
211
|
+
# Interactive chat session
|
|
212
|
+
swizzle-ai chat --model Qwen/Qwen2.5-Coder-7B-Instruct
|
|
213
|
+
|
|
214
|
+
# Inspect student hardware capabilities
|
|
215
|
+
swizzle-ai robot detect
|
|
216
|
+
|
|
217
|
+
# Start local robotics teleop bridge
|
|
218
|
+
swizzle-ai robot teleop --hz 80
|
|
219
|
+
|
|
220
|
+
# Benchmark inference latency and TTFT
|
|
221
|
+
swizzle-ai bench --tokens 1024 --concurrency 4
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## 🛡️ Telemetry Properties
|
|
227
|
+
|
|
228
|
+
Every `response.telemetry` object exposes:
|
|
229
|
+
* `ttft_ms`: Exact Time-To-First-Token in milliseconds.
|
|
230
|
+
* `cache_hit_tokens`: Tokens loaded directly from GPU HBM prefix cache.
|
|
231
|
+
* `speculative_speedup`: Effective throughput acceleration factor (e.g. `2.76x`).
|
|
232
|
+
* `speculative_acceptance`: Percentage of candidate draft tokens accepted (e.g. `90.5%`).
|
|
233
|
+
* `ast_reuse_pct`: Non-linear AST block cache reuse percentage (e.g. `89.6%`).
|
|
234
|
+
* `pd_mode`: `Disaggregated (Prefill->Decode)` or `Colocated`.
|
|
235
|
+
* `worker_node`: Target accelerator node ID.
|
|
236
|
+
* `cost_usd` & `saved_usd`: Exact metered micro-dollar accounting.
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## 🧪 Testing
|
|
241
|
+
|
|
242
|
+
Run unit tests locally:
|
|
243
|
+
|
|
244
|
+
```bash
|
|
245
|
+
pytest -v tests/
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## 📄 License
|
|
251
|
+
|
|
252
|
+
Licensed under the [Apache License, Version 2.0](LICENSE).
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# Swizzle Python SDK (`swizzle-ai`)
|
|
2
|
+
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
### Official High-Performance Python Client for Swizzle AI
|
|
6
|
+
|
|
7
|
+
**Speculative Decoding Streaming · Dual-Wire Compatibility · 80.5 Hz Robotics Visual Servoing · Latent World Models**
|
|
8
|
+
|
|
9
|
+
[](https://pypi.org/project/swizzle-ai/)
|
|
10
|
+
[](https://pypi.org/project/swizzle-ai/)
|
|
11
|
+
[](https://github.com/Swizzle-AI/swizzle-python-sdk)
|
|
12
|
+
[](LICENSE)
|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## ⚡ Architecture Overview
|
|
19
|
+
|
|
20
|
+
```mermaid
|
|
21
|
+
flowchart TD
|
|
22
|
+
subgraph Client["swizzle-ai Python SDK (Client Layer)"]
|
|
23
|
+
direction TB
|
|
24
|
+
Init["swizzle.Swizzle(api_key, base_url)"]
|
|
25
|
+
|
|
26
|
+
subgraph SubClients["Client Modules"]
|
|
27
|
+
C1["client.chat.completions<br/>• Sync & Async Streaming<br/>• Speculative Burst Token Unpacking<br/>• Hardware Telemetry Header Parsing"]
|
|
28
|
+
C2["client.robotics (VLAPolicy)<br/>• 80.5 Hz Real-Time Control Loop<br/>• ViT Patch Delta Cache (97.1% Hit)<br/>• 7-DoF 2nd-Order Kinematic SpecAct<br/>• Quintic Spline Temporal Ensembling"]
|
|
29
|
+
C3["client.world (WorldPlanner)<br/>• Latent Transition Dynamics<br/>• 128-Rollout Batched CEM Planning<br/>• Horizon Cost Optimization"]
|
|
30
|
+
C4["swizzle CLI<br/>• swizzle-ai chat<br/>• swizzle-ai robot<br/>• swizzle-ai bench"]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
Init --> C1
|
|
34
|
+
Init --> C2
|
|
35
|
+
Init --> C3
|
|
36
|
+
Init --> C4
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
subgraph Transport["Dual-Wire Transport"]
|
|
40
|
+
HTTP["HTTP/2 & Server-Sent Events (SSE)"]
|
|
41
|
+
WS["Sub-15ms WebSocket Stream"]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
subgraph Backend["Swizzle Distributed Cluster"]
|
|
45
|
+
GW["Swizzle Gateway (Go 1.22+)<br/>Dual Wire Protocol & AST-Diff Trie"]
|
|
46
|
+
ENG["Swizzle Engine & Kernels<br/>Speculative Tree Verification & Paged XOR Attention"]
|
|
47
|
+
ROBOT["Swizzle Robotics Edge/Cloud Worker<br/>Cosmos, SmolVLA, OpenVLA, Pi0, V-JEPA 2"]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
C1 -->|OpenAI / Anthropic Spec| HTTP
|
|
51
|
+
C2 -->|Real-Time Frame & Motor Telemetry| WS
|
|
52
|
+
C3 -->|Latent Goal / Rollout Queries| HTTP
|
|
53
|
+
HTTP --> GW
|
|
54
|
+
WS --> GW
|
|
55
|
+
GW --> ENG
|
|
56
|
+
GW --> ROBOT
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 📦 Installation
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install swizzle-ai
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Or install in editable mode for local development:
|
|
68
|
+
```bash
|
|
69
|
+
git clone https://github.com/Swizzle-AI/swizzle-python-sdk.git
|
|
70
|
+
cd swizzle-python-sdk
|
|
71
|
+
pip install -e .[test]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## 🚀 Quickstart & Usage
|
|
77
|
+
|
|
78
|
+
### 1. Speculative Decoding Chat Completions with Hardware Telemetry
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from swizzle import Swizzle
|
|
82
|
+
|
|
83
|
+
client = Swizzle(api_key="swz_live_free_tier")
|
|
84
|
+
|
|
85
|
+
response = client.chat.completions.create(
|
|
86
|
+
model="Qwen/Qwen2.5-Coder-7B-Instruct",
|
|
87
|
+
messages=[
|
|
88
|
+
{"role": "system", "content": "You are a performance systems engineer."},
|
|
89
|
+
{"role": "user", "content": "Explain shared-memory bank conflicts in CUDA."}
|
|
90
|
+
],
|
|
91
|
+
temperature=0.2,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
print(response.choices[0].message.content)
|
|
95
|
+
|
|
96
|
+
# Access hardware-roofline telemetry returned by Swizzle
|
|
97
|
+
print(f"TTFT: {response.telemetry.ttft_ms} ms")
|
|
98
|
+
print(f"Prefix Cache Hit: {response.telemetry.cache_hit_tokens} tokens")
|
|
99
|
+
print(f"Speculative Speedup: {response.telemetry.speculative_speedup}")
|
|
100
|
+
print(f"AST-Tree Reuse: {response.telemetry.ast_reuse_pct}")
|
|
101
|
+
print(f"PD Disaggregation: {response.telemetry.pd_mode}")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### 2. Low-Latency Streaming with Speculative Burst Unpacking
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from swizzle import Swizzle
|
|
110
|
+
|
|
111
|
+
client = Swizzle(api_key="swz_live_free_tier")
|
|
112
|
+
|
|
113
|
+
stream = client.chat.completions.create(
|
|
114
|
+
model="Qwen/Qwen2.5-Coder-7B-Instruct",
|
|
115
|
+
messages=[{"role": "user", "content": "Refactor this HTTP handler into Go"}],
|
|
116
|
+
stream=True
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
for chunk in stream:
|
|
120
|
+
if chunk.choices and chunk.choices[0].delta.content:
|
|
121
|
+
print(chunk.choices[0].delta.content, end="", flush=True)
|
|
122
|
+
|
|
123
|
+
print(f"\nSpeculative Engine: {chunk.telemetry.speculative_engine}")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
### 3. Asynchronous Client (`AsyncSwizzle`)
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
import asyncio
|
|
132
|
+
from swizzle import AsyncSwizzle
|
|
133
|
+
|
|
134
|
+
async def main():
|
|
135
|
+
async with AsyncSwizzle(api_key="swz_live_free_tier") as client:
|
|
136
|
+
response = await client.chat.completions.create(
|
|
137
|
+
model="Qwen/Qwen2.5-Coder-7B-Instruct",
|
|
138
|
+
messages=[{"role": "user", "content": "Benchmark matrix multiplication in Python"}]
|
|
139
|
+
)
|
|
140
|
+
print(response.choices[0].message.content)
|
|
141
|
+
|
|
142
|
+
asyncio.run(main())
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
### 4. Robotics VLAs & Latent World Models (`swizzle.robotics` & `swizzle.world`)
|
|
148
|
+
|
|
149
|
+
Execute high-frequency (80.5 Hz) Vision-Language-Action policies (`SmolVLA`, `OpenVLA`, $\pi_0$-FAST) and Latent World Models (`NVIDIA Cosmos`, `Meta V-JEPA 2`) across 2 GB–8 GB student laptops:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
from swizzle import VLAPolicy, WorldPlanner, HardwareDetector
|
|
153
|
+
|
|
154
|
+
# 1. Auto-detect student laptop VRAM and recommended quantized stack
|
|
155
|
+
hw = HardwareDetector.detect()
|
|
156
|
+
print(f"Recommended VLA: {hw.recommended_vla} | World Model: {hw.recommended_world_model}")
|
|
157
|
+
|
|
158
|
+
# 2. 80.5 Hz VLA Control with 97.1% ViT Patch Reuse + 7-DoF Kinematic SpecAct + 50Hz Spline
|
|
159
|
+
policy = VLAPolicy(
|
|
160
|
+
model=hw.recommended_vla,
|
|
161
|
+
patch_cache=True,
|
|
162
|
+
speculative_kinematics=True,
|
|
163
|
+
temporal_ensemble_hz=50,
|
|
164
|
+
)
|
|
165
|
+
step = policy.act(camera_patches, instruction="pick up the red block")
|
|
166
|
+
print(f"7-DoF Action: {step.action} | Patch Hit Ratio: {step.patch_hit_ratio:.1%}")
|
|
167
|
+
|
|
168
|
+
# 3. Batched 128-Rollout Cross-Entropy Method (CEM) World-Model Planning (25.0 ms)
|
|
169
|
+
planner = WorldPlanner(model=hw.recommended_world_model, num_trajectories=128, horizon=5)
|
|
170
|
+
plan = planner.plan(current_latent=[0.1, 0.2, 0.0, 0.0], goal_latent=[0.8, 0.7, 0.0, 0.0])
|
|
171
|
+
print(f"Optimal First Action: {plan.optimal_actions[0]} (Cost: {plan.final_cost:.4f})")
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
### 5. CLI Tooling
|
|
177
|
+
|
|
178
|
+
`swizzle-ai` ships with an interactive command-line interface:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# Authenticate or inspect active endpoint
|
|
182
|
+
swizzle-ai login --key swz_live_free_tier
|
|
183
|
+
|
|
184
|
+
# Interactive chat session
|
|
185
|
+
swizzle-ai chat --model Qwen/Qwen2.5-Coder-7B-Instruct
|
|
186
|
+
|
|
187
|
+
# Inspect student hardware capabilities
|
|
188
|
+
swizzle-ai robot detect
|
|
189
|
+
|
|
190
|
+
# Start local robotics teleop bridge
|
|
191
|
+
swizzle-ai robot teleop --hz 80
|
|
192
|
+
|
|
193
|
+
# Benchmark inference latency and TTFT
|
|
194
|
+
swizzle-ai bench --tokens 1024 --concurrency 4
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
---
|
|
198
|
+
|
|
199
|
+
## 🛡️ Telemetry Properties
|
|
200
|
+
|
|
201
|
+
Every `response.telemetry` object exposes:
|
|
202
|
+
* `ttft_ms`: Exact Time-To-First-Token in milliseconds.
|
|
203
|
+
* `cache_hit_tokens`: Tokens loaded directly from GPU HBM prefix cache.
|
|
204
|
+
* `speculative_speedup`: Effective throughput acceleration factor (e.g. `2.76x`).
|
|
205
|
+
* `speculative_acceptance`: Percentage of candidate draft tokens accepted (e.g. `90.5%`).
|
|
206
|
+
* `ast_reuse_pct`: Non-linear AST block cache reuse percentage (e.g. `89.6%`).
|
|
207
|
+
* `pd_mode`: `Disaggregated (Prefill->Decode)` or `Colocated`.
|
|
208
|
+
* `worker_node`: Target accelerator node ID.
|
|
209
|
+
* `cost_usd` & `saved_usd`: Exact metered micro-dollar accounting.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 🧪 Testing
|
|
214
|
+
|
|
215
|
+
Run unit tests locally:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
pytest -v tests/
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## 📄 License
|
|
224
|
+
|
|
225
|
+
Licensed under the [Apache License, Version 2.0](LICENSE).
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "swizzle-ai"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Official Python SDK & Student CLI for Swizzle: Sub-40ms LLM TTFT, 60Hz Robotics VLA (PatchCache, SpecAct, Teleop), and Batched Latent World-Model MPC."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [{ name = "Paramveer Singh", email = "param15.veer.singh@gmail.com" }]
|
|
11
|
+
license = { text = "Apache-2.0" }
|
|
12
|
+
keywords = ["llm", "inference", "speculative-decoding", "prefix-caching", "vllm", "agents", "swizzle"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3.9",
|
|
16
|
+
"Programming Language :: Python :: 3.10",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"License :: OSI Approved :: Apache Software License",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
22
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
|
+
]
|
|
24
|
+
requires-python = ">=3.9"
|
|
25
|
+
dependencies = [
|
|
26
|
+
"httpx>=0.24.0",
|
|
27
|
+
"pydantic>=2.0.0",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.scripts]
|
|
31
|
+
swizzle = "swizzle.cli:main"
|
|
32
|
+
swizzle-ai = "swizzle.cli:main"
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
test = [
|
|
36
|
+
"pytest>=7.0.0",
|
|
37
|
+
"pytest-asyncio>=0.21.0",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://swizzle-ten.vercel.app"
|
|
42
|
+
Repository = "https://github.com/Swizzle-AI/swizzle-python-sdk"
|
|
43
|
+
Documentation = "https://github.com/Swizzle-AI/swizzle-python-sdk#readme"
|
|
44
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Swizzle Python SDK
|
|
3
|
+
~~~~~~~~~~~~~~~~~~
|
|
4
|
+
Ultra-low latency, prefix-cached, speculative LLM, Robotics VLA, and World-Model inference client.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .client import Swizzle, AsyncSwizzle
|
|
8
|
+
from .exceptions import SwizzleError, AuthenticationError, RateLimitError, WorkerUnavailableError
|
|
9
|
+
from .types import SwizzleTelemetry, ChatCompletion, ChatCompletionChunk
|
|
10
|
+
from .robotics import (
|
|
11
|
+
HardwareDetector,
|
|
12
|
+
StudentHardwareProfile,
|
|
13
|
+
PatchCacheFilter,
|
|
14
|
+
KinematicSpecActPredictor,
|
|
15
|
+
TemporalActionEnsembler,
|
|
16
|
+
VLAPolicy,
|
|
17
|
+
VLAActionOutput,
|
|
18
|
+
extract_patch_intensities_from_frame,
|
|
19
|
+
quantize_action_to_token,
|
|
20
|
+
dequantize_token_to_action,
|
|
21
|
+
)
|
|
22
|
+
from .world import WorldPlanner, WorldPlanResult
|
|
23
|
+
|
|
24
|
+
__version__ = "0.2.0"
|
|
25
|
+
__all__ = [
|
|
26
|
+
"Swizzle",
|
|
27
|
+
"AsyncSwizzle",
|
|
28
|
+
"SwizzleError",
|
|
29
|
+
"AuthenticationError",
|
|
30
|
+
"RateLimitError",
|
|
31
|
+
"WorkerUnavailableError",
|
|
32
|
+
"SwizzleTelemetry",
|
|
33
|
+
"ChatCompletion",
|
|
34
|
+
"ChatCompletionChunk",
|
|
35
|
+
"HardwareDetector",
|
|
36
|
+
"StudentHardwareProfile",
|
|
37
|
+
"PatchCacheFilter",
|
|
38
|
+
"KinematicSpecActPredictor",
|
|
39
|
+
"TemporalActionEnsembler",
|
|
40
|
+
"VLAPolicy",
|
|
41
|
+
"VLAActionOutput",
|
|
42
|
+
"extract_patch_intensities_from_frame",
|
|
43
|
+
"WorldPlanner",
|
|
44
|
+
"WorldPlanResult",
|
|
45
|
+
"quantize_action_to_token",
|
|
46
|
+
"dequantize_token_to_action",
|
|
47
|
+
]
|