aiden4x-launch.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. # Aiden production-1.6 launch wrapper for sm121 (per-rank Engram row ranges).
  3. #
  4. # The model's two Engram tables (layers 1 and 14) hold a different number of
  5. # rows each (384,006,168 / 384,016,682 for this snapshot), and the overlay
  6. # refuses to start unless the ranks' ranges tile [0, N) exactly per layer.
  7. # A full snapshot has no manifest, so the ranges come from SPARK_ENGRAM_ROWS;
  8. # a full range on every rank would double-count row contributions in the
  9. # reduce, so each rank gets its own contiguous slice. The per-layer row count
  10. # is read from the checkpoint's safetensors headers at launch (the table is
  11. # 384M rows of fp8 e4m3 + scale, so the per-layer N is not in config.json).
  12. set -e
  13. DIR="$(dirname "$(readlink -f "$0" 2>/dev/null || echo /)")/models--deepseek-ai--DeepSeek-V4.1-Flash/snapshots"
  14. SNAP="$(ls -d /root/.cache/huggingface/hub/models--deepseek-ai--DeepSeek-V4.1-Flash/snapshots/* | head -1)"
  15. R="${NODE_RANK:-0}"
  16. export SPARK_ENGRAM_ROWS="$(python3 - "$SNAP" "$R" <<'PY'
  17. import json, struct, sys
  18. snap, rank = sys.argv[1], int(sys.argv[2])
  19. def rows(path, key):
  20. with open(path, "rb") as f:
  21. n = struct.unpack("<Q", f.read(8))[0]
  22. h = json.loads(f.read(n))
  23. return h[key]["shape"][0]
  24. n1 = rows(snap + "/model-00047-of-00048.safetensors", "layers.1.engram.embed.weight")
  25. n14 = rows(snap + "/model-00048-of-00048.safetensors", "layers.14.engram.embed.weight")
  26. def tile(n, r, parts=4):
  27. base, rem = divmod(n, parts)
  28. sizes = [base + (1 if i < rem else 0) for i in range(parts)]
  29. lo = sum(sizes[:r])
  30. return lo, lo + sizes[r]
  31. lo1, hi1 = tile(n1, rank)
  32. lo14, hi14 = tile(n14, rank)
  33. print(f"1:{lo1}:{hi1},14:{lo14}:{hi14}")
  34. PY
  35. )"
  36. # the b12x RoCE runtime takes the same GID index the launcher resolved for NCCL
  37. [ -n "${NCCL_IB_GID_INDEX:-}" ] && export B12X_ROCE_GID_INDEX="$NCCL_IB_GID_INDEX"
  38. exec python3 -m sglang.launch_server "$@"