Tensor View Layout
Strided parameter views with write-through to original storage.
- class sparsekit.view.View(param, shape, stride)[source]
Bases:
objectA strided view of a Parameter that duck-types as a Parameter.
Wraps an
nn.Parameterwith an arbitrary(size, stride)view viatorch.as_strided. The.dataproperty returns a live view into the original parameter’s storage – no copy is made, so in-place operations on the data write through to the underlying parameter.Workflow:
view = View(param, shape, stride) block = BlockSpec(view, shape=...) scope = ScopeSpec(block, shape=...) # ... pruning / thresholding -- writes go to param directly ...
- Parameters:
- static block_view_of(t, block_shape, reorder=True, merge=False)[source]
Block-structured view of t via
as_strided.- Parameters:
- Returns:
(B0, b0, B1, b1, …)interleaved view.reorder=True:(B0, B1, …, b0, b1, …)reordered view.merge=True:(B0, B1, …, b0*b1*…)merged view.- Return type:
reorder=False
- static broadcast_block_to_element(block_values, block_shape, fake=False)[source]
Expand a grid-shaped tensor to the full element shape.
- Parameters:
- Returns:
(B0, 1, B1, 1, …)fake=False:(s0, s1, …)withsi = Bi * bi.- Return type:
fake=True
- apply_multiplier(multiplier, block_shape)[source]
In-place multiply each block of
self.databy a grid scalar.