flash-rt 0.2.0__py3-none-any.whl

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.
Files changed (455) hide show
  1. flash_rt/__init__.py +107 -0
  2. flash_rt/_extensions.py +119 -0
  3. flash_rt/amd/__init__.py +9 -0
  4. flash_rt/amd/core/__init__.py +0 -0
  5. flash_rt/amd/core/hip_buffer.py +176 -0
  6. flash_rt/amd/core/hip_graph.py +102 -0
  7. flash_rt/amd/frontends/__init__.py +1 -0
  8. flash_rt/amd/frontends/torch/__init__.py +1 -0
  9. flash_rt/amd/frontends/torch/groot_n17.py +1013 -0
  10. flash_rt/amd/frontends/torch/pi05.py +1431 -0
  11. flash_rt/amd/hardware/__init__.py +1 -0
  12. flash_rt/amd/hardware/cdna4/__init__.py +1 -0
  13. flash_rt/amd/hardware/cdna4/attn_backend.py +338 -0
  14. flash_rt/amd/hardware/cdna4/attn_backend_aiter.py +410 -0
  15. flash_rt/amd/hardware/cdna4/attn_backend_groot_n17.py +297 -0
  16. flash_rt/amd/models/__init__.py +1 -0
  17. flash_rt/amd/models/groot_n17/__init__.py +1 -0
  18. flash_rt/amd/models/groot_n17/pipeline.py +1058 -0
  19. flash_rt/amd/models/pi05/__init__.py +1 -0
  20. flash_rt/amd/models/pi05/pipeline.py +1860 -0
  21. flash_rt/api.py +1144 -0
  22. flash_rt/catalog/__init__.py +39 -0
  23. flash_rt/catalog/binding.py +412 -0
  24. flash_rt/catalog/bindings/cosmos3_video_pipeline.yaml +94 -0
  25. flash_rt/catalog/bindings/groot_n16_dit.yaml +23 -0
  26. flash_rt/catalog/bindings/groot_n16_llm.yaml +21 -0
  27. flash_rt/catalog/bindings/groot_n16_pipeline.yaml +107 -0
  28. flash_rt/catalog/bindings/groot_n16_tick.yaml +26 -0
  29. flash_rt/catalog/bindings/groot_n16_vision.yaml +23 -0
  30. flash_rt/catalog/bindings/groot_n17_pipeline.yaml +117 -0
  31. flash_rt/catalog/bindings/lingbot_vla_pipeline.yaml +106 -0
  32. flash_rt/catalog/bindings/motus_tick.yaml +120 -0
  33. flash_rt/catalog/bindings/nexn2_pipeline.yaml +112 -0
  34. flash_rt/catalog/bindings/pi05.yaml +29 -0
  35. flash_rt/catalog/bindings/pi05_prefix.yaml +21 -0
  36. flash_rt/catalog/bindings/pi05_tick.yaml +94 -0
  37. flash_rt/catalog/bindings/pi05_vision.yaml +23 -0
  38. flash_rt/catalog/bindings/qwen25_15b.yaml +22 -0
  39. flash_rt/catalog/bindings/qwen36_27b_pipeline.yaml +130 -0
  40. flash_rt/catalog/bindings/qwen3_8b.yaml +22 -0
  41. flash_rt/catalog/bindings/qwen3_8b_pipeline.yaml +98 -0
  42. flash_rt/catalog/bindings/qwen3_vl_8b_pipeline.yaml +131 -0
  43. flash_rt/catalog/bindings/qwen3_vl_8b_text.yaml +22 -0
  44. flash_rt/catalog/bindings/qwen3_vl_8b_vision.yaml +23 -0
  45. flash_rt/catalog/bindings/smolvla_base.yaml +21 -0
  46. flash_rt/catalog/bindings/smolvla_expert.yaml +21 -0
  47. flash_rt/catalog/bindings/smolvla_pipeline.yaml +93 -0
  48. flash_rt/catalog/bindings/smolvla_tick.yaml +27 -0
  49. flash_rt/catalog/bindings/smolvla_vision.yaml +23 -0
  50. flash_rt/catalog/bindings/wan22_video_pipeline.yaml +119 -0
  51. flash_rt/catalog/registry.py +108 -0
  52. flash_rt/catalog/structures/__init__.py +0 -0
  53. flash_rt/catalog/structures/adaln_producer/__init__.py +0 -0
  54. flash_rt/catalog/structures/adaln_producer/reference.py +40 -0
  55. flash_rt/catalog/structures/adaln_producer/structure.yaml +106 -0
  56. flash_rt/catalog/structures/attention_core/__init__.py +0 -0
  57. flash_rt/catalog/structures/attention_core/reference.py +36 -0
  58. flash_rt/catalog/structures/attention_core/structure.yaml +72 -0
  59. flash_rt/catalog/structures/autoregressive_decode_pipeline/structure.yaml +82 -0
  60. flash_rt/catalog/structures/cadence_static/__init__.py +0 -0
  61. flash_rt/catalog/structures/cadence_static/reference.py +24 -0
  62. flash_rt/catalog/structures/cadence_static/structure.yaml +56 -0
  63. flash_rt/catalog/structures/decoder_block/__init__.py +0 -0
  64. flash_rt/catalog/structures/decoder_block/reference.py +38 -0
  65. flash_rt/catalog/structures/decoder_block/structure.yaml +86 -0
  66. flash_rt/catalog/structures/decoder_ffn/__init__.py +0 -0
  67. flash_rt/catalog/structures/decoder_ffn/reference.py +64 -0
  68. flash_rt/catalog/structures/decoder_ffn/structure.yaml +44 -0
  69. flash_rt/catalog/structures/gated_delta_core/reference.py +54 -0
  70. flash_rt/catalog/structures/gated_delta_core/structure.yaml +60 -0
  71. flash_rt/catalog/structures/linear_proj/__init__.py +3 -0
  72. flash_rt/catalog/structures/linear_proj/reference.py +35 -0
  73. flash_rt/catalog/structures/linear_proj/structure.yaml +74 -0
  74. flash_rt/catalog/structures/modnorm_qkv_chain/__init__.py +1 -0
  75. flash_rt/catalog/structures/modnorm_qkv_chain/reference.py +39 -0
  76. flash_rt/catalog/structures/modnorm_qkv_chain/structure.yaml +59 -0
  77. flash_rt/catalog/structures/norm_fused/__init__.py +0 -0
  78. flash_rt/catalog/structures/norm_fused/reference.py +26 -0
  79. flash_rt/catalog/structures/norm_fused/structure.yaml +50 -0
  80. flash_rt/catalog/structures/patch_projection/reference.py +15 -0
  81. flash_rt/catalog/structures/patch_projection/structure.yaml +53 -0
  82. flash_rt/catalog/structures/qk_norm_rope/__init__.py +3 -0
  83. flash_rt/catalog/structures/qk_norm_rope/reference.py +114 -0
  84. flash_rt/catalog/structures/qk_norm_rope/structure.yaml +83 -0
  85. flash_rt/catalog/structures/qkv_pack/__init__.py +0 -0
  86. flash_rt/catalog/structures/qkv_pack/reference.py +33 -0
  87. flash_rt/catalog/structures/qkv_pack/structure.yaml +65 -0
  88. flash_rt/catalog/structures/qkv_rope/__init__.py +1 -0
  89. flash_rt/catalog/structures/qkv_rope/reference.py +39 -0
  90. flash_rt/catalog/structures/qkv_rope/structure.yaml +55 -0
  91. flash_rt/catalog/structures/video_generation_pipeline/__init__.py +2 -0
  92. flash_rt/catalog/structures/video_generation_pipeline/structure.yaml +81 -0
  93. flash_rt/catalog/structures/vision_ffn/__init__.py +0 -0
  94. flash_rt/catalog/structures/vision_ffn/reference.py +35 -0
  95. flash_rt/catalog/structures/vision_ffn/structure.yaml +42 -0
  96. flash_rt/catalog/structures/vla_tick_pipeline/__init__.py +7 -0
  97. flash_rt/catalog/structures/vla_tick_pipeline/structure.yaml +82 -0
  98. flash_rt/configs/__init__.py +0 -0
  99. flash_rt/configs/cosmos3_edge.yaml +21 -0
  100. flash_rt/configs/cosmos3_video.yaml +24 -0
  101. flash_rt/configs/groot.yaml +73 -0
  102. flash_rt/configs/groot_n17.yaml +53 -0
  103. flash_rt/configs/hyvla.yaml +65 -0
  104. flash_rt/configs/ltx25.yaml +41 -0
  105. flash_rt/configs/motus.yaml +85 -0
  106. flash_rt/configs/nexn2.yaml +79 -0
  107. flash_rt/configs/pi0.yaml +38 -0
  108. flash_rt/configs/pi05.yaml +38 -0
  109. flash_rt/configs/qwen36.yaml +68 -0
  110. flash_rt/configs/wan22_ti2v_5b.yaml +24 -0
  111. flash_rt/core/__init__.py +0 -0
  112. flash_rt/core/calibration.py +301 -0
  113. flash_rt/core/calibration_api.py +70 -0
  114. flash_rt/core/config.py +96 -0
  115. flash_rt/core/context.py +47 -0
  116. flash_rt/core/cuda_buffer.py +189 -0
  117. flash_rt/core/cuda_graph.py +81 -0
  118. flash_rt/core/parity.py +37 -0
  119. flash_rt/core/precision_spec.py +164 -0
  120. flash_rt/core/quant/__init__.py +0 -0
  121. flash_rt/core/quant/calibrator.py +170 -0
  122. flash_rt/core/quantization.py +73 -0
  123. flash_rt/core/rl/__init__.py +75 -0
  124. flash_rt/core/rl/acp_tags.py +51 -0
  125. flash_rt/core/rl/advantage.py +163 -0
  126. flash_rt/core/rl/cfg_sampler.py +72 -0
  127. flash_rt/core/rl/reward.py +233 -0
  128. flash_rt/core/rl/value_function.py +198 -0
  129. flash_rt/core/thor_frontend_utils.py +152 -0
  130. flash_rt/core/utils/__init__.py +0 -0
  131. flash_rt/core/utils/actions.py +19 -0
  132. flash_rt/core/utils/hardware.py +50 -0
  133. flash_rt/core/utils/norm_stats.py +359 -0
  134. flash_rt/core/utils/pi05_prompt.py +35 -0
  135. flash_rt/core/weights/__init__.py +0 -0
  136. flash_rt/core/weights/loader.py +135 -0
  137. flash_rt/core/weights/transformer.py +691 -0
  138. flash_rt/core/weights/weight_cache.py +147 -0
  139. flash_rt/datasets/__init__.py +11 -0
  140. flash_rt/datasets/libero.py +306 -0
  141. flash_rt/executors/__init__.py +6 -0
  142. flash_rt/executors/fp4_utils.py +241 -0
  143. flash_rt/executors/fp4_utils_cb.py +207 -0
  144. flash_rt/executors/jax_weights.py +270 -0
  145. flash_rt/executors/torch_weights.py +500 -0
  146. flash_rt/executors/weight_loader.py +331 -0
  147. flash_rt/frontends/__init__.py +8 -0
  148. flash_rt/frontends/_fp8_layout.py +32 -0
  149. flash_rt/frontends/jax/__init__.py +1 -0
  150. flash_rt/frontends/jax/_pi05_thor_spec.py +52 -0
  151. flash_rt/frontends/jax/_pi0_thor_spec.py +32 -0
  152. flash_rt/frontends/jax/_thor_spec_common.py +114 -0
  153. flash_rt/frontends/jax/pi05_rtx.py +576 -0
  154. flash_rt/frontends/jax/pi05_thor.py +2768 -0
  155. flash_rt/frontends/jax/pi05_thor_fp4.py +879 -0
  156. flash_rt/frontends/jax/pi0_rtx.py +483 -0
  157. flash_rt/frontends/jax/pi0_thor.py +1425 -0
  158. flash_rt/frontends/jax/pi0fast.py +1337 -0
  159. flash_rt/frontends/jetson_pi/__init__.py +12 -0
  160. flash_rt/frontends/jetson_pi/llm.py +261 -0
  161. flash_rt/frontends/jetson_pi/mllm.py +289 -0
  162. flash_rt/frontends/jetson_pi/pi0.py +420 -0
  163. flash_rt/frontends/torch/__init__.py +1 -0
  164. flash_rt/frontends/torch/_chameleon_quant.py +251 -0
  165. flash_rt/frontends/torch/_chameleon_rtx_sm87_spec.py +85 -0
  166. flash_rt/frontends/torch/_chameleon_thor_spec.py +92 -0
  167. flash_rt/frontends/torch/_cosmos3_edge_thor_spec.py +177 -0
  168. flash_rt/frontends/torch/_groot_n17_rtx_spec.py +13 -0
  169. flash_rt/frontends/torch/_groot_n17_thor_spec.py +406 -0
  170. flash_rt/frontends/torch/_groot_thor_spec.py +105 -0
  171. flash_rt/frontends/torch/_higgs_audio_v3_bf16.py +374 -0
  172. flash_rt/frontends/torch/_higgs_audio_v3_fp8.py +464 -0
  173. flash_rt/frontends/torch/_hyvla_thor_spec.py +196 -0
  174. flash_rt/frontends/torch/_lingbot_thor_spec.py +321 -0
  175. flash_rt/frontends/torch/_motus_rtx_spec.py +47 -0
  176. flash_rt/frontends/torch/_nexn2_rtx_decode.py +1621 -0
  177. flash_rt/frontends/torch/_nexn2_rtx_forward.py +1815 -0
  178. flash_rt/frontends/torch/_nexn2_rtx_nvfp4_weights.py +416 -0
  179. flash_rt/frontends/torch/_pi05_thor_spec.py +100 -0
  180. flash_rt/frontends/torch/_pi0_thor_spec.py +81 -0
  181. flash_rt/frontends/torch/_qwen36_rtx_dflash_forward.py +940 -0
  182. flash_rt/frontends/torch/_qwen36_rtx_dflash_weights.py +396 -0
  183. flash_rt/frontends/torch/_qwen36_rtx_nvfp4_weights.py +741 -0
  184. flash_rt/frontends/torch/_qwen36_rtx_turboquant.py +872 -0
  185. flash_rt/frontends/torch/_qwen36_rtx_weights.py +411 -0
  186. flash_rt/frontends/torch/_qwen3_rtx_nvfp4_weights.py +575 -0
  187. flash_rt/frontends/torch/_qwen3_vl_bf16_weights.py +191 -0
  188. flash_rt/frontends/torch/_qwen3_vl_fp8_weights.py +245 -0
  189. flash_rt/frontends/torch/_qwen3_vl_geometry.py +337 -0
  190. flash_rt/frontends/torch/_qwen3_vl_vision_rtx.py +625 -0
  191. flash_rt/frontends/torch/_template/attention.py +124 -0
  192. flash_rt/frontends/torch/_template/frontend.py +330 -0
  193. flash_rt/frontends/torch/_template/pipeline.py +263 -0
  194. flash_rt/frontends/torch/_template/weights_spec.py +215 -0
  195. flash_rt/frontends/torch/_thor_spec_common.py +147 -0
  196. flash_rt/frontends/torch/chameleon_rtx_sm87.py +721 -0
  197. flash_rt/frontends/torch/chameleon_thor.py +911 -0
  198. flash_rt/frontends/torch/cosmos3_edge_thor.py +571 -0
  199. flash_rt/frontends/torch/cosmos3_video_rtx.py +130 -0
  200. flash_rt/frontends/torch/groot_n17_rtx.py +152 -0
  201. flash_rt/frontends/torch/groot_n17_rtx_fp16.py +655 -0
  202. flash_rt/frontends/torch/groot_n17_rtx_fp8.py +582 -0
  203. flash_rt/frontends/torch/groot_n17_rtx_sm89.py +609 -0
  204. flash_rt/frontends/torch/groot_n17_rtx_sm89_fp16.py +652 -0
  205. flash_rt/frontends/torch/groot_n17_thor.py +1965 -0
  206. flash_rt/frontends/torch/groot_n17_thor_fp16.py +49 -0
  207. flash_rt/frontends/torch/groot_n17_thor_fp4.py +165 -0
  208. flash_rt/frontends/torch/groot_n17_thor_fp8.py +780 -0
  209. flash_rt/frontends/torch/groot_rtx.py +1876 -0
  210. flash_rt/frontends/torch/groot_rtx_fp16.py +1162 -0
  211. flash_rt/frontends/torch/groot_thor.py +3623 -0
  212. flash_rt/frontends/torch/groot_thor_fp16.py +28 -0
  213. flash_rt/frontends/torch/higgs_audio_v3_rtx.py +601 -0
  214. flash_rt/frontends/torch/hyvla_orin.py +306 -0
  215. flash_rt/frontends/torch/hyvla_thor.py +683 -0
  216. flash_rt/frontends/torch/lingbot_thor.py +116 -0
  217. flash_rt/frontends/torch/ltx25_rtx.py +378 -0
  218. flash_rt/frontends/torch/motus_rtx.py +1562 -0
  219. flash_rt/frontends/torch/nexn2_rtx.py +310 -0
  220. flash_rt/frontends/torch/pi05_rtx.py +1949 -0
  221. flash_rt/frontends/torch/pi05_rtx_fp16.py +1806 -0
  222. flash_rt/frontends/torch/pi05_thor.py +3083 -0
  223. flash_rt/frontends/torch/pi05_thor_fp4.py +1500 -0
  224. flash_rt/frontends/torch/pi0_rtx.py +957 -0
  225. flash_rt/frontends/torch/pi0_thor.py +1405 -0
  226. flash_rt/frontends/torch/pi0fast.py +1402 -0
  227. flash_rt/frontends/torch/qwen36_moe.py +426 -0
  228. flash_rt/frontends/torch/qwen36_moe_rtx.py +20 -0
  229. flash_rt/frontends/torch/qwen36_rtx.py +12388 -0
  230. flash_rt/frontends/torch/qwen36_spark.py +200 -0
  231. flash_rt/frontends/torch/qwen36_thor.py +1320 -0
  232. flash_rt/frontends/torch/qwen3_rtx.py +2166 -0
  233. flash_rt/frontends/torch/qwen3_vl_fp8_sm89.py +912 -0
  234. flash_rt/frontends/torch/qwen3_vl_fp8_sm89_multimodal.py +456 -0
  235. flash_rt/frontends/torch/qwen3_vl_rtx.py +642 -0
  236. flash_rt/frontends/torch/qwen3_vl_rtx_bf16.py +1031 -0
  237. flash_rt/frontends/torch/qwen3_vl_thor.py +856 -0
  238. flash_rt/frontends/torch/wan22_rtx.py +477 -0
  239. flash_rt/hardware/__init__.py +311 -0
  240. flash_rt/hardware/backend.py +407 -0
  241. flash_rt/hardware/blackwell/__init__.py +12 -0
  242. flash_rt/hardware/rtx/__init__.py +37 -0
  243. flash_rt/hardware/rtx/attn_backend.py +856 -0
  244. flash_rt/hardware/rtx/attn_backend_batched_pi05.py +303 -0
  245. flash_rt/hardware/rtx/attn_backend_chameleon.py +237 -0
  246. flash_rt/hardware/rtx/attn_backend_groot.py +447 -0
  247. flash_rt/hardware/rtx/attn_backend_groot_n17.py +251 -0
  248. flash_rt/hardware/rtx/attn_backend_groot_n17_backbone.py +191 -0
  249. flash_rt/hardware/rtx/attn_backend_motus.py +128 -0
  250. flash_rt/hardware/rtx/attn_backend_nexn2.py +409 -0
  251. flash_rt/hardware/rtx/attn_backend_qwen3.py +520 -0
  252. flash_rt/hardware/rtx/attn_backend_qwen36.py +272 -0
  253. flash_rt/hardware/thor/__init__.py +9 -0
  254. flash_rt/hardware/thor/attn_backend.py +559 -0
  255. flash_rt/hardware/thor/attn_backend_chameleon.py +362 -0
  256. flash_rt/hardware/thor/attn_backend_groot.py +328 -0
  257. flash_rt/hardware/thor/attn_backend_groot_n17.py +423 -0
  258. flash_rt/hardware/thor/attn_backend_qwen3.py +229 -0
  259. flash_rt/hardware/thor/attn_backend_qwen36.py +530 -0
  260. flash_rt/hardware/thor/fa4_backend.py +117 -0
  261. flash_rt/hardware/thor/shared_primitives.py +727 -0
  262. flash_rt/hardware/thor/shared_primitives_batched.py +178 -0
  263. flash_rt/hardware/thor/shared_primitives_fp4.py +512 -0
  264. flash_rt/hardware/thor/vqgan_trt_backend.py +187 -0
  265. flash_rt/models/__init__.py +11 -0
  266. flash_rt/models/chameleon/__init__.py +18 -0
  267. flash_rt/models/chameleon/pipeline_rtx.py +305 -0
  268. flash_rt/models/chameleon/pipeline_thor.py +1126 -0
  269. flash_rt/models/chameleon/vqvae_hf.py +124 -0
  270. flash_rt/models/cosmos3_edge/__init__.py +37 -0
  271. flash_rt/models/cosmos3_edge/action_only_official.py +3447 -0
  272. flash_rt/models/cosmos3_edge/boundary_dump.py +151 -0
  273. flash_rt/models/cosmos3_edge/denoise_ref.py +325 -0
  274. flash_rt/models/cosmos3_edge/dump_replay.py +195 -0
  275. flash_rt/models/cosmos3_edge/layer_ref.py +1040 -0
  276. flash_rt/models/cosmos3_edge/pipeline_thor.py +549 -0
  277. flash_rt/models/cosmos3_edge/static_engine.py +346 -0
  278. flash_rt/models/cosmos3_edge/static_unipc.py +234 -0
  279. flash_rt/models/cosmos3_edge/vae_native.py +304 -0
  280. flash_rt/models/cosmos3_edge/weights.py +91 -0
  281. flash_rt/models/cosmos3_reasoner/__init__.py +1 -0
  282. flash_rt/models/cosmos3_reasoner/pipeline_thor.py +691 -0
  283. flash_rt/models/cosmos3_video/__init__.py +6 -0
  284. flash_rt/models/cosmos3_video/fm_solvers_unipc.py +808 -0
  285. flash_rt/models/cosmos3_video/kernels/__init__.py +22 -0
  286. flash_rt/models/cosmos3_video/kernels/csrc/bindings.cpp +17 -0
  287. flash_rt/models/cosmos3_video/kernels/csrc/fused_qk_norm_rope.cu +61 -0
  288. flash_rt/models/cosmos3_video/kernels/setup.py +33 -0
  289. flash_rt/models/cosmos3_video/pipeline_rtx.py +234 -0
  290. flash_rt/models/groot/__init__.py +32 -0
  291. flash_rt/models/groot/embodiments.py +69 -0
  292. flash_rt/models/groot/pipeline_rtx.py +1179 -0
  293. flash_rt/models/groot/pipeline_rtx_fp16.py +1034 -0
  294. flash_rt/models/groot/pipeline_thor.py +981 -0
  295. flash_rt/models/groot_n17/__init__.py +50 -0
  296. flash_rt/models/groot_n17/calibration.py +439 -0
  297. flash_rt/models/groot_n17/embodiments.py +38 -0
  298. flash_rt/models/groot_n17/mrope_table.py +178 -0
  299. flash_rt/models/groot_n17/pipeline_rtx.py +11 -0
  300. flash_rt/models/groot_n17/pipeline_rtx_fp16.py +836 -0
  301. flash_rt/models/groot_n17/pipeline_rtx_fp8.py +413 -0
  302. flash_rt/models/groot_n17/pipeline_rtx_sm89.py +541 -0
  303. flash_rt/models/groot_n17/pipeline_thor.py +1386 -0
  304. flash_rt/models/higgs_audio_v3/__init__.py +14 -0
  305. flash_rt/models/higgs_audio_v3/_codec/__init__.py +0 -0
  306. flash_rt/models/higgs_audio_v3/_codec/env_guard.py +42 -0
  307. flash_rt/models/higgs_audio_v3/_codec/tokenizer_config.json +129 -0
  308. flash_rt/models/higgs_audio_v3/_codec/tokenizer_model.py +940 -0
  309. flash_rt/models/higgs_audio_v3/codec.py +81 -0
  310. flash_rt/models/higgs_audio_v3/pipeline_rtx.py +64 -0
  311. flash_rt/models/hyvla/__init__.py +1 -0
  312. flash_rt/models/hyvla/pipeline_orin.py +430 -0
  313. flash_rt/models/hyvla/pipeline_thor.py +572 -0
  314. flash_rt/models/lingbot/__init__.py +17 -0
  315. flash_rt/models/lingbot/_csrc_loader.py +70 -0
  316. flash_rt/models/lingbot/buffer_binder.py +156 -0
  317. flash_rt/models/lingbot/calibration.py +163 -0
  318. flash_rt/models/lingbot/forward.py +784 -0
  319. flash_rt/models/lingbot/fp4_ops.py +90 -0
  320. flash_rt/models/lingbot/graph_runner.py +265 -0
  321. flash_rt/models/lingbot/kernel_ops.py +1487 -0
  322. flash_rt/models/lingbot/mixed_attention.py +793 -0
  323. flash_rt/models/lingbot/norms.py +113 -0
  324. flash_rt/models/lingbot/pipeline_thor.py +169 -0
  325. flash_rt/models/lingbot/rope_adapter.py +156 -0
  326. flash_rt/models/lingbot/sample_actions.py +394 -0
  327. flash_rt/models/lingbot/vit.py +486 -0
  328. flash_rt/models/lingbot/vit_rope_adapter.py +247 -0
  329. flash_rt/models/ltx25/__init__.py +16 -0
  330. flash_rt/models/ltx25/_attn_swap.py +244 -0
  331. flash_rt/models/ltx25/_nvfp4_ffn_swap.py +301 -0
  332. flash_rt/models/ltx25/_resident_graph.py +206 -0
  333. flash_rt/models/melband_roformer/__init__.py +13 -0
  334. flash_rt/models/melband_roformer/pipeline.py +329 -0
  335. flash_rt/models/minimax_remover/__init__.py +27 -0
  336. flash_rt/models/minimax_remover/_attention.py +428 -0
  337. flash_rt/models/minimax_remover/_fp8_linear.py +426 -0
  338. flash_rt/models/minimax_remover/_fp8_manual_denoise.py +298 -0
  339. flash_rt/models/minimax_remover/_fp8_pipeline.py +617 -0
  340. flash_rt/models/minimax_remover/_kern_block.py +282 -0
  341. flash_rt/models/minimax_remover/_kernels.py +282 -0
  342. flash_rt/models/minimax_remover/_manual_denoise.py +413 -0
  343. flash_rt/models/minimax_remover/_nvfp4_linear.py +236 -0
  344. flash_rt/models/minimax_remover/_triton_flash_attn.py +139 -0
  345. flash_rt/models/minimax_remover/_utils.py +94 -0
  346. flash_rt/models/minimax_remover/_vae_nvfp4.py +569 -0
  347. flash_rt/models/minimax_remover/_vae_opt.py +880 -0
  348. flash_rt/models/minimax_remover/pipeline.py +209 -0
  349. flash_rt/models/motus/__init__.py +0 -0
  350. flash_rt/models/motus/_action_ffn_v6t_install.py +162 -0
  351. flash_rt/models/motus/_action_und_qkv_fp8_swap.py +266 -0
  352. flash_rt/models/motus/_attn_swap.py +224 -0
  353. flash_rt/models/motus/_awq_fp8_swap.py +525 -0
  354. flash_rt/models/motus/_easycache_swap.py +279 -0
  355. flash_rt/models/motus/_ffn_swap.py +225 -0
  356. flash_rt/models/motus/_fp8_swap.py +635 -0
  357. flash_rt/models/motus/_graph_capture.py +203 -0
  358. flash_rt/models/motus/_handtuned_fp8_dispatch.py +235 -0
  359. flash_rt/models/motus/_kv_cache_swap.py +539 -0
  360. flash_rt/models/motus/_linear_swap.py +248 -0
  361. flash_rt/models/motus/_mixcache_swap.py +276 -0
  362. flash_rt/models/motus/_modulate_fuse_swap.py +1649 -0
  363. flash_rt/models/motus/_motus_nvfp4_ffn_video_swap.py +677 -0
  364. flash_rt/models/motus/_norm_swap.py +240 -0
  365. flash_rt/models/motus/_rope_swap.py +226 -0
  366. flash_rt/models/motus/_stream.py +22 -0
  367. flash_rt/models/motus/_taylorseer_swap.py +275 -0
  368. flash_rt/models/motus/_teacache_swap.py +210 -0
  369. flash_rt/models/motus/_tinyfp8_dispatch_install.py +170 -0
  370. flash_rt/models/motus/_und_ffn_v5t_install.py +180 -0
  371. flash_rt/models/motus/_vae_fp4_swap.py +849 -0
  372. flash_rt/models/motus/_vae_fp8_resample_swap.py +534 -0
  373. flash_rt/models/motus/_vae_fp8_swap.py +1082 -0
  374. flash_rt/models/motus/_vae_swap.py +80 -0
  375. flash_rt/models/motus/_vae_time_conv_fp8_swap.py +292 -0
  376. flash_rt/models/motus/_wan_qkv_fuse_swap.py +905 -0
  377. flash_rt/models/motus/pipeline_rtx.py +1164 -0
  378. flash_rt/models/nexn2/__init__.py +17 -0
  379. flash_rt/models/nexn2/pipeline_rtx.py +137 -0
  380. flash_rt/models/omnivoice/__init__.py +30 -0
  381. flash_rt/models/omnivoice/pipeline_rtx.py +546 -0
  382. flash_rt/models/pi0/__init__.py +9 -0
  383. flash_rt/models/pi0/pipeline_rtx.py +1110 -0
  384. flash_rt/models/pi0/pipeline_thor.py +434 -0
  385. flash_rt/models/pi05/__init__.py +28 -0
  386. flash_rt/models/pi05/pipeline_rtx.py +2209 -0
  387. flash_rt/models/pi05/pipeline_rtx_batched.py +1188 -0
  388. flash_rt/models/pi05/pipeline_rtx_cfg.py +657 -0
  389. flash_rt/models/pi05/pipeline_rtx_cfg_batched.py +435 -0
  390. flash_rt/models/pi05/pipeline_rtx_fp16.py +2276 -0
  391. flash_rt/models/pi05/pipeline_thor.py +929 -0
  392. flash_rt/models/pi05/pipeline_thor_batched.py +346 -0
  393. flash_rt/models/pi05/pipeline_thor_cfg.py +238 -0
  394. flash_rt/models/pi05/pipeline_thor_cfg_batched.py +180 -0
  395. flash_rt/models/pi05/runtime_export.py +449 -0
  396. flash_rt/models/pi0fast/__init__.py +1 -0
  397. flash_rt/models/pi0fast/pipeline.py +840 -0
  398. flash_rt/models/qwen3/__init__.py +11 -0
  399. flash_rt/models/qwen3/pipeline_rtx.py +90 -0
  400. flash_rt/models/qwen36/__init__.py +27 -0
  401. flash_rt/models/qwen36/pipeline_rtx.py +159 -0
  402. flash_rt/models/qwen3_vl/__init__.py +19 -0
  403. flash_rt/models/qwen3_vl/pipeline_rtx.py +145 -0
  404. flash_rt/models/wan22/__init__.py +1 -0
  405. flash_rt/models/wan22/pipeline_rtx.py +28 -0
  406. flash_rt/npu/__init__.py +6 -0
  407. flash_rt/npu/core/__init__.py +0 -0
  408. flash_rt/npu/core/abi.py +81 -0
  409. flash_rt/npu/core/acl_runtime.py +165 -0
  410. flash_rt/npu/core/decode_attention.py +26 -0
  411. flash_rt/npu/core/decoder_int8.py +399 -0
  412. flash_rt/npu/core/device.py +73 -0
  413. flash_rt/npu/core/gu_int8.py +99 -0
  414. flash_rt/npu/core/linear.py +283 -0
  415. flash_rt/npu/core/native_kernels.py +269 -0
  416. flash_rt/npu/core/npu_graph.py +68 -0
  417. flash_rt/npu/frontends/__init__.py +0 -0
  418. flash_rt/npu/frontends/torch/__init__.py +0 -0
  419. flash_rt/npu/frontends/torch/pi05.py +438 -0
  420. flash_rt/npu/hardware/__init__.py +9 -0
  421. flash_rt/npu/models/__init__.py +1 -0
  422. flash_rt/npu/models/pi05/__init__.py +1 -0
  423. flash_rt/npu/models/pi05/attention.py +128 -0
  424. flash_rt/npu/models/pi05/captured.py +212 -0
  425. flash_rt/npu/models/pi05/fast.py +666 -0
  426. flash_rt/npu/models/pi05/pipeline.py +336 -0
  427. flash_rt/npu/models/pi05/quantization.py +235 -0
  428. flash_rt/npu/verify.py +110 -0
  429. flash_rt/py.typed +0 -0
  430. flash_rt/refs/__init__.py +17 -0
  431. flash_rt/refs/pi05_cfg_reference.py +310 -0
  432. flash_rt/runtime/__init__.py +47 -0
  433. flash_rt/runtime/cuda_libraries.py +108 -0
  434. flash_rt/runtime/exec.py +53 -0
  435. flash_rt/runtime/export.py +520 -0
  436. flash_rt/runtime/provider.py +113 -0
  437. flash_rt/runtime/rtc.py +261 -0
  438. flash_rt/runtime/rtc_temporal_fusion.py +545 -0
  439. flash_rt/runtime/vlash.py +420 -0
  440. flash_rt/subgraphs/__init__.py +43 -0
  441. flash_rt/subgraphs/capture.py +179 -0
  442. flash_rt/subgraphs/pi05/__init__.py +3 -0
  443. flash_rt/subgraphs/pi05/context_action.py +67 -0
  444. flash_rt/subgraphs/pi05/rtc_prefix.py +79 -0
  445. flash_rt/subgraphs/pi05/rtc_vjp_guided.py +96 -0
  446. flash_rt/subgraphs/pi05/stage_plans.py +89 -0
  447. flash_rt/subgraphs/pi05/vlash.py +29 -0
  448. flash_rt/subgraphs/stage_plan.py +214 -0
  449. flash_rt/utils/__init__.py +1 -0
  450. flash_rt/utils/paligemma_tokenizer.py +135 -0
  451. flash_rt-0.2.0.dist-info/METADATA +1341 -0
  452. flash_rt-0.2.0.dist-info/RECORD +455 -0
  453. flash_rt-0.2.0.dist-info/WHEEL +5 -0
  454. flash_rt-0.2.0.dist-info/licenses/LICENSE +202 -0
  455. flash_rt-0.2.0.dist-info/top_level.txt +1 -0
