rlightning.weights.weight_buffer_mixin

class rlightning.weights.weight_buffer_mixin.WeightBufferMixin[source]

Bases: object

Mixin class for weight buffer management functionality. This mixin provides methods for initializing, updating, and managing weight buffers for policy weight transfer between train and eval policies.

clear_memory(sync=False)[source]

Clear the memory.

get_weight_buffer()[source]

Get the weight buffer instance.

init_weight_buffer(shared_weight_buffer=None)[source]

Initialize the weight buffer.

offload_model()[source]

offload model to cpu

offload_model_param_and_grad(offload_grad=False)[source]

offload model param and grad to cpu

offload_optimizer()[source]

offload optimizer to cpu

recv_weights(metadata_by_dtype)[source]

Receive the weights from the train policy. Only call this method from train policy, in weight_transfer_manager.send_weights()

recv_weights_ipc(data)[source]

Receive the weights from the eval policy using IPC.

recv_weights_local(state_dict)[source]

This method is used to receive weights locally without using ray in running on a single process.

reload_model()[source]

load model to device

reload_model_param_and_grad(load_grad=False)[source]

load model param and grad to device

reload_optimizer()[source]

load optimizer to device

send_weights(eval_policys, shared_weight_buffer=None)[source]

Send the weights to the eval policy.

send_weights_ipc()[source]

Send the weights to the eval policy using IPC.

sync_weights_layer_by_layers(module_name, name, dtype, shape, is_last: bool = False)[source]

Sync the weight from the train policy layer by layer.

update_weights()[source]

Update the weights from weight_buffer. This method runs in a daemon thread and continuously waits for update signals.

update_weights_from_buffer()[source]

Update weights from the weight buffer.