vortex_torch.indexer.save_load¶
Classes
|
Format-aware load (copy/convert) dispatcher. |
|
Format-aware save (copy/convert) dispatcher. |
- class vortex_torch.indexer.save_load.Save[source]¶
Bases:
vOpFormat-aware save (copy/convert) dispatcher.
This operator copies or converts data from an input tensor
xinto a preallocated output tensoro. Both tensors are treated as rank-3 objects with logical shape\[[S, D_0, D_1],\]where \(S\) is a generic leading dimension (it may represent a batch, a sequence length, or a page count, depending on the surrounding runtime).
Key properties:
Dispatch is keyed only by the format of
x(x._format).No internal buffer is allocated; the provided output tensor
ois validated and written into directly.The output format is determined by the dispatch table and must match
o._format.
- _impl_map¶
Dispatch table keyed by
x_format. Each entry maps to(callable_impl, resolved_output_format).
- profile(x, o, ctx)[source]¶
Validate inputs, resolve the implementation, and return
oas the output view.This method checks:
that both
xandoare rank-3vTensorinstances with logical shape[S, D_0, D_1],that their inner dimensions
D_0andD_1match,that a save implementation is registered for
x._format, andthat
o._formatmatches the format required by the dispatch.
No new buffers are allocated; the provided
owill be used as the destination.- Parameters:
x (vTensor) – Input tensor to be copied/converted. Expected logical shape
[S, D_0, D_1].o (vTensor) – Preallocated output tensor. Must have logical shape compatible with
x(matchingD_0andD_1) and the format expected by the selected implementation.ctx (Context) – Execution context (included for API symmetry; not used for buffer allocation in this dispatcher).
- Returns:
The same object as
o, returned as the resolved output view.- Return type:
- Raises:
AssertionError – If types, ranks, shapes, formats, or devices are incompatible, or if no implementation is registered for
x._format.
- execute(x, o, ctx)[source]¶
Execute the resolved save operation from
xintoo.The selected implementation is expected to copy or convert the contents of
xinto the preallocated tensorowithout changing its shape or device.- Parameters:
x (torch.Tensor) – Input tensor to be copied/converted.
o (torch.Tensor) – Preallocated output tensor that will receive the data.
ctx (Context) – Execution context passed through to the implementation.
- Returns:
The same tensor as
o, after the copy/convert operation.- Return type:
torch.Tensor
- Raises:
AssertionError – If
profile()has not been called and no implementation is available.
- class vortex_torch.indexer.save_load.Load[source]¶
Bases:
vOpFormat-aware load (copy/convert) dispatcher.
This operator copies or converts data from an input tensor
xinto an internally allocated output buffer. Both input and output are treated as rank-3 tensors with logical shape\[[S, D_0, D_1],\]where \(S\) is a generic leading dimension (it may represent a batch size, a sequence length, or a page count, depending on the surrounding runtime).
Key properties¶
Dispatch is keyed only by the format of
x(x._format).The output buffer is allocated during
profile()using the runtime valuectx.max_num_pagesfor the leading dimension.The output format is determined by the dispatch table and used when wrapping the internal buffer as a
vTensor.
- _impl_map¶
Dispatch table keyed by
x_format. Each entry maps to(callable_impl, resolved_output_format).
- output_buffer¶
Preallocated output tensor buffer with logical shape
[S_out, D_0, D_1], whereS_outcomes from the runtime context.- Type:
Optional[torch.Tensor]
- profile(x, ctx)[source]¶
Validate the input, select an implementation, allocate the output buffer, and return an
as_vtensor()view with the resolved format.The input tensor is expected to have logical shape
[S_in, D_0, D_1]. The output tensor is allocated with shape\[[S_{\text{out}}, D_0, D_1],\]where \(S_{\text{out}}\) is taken from
ctx.max_num_pagesto match the runtime configuration for the leading dimension.- Parameters:
- Returns:
A
vTensorview wrapping the internally allocated output buffer with the resolved output format.- Return type:
- Raises:
AssertionError – If
xis not avTensor, if its rank is not 3, or if no implementation is registered forx._format.
- execute(x, ctx)[source]¶
Run the selected load operation into the internally allocated buffer.
The selected implementation is expected to copy or convert the contents of
xinto the internal buffer stored inoutput_buffer.- Parameters:
x (torch.Tensor) – Input tensor to be copied/converted, on the same device as the internal output buffer.
ctx (Context) – Execution context passed through to the implementation.
- Returns:
The internally allocated output tensor stored in
output_buffer.- Return type:
torch.Tensor
- Raises:
AssertionError – If
profile()has not been called (no implementation or internal output buffer available).