estimate_chunk_size#
- t3toolbox.backend.sampling_derivatives.estimate_chunk_size(mode_shapes, tucker_ranks, tt_ranks, order, n_probes, *, n_tangent=1, stack_shape=(), n_shards=1, dtype=None, hessian='gauss_newton')#
def estimate_chunk_size( mode_shapes: typ.Sequence[int], # (N_1..N_d) ambient dims (as passed to TuckerTensorTrain.randn) tucker_ranks: typ.Sequence[int], # (nD_1..nD_d) Tucker ranks tt_ranks: typ.Sequence[int], # (r_0..r_d) the d+1 TT bonds order: int, # highest derivative order n_probes: int, # |W|, the number of probes (global; divided by n_shards) *, n_tangent: int = 1, # tangent stack K (a batch of tangents sharing the frame) stack_shape: typ.Sequence[int] = (), # frame stack C (a batch of base points); () = unstacked n_shards: int = 1, # W split across this many devices -> chunk sizes the LOCAL shard dtype: typ.Any = None, # array dtype; default float32 (jax default). float64 under x64 hessian: str = 'gauss_newton', # or 'exact': also bound the exact Hessian's two-hole assemblies ) -> int: # a memory-balanced chunk_size for tv_probe_derivatives_transpose
A memory-balanced
chunk_sizefor the probe-derivative transpose assembly, from the problem shapes – call it once (eagerly, outsidejit) and pass the int aschunk_size.Picks the largest chunk whose assembly peak is comparable to the edge-variable jets already resident (the necessary floor), so the assembly is never the tallest pole – if the rest of the pipeline fits, so does the assembly (total peak
~2xthe floor). Device-agnostic: no device-memory query, only the shapes. The assembly per-row cost is measured in the compiled chunked transpose itself, via XLA’s own scratch accounting (needs jax; a ~2 s one-time abstract compile, cached by shape). For an absolute byte cap instead, seemax_chunk_size_within(); the memory model is in the chunking design note.Sized by the whole transpose, so both the TT-core and the Tucker gradients count (Tucker wins when
N >> n). When the assemblies cost less per row than the resident jets – the usual case since they became recurrences – the balance admits the wholeWand this returnsW.n_shardsdividesWso the chunk sizes each device’s shard (useshard_map; see the chunking note). Only meaningful on the uniform+jax path – numpy/ragged never chunk.Pass
stack_shapefor a batch of base points (the frame stackC): every edge-variable jet carries it, so it multiplies both sides of the balance. This policy is therefore only mildly sensitive to it – the probe vectorsww/ppcarry noC, so the two sides do not scale quite together – butmax_chunk_size_within()is very sensitive, since its budget is an absolute byte count that does not scale at all.Pass
hessian='exact'(the solver’s mode vocabulary, case-insensitive;'gauss_newton'is the default) when the samechunk_sizealso drives the exact Hessian’s probe-derivative two-hole (t3_probe_corewise_derivatives_hessian()). Its chunk costs~1.3-2.2xthe transpose’s per row on current jax (the dotted companion of every pair; measured in its own compiled program;~1xon jaxlib 0.4.30, whose chunk cost is one jet slice in both), against a jet floor~1.1-1.6xthe transpose’s; the result is the smaller of the two balanced chunks, so both programs stay within their floors.n_tangentis then also the two-hole’s direction stack (one in a CG solve).- Parameters:
mode_shapes (t3toolbox.backend.common.typ.Sequence[int])
tucker_ranks (t3toolbox.backend.common.typ.Sequence[int])
tt_ranks (t3toolbox.backend.common.typ.Sequence[int])
order (int)
n_probes (int)
n_tangent (int)
stack_shape (t3toolbox.backend.common.typ.Sequence[int])
n_shards (int)
dtype (t3toolbox.backend.common.typ.Any)
hessian (str)
- Return type:
int