Skip to content

Commit 10c106b

Browse files
fix lint
1 parent 89ba376 commit 10c106b

File tree

15 files changed

+25
-38
lines changed

15 files changed

+25
-38
lines changed

primus/core/projection/memory_projection/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__all__ = [
44
launch_projection_from_cli,
5-
]
5+
]

primus/core/projection/memory_projection/projection.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
import argparse
21
import os
3-
import sys
42
from pathlib import Path
5-
3+
64
from primus.core.launcher.parser import PrimusParser
75
from primus.core.projection.training_config import convert_primus_config_to_projection_config
86
from primus.core.projection.module_profilers.language_model import build_profiler, get_language_model_profiler_spec
@@ -11,7 +9,7 @@
119
def print_profiler_hierarchy(profiler, batch_size, seq_len, rank=None, name="root", depth=0, visited=None):
1210
"""
1311
Recursively print the profiler hierarchy with num_params and activation_memory for each component.
14-
12+
1513
Args:
1614
profiler: The profiler instance to print
1715
batch_size: Batch size for activation memory calculation
@@ -23,15 +21,15 @@ def print_profiler_hierarchy(profiler, batch_size, seq_len, rank=None, name="roo
2321
"""
2422
if visited is None:
2523
visited = set()
26-
24+
2725
# Avoid infinite recursion if profilers reference each other
2826
profiler_id = id(profiler)
2927
if profiler_id in visited:
3028
return
3129
visited.add(profiler_id)
32-
30+
3331
indent = " " * depth
34-
32+
3533
# Calculate metrics for this profiler
3634
try:
3735
if depth == 0:
@@ -44,7 +42,7 @@ def print_profiler_hierarchy(profiler, batch_size, seq_len, rank=None, name="roo
4442
print(f"{indent}[{name}]")
4543
print(f"{indent} Params: {num_params / 1e9:.6f} Billion ({num_params:,})")
4644
print(f"{indent} Activation Memory: {activation_mem / 1024 / 1024 / 1024:.4f} GB")
47-
45+
4846
# Recursively process sub_profilers if they exist
4947
if hasattr(profiler, 'sub_profilers') and profiler.sub_profilers:
5048
for sub_name, sub_profiler in profiler.sub_profilers.items():
@@ -75,16 +73,16 @@ def launch_projection_from_cli(args, overrides):
7573
seq_len = training_config.runtime_config.sequence_length
7674
batch_size = training_config.runtime_config.micro_batch_size
7775
rank = int(os.getenv('RANK', '0'))
78-
76+
7977
# Print recursive profiler hierarchy with detailed breakdown
8078
print("\n" + "=" * 100)
8179
print(f"[Primus:Projection] Component-wise Profiling Results (Rank {rank}):")
8280
print("=" * 100)
8381
print()
84-
82+
8583
# Print the complete hierarchy recursively
8684
print_profiler_hierarchy(model_profiler, batch_size, seq_len, rank=rank, name="LanguageModelProfiler", depth=0)
87-
85+
8886
# Get overall totals from the model profiler for this rank
8987
num_params = model_profiler.estimated_num_params(rank=rank)
9088
activation_memory = model_profiler.estimated_activation_memory(batch_size, seq_len)
@@ -98,4 +96,4 @@ def launch_projection_from_cli(args, overrides):
9896
f"{activation_memory / 1024 / 1024 / 1024:.4f} GB")
9997
print(f" Projected Total Memory: "
10098
f"{(num_params * num_bytes_per_param + activation_memory) / 1024 / 1024 / 1024:.4f} GB")
101-
print("=" * 100)
99+
print("=" * 100)

primus/core/projection/module_profilers/attention.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77

88
from primus.core.projection.base_module_profiler import BaseModuleProfiler
9-
from primus.core.projection.profiler_spec import ModuleProfilerSpec
10-
from primus.core.projection.training_config import TrainingConfig
119

1210

1311
class AttentionProfiler(BaseModuleProfiler):

primus/core/projection/module_profilers/embedding.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77

88
from primus.core.projection.base_module_profiler import BaseModuleProfiler
9-
from primus.core.projection.profiler_spec import ModuleProfilerSpec
10-
from primus.core.projection.training_config import TrainingConfig
119

1210

1311
class EmbeddingProfiler(BaseModuleProfiler):
@@ -17,5 +15,5 @@ def estimated_num_params(self, rank: int | None = None) -> int:
1715
def estimated_activation_memory(self, batch_size: int, seq_len: int) -> int:
1816
return (batch_size * seq_len //
1917
self.config.model_parallel_config.tensor_model_parallel_size //
20-
self.config.model_parallel_config.context_model_parallel_size *
18+
self.config.model_parallel_config.context_model_parallel_size *
2119
self.config.model_config.hidden_size * 2) # bf16

