devinterp package¶
Subpackages¶
- devinterp.backends package
- devinterp.mechinterp package
- Submodules
- devinterp.mechinterp.activations module
- devinterp.mechinterp.hooks module
HookedList
HookedList.T_destination
HookedList.add_module()
HookedList.append()
HookedList.apply()
HookedList.bfloat16()
HookedList.buffers()
HookedList.call_super_init
HookedList.children()
HookedList.collect_cache()
HookedList.compile()
HookedList.cpu()
HookedList.cuda()
HookedList.double()
HookedList.dump_patches
HookedList.eval()
HookedList.extend()
HookedList.extra_repr()
HookedList.float()
HookedList.forward()
HookedList.get_buffer()
HookedList.get_extra_state()
HookedList.get_parameter()
HookedList.get_submodule()
HookedList.half()
HookedList.insert()
HookedList.ipu()
HookedList.load_state_dict()
HookedList.modules()
HookedList.named_buffers()
HookedList.named_children()
HookedList.named_modules()
HookedList.named_parameters()
HookedList.parameters()
HookedList.register_backward_hook()
HookedList.register_buffer()
HookedList.register_forward_hook()
HookedList.register_forward_pre_hook()
HookedList.register_full_backward_hook()
HookedList.register_full_backward_pre_hook()
HookedList.register_load_state_dict_post_hook()
HookedList.register_module()
HookedList.register_parameter()
HookedList.register_state_dict_pre_hook()
HookedList.requires_grad_()
HookedList.set_extra_state()
HookedList.share_memory()
HookedList.state_dict()
HookedList.to()
HookedList.to_empty()
HookedList.train()
HookedList.training
HookedList.type()
HookedList.xpu()
HookedList.zero_grad()
HookedSequential
HookedSequential.T_destination
HookedSequential.add_module()
HookedSequential.append()
HookedSequential.apply()
HookedSequential.bfloat16()
HookedSequential.buffers()
HookedSequential.call_super_init
HookedSequential.children()
HookedSequential.collect_cache()
HookedSequential.compile()
HookedSequential.cpu()
HookedSequential.cuda()
HookedSequential.double()
HookedSequential.dump_patches
HookedSequential.eval()
HookedSequential.extra_repr()
HookedSequential.float()
HookedSequential.get_buffer()
HookedSequential.get_extra_state()
HookedSequential.get_parameter()
HookedSequential.get_submodule()
HookedSequential.half()
HookedSequential.ipu()
HookedSequential.load_state_dict()
HookedSequential.modules()
HookedSequential.named_buffers()
HookedSequential.named_children()
HookedSequential.named_modules()
HookedSequential.named_parameters()
HookedSequential.parameters()
HookedSequential.register_backward_hook()
HookedSequential.register_buffer()
HookedSequential.register_forward_hook()
HookedSequential.register_forward_pre_hook()
HookedSequential.register_full_backward_hook()
HookedSequential.register_full_backward_pre_hook()
HookedSequential.register_load_state_dict_post_hook()
HookedSequential.register_module()
HookedSequential.register_parameter()
HookedSequential.register_state_dict_pre_hook()
HookedSequential.requires_grad_()
HookedSequential.run_with_cache()
HookedSequential.set_extra_state()
HookedSequential.share_memory()
HookedSequential.state_dict()
HookedSequential.to()
HookedSequential.to_empty()
HookedSequential.train()
HookedSequential.training
HookedSequential.type()
HookedSequential.xpu()
HookedSequential.zero_grad()
hook()
prepend_dict()
- Module contents
- devinterp.optim package
- Submodules
- devinterp.optim.sgld module
SGLD
SGLD.OptimizerPostHook
SGLD.OptimizerPreHook
SGLD.add_param_group()
SGLD.load_state_dict()
SGLD.register_load_state_dict_post_hook()
SGLD.register_load_state_dict_pre_hook()
SGLD.register_state_dict_post_hook()
SGLD.register_state_dict_pre_hook()
SGLD.register_step_post_hook()
SGLD.register_step_pre_hook()
SGLD.state_dict()
SGLD.step()
SGLD.zero_grad()
- devinterp.optim.sgnht module
SGNHT
SGNHT.OptimizerPostHook
SGNHT.OptimizerPreHook
SGNHT.add_param_group()
SGNHT.load_state_dict()
SGNHT.register_load_state_dict_post_hook()
SGNHT.register_load_state_dict_pre_hook()
SGNHT.register_state_dict_post_hook()
SGNHT.register_state_dict_pre_hook()
SGNHT.register_step_post_hook()
SGNHT.register_step_pre_hook()
SGNHT.state_dict()
SGNHT.zero_grad()
- Module contents
- devinterp.slt package
Submodules¶
devinterp.utils module¶
- class devinterp.utils.Outputs(loss)¶
Bases:
tuple
- count(value, /)¶
Return number of occurrences of value.
- index(value, start=0, stop=9223372036854775807, /)¶
Return first index of value.
Raises ValueError if the value is not present.
- loss: Tensor¶
Alias for field number 0
- devinterp.utils.prepare_input(data: Tensor | Any, device, is_deepspeed_enabled=False, accelerator=None) Tensor | Any ¶
Prepares one data before feeding it to the model, be it a tensor or a nested list/dictionary of tensors.
Adapted from HuggingFace’s transformers’s Trainer._prepare_input().
- devinterp.utils.set_seed(seed: int, device: str | device | None = None)¶
Sets the seed for the Learner.
- Parameters:
seed (int) – Seed to set.
devinterp.vis_utils module¶
- class devinterp.vis_utils.EpsilonBetaAnalyzer¶
Bases:
object
A class for analyzing and visualizing the local learning coefficient (LLC) across different epsilon and beta values.
Includes methods to configure, run, and visualize sweeps of the local learning coefficient over epsilon and beta.
- configure_sweep(llc_estimator: Callable, llc_estimator_kwargs: dict, min_epsilon: float | None = 1e-06, max_epsilon: float | None = 0.01, epsilon_samples: float = 8, epsilon_range: List[float] | None = None, min_beta: float | None = None, max_beta: float | None = None, beta_samples: float = 8, beta_range: List[float] | None = None, dataloader: DataLoader | None = None) None ¶
Configure the sampling parameters for the LLC analysis. :param llc_estimator: Callable function to estimate the local learning coefficient.
Note: The estimator function expected by EpsilonBetaAnalyzer must have the following signature: def estimator(epsilon: float, beta: float, **kwargs) -> dict where kwargs are the arguments to estimate_learning_coeff_with_summary The return value must be a dict with a “llc/trace” key corresponding to a numpy array of shape (num_chains, num_draws) Additional keys can represent other values of interest (e.g. acceptance rates, true LLC.)
- Parameters:
llc_estimator_kwargs – Keyword arguments for the llc_estimator function.
min_epsilon – Minimum value for epsilon range (if epsilon_range not provided).
max_epsilon – Maximum value for epsilon range (if epsilon_range not provided).
epsilon_samples – Number of samples in epsilon range (if epsilon_range not provided).
epsilon_range – Explicit range of epsilon values to use (overrides min/max_epsilon).
min_beta – Minimum value for beta range (if beta_range not provided).
max_beta – Maximum value for beta range (if beta_range not provided).
beta_samples – Number of samples in beta range (if beta_range not provided).
beta_range – Explicit range of beta values to use (overrides min/max_beta).
dataloader – Optional dataloader for calculating optimal beta.
- plot(true_lambda: float | int | str | Container | None = None, num_last_steps_to_average: int = 50, color: str | None = None, slider: str | None = None, slider_plane: str | None = False, **kwargs) Figure ¶
Plot the results of the LLC sweep.
- Parameters:
true_lambda – True value of lambda for comparison (optional). Can be a scalar, a list, or a string column name of sweep_df. Will plot a horizontal plane at the true_lambda value.
num_last_steps_to_average – Number of last steps to average for final LLC value.
color – Column name to use for coloring the scatter points.
slider – Column name to use for creating a slider in the plot.
slider_plane – If True, adds a plane for each slider value.
kwargs – Additional keyword arguments to pass to the plotting function. Example: range_color=[0, 0.15] to set the color range.
- Returns:
A plotly Figure object containing the LLC sweep visualization.
- save_fig(path: str) None ¶
Save the current figure to a file. :param path: Path to save the figure to.
- sweep(add_to_existing=False) None ¶
Perform the LLC sweep using the configured parameters.
This method runs the LLC estimator for each combination of epsilon and beta values and stores the results in self.sweep_df.
- Parameters:
add_to_existing – If True, adds new sweep results to existing ones. If False, replaces existing results. Useful for sweeping over multiple models or datasets.