Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion docs/GLM53_DFLASH7_PYTHON_OVERLAY_SPARKCACHE_TP4_QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ store/restart/restore, or concurrency qualification.
| B12X | `b1d541f9e71a35f030d45fae437630fff7507c2a`, tree `c69cdec1c59a08e8e0e549f930fa8abcfb5134ae` |
| SparkCache reconstructed-page placement | `5d571018de5b63a9a90e5c11e6d6e86bbff4a957`, tree `e864ed9ad64f771188fdb59aa9738e348134d636` |
| DFlash draft-loader separation | Patch SHA-256 `39b567013ee7aed79f63200ed460129587933dc77fb430decdf19f78178de279`, postimage SHA-256 `98acbae2b3bb4482d83f9637c163ce7c92707ccdf6561b7e431f23337f151cf4` |
| Unused DeepEP removal | Distribution `deep_ep==2.0.0+local`, removal receipt SHA-256 `65514f44829e7d176b0b2cacc9559ed22724e525b7041a8bcd4d2e02d1f372e3` |
| Target | `local-inference-lab/GLM-5.3-Flash-NVFP4@520de24eabf507659eaef7c70f14fd584527facc` |
| External draft | `incoai/GLM-5.3-Flash-DFlash2@dc77ff1c99eeb2df044ee3d4f0094eb033fee410`, BF16 weights SHA-256 `b33c03475ba7322cf398828f2d8d1be376df30dc05c6b40c28c8ea8da23e410b` |

Expand All @@ -35,7 +36,19 @@ bash runtime/glm53-flash-dflash7-python-overlay/build-image.sh
The builder verifies the public da4 image, the 31-file Python overlay, retained
native ELFs and dispatch operators, B12X, SparkCache clean source, the CUDA
placement library, four exact vLLM patches, and the eleven-file lease contract.
It does not push the image.
The base-image inspection must identify exactly one installed distribution,
`deep_ep==2.0.0+local`, as the owner of the `deep_ep` module. The derived image
uninstalls that exact distribution and verifies that `deep_ep` is absent. The
profiles use B12X kernels and PYNCCL collectives, so DeepEP is not a serving
dependency. The builder does not push the image.

Both profiles leave Torch thread selection to vLLM, select language-model-only
serving, and disable the unsupported symmetric-memory and FlashInfer all-reduce
candidates. PYNCCL remains bound to `/opt/sparkring/nccl/libnccl.so.2`, B12X
remains the attention, MoE, and linear backend, and the all-reduce RMS fusion is
disabled. ModelOpt experimental-quantization and FP8 KV accuracy warnings remain
visible because they describe real format and accuracy limitations; the profiles
do not suppress warnings.

## Choose the target loader

Expand Down
47 changes: 47 additions & 0 deletions runtime/glm53-flash-adaptive-mtp-python-overlay/verify_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ def expected_output_labels(pins: dict[str, Any]) -> dict[str, str]:
labels["org.sparkring.vllm.dflash-draft-loader-postimage-sha256"] = patch[
"postimage_sha256"
]
cleanup = pins.get("runtime_cleanup", {}).get("deep_ep")
if cleanup is not None:
labels["org.sparkring.runtime.removed-deep-ep-distribution"] = (
f"{cleanup['distribution']}=={cleanup['version']}"
)
labels["org.sparkring.runtime.deep-ep-removal-receipt-sha256"] = cleanup[
"receipt_sha256"
]
return labels


