Skip to content

feat(tensorfold): upstream TensorFold runtime with NFS and native TP - #332

Open
Marker689 wants to merge 22 commits into
spark-arena:develop-nextfrom
Marker689:feature/tensorfold-support
Open

Marker689 wants to merge 22 commits into
spark-arena:develop-nextfrom
Marker689:feature/tensorfold-support

Conversation

@Marker689

@Marker689 Marker689 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

TensorFold runtime (upstream-only)

Adds a first-class tensorfold runtime for the upstream TensorFold native CUDA server.

  • Solo on one GB10: tensorfold-native serve <model> --host ... --port ....
  • NFS / pre-placed weights through sparkrun's existing absolute model: and cluster_config.resolved_model_path path — no download or distribution, identity-mounted into the container.
  • Native TP with the upstream --tp/--rank/--master/--master-port flags: one rank per host, followers start before rank 0, and the engine remains the authority on which worlds a model supports.
  • Container images are built outside sparkrun; recipes may pin container: or use the platform default.
  • Runtime is gated by the new runtime.tensorfold feature flag and keeps the upstream API/readiness surface (Chat/Completions, Responses, Anthropic Messages, /health).

The runtime is deliberately upstream-only: there is no tf_family, no per-model family layer, and no out-of-tree DeepSeek/Jayleaton bundle path in this PR.

Validation

  • pytest tests/test_runtime_tensorfold.py tests/test_features.py tests/test_platforms.py tests/test_launch_env.py tests/test_recipe.py tests/test_recipe_validation.py — 584 passed.
  • ruff check clean.
  • Dry-run solo and TP2 on two DGX Sparks render the expected commands.

TensorFold's native ranks must be listening before rank 0 starts serving,
which deadlocks the historical head-first native path. Add a runtime hook
native_start_order() ("head_first" by default, unchanged for every existing
runtime) and a native_rendezvous_port_span() hook so an engine that also opens
port+1 gets a contiguous reservation instead of a single free port.

The native orchestrator's exec blocks are split into helpers used by both
orders; the default path keeps the head-first gate and its logging. Tests cover
the unchanged path, workers-first ordering, contiguous port spans and the
existing no-rendezvous case.
… lane

Add two runtimes for the TensorFold Zig/CUDA engine:

* tensorfold: upstream release (pinned image) solo on one GB10, NFS/pre-placed
  checkpoints through the existing absolute-model mechanism, and native TP2 for
  the engine families that place their own ranks (glm and nemotron) via
  TF_*_RANK/TF_*_WORLD + NCCL_COMM_ID. Workers start before rank 0; a recipe
  command template is refused for TP because the follower ranks take different
  argv.

* tensorfold-dsv41: experimental DeepSeek-V4.1-Flash TP2/TP4 on the community
  fork (bertholomus/TensorFold @ 3ff3b2a + the tonyd2wild patches). Rank 0 runs
  tensorfold-native; followers run tf-dsv41-lanes from a prepared bundle with
  per-rank caches, kernel kit and Engram tables.

Ship the pinned image definitions and build workflows for both runtimes, the
one-time bundle preparation script, example recipes (solo, GLM/Nemotron TP2,
DeepSeek TP2/TP4), a drift guard between the image pins and the platform
defaults, and docs/TENSORFOLD.md with the NFS/TP limits and a hardware
validation checklist. The monitor colorizer alias covers tensorfold-dsv41 too.
validate_recipe returns list[str | RecipeIssue] in the base contract; annotate
both new runtimes accordingly. Also add the upstream image README.
The blanket *.env ignore silently excluded docker/tensorfold{, -dsv41}/image.env
from the branch, so the image workflows could not source their pins. Add explicit
negations next to the RDMA test image exception and add the missing files.
@dbotwinick

Copy link
Copy Markdown
Contributor

Thanks for the PR. Happy to add runtimes and tensorflow seems like it could be relevant to add. Some obvious items that I noticed pretty much immediately:

  1. docker container definitions and recipes do not belong in the sparkrun repository.
  2. there shouldn't need to be separate runtime implementations for the different recipes/usages -- there should be a single tensorflow runtime implementation

