Skip to content
Merged
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
17 changes: 13 additions & 4 deletions src/inferrsi/knowledge/atomic_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
from tempfile import TemporaryDirectory

from .atomic_composition import AtomPin, applies, select_routes
from .atomic_generation import FORMAT, PUBLIC_TASKS, SEAL, InstalledGeneration, digest, owned_path
from .atomic_generation import (
FORMAT,
PUBLIC_TASKS,
SEAL,
InstalledGeneration,
digest,
filesystem_root,
owned_path,
)
from .atomic_json import matches_span, member_spans
from .atomic_reader import atom_material, permits_operations
from .atomic_skill_directory import directory_content, export_directory_skill, skill_spans
Expand Down Expand Up @@ -378,13 +386,14 @@ def _prepare(source: Path, permits: Callable[[AtomPin, str], bool], roots: Mappi
def build_generation(source: Path, target: Path, *, permits: Callable[[AtomPin, str], bool],
source_roots: Mapping[str, Path] | None = None) -> str:
"""Stage and verify a complete new generation; repeat installs must have identical bytes."""
source = Path(source).resolve(strict=True)
target = Path(target).absolute()
source = filesystem_root(source).resolve(strict=True)
target = filesystem_root(target)
if target.is_symlink() or target.resolve() != target:
raise ValueError("Generation target must be a physical directory")
if target.is_relative_to(source) or source.is_relative_to(target):
raise ValueError("Separate the authored and installed generation roots")
roots = {key: Path(path).resolve(strict=True) for key, path in (source_roots or {}).items()}
roots = {key: filesystem_root(path).resolve(strict=True)
for key, path in (source_roots or {}).items()}
generation, files = _prepare(source, permits, roots)
if target.exists():
return InstalledGeneration(target, expected=generation).generation
Expand Down
16 changes: 15 additions & 1 deletion src/inferrsi/knowledge/atomic_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import hashlib
import json
import os
from pathlib import Path, PurePosixPath

from .atomic_composition import AtomPin
Expand All @@ -21,6 +22,19 @@ def digest(data: bytes) -> str:
return hashlib.sha256(data).hexdigest()


def filesystem_root(root: Path) -> Path:
"""Use absolute filesystem paths that accommodate deep installed resources on Windows."""
absolute = Path(root).absolute()
if os.name != "nt":
return absolute
name = str(absolute)
if name.startswith(("\\\\?\\", "\\\\.\\")):
return absolute
if name.startswith("\\\\"):
return Path("\\\\?\\UNC\\" + name[2:])
return Path("\\\\?\\" + name)


def directory_skill_path(metadata: dict, name: str) -> str:
entry = PurePosixPath(safe_path(metadata["entrypoint"]))
relative = PurePosixPath(safe_path(name)).relative_to(entry.parent)
Expand Down Expand Up @@ -55,7 +69,7 @@ class InstalledGeneration:
"""An internally consistent snapshot, optionally pinned by its caller's release record."""

def __init__(self, root: Path, *, expected: str | None = None):
root = Path(root).resolve(strict=True)
root = filesystem_root(root).resolve(strict=True)
seal = json.loads(owned_path(root, SEAL).read_bytes())
generation = seal.pop("generation")
if seal.get("format") != FORMAT or generation != "sha256:" + digest(_json(seal)):
Expand Down
177 changes: 177 additions & 0 deletions src/inferrsi/knowledge/atoms/playbooks/training-resource-budget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
---
name: training-resource-budget
description: 'Choose training offload and resource-budget changes using pinned DeepSpeed configuration, attributed expert diagnosis and a historical MindSpeed case. Balance accelerator capacity, CPU work, pinned RAM and local storage; keep host/device transfer exposure distinct from collective network bottlenecks.

'
metadata:
inferrsi: |
{
"tags": [
"training",
"offload",
"resource-budget",
"memory",
"cpu",
"numa"
],
"status": "candidate",
"profile": "local-skill-v1",
"schema_version": 1,
"kind": "skill",
"origin": [
"external"
],
"empirical_validation": "not_run",
"applicability": {
"scope": "Choosing training offload and resource-budget changes from pinned DeepSpeed configuration, attributed expert diagnosis and a historical MindSpeed case, balancing accelerator capacity, CPU work, pinned RAM and local storage while keeping host/device transfer exposure distinct from collective network bottlenecks",
"prerequisites": "The source boundaries are read; garbage-collection or affinity changes, privileged memlock changes and delayed parameter updates each need separate approval, and the skill authorizes no newest-wheel installation, scheduler-priority change, benchmark or failure injection; historical MindSpeed reuse requires compatible allocator symbols, tracked swappable storage, sufficient host capacity and verified device/NUMA/CPU mapping, not merely the presence of npu-smi and lspci",
"input_contract": "State attributed to parameters, optimizer state, gradients or activations with its current memory tier, lifetime and next consumer; whether the failure is allocation capacity or throughput; a per-host budget for input buffers, checkpoint snapshots, offloaded state, OS cache and CPU workers with the actual ranks sharing the host; the host/device link recorded apart from collective traffic; the exact source version and enabled execution mode",
"produced_artifact": "A candidate decision record per proposal: the observed limiting interval and owning state or resource, source version and execution mode, capacity released and resources consumed with units and uncertainty, overlap readiness and mutation boundaries with expected contention, and the fixed-workload step and correctness evidence required for later validation",
"failure_modes": [
"A change that lets the model fit is presented as a speedup, although it can slow each step",
"A tensor copied to CPU is taken as an InfiniBand/RoCE bottleneck, or CPU/NVMe offload is counted as network evidence",
"Parameter max_in_cpu is read as a byte or total-host-memory cap instead of an element count",
"NVMe optimizer placement is assumed to remove CPU optimizer demand",
"The parameter buffer-pool count is transplanted to the optimizer, or all optimizers are assumed to hold identical states",
"Configuration presence or schema documentation is taken as evidence that a knob or overlap actually ran",
"Ordinary overlap is taken as permission for delayed, stale parameter updates"
],
"refusal_point": "Claims no hardware validation, measured gain or current NPU compatibility, keeps source support and extracted coverage separate from measured improvement, and does not reuse the MindSpeed headline gain; historical source observations do not establish current-stack compatibility, whole-model correctness or measured benefit"
},
"recommendations": [
"Attribute the state and separate a capacity failure from a throughput bottleneck before choosing an offload surface.",
"Verify the consumer of buffer_size before calculating bytes or tuning it, and measure the executing path before claiming a knob ran.",
"Compare the whole step's critical path, not host capacity alone.",
"Use plan-activation-residency, choose-parallel-training-plan and assess-split-backward-schedule for live-range, parallel-plan and backward-ordering questions."
],
"limitations": [
"Source-derived candidate; no local efficacy validation.",
"Original typed source inventory is not normalized; retain source identities and limits in the procedure/readsets."
],
"provenance_readsets": [
"references/mindspeed-historical.md",
"references/mindspeed-source-readset.md",
"references/papers-20261015/cases/paper-grounded-cases.md",
"references/papers-20261015/INTEGRATION_NOTES.md",
"references/papers-20261015/knowledge/offload-delta.md",
"references/papers-20261015/notes/training-memory-scheduling.md",
"references/papers-20261015/references/source-readset.md",
"references/sources.md",
"references/stas-decision-notes.md"
],
"consumption_mode": "packaged"
}
---

# Training Cross-Resource Budget Decisions

Status: candidate. No hardware validation, measured gain or current NPU
compatibility claim. [Source boundaries](references/sources.md) identify exactly
what was inspected; no checkpoint implementations are mined by this skill.

## Start with ownership and one bottleneck

Attribute state to parameters, optimizer state, gradients or activations;
record its current memory tier, lifetime and next consumer. Distinguish an
allocation-capacity failure from a throughput bottleneck. A change that enables
a model to fit can still slow each training step.

Keep a per-host budget for input buffers, checkpoint snapshots, offloaded state,
OS cache and CPU workers. Count the actual ranks sharing that host. Record the
host/device link separately from inter-device/inter-node collective traffic.
A tensor copied to CPU does not establish an InfiniBand/RoCE bottleneck.

SearchSpace: Accelerator and RAM / Host → Diagnose, Configure, Optimize;
SSD / Storage → Configure, Optimize (DeepSpeed NVMe state); OS / System →
Diagnose, Configure (CPU share/locality/garbage-collection attribution).
Network → Observe, Diagnose, Verify only through the scoped expert collective
measurement principles, not through CPU/NVMe offload itself.

## CR1 — DeepSpeed offload decision surfaces

| Surface | Inspected contract | Decision consequence |
|---|---|---|
| Parameter offload `device=cpu/nvme` | ZeRO stage 3 only | Establish parameter state residency before spending buffers or CPU RAM |
| Optimizer offload `device=cpu/nvme` | Stages 1/2/3; computation remains on CPU for either target | NVMe placement does not remove CPU optimizer demand |
| Parameter `max_in_cpu` | Parameter **elements** retained in CPU when NVMe is enabled | Convert using actual dtype/storage; this is not a byte or total-host-memory cap |
| Parameter `buffer_count`, `buffer_size` | NVMe buffer-pool count and size | The approved config/doc excerpt does not explicitly define `buffer_size` units; verify its consumer before calculating bytes or tuning it |
| Optimizer `buffer_count` | At least the number of optimizer states per parameter; source illustrates Adam's four | Do not transplant the parameter-pool count or assume all optimizers have identical states |
| `pin_memory` | Defaults True at this pin; page-locked CPU memory supports async transfers/overlap | Budget resident memory and existing memlock allowance; no privileged limit change authorized |
| `pipeline_read` / `pipeline_write` | Next-tile read / previous-tile write overlap with current optimizer tile compute | Applicable to tiled ZeRO-Infinity execution; configuration presence does not prove actual overlap |
| `ratio` | Fraction in [0,1] for CPU Adam, stage 3 only | Not a general placement ratio for parameters or activations |
| `super_offload`, `cpuadam_cores_perc` | Superchip CPU offload; core fraction valid with stage 3 plus `super_offload=True` | Not a universal CPU throttle or generic recommendation on every host |
| `fast_init` | NVMe optimizer initialization | Startup cost and steady-state step time have different denominators |

A justified overlap proposal needs evidence that compute can hide the relevant
read/write segment, sufficient CPU/pinned-RAM/storage capacity and unchanged
state semantics. Measure the executing path before claiming a knob ran. The
config schema and live documentation are not dispatch/performance evidence.

## CR6 — Attributed expert diagnosis

Read [the scoped Stas Bekman note](references/stas-decision-notes.md) for
MFU/HFU denominator checks, transient-versus-sustained compute, collective
measurement semantics, NUMA locality and garbage-collection stragglers. This
note explicitly retains CC BY-SA 4.0 attribution and share-alike conditions;
no upstream runbook commands or automatic-update instructions are adopted.

Use these principles to form a hypothesis, not to import a platform tuning
constant. Garbage-collection or affinity changes require separate task
approval and memory/correctness evidence; this extraction changes neither.

## CR5 — Historical NPU case

[MindSpeed adaptive memory](references/mindspeed-historical.md) illustrates
spending spare NPU memory versus CPU swapping/recomputation. Preserve the
`core_r0.8.0` exclusions and distinguish its validation assertions from the
separate feature-selection guard. The [pinned source readset](references/mindspeed-source-readset.md)
recovers the historical full revision and license, allocator-to-swap callback
and 910A/910B affinity branch. Check compatible allocator symbols, tracked
swappable storage, host capacity and actual device/NUMA/CPU mapping before
separately authorized reuse; `npu-smi` and `lspci` presence alone is insufficient.
One reported comparison changes layer count; its headline gain is not reused.
Current-stack compatibility, whole-model correctness and measured benefit remain
unverified. These historical source observations do not establish current Ascend
support.

## Paper-derived training decisions

[ZeRO-Offload ownership and semantics](references/papers-20261015/knowledge/offload-delta.md)
extends the configuration evidence above with CPU optimizer state/compute
colocation, shard ownership and tiled update/return costs. Compare the whole
step's critical path, not host capacity alone. Delayed parameter updates change
training semantics and require explicit approval and quality evidence; ordinary
overlap does not imply permission for staleness.

Use [activation residency](../plan-activation-residency/SKILL.md) for live-range,
address-packing and rematerialization choices;
[parallel training plans](../choose-parallel-training-plan/SKILL.md) for stage,
mesh and sharding choices; and
[split backward](../assess-split-backward-schedule/SKILL.md) for input-gradient
versus weight-gradient ordering and optimizer post-validation. These are distinct
contracts: activation checkpoints are not restart snapshots, Alpa's conditional
plans are not unrestricted global optima, and Zero Bubble's rollback preserves
semantics rather than authorizing ZeRO-Offload's stale updates.

The [mechanism comparison](references/papers-20261015/notes/training-memory-scheduling.md),
[readset](references/papers-20261015/references/source-readset.md) and
[hypothetical cases](references/papers-20261015/cases/paper-grounded-cases.md)
retain resource costs, counter-signals and unresolved table discrepancies.
Paper versions are separate from the DeepSpeed implementation pin. No current
runtime, NPU support or measured application outcome follows from these notes.

## Candidate decision record

For each proposal, retain:

1. The observed limiting interval and owning state/resource.
2. The exact source version and enabled execution mode.
3. Capacity released and resources consumed, with units and uncertainty.
4. Overlap readiness/mutation boundaries and expected contention with input,
checkpoint and network activity.
5. Fixed-workload training step/throughput and correctness evidence required
for later validation; initialization and auxiliary metrics separately.

No broad source expansion, newest-wheel installation, scheduler-priority
changes, benchmarks or failure injection follow from this skill. Source
support and extracted coverage remain separate from measured improvement.
Loading
Loading