pub struct MultiTaskModel {
pub shared_backbone_dim: usize,
pub task_heads: Vec<TaskHead>,
pub loss: MultiTaskLoss,
}Expand description
A multi-task model composed of a shared backbone and per-task heads.
The backbone produces a shared representation vector of dimension
shared_backbone_dim. Each TaskHead then projects this into its own
output space. The MultiTaskLoss combiner aggregates per-task scalar
losses into a single training objective.
Fields§
Dimension of the shared backbone output.
task_heads: Vec<TaskHead>Ordered task-specific output heads.
loss: MultiTaskLossLoss combiner.
Implementations§
Source§impl MultiTaskModel
impl MultiTaskModel
Sourcepub fn new(shared_backbone_dim: usize) -> Self
pub fn new(shared_backbone_dim: usize) -> Self
Create a new model with no task heads. Uses equal task weighting.
Sourcepub fn add_task(&mut self, head: TaskHead)
pub fn add_task(&mut self, head: TaskHead)
Add a task head to the model.
The loss combiner is rebuilt after each addition to keep num_tasks
in sync, preserving the Equal weighting strategy.
Sourcepub fn task_names(&self) -> Vec<&str>
pub fn task_names(&self) -> Vec<&str>
Names of all registered tasks in registration order.
Sourcepub fn forward_all<'a>(
&'a self,
shared_repr: &[f32],
) -> Vec<(&'a str, Vec<f32>)>
pub fn forward_all<'a>( &'a self, shared_repr: &[f32], ) -> Vec<(&'a str, Vec<f32>)>
Run a forward pass through every task head.
Returns a vector of (task_name, output) pairs in registration order.
Sourcepub fn total_loss(
&mut self,
shared_repr: &[f32],
targets: &[(&str, &[f32])],
loss_fn: impl Fn(&[f32], &[f32]) -> f32,
) -> Result<f32, MultiTaskError>
pub fn total_loss( &mut self, shared_repr: &[f32], targets: &[(&str, &[f32])], loss_fn: impl Fn(&[f32], &[f32]) -> f32, ) -> Result<f32, MultiTaskError>
Compute the total weighted multi-task loss.
For each task, the per-task scalar loss is computed by applying
loss_fn(predictions, targets). The results are then combined via
the configured MultiTaskLoss.
targets is a slice of (task_name, target_values) pairs. Tasks
not present in targets are skipped (their loss is zero).
§Errors
Returns MultiTaskError::NoTasks when no heads are registered, or
MultiTaskError::TaskNotFound when a target task name is not in the
model.
Trait Implementations§
Source§impl Clone for MultiTaskModel
impl Clone for MultiTaskModel
Auto Trait Implementations§
impl Forget for MultiTaskModel
impl Freeze for MultiTaskModel
impl Move for MultiTaskModel
impl RefUnwindSafe for MultiTaskModel
impl Send for MultiTaskModel
impl Sync for MultiTaskModel
impl Unpin for MultiTaskModel
impl UnsafeUnpin for MultiTaskModel
impl UnwindSafe for MultiTaskModel
Blanket Implementations§
impl<T> Allocation for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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