Skip to main content

NetworkHandle

Struct NetworkHandle 

Source
pub struct NetworkHandle {
    pub name: String,
    pub module: Option<PyObject>,
    pub optimizer: Option<PyObject>,
    pub scheduler: Option<PyObject>,
    pub batching: bool,
    pub k: Option<usize>,
    pub det: bool,
    pub train_mode: bool,
    pub cache_enabled: bool,
    pub cache_size: usize,
}
Expand description

Handle to a registered neural network.

This struct holds the PyTorch module and associated training state. When the python feature is enabled, it can hold PyO3 PyObject references.

Fields§

§name: String

Unique name identifying this network

§module: Option<PyObject>

The PyTorch nn.Module (set via Python API) Only available with the python feature

§optimizer: Option<PyObject>

The optimizer for training (e.g., Adam, SGD) Only available with the python feature

§scheduler: Option<PyObject>

Learning rate scheduler Only available with the python feature

§batching: bool

Whether to batch inputs for efficient GPU processing

§k: Option<usize>

Top-k sampling: if Some(k), only consider top k outputs

§det: bool

Deterministic mode: use argmax instead of sampling

§train_mode: bool

Whether the network is in training mode

§cache_enabled: bool

Whether output caching is enabled

§cache_size: usize

Maximum number of cached outputs

Implementations§

Source§

impl NetworkHandle

Source

pub fn new(name: String) -> Self

Create a new network handle with the given name and default settings.

Source

pub fn from_config(config: &NetworkConfig) -> Self

Create a handle from a configuration.

Source

pub fn has_module(&self) -> bool

Check if the PyTorch module has been set.

Source

pub fn has_optimizer(&self) -> bool

Check if an optimizer has been configured.

Source

pub fn has_scheduler(&self) -> bool

Check if a scheduler has been configured.

Source

pub fn set_module(&mut self, module: PyObject)

Set the PyTorch module.

Source

pub fn set_optimizer(&mut self, optimizer: PyObject)

Set the optimizer.

Source

pub fn set_scheduler(&mut self, scheduler: PyObject)

Set the learning rate scheduler.

Source

pub fn module(&self) -> Option<&PyObject>

Get a reference to the PyTorch module.

Source

pub fn optimizer(&self) -> Option<&PyObject>

Get a reference to the optimizer.

Source

pub fn scheduler(&self) -> Option<&PyObject>

Get a reference to the scheduler.

Source

pub fn clear(&mut self)

Clear the module and training state.

Trait Implementations§

Source§

impl Debug for NetworkHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for NetworkHandle

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Ungil for T
where T: Send,