Repository navigation
RBLN (ATOM) training backend - #20
Merged
Merged
Conversation
4 of 5 tasks
Graph parts compiled with rebel.compile_from_torch and run by an RBLN runtime (host tensors in and out), cached as .rbln per graph key, shapes and compiler version. rebel-compiler 0.11 segfaults or fails on some backward parts (the SiLU backward), so each part compiles in a child process and a part that does not compile runs on the host, recorded. Arguments are mapped by name to the inputs the compiled graph kept (the compiler drops folded or unused inputs). ATOM (RBLN-CA22), Llama-3.2-1B-Instruct, LoRA r16 q,v, S=128, --max-mm 2: 30 steps loss 3.72 -> 0.53, 2.35 s/step, 1 of 51 parts on the host. Gradient check (2 layers): loss rel 0.16 %, gradients cos >= 0.986 but worst rel 16 % (> 5 % threshold); per stage with identical inputs within 0.7-3.4 %. Refs #15. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gspark-etri
force-pushed
the
feat/15-rbln-backend
branch
from
October 21, 2026 20:10
c085669 to
7fd8a95
Compare
rebel-compiler 0.11 rejects aten.add(aten.neg(x), c) in any graph with DEVICE_GRAPH_CONVERSION and segfaults when a matmul follows in the same part. scalarize_constants writes 1 - sigmoid(x) that way. The RBLN backend now rewrites the pair to rsub.Scalar before compiling, and the cache path hashes the rewritten graph so old .host markers are not reused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…erence ATOM rounds away from zero far more often than round-to-nearest-even and fp32 outputs carry bf16-level error. With every part on ATOM, npu-lora check on 2 layers of Llama-3.2-1B was 13 % off the CPU (cos 0.991). Placing the layer forward graph parts on the host (--host-parts, default fwd for rbln) brings it to 1.4 % (cos 0.99991); the backward and the vocabulary-chunked head stay on ATOM. Steps report graph-part time by where it ran. check now also reports both runs against an fp32 autograd reference (dense LoRA); the pass criterion is unchanged. RBLN log lines go to stderr so check prints clean JSON. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
experiments/2026-10-22-rbln-atom-check.md with raw data and two standalone repros (neg + add.Scalar compile failure, ATOM rounding bias) for the vendor. README backend table and limitations mention rbln:N and --host-parts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Background
npu-lora could not train on ATOM (#15). The first version of this PR compiled 50 of 51 graph parts with
rebel-compiler 0.11.0, but it left two problems:
npu-lora check --backend rbln:0failed: the worst LoRA gradient was 16 % off the CPU, against a 5 % threshold.This update finds the cause of both and makes
checkpass. The branch is rebased onmain(#42–#45).Changes
npu_lora/backends.pyRBLNBackend(--backend rbln:N):rebel.compile_from_torchand run by an RBLN runtime, with host tensors in and out..rbln. Each part compiles in a child process, and a part that fails to compilefalls back to the host.
graph.fold_neg_addrewritesadd(neg(x), c)→rsub(x, c). rebel-compiler 0.11rejects that pair (DEVICE_GRAPH_CONVERSION), and it segfaults when a matmul follows; this was the SiLU backward.
The cache path hashes the rewritten graph.
host_parts/--host-partsputs whole part groups (fwd,bwd,rms,ce-stats,ce-grad,rms-bwd) on the host on purpose.fwd. The layer forward runs on the host; the layer backward (which recomputes the forward)and the head run on ATOM.
noneputs every part on ATOM.parts_device_s/parts_host_s. Log lines go to stderr.npu_lora/cli.py:checkalso reports both runs against an fp32 autograd reference (--reference fp32, dense LoRA). The passcriterion is unchanged: NPU vs CPU.
_backendpasses--cache-dirand--host-partsto rbln.npu_lora/trainer.py:LoRATrainer.reference_grads(fp32 autograd with the graphs' bf16 weights and adapters).fold_neg_addkeeps the SiLU-backward values; host placement and group parsing; the fp32 referencematches HF's loss and the CPU gradients.
experiments/2026-10-22-rbln-atom-check.md+experiments/data/rbln-atom/: the record, raw results, and twostandalone repros for the vendor.
Verification
rbln-stat.rebel-compiler 0.12.0. That is only on the vendor index, which answers 401 (no credentials on the node), so it
was not tested.
check:unsloth/Llama-3.2-1B-Instruct, first 2 layers, S=128, LoRA r16 q·v, B ~ N(0, 0.01), random ids(check's seed). The diagnostics also varied the ids and B (seeds 2–4).
checkpasses when the loss is within 1 % and every LoRA gradient within 5 % of the CPU (unchanged), anda LoRA run reduces the loss.
were moved to the host by group.
CPU suite on Windows / torch 2.9.1: the 3 new or extended tests pass. 8 tests also fail on
mainin that localenvironment (transformers 4.57, ai-rm entry points not installed); CI runs the full suite.
Compile: before, 1 of 39 backward parts was on the host (segfault). After, all 59 parts compile. The SiLU-backward
part is within 0.7 % of the CPU on ATOM.
npu-lora check --backend rbln:0 --layers 2 --seq-len 128 --max-mm 2:--host-parts none(59 parts on ATOM)fwdon the host: 44 parts on ATOM, 15 on the host)The default was re-run from the pushed head (
a472883): same numbers, exit code 0.Other inputs (seeds 2–4), worst gradient vs CPU:
Cause: ATOM rounds away from zero far more often than round-to-nearest-even (bias +0.5…+0.9), and fp32 outputs
have bf16-level error (repro table in the record).
ce-gradup to 4.3 %), but the forward activations that leave alayer drift and the head's softmax amplifies that.
ce-gradon the host,lsefrom ATOM) makes itworse.
The fp32 reference shows the CPU bf16 run is not exact either: on check's inputs it is 9.1 % off fp32. On seeds
2–4 all-ATOM is 1.2–3× further from fp32 than the CPU.
LoRA, r16 q·v, S=128, default placement vs
--backend cpu, same code and seed:lsecomes from ATOM'slogits and the target logit from the host.
Median step time, 1B: ATOM 1.39 s, of which ATOM parts 1.09 s and host parts 0.14 s; CPU 0.79 s. Not tuned: the
runtime uploads every input, weights included, per call.
.research/check_sensitive.py: clean.Compatibility and limits
rsubrewrite and host placement apply only to the RBLN backend.checkprints extra fp32 fields;--reference noneskips them.choice.
neg+add.Scalarcompile failure, and the rounding bias.They are for the lead to send; nothing was sent.
Related Issue
Closes #15 (
checkpasses on 2 layers with the default placement, and a LoRA run on ATOM reduces the loss). Thecompiler and rounding issues are documented with standalone repros.
Checklist
checkpass, LoRA runs).research/check_sensitive.py: clean)🤖 Generated with Claude Code