[Bugfix] Re-sync parameter tp_rank after process_weights_after_loading (fix replicated / disable_tp weight reload) (#48025)
Signed-off-by: Alex Xu <alexxu@roblox.com> Co-authored-by: YQ-Wang <yiqingwang@roblox.com> Co-authored-by: alexhxu <alex.xu1015@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
YQ-Wang
alexhxu
Cursor
parent
c71a583aa9
commit
d96aee0951
@@ -281,6 +281,15 @@ class LinearBase(PluggableLayer):
|
||||
self.tp_size = get_tensor_model_parallel_world_size() if not disable_tp else 1
|
||||
|
||||
def update_param_tp_status(self):
|
||||
# Single source of truth for a parameter's TP state. BasevLLMParameter
|
||||
# stamps self.tp_rank with the *global* rank in __init__; this reconciles
|
||||
# every child parameter to the *layer's* tp_rank/tp_size (which correctly
|
||||
# accounts for disable_tp -> replicated weights with tp_rank == 0).
|
||||
#
|
||||
# Must be re-run whenever parameters are (re-)created after construction,
|
||||
# e.g. after quant_method.process_weights_after_loading() swaps in fresh
|
||||
# Parameters. Otherwise a later load_weights()/weight-refit would narrow a
|
||||
# replicated weight at global_rank * shard_size and overflow.
|
||||
for param in self.parameters():
|
||||
if isinstance(param, BasevLLMParameter):
|
||||
param.tp_rank = self.tp_rank
|
||||
@@ -910,7 +919,6 @@ class MergedColumnParallelLinear(ColumnParallelLinear):
|
||||
shard_id=loaded_shard_id,
|
||||
shard_offset=shard_offset,
|
||||
shard_size=shard_size,
|
||||
tp_rank=self.tp_rank,
|
||||
)
|
||||
|
||||
def load_weights(
|
||||
@@ -1110,12 +1118,10 @@ class QKVParallelLinear(ColumnParallelLinear):
|
||||
# to ensure that any subsequent reduction (like .max())
|
||||
# works correctly while preserving the parameter shape.
|
||||
for idx in range(param.data.shape[0]):
|
||||
param.load_qkv_weight(
|
||||
loaded_weight=loaded_weight, shard_id=idx, tp_rank=self.tp_rank
|
||||
)
|
||||
param.load_qkv_weight(loaded_weight=loaded_weight, shard_id=idx)
|
||||
return
|
||||
elif type(param) in (RowvLLMParameter, BasevLLMParameter):
|
||||
param.load_qkv_weight(loaded_weight=loaded_weight, tp_rank=self.tp_rank)
|
||||
param.load_qkv_weight(loaded_weight=loaded_weight)
|
||||
return
|
||||
# TODO: @dsikka - move to parameter.py
|
||||
self._load_fused_module_from_checkpoint(param, loaded_weight)
|
||||
@@ -1139,7 +1145,6 @@ class QKVParallelLinear(ColumnParallelLinear):
|
||||
shard_id=loaded_shard_id,
|
||||
shard_offset=shard_offset,
|
||||
shard_size=shard_size,
|
||||
tp_rank=self.tp_rank,
|
||||
)
|
||||
|
||||
def weight_loader(
|
||||
@@ -1493,7 +1498,6 @@ class MinimaxM3QKVParallelLinearWithIndexer(QKVParallelLinear):
|
||||
shard_id=loaded_shard_id,
|
||||
shard_offset=shard_offset,
|
||||
shard_size=shard_size,
|
||||
tp_rank=self.tp_rank,
|
||||
)
|
||||
|
||||
def weight_loader(
|
||||
|
||||
Reference in New Issue
Block a user