@dbotwinick
dbotwinick changed the base branch from main to develop-next October 24, 2026 04:37
The TP2 and TP4 deployments use different fork branches and patch sets. The
shared Dockerfile now takes TF_SHA/PATCH_SET, image.env pins both
(3ff3b2a/tp2 and 5940208/tp4), the build script and CI matrix build both, and
the TP4 recipe names its image explicitly because the platform default stays on
the TP2 tag. The TP4 environment also needs TF_RDMA_GID (the TP2 branch spells
it TF_RDMA_GID_INDEX), TF_DS_SERVED_K=solo, and the 2D sampling/pool settings;
those are covered by the recipe's tf_env and the runtime defaults.

Both image variants were built locally on x86_64 (Zig+CUDA compile ~193 s each)
and their binaries/venv inspected.
A DGX Spark's Docker Engine may not ship the buildx plugin. For a native local
build the classic docker builder is enough; keep buildx for push/cross builds
and pass every pin through --build-arg in the fallback.
@Marker689 Marker689 changed the title feat(tensorfold): TensorFold runtime with TP2/NFS and experimental DeepSeek-V4.1 lane feat(tensorfold): TensorFold runtime with NFS + TP2/TP4 and experimental DeepSeek-V4.1 lane Oct 24, 2026
Address review feedback:

- Remove the Dockerfile/build-script/workflow definitions and the example
  recipes from this repository.  Runtime images are built outside sparkrun,
  like the other first-party runtime images; the platform default still names
  the upstream image tag and the DeepSeek fork requires an explicit
  container: (built externally) that validation enforces.

- Collapse tensorfold-dsv41 into the single tensorfold runtime.  The
  DeepSeek-V4.1 fork is now tf_family: dsv41 inside the same plugin: only its
  command shape, bundle validation and follower binary differ.  No duplicate
  RuntimePlugin class, no second platform entry, no alias.

Docs, tests, changelog and the recipes table are updated for the single
runtime; the deep bundle/preparation details and the hardware checklist stay in
docs/TENSORFOLD.md.
@Marker689

Copy link
Copy Markdown
Contributor Author

Thanks for the review — both points are addressed in a89d7f46:

  1. Docker definitions and recipes removed from the repo. I dropped docker/tensorfold*, the image build scripts/workflows, recipes/, the bundle-prep script, and their tests. Runtime images are now treated as externally built, like the other first-party runtime images. Docs describe the required image contents/libraries and the DeepSeek bundle layout, but nothing container- or recipe-shaped ships here.

  2. Single runtime implementation. tensorfold-dsv41 is gone. The DeepSeek fork is now defaults.tf_family: dsv41 inside the same tensorfold runtime — same RuntimePlugin, same platform entry, same colorizer. Only the internal command builder/validation differs per family:

    • no family → solo upstream TensorFold;
    • glm / nemotron → upstream native TP2 (TF_GLM_* / TF_NEMOTRON_* + NCCL_COMM_ID);
    • dsv41 → DeepSeek fork (TF_TP_*, follower binary, prepared per-rank-cache bundle), requires an explicit container: because the fork image is built outside sparkrun.

The native orchestration hook (native_start_order(), native_rendezvous_port_span()) is unchanged and still defaults to the old head-first/no-span behavior for every existing runtime.

One open question: the DGX Spark platform default still names ghcr.io/spark-arena/tensorfold:1.1.3 for the upstream runtime (the tag would need publishing from wherever spark-arena builds first-party images). If you'd rather have no default image until that image exists, I can drop the platform entry and require an explicit container: for all TensorFold recipes.

I have no GB10 hardware in this environment, so this is still awaiting a hardware run (solo → NFS → TP2 → DeepSeek TP2/TP4). Tests/lint/pyright pass locally; the latest commit's GitHub workflows likely need approval for the fork PR. Happy to adjust the split/scope further.

