Skip to content

tensor-0.8.0

Choose a tag to compare

@sonic182 sonic182 released this 30 Nov 23:34
· 2 commits to main since this release
38de454
  • Breaking: tensor asks for Agentica 0.40.0 and keeps its modules in src/: pkg/tensor/tensor and pkg/tensor/trace are unchanged, an import of pkg/tensor/src/NAME becomes pkg/tensor/NAME (ml#302).
  • On XLA a program is compiled once for every device and runs on the device of its call (a portable PJRT program), so the NeuronCores of a process share their programs; a plugin that refuses a portable program, or AGENTICA_ML_XLA_PORTABLE=0, compiles one per device, as before (ml#508).
  • On a NeuronCore the prompt and decode phases add --internal-hlo2tensorizer-options=--modular-flow-mac-threshold=10, and every program is compiled for the scratchpad page of the runtime (NEURON_SCRATCHPAD_PAGE_SIZE); Tensor.xla_scratchpad(bytes) sets the page before the plugin opens, and Qwen3.open asks for one that holds a layer's KV cache of one sequence (ml#508). The programs in Neuron's compile cache compile once more under the new flags.
  • On a NeuronCore each compiled program gets the compiler flags of its phase: Trace.compile(specs, f, phase) takes Trace.Phase.Prompt, Decode or Any (the default). A prompt adds --model-type=transformer -O1 to NEURON_CC_FLAGS and a decode step --model-type=transformer -O2, as NxD Inference does; AGENTICA_ML_NEURON_PROMPT_FLAGS and AGENTICA_ML_NEURON_DECODE_FLAGS replace them. The flags are part of what a program is, so the same text with other flags compiles again (ml#490).
  • On XLA, a compiled function writes a set_rows into its cache in place when the cache is an input that nothing else reads and the result is an output, as ggml does: the run consumes the old cache tensor, even when it fails, and answers the new one. Any other cache is copied, as before (ml#491).
  • Backend.Xla serves every NeuronCore the process sees, Neuron(0), Neuron(1) and up (Tensor.xla_devices()); a compiled function runs on the core of its inputs, and to_device copies between cores; two cores have run with our CPU plugin standing in, not yet on an inf2 (ml#477).
  • On a NeuronCore, top_ids compiles (chlo.top_k), to_dtype from a float to an integer truncates, an index of scatter_add or set_rows outside the rows is the usual error, and half weights compute as F32 (ml#475). In the text of Trace.stablehlo those indices are clamped into the rows, so an index outside them writes the nearest row where XLA dropped it.
  • Breaking: Tensor.Device has a new variant, Neuron(Int), so an exhaustive case over it needs its arm (ml#241).
  • Backend.Xla runs on an AWS NeuronCore: AGENTICA_ML_NEURON_PLUGIN names Neuron's PJRT plugin, Tensor.xla_device() gives Neuron(0) then, and the site has a guide (ml#241).
  • On ggml a gather reads the rows of an F16 cache that a set_rows wrote, widened to F32: how a paged cache reads its pool (ml#92).
  • exp on Backend.Torch flushes a denormal result to 0 on purpose (an input below -87.33 in F32, -708.39 in F64; libtorch is 3 to 10 times slower on them), so a masked softmax and the gradient of gelu_erf run faster; every result of 1.18e-38 or more is kept. The finite checks of the torch ops are one aminmax reduction instead of a boolean temporary and a scan, so sigmoid and gelu_erf run in half the time (ml#407).
  • Dtype.BF16: ggml, libtorch and XLA keep checkpoint weights in 16-bit buffers. Tensor.from_file(..., dtype: BF16) preserves BF16 file values and rounds F32 or F16 sources to nearest even. Products with F32 activations widen BF16 weights at compute time, and embeddings can widen only the selected rows.
  • Backend.Xla holds F16 tensors: Tensor.from_file(..., dtype: F16), from_bytes and from_list make half weights in 16-bit buffers, and a compiled product or lookup widens them to F32 inside the program; Qwen3.open(dir, xla, F16) and the other weights: F16 models load on XLA (ml#386).
  • The StableHLO emitter builds every op with agc-ir, so Trace.stablehlo and the programs XLA compiles are in MLIR's generic form ("stablehlo.reduce"(...) ({...}) {dimensions = array<i64: 1>}), each reduction's, sort's and scatter's combiner an explicit region; only the module, its function and the gated-delta call stay text. The programs compute the same: the IREE goldens of train/ are unchanged (ml#417).
  • Tensor.adam_step on Backend.Torch is one native pass over the weight and its moments, where it was ten libtorch kernels per weight (ml#407).
  • The default build of the optional torch module, without libtorch, stops with one clear error (no libtorch found, and how to find it) instead of errors about pread and O_CLOEXEC (ml#379).
  • A traced run on Backend.Torch frees each node's tensor after its last reader, and the Adam step of a computing backend makes one statement at a time: a MiniLM step with every weight trained peaks at 1.4 GiB of resident memory (it was killed at 2.5 GB), and a Trace.eval of 16 sentences of 64 tokens no longer keeps 660 MB per call (ml#394).
  • Torch.memory reads the bytes of the live libtorch tensors and their peak, for the tests of what a run frees (ml#394).
  • Tensor.batch_matmul runs on Backend.Torch(Cpu), so the gradient of Tensor.attention (written with it) runs on libtorch too: 51 of the 52 primitives (ml#203).
  • The StableHLO emitter (so Backend.Xla) compiles sigmoid, pow, clamp, to_dtype, permute, concat, stack, squeeze, unsqueeze, batch_matmul and argmax (ml#243).
  • The StableHLO emitter compiles layer_norm, rms_norm, gelu_erf and rope too (ml#243).
  • The StableHLO emitter compiles attention and scatter_add (the gradient of an embedding) too, and a program with a scatter_add checks its indices as one with a gather does (ml#243).
  • The StableHLO emitter compiles top_ids too (ml#243).
  • Tensor.from_file and Tensor.from_bytes on Backend.Xla read and widen the range in C, straight into the buffer, as ggml does (no list of floats): Qwen3-0.6B opens in 2.8 GB instead of over 6 GB (ml#243).
  • Tensor.device_memory(backend) gives the free and total bytes of the device of a ggml backend (ggml_backend_dev_memory), for a memory budget of layers_on_device (ml#331).