Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-bridge/patches/7fc21d31fa00067d # omega-bridge Omega-first language interoperability: checked conversion backends and native language bindings Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## GitHub aien-dev/omega-bridge#48 (code only) closed derived `7fc21d31fa00067d` #48 Imported from GitHub aien-dev/omega-bridge#48 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `2cd8218f481f62c400f65232ca8a0b37dba201d8` · Head `7b6c76f0d9dc348c9363ef8c9c84490f8693adc7` cursor[bot] reviewed (APPROVED) on 2026-11-01 21:30 UTC Risk: low. Approved. Cursor Security Agent passed with no findings that need human review; Cursor Bugbot was not present, and this is documentation and evidence-only.
Open in Web View Automation
Sent by Cursor Approval Agent: Pull Request Router and Approver ### Fetch it A git bundle of the pull request's head, 18080 bytes. ``` curl -fsSL https://interplane.io/drakestapleton/omega-bridge/patches/7fc21d31fa00067d.bundle -o 7fc21d31fa00067d.bundle git fetch 7fc21d31fa00067d.bundle refs/pull/48/head ``` Raw bundle · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/omega-bridge 48 7b6c76f0d9dc348c9363ef8c9c84490f8693adc7 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"omega-bridge","number":48,"url":"https://github.com/aien-dev/omega-bridge/pull/48","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:40:00Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/README.md b/README.md index 09e3fd7..0bd8689 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ quiet-build python3 tests/attachments.py See [supported features and limits](docs/CAPABILITIES.md), [caller ABI and ownership](docs/ABI.md), [design and study decisions](docs/DESIGN.md), and [provenance](docs/PROVENANCE.md). Text constants, floats, heap operations and other target languages are explicitly unsupported by the C/Python converters. GPU interoperability is a separate, opt-in adapter boundary (it converts no host program): see [GPU adapter](docs/GPU-ADAPTER.md) and the [support matrix](docs/GPU-SUPPORT-MATRIX.md). Python/C input conversion is not implemented. The Python test harness is infrastructure; all conversion logic and both runtime emitters are in [src/toc.om](src/toc.om). +DeepInfer (deepseek-ai/DeepInfer) is a proposed translation and attachment target; its inventory, measured import coverage and extension plan are in [DeepInfer as a bridge target](docs/DEEPINFER.md). + Call compiled Omega in place from six languages (the native call adapter, a separate claim from conversion: it runs Omega's own machine code, it does not turn Omega into another language): ```sh diff --git a/docs/DEEPINFER.md b/docs/DEEPINFER.md new file mode 100644 index 0000000..5e90244 --- /dev/null +++ b/docs/DEEPINFER.md @@ -0,0 +1,152 @@ +# DeepInfer as a bridge target + +Status: PROPOSED target. The inventory and the import verdicts below are EXERCISED on the host +(AArch64, no GPU). No DeepInfer function is converted today. Nothing here is QUALIFIED, MERGED or +DEPLOYED. + +Ownership follows ARCH-0042: Omega owns computation, CUDA++ (aien-dev/CUDApp) owns GPU execution, +Omega Bridge owns compatibility. Source translation adapters live in omega-mv; the Python front end of +the porting tool lives in aien-dev/babel. + +## Pins + +| item | pin | +|---|---| +| deepseek-ai/DeepInfer | `553741557a57df44a46fb3ab72b6aafeaf945337` (2026-10-25), Apache-2.0, package 0.1.0, Python >= 3.12 | +| vendor submodules (gitlinks, not fetched) | DeepEP `f6aa38fe`, DeepEP-Ascend `3b25377d`, DeepGEMM `1fc9c669`, DeepGEMM-Ascend `3a353262`, DeepSelect `bfa4507d`, FlashMLA `2e5429fc` | +| omega-bridge | `1958a189` (main) | +| 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…` | +| aien-dev/babel | `156360f8` (adapter pin omega-mv `2d4c6407`) | +| aien-dev/CUDApp | `b5746b94` | + +Upstream targets NVIDIA SM100 and Huawei Ascend 950 (README lines 35-36). The Spark GPU is GB10 +(sm_121). Running any DeepInfer kernel on GB10 is NOT_RUN and outside upstream's stated support. + +## Three layers + +Every DeepInfer component falls in one or more of these layers, each owned by an existing component. + +1. Source translation: a function is imported by an omega-mv adapter (directly or through babel) into + OMSA, lowered to `.om`, and called through bridge bindings. Bounded by the import profiles. +2. Operator mapping: a tensor kernel (TileLang, DeepGEMM, FlashMLA, DeepEP, DeepSelect) is matched to + an Omega computation and a CUDA++ realization. Nothing converts these automatically today. +3. Framework attachment: torch and `deepinfer._C` callers are switched to Omega-generated code through + bridge bindings (`tools/native`) or the PyTorch attachment (bridge #23, #30, both open drafts). + +## Component inventory + +Python sizes are file and line counts at the pin; csrc is C/C++. + +| component | size | layer | today | +|---|---|---|---| +| `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 | +| `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 | +| 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 | +| `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 | +| `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) | +| `engine`, `worker`, `distributed`, `entrypoints` | 20 files, 5,421 lines | 1, 3 | 0 functions import | +| `structure_output` (xgrammar) | 5 files, 595 lines | 3 | no Omega counterpart | +| `hugging_face`, `ve`, `npu_ops`, `deep_cluster` | 29 files, 3,221 lines | 1, 3 | no Omega counterpart; `npu_ops` is Ascend-only | +| `tests` | 19 files, 3,117 lines | oracle | need torch and an SM100 or Ascend device; NOT_RUN | + +## External dependencies + +"Files" counts DeepInfer Python files that import the module at the pin. + +| dependency | version | files | role | Omega replacement | +|---|---|---|---|---| +| 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) | +| tilelang | 0.1.15 | 60 | JIT kernel DSL for every `tilelang_ops` family | none; extension E | +| tile-kernels | 2.1.0 | 46 | prebuilt TileLang kernels | none; extension E | +| 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) | +| FlashMLA | `2e5429fc` | 4 | MLA attention | none | +| flash-attn-4 | 4.0.0b34 | 1 | prefill attention | CUDApp attn/attn256/pattn at Qwen shapes | +| DeepEP | `f6aa38fe` | 5 | expert-parallel all-to-all across GPUs | none; a single GB10 has no expert-parallel peer [INFERENCE] | +| DeepSelect | `bfa4507d` | 4 | sparse index selection | none | +| xgrammar | 0.2.2 | 3 | grammar token masks | none | +| transformers, tokenizers | 4.50.0, 0.21.4 | 4, 1 | config and tokenizer | none | +| safetensors | 0.8.0 | 2 | weight files | none recorded here | +| pybind11 | 3.0.1 | (csrc) | `deepinfer._C` | `tools/native` bindings, scalars and arrays only (extension F) | +| pyzmq, posix_ipc | 27.1.0, 1.3.2 | 1, 1 | process messaging | none | +| 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 | +| einops, numpy, scipy, sympy, orjson, pillow, psutil, requests, huggingface_hub, tabulate, tqdm, ninja | requirements.txt pins | | host support | not on the conversion path; none | + +## Measured translation coverage (layer 1) + +Replay: `OMEGA_MV= sh evidence/deepinfer/run.sh` re-runs all 32 inputs below and prints +`DEEPINFER-COVERAGE REPLAY PASS` when every exit status matches. Negative control: replacing +`ctrl_pos.py` with the unmasked control makes that row `FAIL` and the script prints +`DEEPINFER-COVERAGE REPLAY FAIL`. Both outcomes were observed on 2026-10-31. + +### Python (profile python-u64-v1) + +`evidence/deepinfer/select_candidates.py` walks all 270 `.py` files (1,915 functions) and keeps +functions whose body is one `return` over parameters and integer literals. Six qualify; the remaining +1,909 are outside every Python profile by shape (statements, calls, tensors, attributes) and were not +sent to the adapter. The six were sent verbatim (`py-verbatim/`) and then with annotations, +docstrings and leading underscores removed (`py-stripped/`) to expose the next refusal. + +| function | location | verbatim | stripped | +|---|---|---|---| +| `is_power_of_two` | `model_executor/layers/tilelang_ops/common.py:30` | 66 TYPE (annotation) | 68 ARITHMETIC (`&`, `==`) | +| `ceil_div` | `tilelang_ops/common.py:34` | 66 TYPE | 68 ARITHMETIC (`//`, unmasked) | +| `i64` | `tilelang_ops/random_sampling.py:49` | 66 TYPE | 69 CONSTRUCT (conditional expression) | +| `expanded_image_token_len` | `ve/processor/image_processor.py:76` | 72 SOURCE_FORM (non-ASCII docstring) | 68 ARITHMETIC (unmasked `+ *`) | +| `_align_to_multiple` | `worker/cache_engine.py:36` | 72 SOURCE_FORM (non-ASCII docstring) | 68 ARITHMETIC (`//`) | +| `_needs_compress_state` | `worker/cache_engine.py:119` | 71 SIGNATURE (leading `_`) | 68 ARITHMETIC (comparison) | + +Controls: `ctrl_pos.py` (one masked u64 add) imports, rc 0, 324 bytes; `ctrl_unmasked.py` refuses 68. +Cause probes: the same positive body with an ASCII docstring refuses 69 CONSTRUCT +(`probe_doc_ascii.py`) and with a non-ASCII comment refuses 72 (`probe_nonascii_comment.py`), so the two +72 verdicts come from the Chinese text, and an ASCII docstring would still refuse. + +The refusals are the profile working as specified, not adapter bugs. python-u64-v1 refuses unmasked +arithmetic because Python `int` is unbounded; idiomatic DeepInfer integer code is unmasked. The S2 Python +form (`python-i64-select-v1`) requires the `_ck(...)` range helper and also excludes `//`, `%`, `&` and +shifts (translation-s2-v1 section 1), so S2 would not accept these either. + +### C and C++ (FlopsEstimator, `csrc/engine/flops_estimator.hpp`) + +`floor_prefix`, `capped_prefix` and `pairs` (lines 239-257) were chosen by reading the file as the csrc +functions closest to the integer profiles. No systematic csrc scan was run; the babel splitter covers +Python only. + +| input | adapter | rc | refusal | +|---|---|---|---| +| verbatim, no header | c-i64-import, cpp-import | 72 | UNSUPPORTED_PREPROCESSOR (missing required header line) | +| verbatim + `#include ` (`*.hdr-c`) | c-i64-import | 66 | UNSUPPORTED_TYPE (`static`, default argument) | +| verbatim + `#include `, `std::int64_t` (`*.hdr-cpp`) | cpp-import | 69 | UNSUPPORTED_CONSTRUCT (specifiers) | +| `floor_prefix` rewritten as one C17 expression (`floor_prefix.c17`) | c-i64-import | 68 | UNSUPPORTED_ARITHMETIC (division) | + +Controls: `ctrl_pos.c17` rc 0 (345 bytes); `ctrl_pos.hdr-cpp` (`calc`, `std::uint64_t`) rc 0 (361 +bytes); `ctrl_name.hdr-cpp` (same body, name `f`) rc 71, because cpp17 profiles accept only `calc` or +`omega_*` names. + +### Result + +No DeepInfer function imports with the current adapters: 1,909 Python functions fall outside every +profile by shape, the 6 in-shape Python functions refuse, and the 3 C/C++ functions tried refuse in +every form. The gaps, in order of reach: integer division and remainder with each language's rounding, +unbounded Python `int`, comparisons and selects outside the `_ck` form, docstrings and non-ASCII source +text, specifiers and default arguments, classes, and every tensor operation. + +## Extensions + +Each gap becomes reusable work in the component that already owns that layer. No DeepInfer-specific +converter is added. + +| id | extension | owner | status | +|---|---|---|---| +| 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 | +| 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) | +| 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) | +| 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 | +| 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 | +| 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 | + +## Switching callers + +A caller moves to Omega only after its `.om` unit is differentially checked against the pinned upstream +function and its bindings pass `tests/native/run.sh` (`NATIVE-CALL PASS` with all seven callers). The +switch is a patch against the DeepInfer pin, kept in this repository (`examples/deepinfer/`), not a fork. +Every dependency in the table above stays listed until its replacement is EXERCISED in that way. diff --git a/evidence/deepinfer/NOTICE b/evidence/deepinfer/NOTICE new file mode 100644 index 0000000..134b7df --- /dev/null +++ b/evidence/deepinfer/NOTICE @@ -0,0 +1,12 @@ +Third-party material in this directory + +The files in py-verbatim/ and cxx/*.verbatim are short excerpts copied from +deepseek-ai/DeepInfer (https://github.com/deepseek-ai/DeepInfer), commit +553741557a57df44a46fb3ab72b6aafeaf945337, which is licensed under the Apache +License, Version 2.0. A copy of that license is in LICENSE at the root of this +repository. Upstream ships no NOTICE file at that commit. + +Changes made here: py-stripped/ holds the same excerpts with type annotations +and docstrings removed. The cxx/*.c17, *.hdr-c and *.hdr-cpp files are +translations or headers derived from those excerpts for the import-coverage +replay in docs/DEEPINFER.md. They are test evidence, not part of any build. diff --git a/evidence/deepinfer/cxx/capped_prefix.hdr-c b/evidence/deepinfer/cxx/capped_prefix.hdr-c new file mode 100644 index 0000000..8196bfe --- /dev/null +++ b/evidence/deepinfer/cxx/capped_prefix.hdr-c @@ -0,0 +1,5 @@ +#include +static int64_t capped_prefix(int64_t n, int64_t ratio, int64_t cap) { + const int64_t stop = std::min(n, ratio * cap); + return floor_prefix(stop, ratio) + (n - stop) * cap; +} diff --git a/evidence/deepinfer/cxx/capped_prefix.hdr-cpp b/evidence/deepinfer/cxx/capped_prefix.hdr-cpp new file mode 100644 index 0000000..27a93ef --- /dev/null +++ b/evidence/deepinfer/cxx/capped_prefix.hdr-cpp @@ -0,0 +1,5 @@ +#include +static std::int64_t capped_prefix(std::int64_t n, std::int64_t ratio, std::int64_t cap) { + const std::int64_t stop = std::min(n, ratio * cap); + return floor_prefix(stop, ratio) + (n - stop) * cap; +} diff --git a/evidence/deepinfer/cxx/capped_prefix.verbatim b/evidence/deepinfer/cxx/capped_prefix.verbatim new file mode 100644 index 0000000..2490e78 --- /dev/null +++ b/evidence/deepinfer/cxx/capped_prefix.verbatim @@ -0,0 +1,4 @@ +static int64_t capped_prefix(int64_t n, int64_t ratio, int64_t cap) { + const int64_t stop = std::min(n, ratio * cap); + return floor_prefix(stop, ratio) + (n - stop) * cap; +} diff --git a/evidence/deepinfer/cxx/ctrl_name.hdr-cpp b/evidence/deepinfer/cxx/ctrl_name.hdr-cpp new file mode 100644 index 0000000..49554a7 --- /dev/null +++ b/evidence/deepinfer/cxx/ctrl_name.hdr-cpp @@ -0,0 +1,2 @@ +#include +std::uint64_t f(std::uint64_t a, std::uint64_t b) { return a + b; } diff --git a/evidence/deepinfer/cxx/ctrl_pos.c17 b/evidence/deepinfer/cxx/ctrl_pos.c17 new file mode 100644 index 0000000..7dad30c --- /dev/null +++ b/evidence/deepinfer/cxx/ctrl_pos.c17 @@ -0,0 +1,4 @@ +#include +int64_t f(int64_t a, int64_t b) { + return a + b; +} diff --git a/evidence/deepinfer/cxx/ctrl_pos.hdr-cpp b/evidence/deepinfer/cxx/ctrl_pos.hdr-cpp new file mode 100644 index 0000000..0ebd8d5 --- /dev/null +++ b/evidence/deepinfer/cxx/ctrl_pos.hdr-cpp @@ -0,0 +1,2 @@ +#include +std::uint64_t calc(std::uint64_t a, std::uint64_t b) { return a + b; } diff --git a/evidence/deepinfer/cxx/floor_prefix.c17 b/evidence/deepinfer/cxx/floor_prefix.c17 new file mode 100644 index 0000000..3162809 --- /dev/null +++ b/evidence/deepinfer/cxx/floor_prefix.c17 @@ -0,0 +1,4 @@ +#include +int64_t floor_prefix(int64_t n, int64_t ratio) { + return n / ratio * (n + 1) - ratio * (n / ratio) * (n / ratio + 1) / 2; +} diff --git a/evidence/deepinfer/cxx/floor_prefix.hdr-c b/evidence/deepinfer/cxx/floor_prefix.hdr-c new file mode 100644 index 0000000..f8761eb --- /dev/null +++ b/evidence/deepinfer/cxx/floor_prefix.hdr-c @@ -0,0 +1,5 @@ +#include +static int64_t floor_prefix(int64_t n, int64_t ratio) { + const int64_t blocks = n / ratio; + return blocks * (n + 1) - ratio * blocks * (blocks + 1) / 2; +} diff --git a/evidence/deepinfer/cxx/floor_prefix.hdr-cpp b/evidence/deepinfer/cxx/floor_prefix.hdr-cpp new file mode 100644 index 0000000..f6c2bc9 --- /dev/null +++ b/evidence/deepinfer/cxx/floor_prefix.hdr-cpp @@ -0,0 +1,5 @@ +#include +static std::int64_t floor_prefix(std::int64_t n, std::int64_t ratio) { + const std::int64_t blocks = n / ratio; + return blocks * (n + 1) - ratio * blocks * (blocks + 1) / 2; +} diff --git a/evidence/deepinfer/cxx/floor_prefix.verbatim b/evidence/deepinfer/cxx/floor_prefix.verbatim new file mode 100644 index 0000000..57d0dac --- /dev/null +++ b/evidence/deepinfer/cxx/floor_prefix.verbatim @@ -0,0 +1,4 @@ +static int64_t floor_prefix(int64_t n, int64_t ratio) { + const int64_t blocks = n / ratio; + return blocks * (n + 1) - ratio * blocks * (blocks + 1) / 2; +} diff --git a/evidence/deepinfer/cxx/pairs.hdr-c b/evidence/deepinfer/cxx/pairs.hdr-c new file mode 100644 index 0000000..d11997d --- /dev/null +++ b/evidence/deepinfer/cxx/pairs.hdr-c @@ -0,0 +1,6 @@ +#include +static int64_t pairs(int64_t begin, int64_t end, int64_t ratio, int64_t cap = 0) { + if (cap == 0) + return floor_prefix(end, ratio) - floor_prefix(begin, ratio); + return capped_prefix(end, ratio, cap) - capped_prefix(begin, ratio, cap); +} diff --git a/evidence/deepinfer/cxx/pairs.hdr-cpp b/evidence/deepinfer/cxx/pairs.hdr-cpp new file mode 100644 index 0000000..32f9414 --- /dev/null +++ b/evidence/deepinfer/cxx/pairs.hdr-cpp @@ -0,0 +1,6 @@ +#include +static std::int64_t pairs(std::int64_t begin, std::int64_t end, std::int64_t ratio, std::int64_t cap = 0) { + if (cap == 0) + return floor_prefix(end, ratio) - floor_prefix(begin, ratio); + return capped_prefix(end, ratio, cap) - capped_prefix(begin, ratio, cap); +} diff --git a/evidence/deepinfer/cxx/pairs.verbatim b/evidence/deepinfer/cxx/pairs.verbatim new file mode 100644 index 0000000..99959ff --- /dev/null +++ b/evidence/deepinfer/cxx/pairs.verbatim @@ -0,0 +1,5 @@ +static int64_t pairs(int64_t begin, int64_t end, int64_t ratio, int64_t cap = 0) { + if (cap == 0) + return floor_prefix(end, ratio) - floor_prefix(begin, ratio); + return capped_prefix(end, ratio, cap) - capped_prefix(begin, ratio, cap); +} diff --git a/evidence/deepinfer/py-stripped/000_is_power_of_two.py b/evidence/deepinfer/py-stripped/000_is_power_of_two.py new file mode 100644 index 0000000..f1acfc0 --- /dev/null +++ b/evidence/deepinfer/py-stripped/000_is_power_of_two.py @@ -0,0 +1,2 @@ +def is_power_of_two(x): + return x & x - 1 == 0 diff --git a/evidence/deepinfer/py-stripped/001_ceil_div.py b/evidence/deepinfer/py-stripped/001_ceil_div.py new file mode 100644 index 0000000..ba2bb2a --- /dev/null +++ b/evidence/deepinfer/py-stripped/001_ceil_div.py @@ -0,0 +1,2 @@ +def ceil_div(x, align): + return (x + align - 1) // align diff --git a/evidence/deepinfer/py-stripped/002_i64.py b/evidence/deepinfer/py-stripped/002_i64.py new file mode 100644 index 0000000..e59cdc3 --- /dev/null +++ b/evidence/deepinfer/py-stripped/002_i64.py @@ -0,0 +1,2 @@ +def i64(x): + return x if x < 9223372036854775808 else x - 18446744073709551616 diff --git a/evidence/deepinfer/py-stripped/003_expanded_image_token_len.py b/evidence/deepinfer/py-stripped/003_expanded_image_token_len.py new file mode 100644 index 0000000..4da2f7a --- /dev/null +++ b/evidence/deepinfer/py-stripped/003_expanded_image_token_len.py @@ -0,0 +1,2 @@ +def expanded_image_token_len(n_llm_h, n_llm_w): + return n_llm_h * (n_llm_w + 1) + 2 diff --git a/evidence/deepinfer/py-stripped/004__align_to_multiple.py b/evidence/deepinfer/py-stripped/004__align_to_multiple.py new file mode 100644 index 0000000..03ce8f7 --- /dev/null +++ b/evidence/deepinfer/py-stripped/004__align_to_multiple.py @@ -0,0 +1,2 @@ +def align_to_multiple(numerator, denominator, alignment): + return (numerator + denominator * alignment - 1) // (denominator * alignment) * alignment diff --git a/evidence/deepinfer/py-stripped/005__needs_compress_state.py b/evidence/deepinfer/py-stripped/005__needs_compress_state.py new file mode 100644 index 0000000..4cf50ea --- /dev/null +++ b/evidence/deepinfer/py-stripped/005__needs_compress_state.py @@ -0,0 +1,2 @@ +def needs_compress_state(compress_ratio): + return compress_ratio > 1 diff --git a/evidence/deepinfer/py-verbatim/000_is_power_of_two.py b/evidence/deepinfer/py-verbatim/000_is_power_of_two.py new file mode 100644 index 0000000..c9fb558 --- /dev/null +++ b/evidence/deepinfer/py-verbatim/000_is_power_of_two.py @@ -0,0 +1,2 @@ +def is_power_of_two(x: int) -> bool: + return x & (x - 1) == 0 diff --git a/evidence/deepinfer/py-verbatim/001_ceil_div.py b/evidence/deepinfer/py-verbatim/001_ceil_div.py new file mode 100644 index 0000000..328e363 --- /dev/null +++ b/evidence/deepinfer/py-verbatim/001_ceil_div.py @@ -0,0 +1,2 @@ +def ceil_div(x: int, align: int) -> int: + return (x + align - 1) // align diff --git a/evidence/deepinfer/py-verbatim/002_i64.py b/evidence/deepinfer/py-verbatim/002_i64.py new file mode 100644 index 0000000..653365e --- /dev/null +++ b/evidence/deepinfer/py-verbatim/002_i64.py @@ -0,0 +1,2 @@ +def i64(x: int) -> int: + return x if x < 0x8000000000000000 else x - 0x10000000000000000 diff --git a/evidence/deepinfer/py-verbatim/003_expanded_image_token_len.py b/evidence/deepinfer/py-verbatim/003_expanded_image_token_len.py new file mode 100644 index 0000000..f5f3097 --- /dev/null +++ b/evidence/deepinfer/py-verbatim/003_expanded_image_token_len.py @@ -0,0 +1,3 @@ +def expanded_image_token_len(n_llm_h: int, n_llm_w: int) -> int: + """图像段展开后的 token 数:IMAGE_START + 每行(n_llm_w 个 IMAGE + 1 个 NEW_LINE)+ IMAGE_END。""" + return n_llm_h * (n_llm_w + 1) + 2 diff --git a/evidence/deepinfer/py-verbatim/004__align_to_multiple.py b/evidence/deepinfer/py-verbatim/004__align_to_multiple.py new file mode 100644 index 0000000..c749fc7 --- /dev/null +++ b/evidence/deepinfer/py-verbatim/004__align_to_multiple.py @@ -0,0 +1,3 @@ +def _align_to_multiple(numerator: int, denominator: int, alignment: int) -> int: + """把 numerator 个元素按每 denominator 个一组分组后,组数向上对齐到 alignment 的倍数。denominator=1 时即普通向上对齐。""" + return (numerator + denominator * alignment - 1) // (denominator * alignment) * alignment diff --git a/evidence/deepinfer/py-verbatim/005__needs_compress_state.py b/evidence/deepinfer/py-verbatim/005__needs_compress_state.py new file mode 100644 index 0000000..7fa326f --- /dev/null +++ b/evidence/deepinfer/py-verbatim/005__needs_compress_state.py @@ -0,0 +1,2 @@ +def _needs_compress_state(compress_ratio: int) -> bool: + return compress_ratio > 1 diff --git a/evidence/deepinfer/py-verbatim/ctrl_pos.py b/evidence/deepinfer/py-verbatim/ctrl_pos.py new file mode 100644 index 0000000..99049e0 --- /dev/null +++ b/evidence/deepinfer/py-verbatim/ctrl_pos.py @@ -0,0 +1,2 @@ +def f(a, b): + return (a + b) & 0xFFFFFFFFFFFFFFFF diff --git a/evidence/deepinfer/py-verbatim/ctrl_unmasked.py b/evidence/deepinfer/py-verbatim/ctrl_unmasked.py new file mode 100644 index 0000000..150ff76 --- /dev/null +++ b/evidence/deepinfer/py-verbatim/ctrl_unmasked.py @@ -0,0 +1,2 @@ +def f(a, b): + return a + b diff --git a/evidence/deepinfer/py-verbatim/probe_doc_ascii.py b/evidence/deepinfer/py-verbatim/probe_doc_ascii.py new file mode 100644 index 0000000..0192eca --- /dev/null +++ b/evidence/deepinfer/py-verbatim/probe_doc_ascii.py @@ -0,0 +1,3 @@ +def calc(a, b): + """doc""" + return ((a + b) & 0xFFFFFFFFFFFFFFFF) diff --git a/evidence/deepinfer/py-verbatim/probe_nonascii_comment.py b/evidence/deepinfer/py-verbatim/probe_nonascii_comment.py new file mode 100644 index 0000000..424ea38 --- /dev/null +++ b/evidence/deepinfer/py-verbatim/probe_nonascii_comment.py @@ -0,0 +1,3 @@ +def calc(a, b): + # é + return ((a + b) & 0xFFFFFFFFFFFFFFFF) diff --git a/evidence/deepinfer/replay-656192e0.txt b/evidence/deepinfer/replay-656192e0.txt new file mode 100644 index 0000000..945f44a --- /dev/null +++ b/evidence/deepinfer/replay-656192e0.txt @@ -0,0 +1,36 @@ +4c74b1f7f35ce2ebfeeb0b9e0c024f0deb7544f071e0a7fe512af199270e0eb9 /home/drakestapleton/workspace/deepinfer-bridge/omega-839/build/L627/import/python-import +4cd9f0181f7d06cb9975bee4488b79cb6b95dede91912021c53de5a4aa190f24 /home/drakestapleton/workspace/deepinfer-bridge/omega-839/build/S2/c-i64-import +ed90e640c6fc694712856b8fdaf8ed4865e8c56f2008203a201301312806bdd0 /home/drakestapleton/workspace/deepinfer-bridge/omega-839/build/L739/cpp-import +PASS python-import want=66 got=66 out= 0B PY_IMPORT_UNSUPPORTED_TYPE py-verbatim/000_is_power_of_two.py +PASS python-import want=66 got=66 out= 0B PY_IMPORT_UNSUPPORTED_TYPE py-verbatim/001_ceil_div.py +PASS python-import want=66 got=66 out= 0B PY_IMPORT_UNSUPPORTED_TYPE py-verbatim/002_i64.py +PASS python-import want=72 got=72 out= 0B PY_IMPORT_UNSUPPORTED_SOURCE_FORM py-verbatim/003_expanded_image_token_len.py +PASS python-import want=72 got=72 out= 0B PY_IMPORT_UNSUPPORTED_SOURCE_FORM py-verbatim/004__align_to_multiple.py +PASS python-import want=71 got=71 out= 0B PY_IMPORT_UNSUPPORTED_SIGNATURE py-verbatim/005__needs_compress_state.py +PASS python-import want=0 got=0 out= 324B py-verbatim/ctrl_pos.py +PASS python-import want=68 got=68 out= 0B PY_IMPORT_UNSUPPORTED_ARITHMETIC py-verbatim/ctrl_unmasked.py +PASS python-import want=68 got=68 out= 0B PY_IMPORT_UNSUPPORTED_ARITHMETIC py-stripped/000_is_power_of_two.py +PASS python-import want=68 got=68 out= 0B PY_IMPORT_UNSUPPORTED_ARITHMETIC py-stripped/001_ceil_div.py +PASS python-import want=69 got=69 out= 0B PY_IMPORT_UNSUPPORTED_CONSTRUCT py-verbatim/probe_doc_ascii.py +PASS python-import want=72 got=72 out= 0B PY_IMPORT_UNSUPPORTED_SOURCE_FORM py-verbatim/probe_nonascii_comment.py +PASS python-import want=69 got=69 out= 0B PY_IMPORT_UNSUPPORTED_CONSTRUCT py-stripped/002_i64.py +PASS python-import want=68 got=68 out= 0B PY_IMPORT_UNSUPPORTED_ARITHMETIC py-stripped/003_expanded_image_token_len.py +PASS python-import want=68 got=68 out= 0B PY_IMPORT_UNSUPPORTED_ARITHMETIC py-stripped/004__align_to_multiple.py +PASS python-import want=68 got=68 out= 0B PY_IMPORT_UNSUPPORTED_ARITHMETIC py-stripped/005__needs_compress_state.py +PASS c-i64-import want=66 got=66 out= 0B C_IMPORT_UNSUPPORTED_TYPE cxx/floor_prefix.hdr-c +PASS c-i64-import want=66 got=66 out= 0B C_IMPORT_UNSUPPORTED_TYPE cxx/capped_prefix.hdr-c +PASS c-i64-import want=66 got=66 out= 0B C_IMPORT_UNSUPPORTED_TYPE cxx/pairs.hdr-c +PASS c-i64-import want=68 got=68 out= 0B C_IMPORT_UNSUPPORTED_ARITHMETIC cxx/floor_prefix.c17 +PASS c-i64-import want=72 got=72 out= 0B C_IMPORT_UNSUPPORTED_PREPROCESSOR cxx/floor_prefix.verbatim +PASS cpp-import want=72 got=72 out= 0B CPP_IMPORT_UNSUPPORTED_PREPROCESSOR cxx/floor_prefix.verbatim +PASS c-i64-import want=72 got=72 out= 0B C_IMPORT_UNSUPPORTED_PREPROCESSOR cxx/capped_prefix.verbatim +PASS cpp-import want=72 got=72 out= 0B CPP_IMPORT_UNSUPPORTED_PREPROCESSOR cxx/capped_prefix.verbatim +PASS c-i64-import want=72 got=72 out= 0B C_IMPORT_UNSUPPORTED_PREPROCESSOR cxx/pairs.verbatim +PASS cpp-import want=72 got=72 out= 0B CPP_IMPORT_UNSUPPORTED_PREPROCESSOR cxx/pairs.verbatim +PASS c-i64-import want=0 got=0 out= 345B cxx/ctrl_pos.c17 +PASS cpp-import want=69 got=69 out= 0B CPP_IMPORT_UNSUPPORTED_CONSTRUCT cxx/floor_prefix.hdr-cpp +PASS cpp-import want=69 got=69 out= 0B CPP_IMPORT_UNSUPPORTED_CONSTRUCT cxx/capped_prefix.hdr-cpp +PASS cpp-import want=69 got=69 out= 0B CPP_IMPORT_UNSUPPORTED_CONSTRUCT cxx/pairs.hdr-cpp +PASS cpp-import want=0 got=0 out= 361B cxx/ctrl_pos.hdr-cpp +PASS cpp-import want=71 got=71 out= 0B CPP_IMPORT_UNSUPPORTED_SIGNATURE cxx/ctrl_name.hdr-cpp +DEEPINFER-COVERAGE REPLAY PASS diff --git a/evidence/deepinfer/run.sh b/evidence/deepinfer/run.sh new file mode 100755 index 0000000..ad8b6ea --- /dev/null +++ b/evidence/deepinfer/run.sh @@ -0,0 +1,54 @@ +#!/bin/sh +# Replays the DeepInfer coverage verdicts in docs/DEEPINFER.md against built omega-mv adapters. +# OMEGA_MV = an omega-mv checkout whose adapters are built (PR #839 head 656192e0 was measured: +# build/L627/import/python-import, build/S2/c-i64-import, build/L739/cpp-import). +# Prints one row per input and exits 1 if any exit status differs from the recorded one. +set -u +: "${OMEGA_MV:?set OMEGA_MV to a built omega-mv checkout}" +here=$(cd "$(dirname "$0")" && pwd) +py="$OMEGA_MV/build/L627/import/python-import" +c="$OMEGA_MV/build/S2/c-i64-import" +cpp="$OMEGA_MV/build/L739/cpp-import" +for t in "$py" "$c" "$cpp"; do [ -x "$t" ] || { echo "missing adapter $t" >&2; exit 2; }; done +sha256sum "$py" "$c" "$cpp" +tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT +bad=0 +check() { # adapter expected-status input + "$1" < "$3" > "$tmp/out" 2> "$tmp/err"; got=$? + verdict=PASS; [ "$got" = "$2" ] || { verdict=FAIL; bad=1; } + printf '%-5s %-14s want=%-3s got=%-3s out=%5sB %-40s %s\n' "$verdict" "$(basename "$1")" "$2" "$got" \ + "$(wc -c < "$tmp/out" | tr -d ' ')" "$(head -c 40 "$tmp/err" | tr '\n' ' ')" "${3#"$here"/}" +} +v="$here/py-verbatim"; s="$here/py-stripped"; x="$here/cxx" +check "$py" 66 "$v/000_is_power_of_two.py" +check "$py" 66 "$v/001_ceil_div.py" +check "$py" 66 "$v/002_i64.py" +check "$py" 72 "$v/003_expanded_image_token_len.py" +check "$py" 72 "$v/004__align_to_multiple.py" +check "$py" 71 "$v/005__needs_compress_state.py" +check "$py" 0 "$v/ctrl_pos.py" +check "$py" 68 "$v/ctrl_unmasked.py" +check "$py" 68 "$s/000_is_power_of_two.py" +check "$py" 68 "$s/001_ceil_div.py" +check "$py" 69 "$v/probe_doc_ascii.py" +check "$py" 72 "$v/probe_nonascii_comment.py" +check "$py" 69 "$s/002_i64.py" +check "$py" 68 "$s/003_expanded_image_token_len.py" +check "$py" 68 "$s/004__align_to_multiple.py" +check "$py" 68 "$s/005__needs_compress_state.py" +check "$c" 66 "$x/floor_prefix.hdr-c" +check "$c" 66 "$x/capped_prefix.hdr-c" +check "$c" 66 "$x/pairs.hdr-c" +check "$c" 68 "$x/floor_prefix.c17" +for f in floor_prefix capped_prefix pairs; do + check "$c" 72 "$x/$f.verbatim" + check "$cpp" 72 "$x/$f.verbatim" +done +check "$c" 0 "$x/ctrl_pos.c17" +check "$cpp" 69 "$x/floor_prefix.hdr-cpp" +check "$cpp" 69 "$x/capped_prefix.hdr-cpp" +check "$cpp" 69 "$x/pairs.hdr-cpp" +check "$cpp" 0 "$x/ctrl_pos.hdr-cpp" +check "$cpp" 71 "$x/ctrl_name.hdr-cpp" +[ "$bad" = 0 ] && echo "DEEPINFER-COVERAGE REPLAY PASS" || echo "DEEPINFER-COVERAGE REPLAY FAIL" +exit "$bad" diff --git a/evidence/deepinfer/select_candidates.py b/evidence/deepinfer/select_candidates.py new file mode 100644 index 0000000..93105ec --- /dev/null +++ b/evidence/deepinfer/select_candidates.py @@ -0,0 +1,43 @@ +"""Inventory every Python function in a pinned DeepInfer tree and pick the ones whose shape +could fall in an existing integer import profile (single `return ` over parameters and +integer literals, arithmetic/comparison/conditional only). Writes candidates as standalone +sources for the real adapters; it decides nothing about acceptance itself.""" +import ast, json, sys +from pathlib import Path + +root = Path(sys.argv[1]); out = Path(sys.argv[2]); out.mkdir(parents=True, exist_ok=True) +ARITH = (ast.Add, ast.Sub, ast.Mult, ast.FloorDiv, ast.Mod, ast.LShift, ast.RShift, + ast.BitAnd, ast.BitOr, ast.BitXor, ast.Div, ast.Pow) + +def pure_int_expr(node, params): + if isinstance(node, ast.Name): return node.id in params + if isinstance(node, ast.Constant): return isinstance(node.value, int) and not isinstance(node.value, bool) + if isinstance(node, ast.BinOp): return isinstance(node.op, ARITH) and pure_int_expr(node.left, params) and pure_int_expr(node.right, params) + if isinstance(node, ast.UnaryOp): return isinstance(node.op, (ast.USub, ast.Invert, ast.UAdd)) and pure_int_expr(node.operand, params) + if isinstance(node, ast.Compare): return all(pure_int_expr(n, params) for n in [node.left, *node.comparators]) + if isinstance(node, ast.IfExp): return all(pure_int_expr(n, params) for n in (node.test, node.body, node.orelse)) + return False + +rows = []; total = 0; files = 0 +for f in sorted(root.rglob('*.py')): + rel = f.relative_to(root).as_posix(); files += 1 + src = f.read_text(encoding='utf-8') + tree = ast.parse(src) + lines = src.splitlines() + for node in ast.walk(tree): + if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): continue + total += 1 + a = node.args + params = [p.arg for p in a.posonlyargs + a.args + a.kwonlyargs] + body = [s for s in node.body if not (isinstance(s, ast.Expr) and isinstance(s.value, ast.Constant) and isinstance(s.value.value, str))] + if not (len(body) == 1 and isinstance(body[0], ast.Return) and body[0].value is not None): continue + if a.vararg or a.kwarg or node.decorator_list or not params: continue + if not pure_int_expr(body[0].value, set(params)): continue + seg = '\n'.join(lines[node.lineno - 1: node.end_lineno]) + name = f'{len(rows):03d}_{node.name}' + (out / f'{name}.py').write_text(ast.unparse(node) + '\n') + rows.append({'id': name, 'file': rel, 'line': node.lineno, 'name': node.name, + 'params': params, 'annotated': any(p.annotation for p in a.args), 'source': seg}) +json.dump({'files': files, 'functions': total, 'candidates': rows}, open(out / 'candidates.json', 'w'), indent=1) +print(f'files={files} functions={total} candidates={len(rows)}') +for r in rows: print(f"{r['id']} {r['file']}:{r['line']} {r['source'].splitlines()[-1].strip()[:90]}") ```