pub struct WithCpuCopy<T: AsModule> { /* private fields */ }
Expand description
Wraps a module to have a lazily-initialized CPU copy if not already in CPU memory.
This is useful for models used both in training and in simulation because large batch size training is most efficient on the GPU while batch-size-1 simulation is most efficient on the CPU.
Implementations§
Source§impl<T: AsModule> WithCpuCopy<T>
impl<T: AsModule> WithCpuCopy<T>
Sourcepub fn as_inner_mut(&mut self) -> &mut T
pub fn as_inner_mut(&mut self) -> &mut T
Get a mutable reference to the inner struct. Invalidates the cached CPU copy if any.
Sourcepub fn shallow_clone_module_cpu(&self) -> T::Module
pub fn shallow_clone_module_cpu(&self) -> T::Module
Create a shallow clone of the module on CPU memory.
If the module is not already on the CPU device then a cached deep copy is created on the CPU first. This cached copy is reused on future calls.
Trait Implementations§
Source§impl<T: AsModule> AsModule for WithCpuCopy<T>
impl<T: AsModule> AsModule for WithCpuCopy<T>
Source§impl<'de, T> Deserialize<'de> for WithCpuCopy<T>where
T: Deserialize<'de> + AsModule,
impl<'de, T> Deserialize<'de> for WithCpuCopy<T>where
T: Deserialize<'de> + AsModule,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<P: Policy> Policy for WithCpuCopy<P>
impl<P: Policy> Policy for WithCpuCopy<P>
type PolicyModule = <P as Policy>::PolicyModule
Source§fn update<AS: ParameterizedDistributionSpace<Tensor> + ?Sized>(
&mut self,
features: &dyn HistoryFeatures,
advantages: PackedTensor,
action_space: &AS,
logger: &mut dyn StatsLogger,
)
fn update<AS: ParameterizedDistributionSpace<Tensor> + ?Sized>( &mut self, features: &dyn HistoryFeatures, advantages: PackedTensor, action_space: &AS, logger: &mut dyn StatsLogger, )
Update the policy module. Read more
Source§fn actor<OS, AS>(
&self,
observation_space: NonEmptyFeatures<OS>,
action_space: AS,
) -> PolicyActor<OS, AS, Self::Module>
fn actor<OS, AS>( &self, observation_space: NonEmptyFeatures<OS>, action_space: AS, ) -> PolicyActor<OS, AS, Self::Module>
Create an actor for the policy module.
Auto Trait Implementations§
impl<T> !Freeze for WithCpuCopy<T>
impl<T> !RefUnwindSafe for WithCpuCopy<T>
impl<T> Send for WithCpuCopy<T>
impl<T> !Sync for WithCpuCopy<T>
impl<T> Unpin for WithCpuCopy<T>
impl<T> UnwindSafe for WithCpuCopy<T>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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