Expand Down Expand Up @@ -170,6 +178,8 @@ def runtime_contract_probe(engine: str, image: str) -> dict[str, Any]:
def artifact_probe(engine: str, image: str) -> dict[str, Any]:
program = r"""
import hashlib
import importlib.metadata
import importlib.util
import json
import pathlib

Expand All @@ -178,13 +188,24 @@ def artifact_probe(engine: str, image: str) -> dict[str, Any]:
contract = pathlib.Path('/opt/sparkcache-src/sparkcache/runtime_patches/vllm-kv-block-lease-contract-glm53-b12x-kda-adaptive-mtp.json')
sparkcache_source_receipt = root / 'sparkcache-source-tree.sha256'
wheel_receipt = (root / 'b12x-wheel.sha256').read_text(encoding='utf-8').split()
deep_ep_receipt = root / 'deep-ep-removal-receipt.json'
try:
importlib.metadata.distribution('deep_ep')
deep_ep_distribution_present = True
except importlib.metadata.PackageNotFoundError:
deep_ep_distribution_present = False
print(json.dumps({
'b12x_wheel_sha256': wheel_receipt[0],
'b12x_wheel': pathlib.Path(wheel_receipt[1]).name,
'sparkcache_cuda_placement_sha256': hashlib.sha256(cuda_placement.read_bytes()).hexdigest(),
'sparkcache_contract_sha256': hashlib.sha256(contract.read_bytes()).hexdigest(),
'sparkcache_source_tree_sha256': sparkcache_source_receipt.read_text(encoding='utf-8').strip(),
'source_receipt_sha256': hashlib.sha256((root / 'source-receipt.json').read_bytes()).hexdigest(),
'deep_ep_receipt': json.loads(deep_ep_receipt.read_text(encoding='utf-8')) if deep_ep_receipt.is_file() else None,
'deep_ep_receipt_sha256': hashlib.sha256(deep_ep_receipt.read_bytes()).hexdigest() if deep_ep_receipt.is_file() else None,
'deep_ep_module_present': importlib.util.find_spec('deep_ep') is not None,
'deep_ep_owners': importlib.metadata.packages_distributions().get('deep_ep') or [],
'deep_ep_distribution_present': deep_ep_distribution_present,
}, sort_keys=True))
""".strip()
output = run(
Expand All @@ -205,6 +226,31 @@ def artifact_probe(engine: str, image: str) -> dict[str, Any]:
raise VerifyError(f"artifact probe did not return JSON: {output!r}") from exc


def verify_runtime_cleanup(artifacts: dict[str, Any], pins: dict[str, Any]) -> None:
cleanup = pins.get("runtime_cleanup", {}).get("deep_ep")
if cleanup is None:
return
expected_removal_receipt = {
"schema": "sparkring-python-distribution-removal/v1",
"status": "implemented",
"module": cleanup["module"],
"distribution": cleanup["distribution"],
"version": cleanup["version"],
"postcondition": "module-absent",
"reason": cleanup["reason"],
}
if artifacts.get("deep_ep_receipt") != expected_removal_receipt:
raise VerifyError("installed DeepEP removal receipt differs from its pin")
if artifacts.get("deep_ep_receipt_sha256") != cleanup["receipt_sha256"]:
raise VerifyError("installed DeepEP removal receipt checksum differs")
if artifacts.get("deep_ep_module_present") is not False:
raise VerifyError("deep_ep remains importable in the composed image")
if artifacts.get("deep_ep_owners") != []:
raise VerifyError("deep_ep still has installed distribution owners")
if artifacts.get("deep_ep_distribution_present") is not False:
raise VerifyError("the attested deep_ep distribution remains installed")


def verify_image(engine: str, image: str, pins_path: Path = PINS) -> dict[str, Any]:
pins = load_pins(pins_path)
inspection = inspect_image(engine, image)
Expand All @@ -228,6 +274,7 @@ def verify_image(engine: str, image: str, pins_path: Path = PINS) -> dict[str, A
"source_tree_sha256"
]:
raise VerifyError("clean SparkCache source receipt differs from its pin")
verify_runtime_cleanup(artifacts, pins)
for name in (
"b12x_wheel_sha256",
"sparkcache_cuda_placement_sha256",
Expand Down
15 changes: 13 additions & 2 deletions runtime/glm53-flash-dflash7-python-overlay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ bash runtime/glm53-flash-dflash7-python-overlay/build-image.sh

The script does not push the image. Its receipt verifies mixed vLLM
provenance, B12X, target loader dependencies, NCCL, SparkCache CUDA placement,
the clean SparkCache source receipt, and the vLLM lease contract. DFlash model
files remain operator-mounted and are verified by the runtime profile.
the clean SparkCache source receipt, the vLLM lease contract, and removal of the
unused `deep_ep==2.0.0+local` distribution. The removal receipt has SHA-256
`65514f44829e7d176b0b2cacc9559ed22724e525b7041a8bcd4d2e02d1f372e3`.
The build accepts removal only when `deep_ep` has that one distribution owner,
then verifies that the module is absent. DFlash model files remain
operator-mounted and are verified by the runtime profile.

Two executable profiles use external DFlash at depth seven and TP4, FP8 target
KV, 256-token vLLM blocks, 32 sequences, and SparkCache page-tail copy-on-write
Expand All @@ -43,3 +47,10 @@ profile uses global fastsafetensors for the target and an exact
`draft_load_config` selecting safetensors for DFlash. The image applies and
verifies the draft-loader patch before installing SparkCache patches. See
`docs/GLM53_DFLASH7_PYTHON_OVERLAY_SPARKCACHE_TP4_QUICKSTART.md`.

Both profiles preserve B12X compute backends and the pinned PYNCCL/NCCL
library. They disable unsupported symmetric-memory and FlashInfer all-reduce
probes, disable the all-reduce RMS fusion, select language-model-only serving,
and leave Torch thread selection unset. ModelOpt and FP8 KV warnings remain
visible because they describe supported-runtime limitations rather than unused
optional backends.
2 changes: 2 additions & 0 deletions runtime/glm53-flash-dflash7-python-overlay/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ b12x_tree="$(read_pin b12x.tree)"
sparkcache_commit="$(read_pin sparkcache.commit)"
sparkcache_tree="$(read_pin sparkcache.tree)"
sparkcache_source_sha256="$(read_pin sparkcache.source_tree_sha256)"
deep_ep_removal_receipt_sha256="$(read_pin runtime_cleanup.deep_ep.receipt_sha256)"
sparkring_revision="$(git -C "${repo_root}" rev-parse HEAD)"

"${engine}" pull --platform linux/arm64 "${public_base}"
Expand Down Expand Up @@ -115,6 +116,7 @@ sparkcache_cuda_placement_sha256="$("${engine}" run --rm --entrypoint sha256sum
--build-arg "NATIVE_ELF_MANIFEST_SHA256=${native_elf_manifest_sha256}" \
--build-arg "NATIVE_DISPATCH_MANIFEST_SHA256=${native_dispatch_manifest_sha256}" \
--build-arg "SPARKCACHE_CUDA_PLACEMENT_SHA256=${sparkcache_cuda_placement_sha256}" \
--build-arg "DEEP_EP_REMOVAL_RECEIPT_SHA256=${deep_ep_removal_receipt_sha256}" \
--tag "${image}" \
"${context}"

Expand Down
9 changes: 9 additions & 0 deletions runtime/glm53-flash-dflash7-python-overlay/pins.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@
}
]
},
"runtime_cleanup": {
"deep_ep": {
"module": "deep_ep",
"distribution": "deep_ep",
"version": "2.0.0+local",
"receipt_sha256": "65514f44829e7d176b0b2cacc9559ed22724e525b7041a8bcd4d2e02d1f372e3",
"reason": "The four-rank DFlash7 profile uses B12X kernels and PYNCCL collectives. Removing unused DeepEP prevents its import probe from loading a second NCCL distribution."
}
},
"runtime_cache_roots": {
"VLLM_CACHE_ROOT": "/cache/jit/vllm/dflash7-py-0b67266-native-da4d7be",
"B12X_CUTE_COMPILE_CACHE_DIR": "/cache/jit/b12x/b1d541f9/dflash7-cute",
Expand Down
64 changes: 64 additions & 0 deletions runtime/glm53-flash-dflash7-python-overlay/prepare_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
COMMON = ROOT / "runtime" / "glm53-flash-adaptive-mtp-python-overlay"
PINS = HERE / "pins.json"
RECEIPT_SCHEMA = "sparkring-glm53-public-python-overlay-context/v1"
DEEP_EP_RECEIPT = "deep-ep-removal-receipt.json"


class PrepareError(RuntimeError):
Expand Down Expand Up @@ -51,6 +52,8 @@ def _longpath_run(argv, *, cwd=None):

def _render_containerfile() -> str:
text = (COMMON / "Containerfile").read_text(encoding="utf-8")
pins = json.loads(PINS.read_text(encoding="utf-8"))
cleanup = pins["runtime_cleanup"]["deep_ep"]
replacements = {
"/cache/jit/vllm/py-0b67266-native-da4d7be": (
"/cache/jit/vllm/dflash7-py-0b67266-native-da4d7be"
Expand Down Expand Up @@ -79,6 +82,40 @@ def _render_containerfile() -> str:
if old not in text:
raise PrepareError(f"shared Containerfile omits required text: {old}")
text = text.replace(old, new)
argument_marker = "ARG SPARKCACHE_CUDA_PLACEMENT_SHA256\n"
if text.count(argument_marker) != 1:
raise PrepareError("shared Containerfile omits the CUDA placement argument")
text = text.replace(
argument_marker,
argument_marker + "ARG DEEP_EP_REMOVAL_RECEIPT_SHA256\n",
)
receipt_marker = (
"COPY receipt.json ${PYTHON_OVERLAY_ROOT}/source-receipt.json\n"
)
if text.count(receipt_marker) != 1:
raise PrepareError("shared Containerfile omits the source receipt copy")
cleanup_block = f"""{receipt_marker}COPY bundle/runtime/remove_distribution.py ${{PYTHON_OVERLAY_ROOT}}/remove_distribution.py
COPY bundle/runtime/{DEEP_EP_RECEIPT} ${{PYTHON_OVERLAY_ROOT}}/{DEEP_EP_RECEIPT}
RUN test \"$(sha256sum \"${{PYTHON_OVERLAY_ROOT}}/{DEEP_EP_RECEIPT}\" | cut -d' ' -f1)\" = \"${{DEEP_EP_REMOVAL_RECEIPT_SHA256}}\" \\
&& python3 \"${{PYTHON_OVERLAY_ROOT}}/remove_distribution.py\" \\
--receipt \"${{PYTHON_OVERLAY_ROOT}}/{DEEP_EP_RECEIPT}\" \\
&& python3 -c 'import importlib.util; assert importlib.util.find_spec("deep_ep") is None'
"""
text = text.replace(receipt_marker, cleanup_block)
label_marker = (
" org.sparkcache.deployment-profile="
'"glm53-flash-dflash7-python-overlay" \\\n'
)
if text.count(label_marker) != 1:
raise PrepareError("rendered Containerfile omits the DFlash7 profile label")
cleanup_labels = (
label_marker
+ " org.sparkring.runtime.removed-deep-ep-distribution="
+ f'"{cleanup["distribution"]}=={cleanup["version"]}" \\\n'
+ " org.sparkring.runtime.deep-ep-removal-receipt-sha256="
+ '"${DEEP_EP_REMOVAL_RECEIPT_SHA256}" \\\n'
)
text = text.replace(label_marker, cleanup_labels)
return text


Expand All @@ -99,11 +136,36 @@ def _render_verify_image() -> str:
return text


def _deep_ep_removal_receipt(pins: dict[str, Any]) -> dict[str, str]:
cleanup = pins["runtime_cleanup"]["deep_ep"]
return {
"schema": "sparkring-python-distribution-removal/v1",
"status": "implemented",
"module": cleanup["module"],
"distribution": cleanup["distribution"],
"version": cleanup["version"],
"postcondition": "module-absent",
"reason": cleanup["reason"],
}


def _replace_runtime_files(context: Path) -> None:
runtime = context / "bundle" / "runtime"
pins = json.loads(PINS.read_text(encoding="utf-8"))
shutil.copy2(PINS, runtime / "pins.json")
shutil.copy2(HERE / "build-image.sh", runtime / "build-image.sh")
shutil.copy2(HERE / "README.md", runtime / "README.md")
shutil.copy2(HERE / "remove_distribution.py", runtime / "remove_distribution.py")
removal_receipt = runtime / DEEP_EP_RECEIPT
removal_receipt.write_text(
json.dumps(_deep_ep_removal_receipt(pins), indent=2, sort_keys=True) + "\n",
encoding="utf-8",
newline="\n",
)
if common.sha256_file(removal_receipt) != pins["runtime_cleanup"]["deep_ep"][
"receipt_sha256"
]:
raise PrepareError("DeepEP removal receipt differs from its pin")
(runtime / "Containerfile").write_text(
_render_containerfile(), encoding="utf-8", newline="\n"
)
Expand All @@ -119,6 +181,8 @@ def _replace_runtime_files(context: Path) -> None:
"Containerfile",
"build-image.sh",
"README.md",
"remove_distribution.py",
DEEP_EP_RECEIPT,
):
relative = f"bundle/runtime/{name}"
receipt["files"][relative] = common.sha256_file(context / relative)
Expand Down
Loading
Loading