rlightning.weights.weight_buffer

class rlightning.weights.weight_buffer.CPUWeightBuffer(config: WeightBufferConfig)[source]

Bases: WeightBuffer

Implements a CPU buffer strategy. Weights are transferred to and stored in CPU memory on the evaluator nodes and moved to the GPU just-in-time for model updates.

VALUE_TYPE: Type = MockModule('numpy.ndarray')
class rlightning.weights.weight_buffer.ShardedWeightBuffer(config: WeightBufferConfig)[source]

Bases: WeightBuffer

Implements a sharded buffer strategy for memory efficiency. Each GPU holds only a fraction of the total weights. Weights are gathered across GPUs on the same node just-in-time for model updates.

add_shard(dtype: MockModule('torch.dtype'), flat_tensor_shard: MockModule('torch.Tensor'), metadata_list: List[Dict], numel_total: int, is_last: bool)[source]

Adds a weight shard for a specific dtype to the buffer.

apply_to_model(policy)[source]

Called by ShardedWeightBuffer. This reconstructs the full weights from shards and applies them to the model.

clear()[source]
class rlightning.weights.weight_buffer.WeightBuffer(config: WeightBufferConfig)[source]

Bases: object

policy weight buffer, for update weights from train policy to eval policy

VALUE_TYPE: Type = MockModule('torch.Tensor')
add(module_name: str, name: str, weight: MockModule('torch.Tensor'), is_last: bool = False)[source]
add_state_dict(state_dict)[source]

Add a complete state dictionary to the buffer.

clear()[source]
get_state_dict()[source]

Retrieves the state dictionary from the buffer.

is_ready()[source]
preprocess(*args, **kwargs)[source]
sample()[source]