@@ -621,7 +621,9 @@ def setup_distributed(self, model):
621621 size_auto_wrap_policy = functools .partial (
622622 size_based_auto_wrap_policy , min_num_params = self .fsdp_bucket_params
623623 )
624- zero_bucket_wrap_policy = lambda module , recurse , nonwrapped_numel : nonwrapped_numel >= 0
624+
625+ def zero_bucket_wrap_policy (module , recurse , nonwrapped_numel ):
626+ return nonwrapped_numel >= 0
625627
626628 self .bucketing_mode = self .bucketing_mode or "block"
627629 custom_wrap_policy = {
@@ -657,7 +659,9 @@ def setup_activation_checkpointing(self):
657659 )
658660 return
659661
660- check_fn = lambda submodule : isinstance (submodule , Block )
662+ def check_fn (submodule ):
663+ return isinstance (submodule , Block )
664+
661665 apply_activation_checkpointing (self .model , checkpoint_wrapper_fn = checkpoint_wrapper , check_fn = check_fn )
662666
663667 # TODO(crcrpar): Think of apply `torch.compile` or `thunder.jit` per block/module
@@ -737,10 +741,13 @@ def calculate_model_flops(self):
737741 meta_model = self .init_model ()
738742
739743 x = torch .randint (0 , 1 , (self .micro_batch_size , meta_model .config .block_size ), device = meta )
740- model_fwd = lambda : meta_model (x )
741- model_loss = lambda y : torch .nn .functional .cross_entropy (
742- y .reshape (- 1 , y .size (- 1 )), x .reshape (- 1 ), ignore_index = - 1
743- )
744+
745+ def model_fwd ():
746+ return meta_model (x )
747+
748+ def model_loss (y ):
749+ return torch .nn .functional .cross_entropy (y .reshape (- 1 , y .size (- 1 )), x .reshape (- 1 ), ignore_index = - 1 )
750+
744751 self .perf_metrics ["model_flops" ] = measure_flops (meta_model , model_fwd , model_loss )
745752 finally :
746753 self .device = device
0 commit comments