primus/core/projection/module_profilers/language_model.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def get_layers_for_rank(
9090
total_stages = pp_size
9191
if num_virtual_pipeline_stages is not None:
9292
total_stages = total_stages * num_virtual_pipeline_stages
93-
93+
9494
if n_layers % total_stages != 0:
9595
raise ValueError(
9696
f"Total number of layers ({n_layers}) must be divisible by "
@@ -100,22 +100,22 @@ def get_layers_for_rank(
100100
model_parallel_size = pp_size * tp_size * cp_size * ep_size
101101
model_parallel_rank = global_rank % model_parallel_size
102102
pp_rank = model_parallel_rank // (tp_size * cp_size * ep_size)
103-
103+
104104
# Calculate how many layers are in each virtual stage (chunk)
105105
layers_per_virtual_stage = n_layers // total_stages
106-
106+
107107
# A physical pp_rank hosts multiple virtual stages in an interleaved fashion.
108108
# pp_rank 0 gets virtual stages: 0, pp_size, 2*pp_size, ...
109109
# pp_rank 1 gets virtual stages: 1, pp_size+1, 2*pp_size+1, ...
110110
my_virtual_stages = range(pp_rank, total_stages, pp_size)
111-
111+
112112
assigned_layers = []
113113
for vs_index in my_virtual_stages:
114114
start_layer = vs_index * layers_per_virtual_stage
115115
end_layer = (vs_index + 1) * layers_per_virtual_stage - 1
116116
for layer in range(start_layer, end_layer + 1):
117117
assigned_layers.append(layer)
118-
118+
119119
return assigned_layers
120120

121121
def get_dp_size(self) -> int:
@@ -160,7 +160,6 @@ def estimated_num_params(self, rank: int | None = None) -> int:
160160
total_params += self.sub_profilers["calc_loss"].estimated_num_params(rank)
161161
return total_params
162162

163-
164163
def estimated_activation_memory(self, batch_size: int, seq_len: int) -> int:
165164
total_act = 0
166165
pp_size = self.config.model_parallel_config.pipeline_model_parallel_size
@@ -186,4 +185,4 @@ def estimated_activation_memory(self, batch_size: int, seq_len: int) -> int:
186185
ga = self.config.runtime_config.global_batch_size // self.get_dp_size()
187186
gs_saving = 1 if ga > pp_size else ga / pp_size
188187
total_act *= gs_saving * interleaved_schedule_memory_penalty
189-
return total_act
188+
return total_act

primus/core/projection/module_profilers/loss.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77

88
from primus.core.projection.base_module_profiler import BaseModuleProfiler
9-
from primus.core.projection.profiler_spec import ModuleProfilerSpec
10-
from primus.core.projection.training_config import TrainingConfig
119

1210

1311
class LossProfiler(BaseModuleProfiler):

primus/core/projection/module_profilers/moe_mlp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def estimated_num_params(self, rank: int | None = None) -> int:
1616
moe_ffn = self.config.model_config.moe_ffn_hidden_size
1717
else:
1818
moe_ffn = self.config.model_config.ffn_hidden_size
19-
19+
2020
# For SwiGLU: 3 projections per expert (gate, up, down)
2121
# For standard FFN: 2 projections per expert (up, down)
2222
num_ffn_projections = 3 if self.config.model_config.swiglu else 2
@@ -31,7 +31,7 @@ def estimated_num_params(self, rank: int | None = None) -> int:
3131
if self.config.model_config.moe_shared_expert_intermediate_size is not None:
3232
shared_sz = self.config.model_config.moe_shared_expert_intermediate_size
3333
shared_params = num_ffn_projections * self.config.model_config.hidden_size * shared_sz
34-
34+
3535
return all_experts_params + shared_params
3636

3737
def estimated_activation_memory(self, batch_size: int, seq_len: int) -> int:
@@ -60,4 +60,4 @@ def get_moe_mlp_profiler_spec(config: TrainingConfig) -> ModuleProfilerSpec:
6060
profiler=MoEMLPProfiler,
6161
config=config,
6262
sub_profiler_specs=None,
63-
)
63+
)

primus/core/projection/module_profilers/output_layer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ def estimated_num_params(self, rank: int | None = None) -> int:
1515
def estimated_activation_memory(self, batch_size: int, seq_len: int) -> int:
1616
return (batch_size * seq_len //
1717
self.config.model_parallel_config.tensor_model_parallel_size //
18-
self.config.model_parallel_config.context_model_parallel_size *
18+
self.config.model_parallel_config.context_model_parallel_size *
1919
self.config.model_config.padded_vocab_size * 2) # bf16

primus/core/projection/training_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,4 @@ def convert_primus_config_to_projection_config(primus_config) -> TrainingConfig:
139139
model_parallel_config=model_parallel_config,
140140
)
141141

142-
return training_config
142+
return training_config

primus/tools/benchmark/deepseek_dense_gemm_bench_args.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ def add_gemm_parser(parser: argparse.ArgumentParser):
3232
parser.add_argument("--output-file", default="./gemm-deepseek_report.md")
3333
parser.add_argument("--append", action="store_true", help="Append to existing report")
3434
return parser
35-

0 commit comments

Comments
 (0)