pub struct SacActor<B: Backend> { /* private fields */ }Expand description
Stochastic, tanh-squashed Gaussian actor for SAC continuous control.
Layout:
obs → fc1 →act→ fc2 →act→ (fc3 →act→)? ┬─ mean_head (μ)
└─ log_std_head (log σ, clamped)Both heads share the trunk activations. Use
sample for a reparameterized stochastic action with
its (squash-corrected) log-probability, and
mean_action for the deterministic
evaluation action tanh(μ).
Implementations§
Source§impl<B: Backend> SacActor<B>
impl<B: Backend> SacActor<B>
Sourcepub fn with_config(
obs_dim: usize,
action_dim: usize,
config: SacActorConfig,
device: &B::Device,
) -> Self
pub fn with_config( obs_dim: usize, action_dim: usize, config: SacActorConfig, device: &B::Device, ) -> Self
Build a fresh actor on device with the given configuration.
obs_dim is the observation width; action_dim is the number of
continuous action dimensions (each squashed into (-1, 1)).
Sourcepub fn forward(&self, obs: Tensor<B, 2>) -> (Tensor<B, 2>, Tensor<B, 2>)
pub fn forward(&self, obs: Tensor<B, 2>) -> (Tensor<B, 2>, Tensor<B, 2>)
Forward pass producing the Gaussian parameters
(mean, log_std), each shape [batch, action_dim].
log_std is clamped to [LOG_STD_MIN, LOG_STD_MAX]
before being returned.
Sourcepub fn mean_action(&self, obs: Tensor<B, 2>) -> Tensor<B, 2>
pub fn mean_action(&self, obs: Tensor<B, 2>) -> Tensor<B, 2>
Deterministic evaluation action tanh(μ), shape
[batch, action_dim], lying in the open box (-1, 1).
Used at evaluation time when the stochastic exploration of
sample is undesirable.
Sourcepub fn sample(
&self,
obs: Tensor<B, 2>,
rng: &mut StdRng,
) -> (Tensor<B, 2>, Tensor<B, 1>)
pub fn sample( &self, obs: Tensor<B, 2>, rng: &mut StdRng, ) -> (Tensor<B, 2>, Tensor<B, 1>)
Draw one reparameterized, tanh-squashed action per row and return
(action, log_prob).
actionis shape[batch, action_dim], every element in the open box(-1, 1).log_probis shape[batch]— the joint log-density over all action dimensions, with the tanh-squash change-of-variables correction applied.
The Gaussian noise eps is drawn on the host from rng (via the
Box–Muller transform, matching crate::policy::seeded_init) and
injected as a constant tensor, so gradients still flow through
mean and std (the reparameterization trick) while the sample
stays bit-exactly reproducible for a given seed — mirroring
crate::policy::mlp::MlpBurnPolicy::get_action_host_seeded.
Sourcepub fn log_std_head(&self) -> &Linear<B>
pub fn log_std_head(&self) -> &Linear<B>
Borrow the log-std head.
Trait Implementations§
Source§impl<B> AutodiffModule<B> for SacActor<B>
impl<B> AutodiffModule<B> for SacActor<B>
Source§type InnerModule = SacActor<<B as AutodiffBackend>::InnerBackend>
type InnerModule = SacActor<<B as AutodiffBackend>::InnerBackend>
Source§fn valid(&self) -> Self::InnerModule
fn valid(&self) -> Self::InnerModule
Source§fn from_inner(module: Self::InnerModule) -> Self
fn from_inner(module: Self::InnerModule) -> Self
Source§impl<B> HasAutodiffModule<B> for SacActor<B::InnerBackend>
impl<B> HasAutodiffModule<B> for SacActor<B::InnerBackend>
Source§type TrainModule = SacActor<B>
type TrainModule = SacActor<B>
Source§impl<B: Backend> Module<B> for SacActor<B>
impl<B: Backend> Module<B> for SacActor<B>
Source§type Record = SacActorRecord<B>
type Record = SacActorRecord<B>
Source§fn load_record(self, record: Self::Record) -> Self
fn load_record(self, record: Self::Record) -> Self
Source§fn into_record(self) -> Self::Record
fn into_record(self) -> Self::Record
Source§fn num_params(&self) -> usize
fn num_params(&self) -> usize
Source§fn visit<Visitor: ModuleVisitor<B>>(&self, visitor: &mut Visitor)
fn visit<Visitor: ModuleVisitor<B>>(&self, visitor: &mut Visitor)
Source§fn map<Mapper: ModuleMapper<B>>(self, mapper: &mut Mapper) -> Self
fn map<Mapper: ModuleMapper<B>>(self, mapper: &mut Mapper) -> Self
Source§fn collect_devices(&self, devices: Devices<B>) -> Devices<B>
fn collect_devices(&self, devices: Devices<B>) -> Devices<B>
Source§fn to_device(self, device: &B::Device) -> Self
fn to_device(self, device: &B::Device) -> Self
Source§fn fork(self, device: &B::Device) -> Self
fn fork(self, device: &B::Device) -> Self
Source§fn devices(&self) -> Vec<<B as BackendTypes>::Device>
fn devices(&self) -> Vec<<B as BackendTypes>::Device>
Source§fn train<AB>(self) -> Self::TrainModulewhere
AB: AutodiffBackend<InnerBackend = B>,
Self: HasAutodiffModule<AB>,
fn train<AB>(self) -> Self::TrainModulewhere
AB: AutodiffBackend<InnerBackend = B>,
Self: HasAutodiffModule<AB>,
Source§fn save_file<FR, PB>(
self,
file_path: PB,
recorder: &FR,
) -> Result<(), RecorderError>
fn save_file<FR, PB>( self, file_path: PB, recorder: &FR, ) -> Result<(), RecorderError>
Source§fn load_file<FR, PB>(
self,
file_path: PB,
recorder: &FR,
device: &<B as BackendTypes>::Device,
) -> Result<Self, RecorderError>
fn load_file<FR, PB>( self, file_path: PB, recorder: &FR, device: &<B as BackendTypes>::Device, ) -> Result<Self, RecorderError>
Source§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
Source§impl<B: Backend> ModuleDisplay for SacActor<B>
impl<B: Backend> ModuleDisplay for SacActor<B>
Source§fn format(&self, passed_settings: DisplaySettings) -> String
fn format(&self, passed_settings: DisplaySettings) -> String
Source§fn custom_settings(&self) -> Option<DisplaySettings>
fn custom_settings(&self) -> Option<DisplaySettings>
Auto Trait Implementations§
impl<B> !Freeze for SacActor<B>
impl<B> !RefUnwindSafe for SacActor<B>
impl<B> !UnwindSafe for SacActor<B>
impl<B> Send for SacActor<B>
impl<B> Sync for SacActor<B>
impl<B> Unpin for SacActor<B>where
<B as BackendTypes>::FloatTensorPrimitive: Unpin,
<B as BackendTypes>::QuantizedTensorPrimitive: Unpin,
<B as BackendTypes>::Device: Unpin,
impl<B> UnsafeUnpin for SacActor<B>where
<B as BackendTypes>::Device: UnsafeUnpin,
<B as BackendTypes>::FloatTensorPrimitive: UnsafeUnpin,
<B as BackendTypes>::QuantizedTensorPrimitive: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more