T-004 — Julia project in training/ with the generic model-file export

Status: done · Area: julia · Depends on: —

Read for that: Model pipeline (the hand-off, row- vs column-major), ADR-0003, ADR-0007 (sources and licence in every manifest), Toolchain (JULIA_PROJECT=@.).

What:

  1. training/Project.toml + Manifest.toml (committed) for a package InstrumentsTraining (training/src/InstrumentsTraining.jl), Julia ≥ 1.10 compatible.
  2. A generic model-file writer: write_model(dir; tensors::Dict{String,<:AbstractArray}, manifest::Dict, golden=nothing) writing model.safetensors, manifest.toml (TOML stdlib), optional golden.safetensors, plus LICENSE/ATTRIBUTION.md from the manifest’s license and sources (refuse to write without them). Use SafeTensors.jl if it is registered and can write; otherwise write the format by hand (8-byte little-endian header length, JSON header with dtype, shape, data_offsets, then raw little-endian bytes) — about 30 lines.
  3. Layout rule: tensors are written row-major (the bytes of permutedims(A, ndims(A):-1:1)) with the Julia shape in the header — see Model pipeline for why the shape is not reversed. A reader read_model(dir) that inverts this, for round-trip tests.
  4. Tests (training/test/runtests.jl): round trip of Float32, UInt8, UInt16 arrays of 1–4 dimensions; a non-square matrix whose bytes are checked by hand against row-major order; manifest without licence is refused.
  5. A short training/README.md: how to run tests (julia --project=training -e 'using Pkg; Pkg.test()').

Done when: the tests pass in the dev shell; the Manifest is committed; Model pipeline names the chosen writer.

Out of scope: the piano-specific format (T-015), data downloads (T-014), any training.

Outcome

  • training/ holds the package InstrumentsTraining (Julia ≥ 1.13 since Dec 2026, raised from 1.10 because later code uses Threads.@threads :greedy (≥ 1.11) and the manifest is resolved with 1.13.4, issue #11; Manifest.toml committed). Deps: SafeTensors.jl 1.3 (registered, writes), TOML stdlib.
  • write_model / read_model in training/src/InstrumentsTraining.jl; the manifest gets a generated [tensors] table (dtype, shape per tensor). Sources are tables with name and license (optional author, url, attribution).
  • Correction to the task text: it said “row-major with the Julia shape reversed (permutedims)“. Doing both garbles non-square tensors; the rule now is row-major bytes with the Julia shape (what SafeTensors.jl does), recorded in Model pipeline.
  • 85 tests pass (julia --project=training -e 'using Pkg; Pkg.test()').