The shared launcher calls generate_command() even for native clusters and only
requires a non-empty string; rank argv still comes from generate_node_command().
The dsv41 family raised there, so every multi-node DeepSeek launch failed before
distribution. Return the rank-0 serve shape for is_cluster=True and keep solo
dsv41 refused. Found while dry-running a real TP2 launch on two DGX Sparks.
When an image exists only on the targets, disable container distribution so the
launcher does not try to pull/save it from the control machine; each target's
local tag is still probed before serving.
The runtime already drives _run_native_cluster, but inherited cluster_strategy()
returned 'ray'. That made get_head_container_name() look for <id>_head while the
native launcher names the ranks <id>_node_N: the engine came up cleanly but the
readiness observer inspected a container that does not exist, so a healthy TP2
launch still exited non-zero. Declaring 'native' fixes readiness and selects the
file-backed log tail used by the sleep-infinity + exec path.

Verified on two GB10 Sparks: readiness now reports TTR 76.6s and the run exits 0.
@Marker689

Copy link
Copy Markdown
Contributor Author

Hardware validation: DeepSeek-V4.1-Flash TP2 on 2× DGX Spark

This PR is not just dry-run tested anymore. I ran the tf_family: dsv41 lane on two real GB10 hosts through sparkrun from a separate control machine, with the weights on NFS. The run exits 0 and serves all three APIs.

Environment

piece value
hosts 192.168.88.164 (gx10-4837), 192.168.88.165 (aitopatom-38ca); GB10, 121 GiB unified memory each, Ubuntu 24.04, Docker 29.2.1
control x86_64 workstation, sparkrun from this branch @ c6738869 (0.4.1-beta), cluster default from the user's ~/.config/sparkrun/clusters/default.yaml
image ghcr.io/spark-arena/tensorfold-dsv41:3ff3b2a built on each arm64 Spark from the external assets (Zig 0.17.0, CUDA 13.0.1, NCCL 2.32.3); labels confirm bertholomus/TensorFold@3ff3b2a, tp2
model Mia-AiLab/DeepSeek-V4.1-Flash-1017-EXL3-EAQ-v1-2.9-bpw (197 GB); rank caches 99 GiB each; accepted by tf-dsv41-rank-cache --index-only
Engram shards 47/48 of deepseek-ai/DeepSeek-V4.1-Flash-1017 (101.5 GB each); hardlinked into the bundle
kit bertholomus/DeepSeek-V4.1-Flash-TensorFold-TP2-2xGB10 v0.6.1; verify_kit.sh: 367/367 files match MANIFEST
bundle /home/marker/.cache/huggingface/tensorfold-dsv41/bundle = 393 GB, on the existing NFS export (10.10.10.165:/ mounted on .164)

No packages were installed on either Spark. Everything ran through Docker and a control-side Python venv; the hosts' apt history is untouched.

Launch

.venv/bin/sparkrun -v run tensorfold-dsv41-flash-tp2.yaml --cluster default --no-follow
# RUN_RC=0

Recipe shape: runtime: tensorfold, container: pinned to the local image, tf_family: dsv41, tensor_parallel: 2, absolute NFS model:, distribution_config.containers.enabled: false (the image exists only on the targets). Rank 1 starts first; rank 0 last.

Results

  • sparkrun status: both containers up on the right hosts (_node_0, _node_1), 2/2.
  • readiness: TTR port-open 76.6 s, HTTP-ready 76.6 s, TTFT 77.1 s, measurement sparkrun-rank0-v1; the engine reported loaded in 72.2 s (rank 0) / 73.3 s (rank 1).
  • model memory: 104.96 GiB on rank 0, 4 streams at a 1,048,576-token context.
  • GET /v1/models → {"id": "deepseek-v4.1-flash"}.
  • POST /v1/chat/completions (thinking off, temperature 0) → exact DEPLOYMENT_OK; streaming SSE works (content deltas + stop).
  • POST /v1/responses → OK; POST /v1/messages (Anthropic shape) → OK.
  • 2,001-token prompt completed a prefill in 2.08 s and generated a reply.
  • sparkrun logs ... follows the in-container /tmp/sparkrun_serve.log correctly; sparkrun stop --all removes both containers and frees ~110 GiB per host; a stop + relaunch is repeatable.
  • NFS proof: both containers have the same identity mount bundle → bundle from the shared NFS path; no per-host copy of model/rank caches.

