Sharded fitting¶
Row-chunked, multi-device fitting for data larger than one GPU. Pass a ShardedFrame to
Robusta(override_frame=...); everything else works as for a dense fit.
ShardedFrame¶
robusta_hmf.ShardedFrame
dataclass
¶
Bases: OptFrame
An OptFrame that chunks and shards the rows.
Reads the likelihood, rotation and ALS ridge off the
HMF it is bound to, so it never duplicates the
model's parameter list. Hand it to
Robusta via override_frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row_block
|
int
|
Target rows per scan chunk. Sets peak scratch memory, roughly
|
4096
|
devices
|
Sequence | None
|
Devices to shard over. Defaults to all visible devices; a single device gives pure chunking, which is the memory fix on its own. |
None
|
store_dtype
|
dtype
|
On-device dtype for |
numpy.float32
|
compute_dtype
|
dtype | None
|
Dtype of the arithmetic and of |
None
|
verbose
|
bool
|
Print the sharding and memory summary when the data is placed. |
True
|
Notes
Results are not bitwise identical to Robusta's dense
path, nor across different row_block or device counts: the arithmetic
is the same but the summation order is not. See the module docstring.
n_devices
property
¶
prepare(Y, W=None, nan_error=False)
¶
Validate and place (Y, W) on the mesh, or pass through an existing handle.
Returns (data, None): the weights live inside the
ShardedData, so there is no second array to carry. See
shard_data() for the checks and nan_error; a handle has
already been through them.
ShardedData¶
robusta_hmf.ShardedData
dataclass
¶
Y and W resident on a mesh, plus the plan describing their layout.
Built once by ShardedFrame.prepare() and reused: a (K, Q)
grid over the same sample would otherwise re-transfer the full matrices for every grid point.
Attributes:
| Name | Type | Description |
|---|---|---|
Y, W |
(Array, shape(n_padded, n_pixels))
|
Sharded, zero-padded data and weights, in |
plan |
RowPlan
|
The row layout. |
mesh |
Mesh
|
The mesh they are resident on. |
n_pixels |
int
|
Columns of the original matrix. |
RowPlan¶
robusta_hmf.RowPlan
dataclass
¶
How n_rows real rows are laid out over devices and scan chunks.
shard_map needs every device to hold the same number of rows, and the
inner lax.scan needs that number to be an exact multiple of the chunk
size, so the row axis is padded up to n_padded. The chunk size is
shrunk from the requested row_block where that makes the padding
smaller -- for the full RVS sample on 4 devices this is 18 padded rows
rather than the 8082 a fixed 8192-row block would need.
Attributes:
| Name | Type | Description |
|---|---|---|
n_rows |
int
|
Real rows, before padding. |
n_devices |
int
|
Devices in the mesh. |
chunk |
int
|
Rows per |
n_chunks |
int
|
Scan steps per device. |
GramInitialiser¶
robusta_hmf.GramInitialiser
dataclass
¶
Bases: Initialiser
SVD initialisation via the Gram matrix, for data too large to svd.
Identical in exact arithmetic to
svd_init(): for Y = U S V.T,
Y.T @ Y = V S^2 V.T, so the top-K eigenvectors of the Gram matrix are
V[:, :K] and Y @ V = U S. This returns A = U sqrt(S) and
G = V sqrt(S), matching the library's convention, without ever forming
the (N, min(N, M)) U that jnp.linalg.svd wants -- which for the
Gaia RVS sample is as large as Y itself.
Equivalent does not mean identical in floating point: forming Y.T @ Y
squares the condition number, so the recovered subspace agrees with
svd_init at around sqrt(eps) (~1e-8 in float64) rather than
eps. This is an initialiser, and the first few ALS iterations wash the
difference out -- fits started from either route agree to ~1e-12 -- but do
not expect bitwise agreement at iteration zero.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
N
|
int | None
|
Filled in by |
None
|
M
|
int | None
|
Filled in by |
None
|
K
|
int | None
|
Filled in by |
None
|
strategy
|
(svd, random, custom)
|
|
"svd"
|
frame
|
ShardedFrame | None
|
The frame supplying the mesh and row plan. Filled in automatically
when |
None
|