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:
training/Project.toml+Manifest.toml(committed) for a packageInstrumentsTraining(training/src/InstrumentsTraining.jl), Julia ≥ 1.10 compatible.- A generic model-file writer:
write_model(dir; tensors::Dict{String,<:AbstractArray}, manifest::Dict, golden=nothing)writingmodel.safetensors,manifest.toml(TOML stdlib), optionalgolden.safetensors, plusLICENSE/ATTRIBUTION.mdfrom the manifest’slicenseandsources(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 withdtype,shape,data_offsets, then raw little-endian bytes) — about 30 lines. - 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 readerread_model(dir)that inverts this, for round-trip tests. - Tests (
training/test/runtests.jl): round trip ofFloat32,UInt8,UInt16arrays of 1–4 dimensions; a non-square matrix whose bytes are checked by hand against row-major order; manifest without licence is refused. - 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 packageInstrumentsTraining(Julia ≥ 1.13 since Dec 2026, raised from 1.10 because later code usesThreads.@threads :greedy(≥ 1.11) and the manifest is resolved with 1.13.4, issue #11;Manifest.tomlcommitted). Deps: SafeTensors.jl 1.3 (registered, writes), TOML stdlib.write_model/read_modelintraining/src/InstrumentsTraining.jl; the manifest gets a generated[tensors]table (dtype, shape per tensor). Sources are tables withnameandlicense(optionalauthor,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()').