braintrace.add_hidden_perturbation_from_minfo

braintrace.add_hidden_perturbation_from_minfo#

braintrace.add_hidden_perturbation_from_minfo(minfo, descended_scan_eqn_ids=frozenset({}), include_output_bypass=True, new_read_policy=None)#

Add hidden-state perturbations from a ModuleInfo.

Adds perturbations to the hidden states in the module jaxpr and replaces the hidden states with the perturbed states.

Parameters:
  • minfo (ModuleInfo) – The model information.

  • descended_scan_eqn_ids (frozenset of int, default frozenset()) – id() values of scan equations rewritten by structured scan descent (Phase 4); exempt from the unsupported-op checks.

  • include_output_bypass (bool, default True) – Whether to add the same-step bypass gradients of the parameters and of the previous hidden values (see HiddenPerturbation.bypass_param_paths). Disable it for a learning signal that replaces dL/dh ('modulatory').

  • new_read_policy (NewReadPolicy, optional) – Decides which in-step reads of new hidden values to cut (issue #239; see HiddenPerturbation). None (default) cuts none: the signal is the total derivative.

Returns:

HiddenPerturbation – The hidden-perturbation information.

See also

add_hidden_perturbation_in_module

Equivalent helper starting from a model.