File tree Expand file tree Collapse file tree
deepmd/pt/model/descriptor/sezm_nn Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -572,6 +572,14 @@ def __init__(
572572 self .block_attn_res_ffns = None
573573 self ._forward_impl = self ._forward_with_residual_shortcuts
574574
575+ # Inference env policy, sampled once here (see
576+ # ``_use_infer_activation_checkpoint``).
577+ _truthy = {"1" , "true" , "yes" , "on" }
578+ self ._act_infer = os .environ .get ("DP_ACT_INFER" , "" ).strip ().lower () in _truthy
579+ self ._compile_infer = (
580+ os .environ .get ("DP_COMPILE_INFER" , "" ).strip ().lower () in _truthy
581+ )
582+
575583 def forward (
576584 self ,
577585 x : torch .Tensor ,
@@ -638,10 +646,8 @@ def _use_infer_activation_checkpoint(self, *tensors: torch.Tensor) -> bool:
638646 """
639647 return (
640648 not self .training
641- and os .environ .get ("DP_ACT_INFER" , "" ).strip ().lower ()
642- in {"1" , "true" , "yes" , "on" }
643- and os .environ .get ("DP_COMPILE_INFER" , "" ).strip ().lower ()
644- not in {"1" , "true" , "yes" , "on" }
649+ and self ._act_infer
650+ and not self ._compile_infer
645651 and torch .is_grad_enabled ()
646652 and any (tensor .requires_grad for tensor in tensors )
647653 )
You can’t perform that action at this time.
0 commit comments