Repository navigation
compat(epv2): support FlyDSL 0.3.0 alongside 0.2.x - #529
Merged
Merged
Conversation
flydsl 0.3.0 reorganised three things the EPv2 device kernels depend on:
* `flydsl.expr.vector` was dropped; the vector ops now come from the MLIR
vector dialect, where `extract` takes (source, dynamic_position,
static_position) instead of (vector, static_position).
* `flydsl.expr.buffer_ops` was dropped. Buffer-resource access is now
`make_buffer_ptr` on a typed global pointer plus pointer load/store,
rather than an explicit V# with `buffer_load` / `buffer_store`.
* `T.<dtype>` turned from a factory into a property, so `T.i32()` stopped
working, and `T.VectorType` moved to the MLIR ir module.
Add flydsl_compat.py, which resolves all three behind the spellings the
kernels already use, so intranode_kernels.py only changes its imports — its
~110 buffer calls and ~84 T.* uses are untouched.
Which branch is taken is decided by probing for the modules themselves, so
forks and backports resolve correctly whatever they call themselves; the
reported version is recorded for logs and diagnostics. The two probes differ
in kind: `buffer_ops` is a submodule, so its absence is a ModuleNotFoundError
and anything else means a broken install that must surface as itself, while
`vector` is only a name in `flydsl.expr` (already imported), where a plain
ImportError can only mean the name is gone.
Two details worth noting:
* `T` lookups stay lazy. On 0.3.0 the dtype property needs a live MLIR
context, and module-level uses such as `_BALLOT_INT = T.i64` would
otherwise evaluate at import time; `inspect.getattr_static` reads the
attribute without firing the descriptor.
* The 0.3.x `buffer_load` unwraps to an ArithValue, matching what 0.2.x
returned: callers both do arithmetic on the result and pass it to
`arith.*` ops, and only the unwrapped form is an `ir.Value`.
`mask` / `cache_modifier` are accepted but ignored on 0.3.x — there is no V#
cache-policy equivalent. The only caller passing one is the scatter-combine
Stage-3 read, where it is a hint, not a correctness requirement.
flydsl_prims.py needs no change: it uses `T.i32` without calling it, which is
the type on 0.3.0 and already worked on 0.2.x.
Verified on MI355X (gfx950, 8 GPUs), EP8 bf16 gather, hidden=7168 topk=8:
* flydsl 0.3.0 (expr.vector=False buffer_ops=False): OP-LEC + OP-gather PASS
* flydsl 0.2.4 (expr.vector=True buffer_ops=True): same test, still PASS
tok/rank 8/64/512/2048/8192 on 0.3.0; 128/512 re-run on both after each edit.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
jhchouuu
force-pushed
the
jhchou/flydsl-0.3.0
branch
from
August 6, 2026 08:54
37afbef to
8cc84be
Compare
jhchouuu
added a commit
that referenced
this pull request
Aug 11, 2026
A second kernel backend for python/mori/ops/dispatch_combine_v2/, behind the same
op class as the existing FlyDSL one. Callers keep writing
op = EpDispatchCombineOp(cfg, comm)
and get whichever backend cfg.kernel_backend (or MORI_V2_KERNEL_BACKEND) names,
defaulting to flydsl. The two agree element-for-element at 8 ranks.
Why
---
debug-aa's kernels carry 69 environment gates and 323 `#if` sites, and the cache
key is reassembled by hand in cache.py. That is how NOQUANT once failed to reach
the key and an A/B measurement silently reused the fully-enabled binary. The JIT
here removes the class of bug rather than the instance: the Cfg struct IS the
specialisation, its rendered text IS the source, and that text IS the cache key,
so a config cannot reach hipcc without reaching the key.
Rebased onto main (PR #532)
---------------------------
The FlyDSL dispatch/combine landed on main via #532 (cleaned up) plus #529
(FlyDSL 0.3) and #530 (retune), and became a real package. This backend is
re-applied on top of that: main's FlyDSL files (intranode_kernels, tuning_configs,
flydsl_prims, flydsl_compat) are kept verbatim, and the seam is split out of
main's op rather than the older debug-aa copy. The whole submodule now uses
relative imports; __init__ exports the base from ep_op_base, so importing the
package -- and running the HIP backend -- needs no FlyDSL installed.
Layout
------
include/mori/jit/v2/ render (+field-count guard) util toolchain compiler spec
src/jit/v2/ plan_api (namespace mori::jit::v2) -> libmori_jit.so, pure CXX
.../dispatch_combine_v2/ ep_cfg.hpp Cfg + Args, HIP-free, both sides
ep_spec.hpp Request + the two Specs
src/.../dispatch_combine_v2/ ep_intranode_kernel.hpp DEVICE-ONLY, Cfg as NTTP
ep_spec.cpp -> libmori_ops_v2.so
python/mori/jit/v2/ plan_api.py ctypes binding to the plan_api C
ABI (generic, op-agnostic)
python/.../dispatch_combine_v2/
dispatch_combine_op.py config + op base + selector (entry)
flydsl_backend.py FlyDSL subclass
hip_backend.py HIP subclass
ep_plans.py loads libmori_ops_v2.so, exposes the EP plans
Adding a kernel is three files (Cfg, body, Spec) and one registration macro; the
Python binding needs no edit, because the Plan class is derived from schemas C++
publishes and its args struct size is asserted against C++'s own sizeof.
The kernels are ported from origin/main's intranode MoE kernel. That port is
mechanical because v1's entire symmetric-memory surface is two things:
SymmMemObjPtr::GetAs<T*>(pe) -- a two-dependent-load table lookup, 30 call sites
-- and three Shmem*WaitUntil* spin loops that carry no shmem state. So
memObj->GetAs<T*>(pe) -> ccoGetLsaPeerPtr(win, pe, args.offRegion)
and 13 SymmMemObjPtr fields collapse to one window handle plus eight offsets. The
generated TU never includes mori/shmem, so it carries no device globals and needs
no per-module init.
One op, two backends
--------------------
The base owns the op: dispatch(), combine(), _pick(), the views, the routing
handle, the lifecycle. A subclass supplies three things -- _regions(cfg),
_build_kernels(cfg, arena), _unsupported(cfg). Behavioural differences are DATA
on the KernelSet (stages_in_kernel, self_resets_counters, capabilities), not
methods to override; the calling convention is the one thing that could not
become data, so each backend wraps its own in _build_kernels and the base calls
everything through one named signature.
The feature surface is strict inclusion, not overlap: the HIP backend does
bf16/fp32 gather and nothing else. So the capability gate runs at CONSTRUCTION,
before the arena is allocated -- asking it for fp8 names every missing feature
instead of producing wrong numbers at launch. Selecting a backend imports only
that backend, so the HIP path runs where FlyDSL is not installed.
Measured (8x MI355, gfx950, EP8 hidden=7168 topk=8, us at 128/512/4096 tok/rank)
-------------------------------------------------------------------------------
dispatch hip 47.5 / 128.8 / 857.4 flydsl 76.0 / 127.8 / 857.5
combine hip 57.8 / 124.4 / 781.8 flydsl 82.7 / 133.6 / 888.8
The combine gap at 4096 is the staging copy: FlyDSL issues a separate 311 MB
torch copy before the kernel, the HIP kernel does it inside and overlaps it with
the barrier wait -- ~1 us instead of ~104.
Single-instance compile is 1.6 s against 115 s for debug-aa's whole file (90
kernels, gfx1250), which is what makes compile-on-demand viable at all.
Decisions worth recording
-------------------------
* Arena offsets and rank are LAUNCH arguments, not Cfg fields. As Cfg they were
in the key, so every arena layout and every rank compiled its own copy of an
identical kernel. Measured: 48.0/131.3 us as runtime args vs 49.5/130.6 as
constants -- inside noise, against 16 binaries per 8-rank run instead of 2.
The gfx942 micro-benchmark that suggested the constant form was actively worse
(VGPR 9 -> 22, the compiler loses "the base is uniform") is not contradicted.
* Cfg as a single C++20 structural NTTP, not positional template parameters.
DeepEP and CK both use all-int positional expansion, where swapping two
arguments still compiles and silently produces the wrong kernel.
* FieldCount<T>() makes a field missing from VisitFields a compile error. It
needs C++20: under C++17 both gcc and clang treat "too many initialisers" as a
hard error rather than a substitution failure.
* Host stays free of hipcc. Shared arithmetic is attribute-free constexpr, never
__host__ __device__ -- the latter drags every host TU through hipcc. Guarded in
CI by tools/jit_v2/check_host_device_split.sh.
Bugs found and fixed on the way, two of them pre-existing
---------------------------------------------------------
* The combine barrier needs a release fence in every block, not just the
publisher: every block stages tokens some other block gathers. Half the tokens
came back wrong at 80 blocks. origin/main has the same hole.
* cco left hipErrorNotSupported (801) latched in the HIP runtime's sticky error
slot; torch's next launch reported it as its own. That is the whole of the
long-standing "cco breaks torch GPU kernels" symptom -- one-shot rather than
intermittent, because reading the flag also clears it. Cleared at the
Communicator.init boundary; the real fix is to stop latching it.
* The flat (pe, slot) stride must be the recv capacity, and the null sentinel
must use the same stride, or a deduped slot decodes to a real peer.
* DefaultSourceDeps listed src/ops/dispatch_combine, which is a SIBLING of
src/ops/dispatch_combine_v2 -- the v2 kernel bodies were not in the cache key,
so editing one reloaded a stale hsaco.
Verified
--------
On top of main (ae9635f): C++ test_jit_core 24/24 and the host/device split
guard pass from a clean host build against main's headers. On 8x MI355 (gfx950):
package imports flydsl-free, both backends resolve lazily; test_op.py passes
under both backends (LEC capability-gated off for hip); backend parity is
element-for-element with 0 failures at ct=8/64/512 and exit 0. The kernel sources
are unchanged from the pre-rebase branch, so the measured numbers above still
hold. FlyDSL's scatter, fp8_blockwise, StdMoE, per-token-scales and lifecycle
paths are untouched. gfx1250 compile-only.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
flydsl 0.3.0 reorganised three things the EPv2 device kernels depend on:
flydsl.expr.vectorextracttakes(source, dynamic_position, static_position)instead of(vector, static_position)flydsl.expr.buffer_opsmake_buffer_ptron a typed global pointer + pointer load/store, instead of an explicit V# withbuffer_load/buffer_storeT.<dtype>was a factoryT.i32()stops working;T.VectorTypemoved to the MLIRirmoduleEverything else the kernels use is unchanged: the rocdl instruction wrappers
(
ballot,ds_bpermute,fmed3, thecvt_*family,s_wait*),arith.*,the llvm / scf / vector dialects, and
flyc.kernel/flyc.jit.How
flydsl_compat.pyresolves all three behind the spellings the kernels alreadyuse, so
intranode_kernels.pyonly changes its imports — its ~110 buffer callsand ~84
T.*uses are untouched.Resolution is by probing imports and descriptors rather than parsing
flydsl.__version__, so point releases on either branch need no edit here.Two details worth calling out:
Tlookups stay lazy. On 0.3.0 the dtype property needs a live MLIRcontext, and module-level uses such as
_BALLOT_INT = T.i64would otherwiseevaluate at import time.
inspect.getattr_staticreads the attribute withoutfiring the descriptor.
buffer_loadunwraps to anArithValue, matching what 0.2.xreturned: callers both do arithmetic on the result and pass it to
arith.*ops, and only the unwrapped form is an
ir.Valuethose ops accept.mask/cache_modifierare accepted for signature parity but ignored on0.3.x — there is no V# cache-policy equivalent. The only caller passing one is
the scatter-combine Stage-3 read, where it is a hint, not a correctness
requirement.
flydsl_prims.pyneeds no change: it usesT.i32without calling it, which isthe type on 0.3.0 and already worked on 0.2.x.
Test
MI355X (gfx950, 8 GPUs), EP8 bf16 gather,
hidden=7168 topk=8,tok/rank 8 / 64 / 512 / 2048 / 8192:
OP-LEC+OP-gatherPASS at every size🤖 Generated with Claude Code