@@ -349,9 +349,12 @@ def __init__(
349349 else :
350350 super ().__init__ (in_features , out_features , bias = bias , device = device , dtype = dtype )
351351
352- def forward (self , input : torch .Tensor , no_communication = False ) -> torch .Tensor : # pylint: disable=W0622
352+ self .last_block_layer = False
353+
354+ def forward (self , input : torch .Tensor ) -> torch .Tensor : # pylint: disable=W0622
353355 _class_name = self .__class__ .__name__
354356 assert self ._communicator is not None , f"{ _class_name } should register with a communicator first."
357+ no_communication = bool (gpc .recompute_forward_no_comm and self .last_block_layer )
355358 return fused_dense_func (
356359 input ,
357360 self .weight ,
@@ -414,6 +417,7 @@ def __init__(
414417 multiple_of : int = 1 ,
415418 device : torch .device = None ,
416419 dtype : torch .dtype = None ,
420+ layer_name : str = "default" ,
417421 ) -> None :
418422 if in_features % multiple_of :
419423 raise ValueError (f"in_features ({ in_features } ) must be a multiple of { multiple_of } " )
@@ -430,6 +434,9 @@ def __init__(
430434 split_mode = "row" ,
431435 )
432436
437+ if layer_name == "w2" :
438+ self .last_block_layer = True
439+
433440
434441class ScaleColumnParallelLinear (ParallelLinearWithCommExt ):
435442 """
@@ -471,7 +478,7 @@ def __init__(
471478 self .first_eval_flag = True
472479 self .tmp_weight = None
473480
474- def forward (self , input , no_communication = False ): # pylint: disable=W0622
481+ def forward (self , input ): # pylint: disable=W0622
475482 _class_name = self .__class__ .__name__
476483 assert self ._communicator is not None , f"{ _class_name } should register with a communicator first."
477484
@@ -502,7 +509,6 @@ def forward(self, input, no_communication=False): # pylint: disable=W0622
502509 communicator = self ._communicator ,
503510 module = self ,
504511 bias = self .bias ,
505- no_communication = no_communication ,
506512 )
507513
508514
@@ -603,6 +609,7 @@ def new_linear(
603609 multiple_of ,
604610 device ,
605611 dtype ,
612+ layer_name = name ,
606613 )
607614 else :
608615 err_msg = (
0 commit comments