Bugs found and fixed during the run

  1. generate_command() raised for dsv41 even in cluster mode; the shared launcher always calls it before a native launch. Fixed in 0e3b8061 (rank-0 preview for is_cluster=True, solo dsv41 still refused).
  2. The runtime inherited the default Ray cluster_strategy(), so readiness looked for <id>_head while the native path names ranks <id>_node_N. The engine was healthy but sparkrun run exited 1. Fixed in c6738869 by declaring native; readiness TTR now reports and the run exits 0.
  3. Documented the pre-placed-image switch (distribution_config.containers.enabled: false) in docs/TENSORFOLD.md (48c161bf).

Caveats / follow-ups

  • The image has no Pillow, so the engine logs no Pillow (NoPillow): images other than PNG are refused; text works, image inputs are untested.
  • At 1M context / 4 streams the engine reports 0.00 GiB per stream and 0 GiB left after a 12.2 GiB reserve (it still serves; this is a capacity-tuning issue, not a start failure).
  • TP4 was not run; only the TP2 lane is hardware-validated here.
  • The control-to-rank init network selected management (192.168.88.164); the engine's RDMA ring logs show gid_index=3 on both CX7 rails. No NCCL failure, but this is not a performance claim.
  • No benchmark was run; the numbers above are readiness/smoke checks only.

Checklist

  • arm64 image builds on both Sparks
  • rank caches + token map from the 2.9 bpw pack
  • kit manifest verified
  • Engram shards 47/48 on the shared NFS path
  • sparkrun run TP2, exit 0
  • readiness via rank-0 observation
  • chat / streaming / Responses / Messages
  • sparkrun logs, sparkrun status
  • sparkrun stop --all, detach and relaunch
  • NFS identity mount for the whole bundle
  • TP4
  • performance/benchmark
  • image/audio inputs (Pillow)

Marker689 and others added 4 commits October 24, 2026 16:16
The dsv41 loader already accepted cache_dir/kit_dir/engram_dir/token_map, but
they were not in known_config_keys(), so every split bundle printed a
'defaults the runtime does not understand' warning. List them and document the
latency-motivated split: Engram on each node's local NVMe, model/rank caches/kit
on the shared NFS bundle, with an executor identity mount.
--metrics-open and the new --dashboard flag belong to the serving rank: the
workers have no HTTP listener and the DeepSeek follower binary takes a different
argv. Emit both only when bind=True, map dashboard from the recipe, and document
it. Verified /metrics on the live TP2 server; enables /dashboard and /stats.
The PR targets develop-next; without this merge GitHub reports the branch as
conflicting.  Only the Unreleased CHANGELOG block conflicted (both sides add
entries); keep both.  Targeted runtime/orchestrator/monitor tests pass after
the merge.
The image definitions are intentionally not part of this PR, so the
docker/tensorfold*/image.env exceptions and their test reference no longer
exist; keep only the pre-existing RDMA pin exception.
@Marker689

Copy link
Copy Markdown
Contributor Author

Status after resolving the develop-next conflict (fbfb9448): the PR is now mergeable and CI ran.

  • 10 checks pass (portable daemon on all OS/Python combinations, wheel composition, npm, OpenClaw plugin).
  • Test sparkrun (3.12/3.13): still running.
  • source-types fails on a base-branch regression, not on this PR: the same 4 errors in src/sparkrun/api/model_cache.py reproduce on a clean origin/develop-next checkout. I did not touch that file.

So the remaining blockers are (a) that pre-existing develop-next type failure, (b) the pending Python test jobs, and (c) maintainer re-review + the open question about publishing ghcr.io/spark-arena/tensorfold:1.1.3 (or dropping the platform default). Happy to retarget/fix if you prefer a different base handling.

@Marker689
Marker689 marked this pull request as ready for review October 25, 2026 00:50
Marker689 and others added 2 commits October 25, 2026 05:27
Pick up the latest develop-next tip (rdma-test, model-cache and monitor
fixes); keep the TensorFold CHANGELOG entries alongside the base ones. Only
CHANGELOG.md conflicted.
Add a jayleaton engine variant to the existing TensorFold runtime.  It
targets the Jayleaton Zig fork (tensorfold-dsv41 / tf-dsv41-m1), TP=2 only,
with its own TF_DSV41 serving profile, rank order, assets and per-rank
Engram/prepared/cache layout.  The model pack stays pre-placed (NFS or an
HF-cache path); the engine image and AOT assets remain external to
sparkrun.

