omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / docs / DEEPINFER.md
| 1 | # DeepInfer as a bridge target |
| 2 | |
| 3 | Status: PROPOSED target. The inventory and the import verdicts below are EXERCISED on the host |
| 4 | (AArch64, no GPU). No DeepInfer function is converted today. Nothing here is QUALIFIED, MERGED or |
| 5 | DEPLOYED. |
| 6 | |
| 7 | Ownership follows ARCH-0042: Omega owns computation, CUDA++ (aien-dev/CUDApp) owns GPU execution, |
| 8 | Omega Bridge owns compatibility. Source translation adapters live in omega-mv; the Python front end of |
| 9 | the porting tool lives in aien-dev/babel. |
| 10 | |
| 11 | ## Pins |
| 12 | |
| 13 | | item | pin | |
| 14 | |---|---| |
| 15 | | deepseek-ai/DeepInfer | `553741557a57df44a46fb3ab72b6aafeaf945337` (2026-10-25), Apache-2.0, package 0.1.0, Python >= 3.12 | |
| 16 | | vendor submodules (gitlinks, not fetched) | DeepEP `f6aa38fe`, DeepEP-Ascend `3b25377d`, DeepGEMM `1fc9c669`, DeepGEMM-Ascend `3a353262`, DeepSelect `bfa4507d`, FlashMLA `2e5429fc` | |
| 17 | | omega-bridge | `1958a189` (main) | |
| 18 | | omega-mv adapters | PR #839 head `656192e0`: `build/L627/import/python-import` sha256 `4c74b1f7…`, `build/S2/c-i64-import` `4cd9f018…`, `build/L739/cpp-import` `ed90e640…` | |
| 19 | | aien-dev/babel | `156360f8` (adapter pin omega-mv `2d4c6407`) | |
| 20 | | aien-dev/CUDApp | `b5746b94` | |
| 21 | |
| 22 | Upstream targets NVIDIA SM100 and Huawei Ascend 950 (README lines 35-36). The Spark GPU is GB10 |
| 23 | (sm_121). Running any DeepInfer kernel on GB10 is NOT_RUN and outside upstream's stated support. |
| 24 | |
| 25 | ## Three layers |
| 26 | |
| 27 | Every DeepInfer component falls in one or more of these layers, each owned by an existing component. |
| 28 | |
| 29 | 1. Source translation: a function is imported by an omega-mv adapter (directly or through babel) into |
| 30 | OMSA, lowered to `.om`, and called through bridge bindings. Bounded by the import profiles. |
| 31 | 2. Operator mapping: a tensor kernel (TileLang, DeepGEMM, FlashMLA, DeepEP, DeepSelect) is matched to |
| 32 | an Omega computation and a CUDA++ realization. Nothing converts these automatically today. |
| 33 | 3. Framework attachment: torch and `deepinfer._C` callers are switched to Omega-generated code through |
| 34 | bridge bindings (`tools/native`) or the PyTorch attachment (bridge #23, #30, both open drafts). |
| 35 | |
| 36 | ## Component inventory |
| 37 | |
| 38 | Python sizes are file and line counts at the pin; csrc is C/C++. |
| 39 | |
| 40 | | component | size | layer | today | |
| 41 | |---|---|---|---| |
| 42 | | `model_executor/layers/tilelang_ops` (30 kernel families, each a `cuda/` and an `asc/` file) | 93 files, 23,331 lines | 2 | no Omega or CUDA++ counterpart; extension E | |
| 43 | | `model_executor/models` (deepseek, 23 `v4_modules`: attn, mla_attn, index_attn, compress, engram, hc, mhc, moe, mlp, rope, norm, yoco, linear, heads, …) | 34 files, 7,051 lines | 2 | routed-expert FP4 decode exists as a seeded-Omega host port in aien-sovereign-core-mv #780 (draft, `om/dsv4/fp4dq.om`); MLA, index attention, compress, engram, hc/mhc have no Omega port | |
| 44 | | other `model_executor` (top-level files, layers outside tilelang_ops, eplb, input_metadata, parallel_utils) | 30 files, 4,925 lines | 2, 3 | CUDApp codegen covers attn, attn256, pattn, gdn, gemm, bf16, qmma, moe, moe2, router, dec, pf, tc, tern, qg at Qwen3.6-35B shapes; DeepSeek shapes NOT_RUN | |
| 45 | | `csrc/engine` (scheduler 1,329 lines, prepare_tensor_input_v4, sequence, block_manager, flops_estimator, mtp_varlen, zos, outputs, prepare_sample) + `graph_timer`, `cuda_utils`, `asc_utils` | 33 files, 5,908 lines | 1, 3 | 0 functions import (below); FlopsEstimator pair counts are extension D | |
| 46 | | `deepinfer._C` (pybind11, 15 Python importers) | 22 classes, 153 `def` entries | 3 | the bridge native ABI carries scalars and flat arrays only; no class or handle form (extension F) | |
| 47 | | `engine`, `worker`, `distributed`, `entrypoints` | 20 files, 5,421 lines | 1, 3 | 0 functions import | |
| 48 | | `structure_output` (xgrammar) | 5 files, 595 lines | 3 | no Omega counterpart | |
| 49 | | `hugging_face`, `ve`, `npu_ops`, `deep_cluster` | 29 files, 3,221 lines | 1, 3 | no Omega counterpart; `npu_ops` is Ascend-only | |
| 50 | | `tests` | 19 files, 3,117 lines | oracle | need torch and an SM100 or Ascend device; NOT_RUN | |
| 51 | |
| 52 | ## External dependencies |
| 53 | |
| 54 | "Files" counts DeepInfer Python files that import the module at the pin. |
| 55 | |
| 56 | | dependency | version | files | role | Omega replacement | |
| 57 | |---|---|---|---|---| |
| 58 | | torch | 2.13.0+cu132 | 129 | tensors, CUDA streams and graphs, distributed | CUDA++ runtime plus Omega computation; attachment is bridge #23 (CPU, `torch.compile` backend) and #30 (CUDA++, pending) | |
| 59 | | tilelang | 0.1.15 | 60 | JIT kernel DSL for every `tilelang_ops` family | none; extension E | |
| 60 | | tile-kernels | 2.1.0 | 46 | prebuilt TileLang kernels | none; extension E | |
| 61 | | DeepGEMM | `1fc9c669` | 9 | FP8/FP4 dense and grouped-MoE GEMM | CUDApp gemm/qmma/moe/moe2 at Qwen shapes; FP4 expert decode in core-mv #780 (host, draft) | |
| 62 | | FlashMLA | `2e5429fc` | 4 | MLA attention | none | |
| 63 | | flash-attn-4 | 4.0.0b34 | 1 | prefill attention | CUDApp attn/attn256/pattn at Qwen shapes | |
| 64 | | DeepEP | `f6aa38fe` | 5 | expert-parallel all-to-all across GPUs | none; a single GB10 has no expert-parallel peer [INFERENCE] | |
| 65 | | DeepSelect | `bfa4507d` | 4 | sparse index selection | none | |
| 66 | | xgrammar | 0.2.2 | 3 | grammar token masks | none | |
| 67 | | transformers, tokenizers | 4.50.0, 0.21.4 | 4, 1 | config and tokenizer | none | |
| 68 | | safetensors | 0.8.0 | 2 | weight files | none recorded here | |
| 69 | | pybind11 | 3.0.1 | (csrc) | `deepinfer._C` | `tools/native` bindings, scalars and arrays only (extension F) | |
| 70 | | pyzmq, posix_ipc | 27.1.0, 1.3.2 | 1, 1 | process messaging | none | |
| 71 | | torch-npu, CANN, DeepGEMM-Ascend, DeepEP-Ascend | 2.13.0rc1, 9.2, `3a353262`, `3b25377d` | 2 (torch_npu) | Ascend backend | out of scope: no Ascend device | |
| 72 | | einops, numpy, scipy, sympy, orjson, pillow, psutil, requests, huggingface_hub, tabulate, tqdm, ninja | requirements.txt pins | | host support | not on the conversion path; none | |
| 73 | |
| 74 | ## Measured translation coverage (layer 1) |
| 75 | |
| 76 | Replay: `OMEGA_MV=<built omega-mv> sh evidence/deepinfer/run.sh` re-runs all 32 inputs below and prints |
| 77 | `DEEPINFER-COVERAGE REPLAY PASS` when every exit status matches. Negative control: replacing |
| 78 | `ctrl_pos.py` with the unmasked control makes that row `FAIL` and the script prints |
| 79 | `DEEPINFER-COVERAGE REPLAY FAIL`. Both outcomes were observed on 2026-10-31. |
| 80 | |
| 81 | ### Python (profile python-u64-v1) |
| 82 | |
| 83 | `evidence/deepinfer/select_candidates.py` walks all 270 `.py` files (1,915 functions) and keeps |
| 84 | functions whose body is one `return` over parameters and integer literals. Six qualify; the remaining |
| 85 | 1,909 are outside every Python profile by shape (statements, calls, tensors, attributes) and were not |
| 86 | sent to the adapter. The six were sent verbatim (`py-verbatim/`) and then with annotations, |
| 87 | docstrings and leading underscores removed (`py-stripped/`) to expose the next refusal. |
| 88 | |
| 89 | | function | location | verbatim | stripped | |
| 90 | |---|---|---|---| |
| 91 | | `is_power_of_two` | `model_executor/layers/tilelang_ops/common.py:30` | 66 TYPE (annotation) | 68 ARITHMETIC (`&`, `==`) | |
| 92 | | `ceil_div` | `tilelang_ops/common.py:34` | 66 TYPE | 68 ARITHMETIC (`//`, unmasked) | |
| 93 | | `i64` | `tilelang_ops/random_sampling.py:49` | 66 TYPE | 69 CONSTRUCT (conditional expression) | |
| 94 | | `expanded_image_token_len` | `ve/processor/image_processor.py:76` | 72 SOURCE_FORM (non-ASCII docstring) | 68 ARITHMETIC (unmasked `+ *`) | |
| 95 | | `_align_to_multiple` | `worker/cache_engine.py:36` | 72 SOURCE_FORM (non-ASCII docstring) | 68 ARITHMETIC (`//`) | |
| 96 | | `_needs_compress_state` | `worker/cache_engine.py:119` | 71 SIGNATURE (leading `_`) | 68 ARITHMETIC (comparison) | |
| 97 | |
| 98 | Controls: `ctrl_pos.py` (one masked u64 add) imports, rc 0, 324 bytes; `ctrl_unmasked.py` refuses 68. |
| 99 | Cause probes: the same positive body with an ASCII docstring refuses 69 CONSTRUCT |
| 100 | (`probe_doc_ascii.py`) and with a non-ASCII comment refuses 72 (`probe_nonascii_comment.py`), so the two |
| 101 | 72 verdicts come from the Chinese text, and an ASCII docstring would still refuse. |
| 102 | |
| 103 | The refusals are the profile working as specified, not adapter bugs. python-u64-v1 refuses unmasked |
| 104 | arithmetic because Python `int` is unbounded; idiomatic DeepInfer integer code is unmasked. The S2 Python |
| 105 | form (`python-i64-select-v1`) requires the `_ck(...)` range helper and also excludes `//`, `%`, `&` and |
| 106 | shifts (translation-s2-v1 section 1), so S2 would not accept these either. |
| 107 | |
| 108 | ### C and C++ (FlopsEstimator, `csrc/engine/flops_estimator.hpp`) |
| 109 | |
| 110 | `floor_prefix`, `capped_prefix` and `pairs` (lines 239-257) were chosen by reading the file as the csrc |
| 111 | functions closest to the integer profiles. No systematic csrc scan was run; the babel splitter covers |
| 112 | Python only. |
| 113 | |
| 114 | | input | adapter | rc | refusal | |
| 115 | |---|---|---|---| |
| 116 | | verbatim, no header | c-i64-import, cpp-import | 72 | UNSUPPORTED_PREPROCESSOR (missing required header line) | |
| 117 | | verbatim + `#include <stdint.h>` (`*.hdr-c`) | c-i64-import | 66 | UNSUPPORTED_TYPE (`static`, default argument) | |
| 118 | | verbatim + `#include <cstdint>`, `std::int64_t` (`*.hdr-cpp`) | cpp-import | 69 | UNSUPPORTED_CONSTRUCT (specifiers) | |
| 119 | | `floor_prefix` rewritten as one C17 expression (`floor_prefix.c17`) | c-i64-import | 68 | UNSUPPORTED_ARITHMETIC (division) | |
| 120 | |
| 121 | Controls: `ctrl_pos.c17` rc 0 (345 bytes); `ctrl_pos.hdr-cpp` (`calc`, `std::uint64_t`) rc 0 (361 |
| 122 | bytes); `ctrl_name.hdr-cpp` (same body, name `f`) rc 71, because cpp17 profiles accept only `calc` or |
| 123 | `omega_*` names. |
| 124 | |
| 125 | ### Result |
| 126 | |
| 127 | No DeepInfer function imports with the current adapters: 1,909 Python functions fall outside every |
| 128 | profile by shape, the 6 in-shape Python functions refuse, and the 3 C/C++ functions tried refuse in |
| 129 | every form. The gaps, in order of reach: integer division and remainder with each language's rounding, |
| 130 | unbounded Python `int`, comparisons and selects outside the `_ck` form, docstrings and non-ASCII source |
| 131 | text, specifiers and default arguments, classes, and every tensor operation. |
| 132 | |
| 133 | ## Extensions |
| 134 | |
| 135 | Each gap becomes reusable work in the component that already owns that layer. No DeepInfer-specific |
| 136 | converter is added. |
| 137 | |
| 138 | | id | extension | owner | status | |
| 139 | |---|---|---|---| |
| 140 | | A | Python splitter in babel: split a module into functions, route each to `python-import`, record per-function verdicts and a refusal histogram | aien-dev/babel | PAUSED: aien-dev/babel#4 (C→Rust completion gate) owns the babel driver files first; resumes after that lands | |
| 141 | | B | S2.1 integer profile: i64 division and remainder with C/C++ truncation and Python floor rounding as distinct ops, `min`/`max`, trap on divisor 0 and on `INT64_MIN / -1`. Reaches `floor_prefix`, `capped_prefix`, `pairs`, `ceil_div`, `_align_to_multiple` | omega-mv translation | PROPOSED (protocol change; needs the S2 owner's review) | |
| 142 | | C | `python-int-checked-i64` profile: idiomatic Python `int` (annotations `int`/`bool`, docstrings, `//`, `%`, `&`, comparisons, conditional expressions) imported as i64 whose realization traps whenever CPython's exact result leaves -2^63..2^63-1. Wrapping is not a refinement here, because out-of-range Python results are defined values, not errors. Reaches 5 of the 6 Python candidates; `i64` stays refused (literal 2^63 is outside i64) | omega-mv translation | PROPOSED; depends on B for `//`. The trapping `long` realization exists: omc 734f0a39 and 2c824805 exit with trap 1 on `long` add/sub/mul overflow (measured in omega-bridge#49 `evidence/deepinfer-flops-pairs/overflow-measurement.log`; S2 spec addendum A1 at omega-mv 656192e0 records the same for 734f0a39) | |
| 143 | | D | FlopsEstimator pair counts as native `.om` with domain contracts, bridge bindings, a differential against the upstream functions and a caller-switch patch | omega-bridge | IMPLEMENTED, EXERCISED on host AArch64: [omega-bridge#49](https://github.com/aien-dev/omega-bridge/pull/49) (draft, d7cc8856). A DeepInfer build with the patch and the upstream pytest are NOT_RUN | |
| 144 | | E | TileLang kernel importer: TileLang `T.prim_func` bodies to Omega computation plus CUDA++ kernels, family by family (start with `norm`, `gather`, `quant`) | CUDApp with omega-mv | PROPOSED; parity needs a GPU window; upstream kernels target SM100, GB10 is sm_121 | |
| 145 | | F | Handle ABI for bindings: opaque object handles with constructor, method and destructor entries so `py::class_` surfaces such as `Scheduler`, `BlockManager` and `Sequence` can be served by Omega units | omega-bridge `src/native.om` | PROPOSED | |
| 146 | |
| 147 | ## Switching callers |
| 148 | |
| 149 | A caller moves to Omega only after its `.om` unit is differentially checked against the pinned upstream |
| 150 | function and its bindings pass `tests/native/run.sh` (`NATIVE-CALL PASS` with all seven callers). The |
| 151 | switch is a patch against the DeepInfer pin, kept in this repository (`examples/deepinfer/`), not a fork. |
| 152 | Every dependency in the table above stays listed until its replacement is EXERCISED in that way. |