Skip to content

feat(memory): AllocationSpec + ScopeKind replace the never-consumed StorageSpec (SKEEP-003 P0, S0.3) - #1053

Merged
michalharakal merged 1 commit into
feature/1008-format-and-encodingfrom
feature/1009-allocation-spec
Aug 22, 2026
Merged

michalharakal merged 1 commit into
feature/1008-format-and-encodingfrom
feature/1009-allocation-spec

Conversation

@michalharakal

Copy link
Copy Markdown
Contributor

Summary

SKEEP-003 slice S0.3 (milestone M0 #1001): AllocationSpec replaces the never-consumed StorageSpec ("StorageSpec becomes the allocation spec" — SKEEP-003 prerequisite).

  • sk.ainet.lang.memory.AllocationSpec(format: Format, elementCount, domain = HOST_HEAP, scope: ScopeKind = AMBIENT, mutable = true, alignment = 64) with bytes / bytesOrNull (from the encoding), AllocationSpec.of(format, shape, …), validation (count ≥ 0, power-of-two alignment). Pure description; it is the input of the M0 MemoryPlan line items and, from M1, of Storage.allocate(spec, scope).
  • enum ScopeKind { MODEL, FORWARD, AMBIENT } — the lifetime classes of SKEEP-003 §4.5, declared now so plans/specs can name a lifetime; M1's Scope will expose kind: ScopeKind (no rename later).
  • StorageSpec and its companion factories are @Deprecated(ReplaceWith AllocationSpec) (zero consumers outside its own file and the S0.1 bridge test, which keeps exercising it deliberately — git grep StorageSpec); StorageSpec.toAllocationSpec(elementCount) is the migration path (Format(dtype, encoding), placement domain, MODEL for persistent placements else AMBIENT, mutable only when owned). Removed at the next major.
  • AllocationSpecTest (bytes per encoding incl. Q4_K/Q8_0/TurboQuant, defaults, validation, StorageSpec conversion, ScopeKind).
  • BCV: lang-core jvm dump regenerated (additions only + deprecation annotations).

Stacked on #1051 (S0.4 — Format); retarget to develop after it merges.

Test plan

Full local gate (scripts/pr-gate.sh, JDK 25) on the stacked tree; results in the first comment.

Closes #1009

🤖 Generated with Claude Code

…torageSpec (SKEEP-003 P0)

Milestone M0 (#1001), SKEEP-003 prerequisite "StorageSpec becomes the
allocation spec".

- sk.ainet.lang.memory.AllocationSpec(format, elementCount, domain =
  HOST_HEAP, scope = AMBIENT, mutable = true, alignment = 64): bytes /
  bytesOrNull from the encoding, AllocationSpec.of(format, shape, ...),
  validation (count >= 0, power-of-two alignment). The input of the M0
  MemoryPlan line items and, from M1, of Storage.allocate(spec, scope).
- enum ScopeKind { MODEL, FORWARD, AMBIENT } — the lifetime classes of
  SKEEP-003 §4.5, declared now; M1's Scope exposes kind: ScopeKind.
- StorageSpec and its companion factories @deprecated(ReplaceWith
  AllocationSpec); zero consumers outside its own file and the S0.1 bridge
  test (kept on purpose, suppressed). StorageSpec.toAllocationSpec(count)
  is the migration path. Removed at the next major.
- AllocationSpecTest; BCV lang-core jvm dump regenerated (additions +
  deprecation annotations).

Closes #1009

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@michalharakal

Copy link
Copy Markdown
Contributor Author

Local gate scripts/pr-gate.sh (JDK 25) on aec4a33 (stacked on #1051):

=== pr-gate: JVM tests ===                                      BUILD SUCCESSFUL in 6m 25s
=== pr-gate: apiCheck ===                                       BUILD SUCCESSFUL in 1m 46s
=== pr-gate: verifyNpmPins jsTest wasmJsTest wasmWasiTest ===   BUILD SUCCESSFUL in 2m 42s
=== pr-gate: linuxX64Test ===                                   BUILD SUCCESSFUL in 1m 29s
=== pr-gate: assemble ===                                       BUILD SUCCESSFUL in 2m 8s
=== pr-gate: :skainet-test:skainet-test-java:test ===           BUILD SUCCESSFUL in 21s
pr-gate: all legs passed.

Targeted: lang-core sk.ainet.lang.memory.* + sk.ainet.lang.tensor.storage.* 185/185.

@michalharakal
michalharakal requested a review from aharakal August 22, 2026 20:16
@michalharakal
michalharakal merged commit c802d2e into feature/1008-format-and-encoding Aug 22, 2026
2 checks passed
@michalharakal
michalharakal deleted the feature/1009-allocation-spec branch August 22, 2026 20:16
michalharakal added a commit that referenced this pull request Aug 22, 2026
…boQuant), forward slab, headroom, budget fit, suggestions (SKEEP-003 P1)

Milestone M0 (#1001), PRD M0-F1..F3 / M0-A4: "will this model fit on this
device at this context length?" answered from shapes and encodings only —
no tensor bytes are read.

- sk.ainet.lang.memory.plan: PlanTensor (name, TensorId?, Format, count,
  bytes; allocation = AllocationSpec mapped/MODEL/read-only), ModelGeometry,
  KvCacheMode (BF16, TURBOQUANT_4 via TensorEncoding.TurboQuantPolar),
  PlanInput (model, weights, geometry, ctx, prefill chunk 256, kv mode;
  unmappedWeights listed, never dropped), Budget (explicit or available −
  reserve: 700 MB Android/JVM, 300 MB native — decision #11), MemoryPlan
  (weights resident · kv @ ctx with the alternate mode · forward slab ·
  heap headroom · total · fits · ≥ 2 suggestions with savings: --kv
  turboquant, --ctx N/2, smaller model; render() = the PRD §4.3 table),
  MemoryPlans.plan(input, budget) with the documented estimates.
- io-gguf: StreamingGGUFReader.planInput(ctx, prefillChunk, kvMode,
  nameMap) — header only (tensor table + <arch>.block_count /
  embedding_length / attention.head_count(_kv) / key_length / value_length /
  feed_forward_length / vocab_size / context_length); ggufGeometry();
  ggufFormat(type, nBytes).
- Tests: MemoryPlanTest (Llama-3.2-1B-like geometry: KV bf16 @2048 = 64 MiB,
  TurboQuant ≈ ¼, forward slab scaling, totals/residency, does-not-fit
  suggestions, TurboQuant mode + available-memory budget, no geometry,
  unmapped, byte formatting); GgufMemoryPlanTest (synthetic header-only
  plan, format mapping, fixture-gated Qwen2.5-0.5B real header).
- BCV: lang-core jvm dump regenerated (additions only).

Includes the AllocationSpec commit of #1053 (cherry-picked: the plan's
line items are AllocationSpecs); that commit drops out on rebase once

Closes #1012

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant