Skip to content

Commit 47bc53e

Browse files
authored
make ruff rules similar between models and recipes (#1369)
Signed-off-by: Peter St. John <pstjohn@nvidia.com>
1 parent 1fb789b commit 47bc53e

14 files changed

Lines changed: 16 additions & 16 deletions

File tree

bionemo-recipes/recipes/.ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ line-length = 119
22
target-version = "py312"
33

44
[lint]
5-
ignore = ["D100", "E501", "N811", "N814"]
5+
ignore = ["C901", "D100", "E501", "N811", "N814"]
66
select = [
77
"C", # Pylint conventions
88
"D", # Documentation formatting

bionemo-recipes/recipes/codonfm_ptl_te/src/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242

4343
# Datasets
44-
def get_dataset_config(args: Any, process_item_cfg: fdl.Partial) -> fdl.Config: # noqa: C901
44+
def get_dataset_config(args: Any, process_item_cfg: fdl.Partial) -> fdl.Config:
4545
"""Builds the dataset configuration."""
4646
class_name = args.dataset_name
4747
if class_name == "CodonMemmapDataset":

bionemo-recipes/recipes/codonfm_ptl_te/src/data/codon_memmap_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class CodonMemmapDataset(torch.utils.data.Dataset):
6262
**IMPORTANT** this works because we aren't mutating the underlying data between these splits, and only the indices are modified.
6363
"""
6464

65-
def __init__( # noqa: C901, D107
65+
def __init__( # noqa: D107
6666
self,
6767
data_path: str,
6868
tokenizer: Callable,

bionemo-recipes/recipes/codonfm_ptl_te/src/models/components/encodon_te.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(self, config):
106106
self.te_rope_emb = None
107107
self._init_weights()
108108

109-
def reset_cls_parameters(self): # noqa: C901
109+
def reset_cls_parameters(self):
110110
"""Resets the parameters of the classification head."""
111111
for module in self.cls.modules():
112112
if isinstance(module, (nn.Linear, transformer_engine.pytorch.Linear)):
@@ -136,7 +136,7 @@ def reset_cls_parameters(self): # noqa: C901
136136
if module.layer_norm_bias is not None:
137137
module.layer_norm_bias.data.zero_()
138138

139-
def _init_weights(self): # noqa: C901
139+
def _init_weights(self):
140140
"""Initializes the weights of the model using the MAGNETO initialization scheme."""
141141
for name, module in self.named_modules():
142142
if isinstance(module, (nn.Linear, transformer_engine.pytorch.Linear)):

bionemo-recipes/recipes/codonfm_ptl_te/src/models/components/encodon_te_layer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class EncodonTELayer(torch.nn.Module):
266266
QK normalization at different points.
267267
""" # noqa: D205
268268

269-
def __init__( # noqa: D107, C901
269+
def __init__( # noqa: D107
270270
self,
271271
hidden_size: int,
272272
ffn_hidden_size: int,
@@ -573,7 +573,7 @@ def set_context_parallel_group(
573573
if hasattr(child, "set_context_parallel_group"):
574574
child.set_context_parallel_group(cp_group, cp_global_ranks, cp_stream, cp_comm_type)
575575

576-
def forward( # noqa: C901
576+
def forward(
577577
self,
578578
hidden_states: torch.Tensor,
579579
attention_mask: Optional[torch.Tensor] = None,

bionemo-recipes/recipes/codonfm_ptl_te/src/models/components/encodon_te_mha.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def set_context_parallel_group(
591591
if hasattr(child, "set_context_parallel_group"):
592592
child.set_context_parallel_group(cp_group, cp_global_ranks, cp_stream, cp_comm_type)
593593

594-
def forward( # noqa: C901
594+
def forward(
595595
self,
596596
hidden_states: torch.Tensor,
597597
attention_mask: Optional[Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]] = None,

bionemo-recipes/recipes/codonfm_ptl_te/src/models/encodon_pl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def __init__( # noqa: D107
139139
# When downstream head is disabled, use cross-entropy for language modeling
140140
self.loss = torch.nn.CrossEntropyLoss(ignore_index=ignore_index)
141141

142-
def configure_model(self, state_dict: Optional[Dict[str, Any]] = None) -> None: # noqa: C901
142+
def configure_model(self, state_dict: Optional[Dict[str, Any]] = None) -> None:
143143
"""Configure the underlying model and optionally load weights.
144144
145145
Sets up the base EnCodon model, attaches optional downstream heads, and

bionemo-recipes/recipes/codonfm_ptl_te/src/models/encodon_te_pl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def __init__( # noqa: D107
143143

144144
self.attn_input_format = attn_input_format
145145

146-
def configure_model(self, state_dict: Optional[Dict[str, Any]] = None) -> None: # noqa: C901
146+
def configure_model(self, state_dict: Optional[Dict[str, Any]] = None) -> None:
147147
"""Configure the model, optionally loading a state dict.
148148
149149
Args:

bionemo-recipes/recipes/codonfm_ptl_te/src/runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def get_parser(): # noqa: D103
228228
return parser
229229

230230

231-
def main(): # noqa: C901, D103
231+
def main(): # noqa: D103
232232
parser = get_parser()
233233
args = parser.parse_args()
234234
if args.mode in ["eval"] and not args.checkpoint_path:

bionemo-recipes/recipes/codonfm_ptl_te/src/utils/pred_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _save_predictions(self, trainer, batch_idx):
104104
np.save(file_path, value)
105105
self.predictions_buffer.clear()
106106

107-
def _merge_predictions(self): # noqa: C901
107+
def _merge_predictions(self):
108108
"""Merge per-rank shard files into a single array per key.
109109
110110
The method reconstructs the original sample ordering based on the DDP

0 commit comments

Comments
 (0)