Skip to main content

StrategyContext

Trait StrategyContext 

Source
pub trait StrategyContext {
    // Required methods
    fn num_workers(&self) -> usize;
    fn execute_on_worker(
        &self,
        worker_idx: usize,
        plan: &Value,
        input: &Value,
        y: Option<&Value>,
    ) -> Result<HashMap<String, Value>>;
    fn get_state(
        &self,
        worker_idx: usize,
        node_ids: &[String],
    ) -> Result<HashMap<String, Value>>;
    fn set_state(
        &self,
        worker_idx: usize,
        states: &HashMap<String, Value>,
    ) -> Result<()>;
    fn get_gradients(
        &self,
        worker_idx: usize,
        node_ids: &[String],
    ) -> Result<HashMap<String, Value>>;
    fn apply_gradients(
        &self,
        worker_idx: usize,
        gradients: &HashMap<String, Value>,
    ) -> Result<()>;
}
Expand description

Context provided to strategy executors. Abstracts worker communication — the strategy doesn’t know about WS/HTTP.

Required Methods§

Source

fn num_workers(&self) -> usize

Number of available workers.

Source

fn execute_on_worker( &self, worker_idx: usize, plan: &Value, input: &Value, y: Option<&Value>, ) -> Result<HashMap<String, Value>>

Execute a plan on a specific worker (by index). Returns trained states.

Source

fn get_state( &self, worker_idx: usize, node_ids: &[String], ) -> Result<HashMap<String, Value>>

Get trained states from a worker.

Source

fn set_state( &self, worker_idx: usize, states: &HashMap<String, Value>, ) -> Result<()>

Set states on a worker (e.g. after aggregation).

Source

fn get_gradients( &self, worker_idx: usize, node_ids: &[String], ) -> Result<HashMap<String, Value>>

Get gradients from a worker.

Source

fn apply_gradients( &self, worker_idx: usize, gradients: &HashMap<String, Value>, ) -> Result<()>

Apply gradients on a worker.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§