The family keeps the existing served-model name/port contract and is
covered by command, env, validation and startup-order tests plus a docs
section and changelog entry.
@Marker689

Copy link
Copy Markdown
Contributor Author

Jayleaton Zig engine family validated on the two DGX Sparks (commit 1705127).

  • image: tensorfold-dsv41-zig:local (built from jayleaton/deepseek-v41-tensorfold-spark, ARM64, Zig 0.17.0, CUDA 13.0)
  • model: jayleaton flash17 EXL3 2.8 bpw + drowzeys Keys L10-35 attn.wo_b graft (n_edited=104), pre-placed on NFS and registered as marker/DeepSeek-V4.1-Flash-1017-EXL3-2.8bpw-Abliterated
  • runtime: tf_family: jayleaton, TP=2, rank 1 then rank 0, TF_DSV41_* profile; weights NFS, Engram/prepared/AOT local
  • served model/port: deepseek-v4.1-flash on 0.0.0.0:8000 (same as the previous deployment)
  • boot: loaded in 216.8s; /health ok; /v1/models ok; canary 17 * 23 -> 391; thinking + multi-turn recall ok
  • assets: per-rank Engram bins (2x48G), rope.bin (1,050,624 rows), engram-host.bin, 144 AOT cubins; 2x96G local prepared dirs

The runtime unit tests (tests/test_runtime_tensorfold.py) and native-rendezvous tests pass (60 passed); ruff/pyright clean for the changed files. The source-types CI failure remains the pre-existing base errors in benchmarking/run_state.py, core/coordination.py, schedulers/_occupancy_base.py and utils/command_flags.py (reproduced on clean develop-next); no errors are reported in the changed runtime files.

@Marker689
Marker689 marked this pull request as draft October 30, 2026 20:15
Marker689 and others added 3 commits November 10, 2026 19:06
The current Jayleaton pin installs tf-dsv41 (not tf-dsv41-m1) and its rank-1
entry point is 'tf-dsv41 follow PACK ASSETS'. Point the jayleaton family at the
new binary and update the version probe/test. Verified by rebuilding the latest
pin on the Spark and serving DeepSeek-V4.1 through sparkrun.
Drop tf_family, the dsv41 prepared-bundle path, and the Jayleaton engine
family. TensorFold is now one upstream runtime: solo, NFS/pre-placed
checkpoints, and native TP via the engine's own --tp/--rank/--master
flags. Add the runtime.tensorfold feature gate and rewrite the tests/docs
around the upstream launch contract.
@Marker689 Marker689 changed the title feat(tensorfold): TensorFold runtime with NFS + TP2/TP4 and experimental DeepSeek-V4.1 lane feat(tensorfold): upstream TensorFold runtime with NFS and native TP Nov 23, 2026
@Marker689

Copy link
Copy Markdown
Contributor Author

Upstream-only refactor is ready for review.

What changed:

  • removed tf_family, the dsv41 prepared-bundle path, and the Jayleaton engine family;
  • one upstream runtime: solo, NFS/pre-placed checkpoints, and native TP via tensorfold-native --tp/--rank/--master/--master-port;
  • added the runtime.tensorfold feature gate;
  • rewrote tests and docs/TENSORFOLD.md around the upstream launch contract.

Validation:

  • 584 targeted tests passed (test_runtime_tensorfold, test_features, test_platforms, test_launch_env, test_recipe, test_recipe_validation);
  • ruff check / ruff format --check clean;
  • dry-run solo and TP2 on two DGX Sparks render the expected commands.

CI:

  • portable daemon, npm plugin, wheel composition — pass;
  • Test sparkrun had one failure from stale generated assistant SKILL.md references inherited from the base merge; fixed in e733bca;
  • source-types is still red on pre-existing base type debt in api/_exec.py, benchmarking/run_state.py, core/coordination.py, plugins/connect/cli.py, schedulers/_occupancy_base.py, utils/command_flags.py. There are no TensorFold diagnostics in that failure.

@Marker689
Marker689 marked this pull request as ready for review November 24, 2026 06:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants