#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum GradientCheckpointingStrategy {
Disabled,
Balanced,
Custom(&'static str),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum AutodiffContext {
Disabled,
Enabled(GradientCheckpointingStrategy),
}
impl AutodiffContext {
pub fn merge(self, other: Self) -> Self {
match (self, other) {
(Self::Disabled, context) | (context, Self::Disabled) => context,
(Self::Enabled(left), Self::Enabled(right)) => {
assert_eq!(left, right, "Cannot combine different gradient-checkpointing strategies");
self
}
}
}
}