Skip to content

Commit cae050e

Browse files
committed
docs: Add docstrings and type hints
1 parent a394ab0 commit cae050e

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

‎src/modalities/models/gpt2/gpt2_model.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ def __init__(
806806
ffn_norm_config (LayerNormWrapperConfig): Config for the feed-forward network normalization module.
807807
lm_head_norm_config (LayerNormWrapperConfig): Config for the language model head normalization module.
808808
use_weight_tying (bool): Whether to use weight tying.
809-
seed (int, optional): The random seed. Defaults to None.
809+
seed (Optional[int]): The random seed. Defaults to None.
810810
"""
811811
weight_decay_groups = {
812812
"linear": [".attn", ".mlp", ".lm_head.weight"],
@@ -910,6 +910,15 @@ def forward(self, inputs: torch.Tensor) -> torch.Tensor:
910910
...
911911

912912
def forward(self, inputs: dict[str, torch.Tensor] | torch.Tensor) -> dict[str, torch.Tensor] | torch.Tensor:
913+
"""
914+
Forward pass of the GPT2LLM module.
915+
916+
Args:
917+
inputs (dict[str, torch.Tensor] | torch.Tensor): Input data.
918+
919+
Returns:
920+
dict[str, torch.Tensor] | torch.Tensor: Model output.
921+
"""
913922
if isinstance(inputs, dict):
914923
return {self.prediction_key: self.forward_impl(inputs[self.sample_key])}
915924
else:

‎src/modalities/models/model_factory.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ class ModelFactory:
5858

5959
@staticmethod
6060
def _is_model_on_meta_device(model: nn.Module) -> bool:
61+
"""
62+
Checks if all parameters and buffers of the model are on the meta device.
63+
64+
Args:
65+
model (nn.Module): The model to check.
66+
67+
Returns:
68+
bool: True if all parameters and buffers are on meta device, False otherwise.
69+
"""
6170
meta_counter = 0
6271
param_counter = 0
6372
for _, tensor in itertools.chain(model.named_parameters(), model.named_buffers()):

‎src/modalities/running_env/fsdp/device_mesh.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def get_device_mesh(
8484
enable_loss_parallel: bool,
8585
world_size: int,
8686
) -> DeviceMesh:
87-
"""Gets the device mesh for the specified parallelism degrees.
87+
"""
88+
Gets the device mesh for the specified parallelism degrees.
8889
8990
Args:
9091
device_type (str): The device type.

‎src/modalities/trainer.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,24 @@ class ThroughputAggregationKeys(Enum):
2828

2929

3030
class Trainer:
31+
"""
32+
Trainer class for model training.
33+
34+
Args:
35+
global_rank (int): The global rank.
36+
num_pipeline_parallel_ranks (int): Number of pipeline parallel ranks.
37+
progress_publisher (MessagePublisher[ProgressUpdate]): Progress publisher.
38+
evaluation_result_publisher (MessagePublisher[EvaluationResultBatch]): Evaluation result publisher.
39+
gradient_acc_steps (int): Gradient accumulation steps.
40+
global_num_tokens_per_train_step (int): Global number of tokens per train step.
41+
num_seen_train_steps (int): Number of seen train steps.
42+
global_num_seen_tokens (int): Global number of seen tokens.
43+
num_target_steps (int): Number of target steps.
44+
num_target_tokens (int): Number of target tokens.
45+
gradient_clipper (GradientClipperIF): Gradient clipper.
46+
mfu_calculator (Optional[MFUCalculatorABC]): MFU calculator.
47+
"""
48+
3149
def __init__(
3250
self,
3351
global_rank: int,

0 commit comments

Comments
 (0)