flash_rt/__init__.py ADDED
@@ -0,0 +1,107 @@
1
+ """
2
+ FlashRT — High-performance VLA inference engine.
3
+
4
+ Public exports (stable API — see ``docs/stable_api.md``):
5
+
6
+ flash_rt.load_model(...) → VLAModel
7
+ flash_rt.VLAModel — unified inference wrapper
8
+
9
+ Supported models: Pi0.5, Pi0, Pi0-FAST, GROOT N1.6, GROOT N1.7.
10
+ Supported hardware: Jetson Thor (SM110), RTX 5090 (SM120), RTX 4090
11
+ (SM89), AMD Instinct MI350 series (ROCm gfx950, pi05).
12
+
13
+ Extending with new models: see ``docs/plugin_model_template.md``.
14
+
15
+ Usage::
16
+
17
+ import flash_rt
18
+
19
+ model = flash_rt.load_model(
20
+ checkpoint="/path/to/checkpoint",
21
+ framework="torch",
22
+ autotune=3,
23
+ )
24
+
25
+ actions = model.predict(images=[base_img, wrist_img],
26
+ prompt="pick up the red block")
27
+ """
28
+
29
+ __version__ = "0.2.0"
30
+
31
+ # ── Windows: register CUDA / cuDNN DLL search paths ──
32
+ # Python 3.8+ on Windows ignores PATH for C-extension dependencies
33
+ # (security hardening). The compiled .pyd needs cudart64_*.dll,
34
+ # cublas64_*.dll, cublasLt, cudnn — we add their canonical install
35
+ # directories to the secure DLL loader so `import flash_rt` works
36
+ # without the user pre-loading them. Linux is unaffected: this whole
37
+ # block is skipped via the sys.platform guard.
38
+ import os as _os
39
+ import sys as _sys
40
+ if _sys.platform == 'win32':
41
+ _cuda_roots = [
42
+ _os.environ.get('CUDA_PATH'),
43
+ _os.environ.get('CUDA_PATH_V13_0'),
44
+ _os.environ.get('CUDA_PATH_V12_9'),
45
+ _os.environ.get('CUDA_PATH_V12_8'),
46
+ _os.environ.get('CUDA_PATH_V12_4'),
47
+ r'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.0',
48
+ r'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.9',
49
+ r'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.8',
50
+ _os.environ.get('CUDNN_PATH'),
51
+ ]
52
+ _seen = set()
53
+ for _root in filter(None, _cuda_roots):
54
+ for _sub in ('bin', r'extras\CUPTI\lib64', ''):
55
+ _p = _os.path.join(_root, _sub) if _sub else _root
56
+ if _p in _seen:
57
+ continue
58
+ _seen.add(_p)
59
+ if _os.path.isdir(_p):
60
+ try:
61
+ _os.add_dll_directory(_p)
62
+ except (OSError, ValueError):
63
+ pass
64
+ del _root, _sub, _p, _seen, _cuda_roots
65
+ del _os, _sys
66
+
67
+ from flash_rt import _extensions as _ext # noqa: E402
68
+
69
+ __all__ = ["load_model", "VLAModel", "catalog"]
70
+
71
+
72
+ def __getattr__(name):
73
+ """PEP 562. ``import flash_rt`` stays free of torch and of the
74
+ compiled extensions.
75
+
76
+ The structure catalog is usable without either, and a consumer that
77
+ only wants ``flash_rt.catalog`` should not pay for the VLA API to
78
+ reach it. Naming ``load_model`` still loads everything it needs.
79
+
80
+ ``flash_rt.structures`` moved to its own distribution
81
+ (``flashrt-structures``); asking for it here answers with that
82
+ pointer rather than an AttributeError.
83
+
84
+ An extension name reaching here means the import machinery did not
85
+ find it beside the package — this distribution ships no ``.so`` — so
86
+ answer with the build instructions rather than an AttributeError.
87
+ """
88
+ if name in ("load_model", "VLAModel"):
89
+ from flash_rt import api
90
+ return getattr(api, name)
91
+ if name == "catalog":
92
+ import flash_rt.catalog as mod
93
+ return mod
94
+ if name == "structures":
95
+ raise ImportError(
96
+ "flash_rt.structures moved to the flashrt-structures "
97
+ "distribution: pip install flashrt-structures, then "
98
+ "`import flashrt_structures as structures`. The structure "
99
+ "catalog itself stayed here as flash_rt.catalog. "
100
+ "See https://github.com/flashrt-project/FlashRT-Structures")
101
+ if name in _ext.EXTENSIONS:
102
+ return _ext.require(name)
103
+ raise AttributeError("module %r has no attribute %r" % (__name__, name))
104
+
105
+
106
+ def __dir__():
107
+ return sorted(set(globals()) | set(__all__))
@@ -0,0 +1,119 @@
1
+ """What to say when the compiled half is not there.
2
+
3
+ This distribution is pure Python. It carries the frontends, the structure
4
+ catalog, the host adapters and the kernel sources, but no ``.so``: kernels
5
+ either arrive through the kernel hub, which the structures layer talks to,
6
+ or are built locally for the models actually being run. So the first thing
7
+ a fresh install meets is an absent extension, and that moment has to carry
8
+ its own instructions — a bare ``ModuleNotFoundError: No module named
9
+ 'flash_rt.flash_rt_kernels'`` reads as a broken package rather than as a
10
+ step the user has not taken yet.
11
+
12
+ The structures layer already answers this way: a refusal names its reason
13
+ and the rung below it. This module gives the native path the same manners.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import importlib
19
+ import importlib.util
20
+
21
+ #: extension module → what it serves. ``flash_rt_kernels`` is the core
22
+ #: library every native frontend needs; the rest are per-family.
23
+ EXTENSIONS = {
24
+ "flash_rt_kernels": "core kernels — every native frontend needs these",
25
+ "flash_rt_fa2": "FlashAttention-2, the RTX attention path",
26
+ "flash_rt_qwen3_vl_kernels": "Qwen3-VL SM89 FP8 kernels",
27
+ }
28
+
29
+ #: model family → the CMake switch that builds its kernels and nothing
30
+ #: else. Pair any of these with ``-DFLASHRT_SLIM_BUILD=ON``.
31
+ BUILD_SWITCHES = {
32
+ "lingbot": "FLASHRT_ENABLE_LINGBOT",
33
+ "motus": "FLASHRT_ENABLE_MOTUS",
34
+ "qwen3_5_moe": "FLASHRT_ENABLE_QWEN35MOE",
35
+ "nexn2": "FLASHRT_ENABLE_QWEN35MOE",
36
+ "qwen3_vl": "FLASHRT_BUILD_QWEN3_VL",
37
+ "melband_roformer": "FLASHRT_ENABLE_MELBAND_ROFORMER",
38
+ "omnivoice": "FLASHRT_ENABLE_OMNIVOICE",
39
+ "audio_codebook": "FLASHRT_ENABLE_AUDIO_CODEBOOK",
40
+ "minimax_remover": "FLASHRT_ENABLE_MINIMAX_REMOVER",
41
+ }
42
+
43
+ _REPO = "https://github.com/flashrt-project/FlashRT"
44
+
45
+
46
+ def present(name: str = "flash_rt_kernels") -> bool:
47
+ """True if the named extension is importable beside this package."""
48
+ try:
49
+ return importlib.util.find_spec("flash_rt." + name) is not None
50
+ except (ImportError, AttributeError, ValueError):
51
+ return False
52
+
53
+
54
+ def missing() -> list[str]:
55
+ """The extensions this install does not have."""
56
+ return [n for n in EXTENSIONS if not present(n)]
57
+
58
+
59
+ def build_command(config: str | None = None) -> str:
60
+ """The shortest build that produces what ``config`` needs."""
61
+ switch = BUILD_SWITCHES.get(config or "")
62
+ if switch:
63
+ return ("cmake -B build -S . -DFLASHRT_SLIM_BUILD=ON "
64
+ "-D%s=ON && cmake --build build -j$(nproc)" % switch)
65
+ return "cmake -B build -S . && cmake --build build -j$(nproc)"
66
+
67
+
68
+ def require(name: str = "flash_rt_kernels", *, config: str | None = None):
69
+ """Return the extension module, or refuse with reason and next step.
70
+
71
+ Raises :class:`ImportError` so call sites that already guard imports
72
+ keep behaving as they did when the extension shipped in the wheel.
73
+ """
74
+ if present(name):
75
+ try:
76
+ return importlib.import_module("flash_rt." + name)
77
+ except ImportError as exc:
78
+ # Built, but not for this environment. Worth saying plainly:
79
+ # the fix is a rebuild, not a build, and the two look alike
80
+ # from the traceback alone.
81
+ raise ImportError(
82
+ "flash_rt.{name} is present but will not load here:\n"
83
+ " {exc}\n"
84
+ "The extension is compiled against a specific Python, torch\n"
85
+ "and CUDA ABI. Rebuild it in the environment you are running:\n"
86
+ " {build}".format(name=name, exc=exc,
87
+ build=build_command(config))) from exc
88
+ raise ImportError(
89
+ "flash_rt.{name} is not built ({what}).\n"
90
+ "\n"
91
+ "This distribution ships pure Python; the CUDA extensions are built\n"
92
+ "from the source tree, for the hardware and the models you run:\n"
93
+ " git clone {repo} && cd FlashRT\n"
94
+ " pip install -e .\n"
95
+ " {build}\n"
96
+ "The editable install matters: the build writes the extensions into\n"
97
+ "the clone's own flash_rt/ directory, so that clone has to be what\n"
98
+ "your interpreter imports.\n"
99
+ "Add -DGPU_ARCH=120 for RTX 5090, 110 for Jetson Thor, 89 for RTX\n"
100
+ "4090; see the Build section of the README for the full table.\n"
101
+ "\n"
102
+ "To run without a local build, use the structures layer instead: it\n"
103
+ "obtains kernels from the kernel hub and refuses legibly when one is\n"
104
+ "unavailable.\n"
105
+ " from flash_rt import structures".format(
106
+ name=name, what=EXTENSIONS.get(name, "compiled extension"),
107
+ repo=_REPO, build=build_command(config)))
108
+
109
+
110
+ def report() -> str:
111
+ """One line per extension: present, or the switch that builds it."""
112
+ lines = []
113
+ for name, what in EXTENSIONS.items():
114
+ mark = "present" if present(name) else "absent"
115
+ lines.append(" %-28s %-8s %s" % (name, mark, what))
116
+ if missing():
117
+ lines.append("")
118
+ lines.append(" build: " + build_command())
119
+ return "\n".join(lines)
@@ -0,0 +1,9 @@
1
+ """FlashRT AMD (ROCm/HIP) backend.
2
+
3
+ Self-contained AMD tree: HIP runtime twins of core/cuda_buffer and
4
+ core/cuda_graph, the flash_rt_amd_kernels extension (built by
5
+ csrc/amd/CMakeLists.txt, dropped into this directory), and — as the
6
+ port progresses — CDNA attention backends, pi05 pipeline, frontends.
7
+
8
+ The NVIDIA package tree never imports from here and vice versa.
9
+ """
File without changes
@@ -0,0 +1,176 @@
1
+ """FlashRT AMD — HipBuffer: hipMalloc/managed wrapper for engine-facing GPU buffers.
2
+
3
+ Twin of flash_rt/core/cuda_buffer.py over libamdhip64. Memcpy-kind and
4
+ attach-flag enums are numerically identical to CUDA's (verified at
5
+ bring-up): H2D=1, D2H=2, D2D=3, hipMemAttachGlobal=1.
6
+ """
7
+
8
+ import ctypes
9
+ import logging
10
+ import numpy as np
11
+
12
+ logger = logging.getLogger(__name__)
13
+
14
+ try:
15
+ _hip = ctypes.CDLL("libamdhip64.so")
16
+ except OSError as exc: # no ROCm runtime on this machine
17
+ # Surface the conventional "optional backend unavailable" signal so
18
+ # callers (flash_rt.api's hardware gate, test suites) can guard with
19
+ # a plain ImportError instead of a platform-specific OSError.
20
+ raise ImportError(
21
+ "the AMD backend requires the ROCm runtime (libamdhip64.so), "
22
+ f"which could not be loaded: {exc}") from exc
23
+
24
+
25
+ def _configure_hip_signatures() -> None:
26
+ """Declare ctypes signatures — host pointers ≥2GiB truncate under the
27
+ default c_int argtype (see cuda_buffer.py download() docstring)."""
28
+ ptr_p = ctypes.POINTER(ctypes.c_void_p)
29
+ signatures = {
30
+ "hipMallocManaged": (
31
+ [ptr_p, ctypes.c_size_t, ctypes.c_uint], ctypes.c_int),
32
+ "hipMalloc": ([ptr_p, ctypes.c_size_t], ctypes.c_int),
33
+ "hipFree": ([ctypes.c_void_p], ctypes.c_int),
34
+ "hipMemcpy": (
35
+ [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t,
36
+ ctypes.c_int],
37
+ ctypes.c_int,
38
+ ),
39
+ "hipMemcpyAsync": (
40
+ [ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t,
41
+ ctypes.c_int, ctypes.c_void_p],
42
+ ctypes.c_int,
43
+ ),
44
+ "hipMemset": (
45
+ [ctypes.c_void_p, ctypes.c_int, ctypes.c_size_t], ctypes.c_int),
46
+ "hipMemsetAsync": (
47
+ [ctypes.c_void_p, ctypes.c_int, ctypes.c_size_t,
48
+ ctypes.c_void_p],
49
+ ctypes.c_int,
50
+ ),
51
+ "hipDeviceSynchronize": ([], ctypes.c_int),
52
+ "hipStreamSynchronize": ([ctypes.c_void_p], ctypes.c_int),
53
+ }
54
+ for name, (argtypes, restype) in signatures.items():
55
+ fn = getattr(_hip, name)
56
+ fn.argtypes = argtypes
57
+ fn.restype = restype
58
+
59
+
60
+ _configure_hip_signatures()
61
+
62
+
63
+ def _check(ret, msg=""):
64
+ if ret != 0:
65
+ raise RuntimeError(f"HIP error {ret}: {msg}")
66
+
67
+
68
+ class HipBuffer:
69
+ """GPU buffer — managed or device memory."""
70
+
71
+ def __init__(self, nbytes: int, managed: bool = True):
72
+ self._ptr = ctypes.c_void_p()
73
+ self._managed = managed
74
+ if managed:
75
+ _check(_hip.hipMallocManaged(ctypes.byref(self._ptr), nbytes, 1),
76
+ "hipMallocManaged")
77
+ else:
78
+ _check(_hip.hipMalloc(ctypes.byref(self._ptr), nbytes), "hipMalloc")
79
+ self._nbytes = nbytes
80
+
81
+ @property
82
+ def ptr(self) -> ctypes.c_void_p:
83
+ return self._ptr
84
+
85
+ @property
86
+ def nbytes(self) -> int:
87
+ return self._nbytes
88
+
89
+ @classmethod
90
+ def from_numpy(cls, arr: np.ndarray) -> 'HipBuffer':
91
+ """Create device buffer, upload H2D (device memory for replay bandwidth)."""
92
+ arr = np.ascontiguousarray(arr)
93
+ buf = cls(arr.nbytes, managed=False)
94
+ _check(_hip.hipMemcpy(
95
+ buf._ptr, ctypes.c_void_p(arr.ctypes.data), arr.nbytes, 1), "H2D")
96
+ return buf
97
+
98
+ @classmethod
99
+ def from_numpy_managed(cls, arr: np.ndarray) -> 'HipBuffer':
100
+ """Create managed buffer, upload via memmove. Use for buffers needing D2H readback."""
101
+ arr = np.ascontiguousarray(arr)
102
+ buf = cls(arr.nbytes, managed=True)
103
+ ctypes.memmove(buf._ptr, arr.ctypes.data, arr.nbytes)
104
+ return buf
105
+
106
+ @classmethod
107
+ def zeros(cls, count: int, dtype, managed: bool = True) -> 'HipBuffer':
108
+ nbytes = count * np.dtype(dtype).itemsize
109
+ buf = cls(nbytes, managed=managed)
110
+ _check(_hip.hipMemset(buf._ptr, 0, nbytes), "hipMemset")
111
+ return buf
112
+
113
+ @classmethod
114
+ def empty(cls, count: int, dtype, managed: bool = True) -> 'HipBuffer':
115
+ return cls(count * np.dtype(dtype).itemsize, managed=managed)
116
+
117
+ @classmethod
118
+ def device_zeros(cls, count: int, dtype) -> 'HipBuffer':
119
+ return cls.zeros(count, dtype, managed=False)
120
+
121
+ @classmethod
122
+ def device_empty(cls, count: int, dtype) -> 'HipBuffer':
123
+ return cls.empty(count, dtype, managed=False)
124
+
125
+ def upload(self, arr: np.ndarray):
126
+ """Upload numpy → buffer."""
127
+ assert arr.nbytes <= self._nbytes
128
+ arr = np.ascontiguousarray(arr)
129
+ if self._managed:
130
+ ctypes.memmove(self._ptr, arr.ctypes.data, arr.nbytes)
131
+ else:
132
+ _check(_hip.hipMemcpy(
133
+ self._ptr, ctypes.c_void_p(arr.ctypes.data), arr.nbytes, 1), "H2D")
134
+
135
+ def download(self, arr: np.ndarray):
136
+ """Download buffer → numpy."""
137
+ assert arr.nbytes <= self._nbytes
138
+ _check(_hip.hipDeviceSynchronize(), "hipDeviceSynchronize")
139
+ if self._managed:
140
+ ctypes.memmove(arr.ctypes.data, self._ptr, arr.nbytes)
141
+ else:
142
+ _check(_hip.hipMemcpy(
143
+ ctypes.c_void_p(arr.ctypes.data),
144
+ self._ptr, arr.nbytes, 2), "D2H")
145
+
146
+ def download_new(self, shape, dtype) -> np.ndarray:
147
+ arr = np.empty(shape, dtype=dtype)
148
+ self.download(arr)
149
+ return arr
150
+
151
+ def zero_(self, stream=None):
152
+ if stream is not None:
153
+ _check(_hip.hipMemsetAsync(self._ptr, 0, self._nbytes, stream),
154
+ "hipMemsetAsync")
155
+ else:
156
+ _check(_hip.hipMemset(self._ptr, 0, self._nbytes), "hipMemset")
157
+
158
+ def __del__(self):
159
+ try:
160
+ if _hip is not None and hasattr(self, '_ptr') and self._ptr.value:
161
+ ret = _hip.hipFree(self._ptr)
162
+ self._ptr = ctypes.c_void_p()
163
+ if ret != 0:
164
+ # Raising in __del__ is unraisable; a failed free cannot
165
+ # corrupt results, so log instead of _check here.
166
+ logger.warning("hipFree failed with HIP error %d", ret)
167
+ except Exception:
168
+ pass
169
+
170
+ def __repr__(self):
171
+ t = "managed" if self._managed else "device"
172
+ return f"HipBuffer({self._nbytes}B, {t}, ptr=0x{self._ptr.value:x})"
173
+
174
+
175
+ def sync():
176
+ _check(_hip.hipDeviceSynchronize(), "hipDeviceSynchronize")
@@ -0,0 +1,102 @@
1
+ """FlashRT AMD — Framework-agnostic HIP Graph capture/replay.
2
+
3
+ Twin of flash_rt/core/cuda_graph.py over libamdhip64. Same usage:
4
+
5
+ graph = HipGraph()
6
+ stream = graph.create_stream()
7
+ # warmup ... then:
8
+ graph.begin_capture(stream)
9
+ my_kernel(args..., stream)
10
+ graph.end_capture(stream)
11
+ graph.replay(stream)
12
+
13
+ HIP-vs-CUDA deltas handled here:
14
+ - the 3-arg instantiate is hipGraphInstantiateWithFlags
15
+ (plain hipGraphInstantiate is the 5-arg errorNode/logBuffer form)
16
+ - capture-mode enum verified on hardware: hipStreamCaptureModeRelaxed == 2
17
+ """
18
+
19
+ import ctypes
20
+ import logging
21
+
22
+ logger = logging.getLogger(__name__)
23
+
24
+ try:
25
+ _hip = ctypes.CDLL("libamdhip64.so")
26
+ except OSError as exc: # no ROCm runtime on this machine
27
+ # Same contract as hip_buffer: report an unavailable optional
28
+ # backend as ImportError, not a platform-specific OSError.
29
+ raise ImportError(
30
+ "the AMD backend requires the ROCm runtime (libamdhip64.so), "
31
+ f"which could not be loaded: {exc}") from exc
32
+
33
+
34
+ def _configure_signatures() -> None:
35
+ """Declare ctypes signatures — pointer args must never fall back to
36
+ the 32-bit c_int default (see cuda_buffer.py download() incident)."""
37
+ p = ctypes.c_void_p
38
+ pp = ctypes.POINTER(ctypes.c_void_p)
39
+ signatures = {
40
+ "hipStreamCreate": ([pp], ctypes.c_int),
41
+ "hipStreamBeginCapture": ([p, ctypes.c_uint], ctypes.c_int),
42
+ "hipStreamEndCapture": ([p, pp], ctypes.c_int),
43
+ "hipGraphInstantiateWithFlags": ([pp, p, ctypes.c_ulonglong], ctypes.c_int),
44
+ "hipGraphLaunch": ([p, p], ctypes.c_int),
45
+ "hipStreamSynchronize": ([p], ctypes.c_int),
46
+ }
47
+ for name, (argtypes, restype) in signatures.items():
48
+ fn = getattr(_hip, name)
49
+ fn.argtypes = argtypes
50
+ fn.restype = restype
51
+
52
+
53
+ _configure_signatures()
54
+
55
+
56
+ def _check(status, msg=""):
57
+ if status != 0:
58
+ raise RuntimeError(f"HIP error {status}: {msg}")
59
+
60
+
61
+ class HipGraph:
62
+ """Framework-agnostic HIP Graph using raw HIP Runtime API."""
63
+
64
+ def __init__(self):
65
+ self._graph = ctypes.c_void_p()
66
+ self._graph_exec = ctypes.c_void_p()
67
+ self._captured = False
68
+
69
+ def create_stream(self) -> ctypes.c_void_p:
70
+ stream = ctypes.c_void_p()
71
+ _check(_hip.hipStreamCreate(ctypes.byref(stream)), "hipStreamCreate")
72
+ return stream
73
+
74
+ def begin_capture(self, stream: ctypes.c_void_p):
75
+ """Begin HIP Graph capture on the given stream.
76
+
77
+ hipStreamCaptureModeRelaxed=2: only capture ops on THIS stream,
78
+ same rationale as the CUDA path (don't block framework streams).
79
+ """
80
+ _check(_hip.hipStreamBeginCapture(stream, 2), "hipStreamBeginCapture")
81
+
82
+ def end_capture(self, stream: ctypes.c_void_p):
83
+ """End capture and instantiate the graph for replay."""
84
+ _check(_hip.hipStreamEndCapture(stream, ctypes.byref(self._graph)),
85
+ "hipStreamEndCapture")
86
+ _check(_hip.hipGraphInstantiateWithFlags(
87
+ ctypes.byref(self._graph_exec), self._graph, 0),
88
+ "hipGraphInstantiateWithFlags")
89
+ self._captured = True
90
+
91
+ def replay(self, stream: ctypes.c_void_p):
92
+ """Replay the captured graph (single CPU call → full GPU replay)."""
93
+ if not self._captured:
94
+ raise RuntimeError("No graph captured")
95
+ _check(_hip.hipGraphLaunch(self._graph_exec, stream), "hipGraphLaunch")
96
+
97
+ def sync(self, stream: ctypes.c_void_p):
98
+ _check(_hip.hipStreamSynchronize(stream), "hipStreamSynchronize")
99
+
100
+ @property
101
+ def captured(self) -> bool:
102
+ return self._captured
@@ -0,0 +1 @@
1
+ """FlashRT AMD — framework frontends (weights + preprocessing)."""
@@ -0,0 +1 @@
1
+ """FlashRT AMD — torch (ROCm) frontends."""