Skip to main content

Parameter

Trait Parameter 

pub trait Parameter: ParameterValue {
    // Required methods
    fn is_require_grad(&self) -> bool;
    fn set_require_grad(self, require_grad: bool) -> Self;
    fn device(&self) -> Device;
    fn shape(&self) -> Shape;
    fn load_to_device(self, device: &Device) -> Self;
}
Expand description

A tensor-backed ParameterValue with autodiff, device and loading capabilities.

General module-owned values can implement ParameterValue without pretending to require gradients, reside on a device or have a tensor shape.

Required Methods§

fn is_require_grad(&self) -> bool

Fetch the gradient requirement.

fn set_require_grad(self, require_grad: bool) -> Self

Set the gradient requirement.

Float tensors without autodiff remain unchanged. Param::set_require_grad stores the configured training state so it can be applied when entering training mode.

fn device(&self) -> Device

Fetch the device.

fn shape(&self) -> Shape

Fetch the shape of the parameter.

fn load_to_device(self, device: &Device) -> Self

Moves the parameter to the target device if it is not already on it, applying any kind-specific preparation required for the loading lifecycle (e.g. detach).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

§

impl<const D: usize> Parameter for Tensor<D, Bool>

§

impl<const D: usize> Parameter for Tensor<D, Int>

§

impl<const D: usize> Parameter for Tensor<D>