Skip to content

Commit dac3f8b

Browse files
committed
modify type check ignores
1 parent 8dd5462 commit dac3f8b

14 files changed

Lines changed: 74 additions & 70 deletions

File tree

RoundPipe/RoundPipe.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""The RoundPipe model wrapper and execution runtime."""
22

3-
from beartype.typing import * # type: ignore[reportWildcardImportFromLibrary]
3+
from beartype.typing import * # pyright: ignore[reportWildcardImportFromLibrary]
44
from beartype import beartype
55
import traceback
66
import copy
@@ -66,7 +66,7 @@ def __init__(self,
6666

6767
self.num_layers: int = len(self.layers)
6868
self.layer_workload: List[float] = []
69-
self.layer_gradient_ready_events: List[torch.cuda.Event] = [torch.cuda.Event() for _ in range(self.num_layers)] # type: ignore[reportAttributeAccessIssue]
69+
self.layer_gradient_ready_events: List[torch.cuda.Event] = [torch.cuda.Event() for _ in range(self.num_layers)] # pyright: ignore[reportAttributeAccessIssue]
7070
for layer in self.layers:
7171
self.layer_workload.append(get_model_size(layer))
7272
self.model_timer: ModelTimer = ModelTimer(self.num_layers)
@@ -76,13 +76,13 @@ def __init__(self,
7676
pinned_tensor = torch.empty_like(parm.data, dtype=torch.float16 if use_fp16 and parm.is_floating_point() else None, pin_memory=True)
7777
pinned_tensor.copy_(parm.data)
7878
parm.data = pinned_tensor
79-
parm.data_cpu = pinned_tensor # type: ignore[attr-defined]
79+
parm.data_cpu = pinned_tensor # pyright: ignore[reportAttributeAccessIssue]
8080
for buffer in tqdm.tqdm(self.model.buffers(), total=sum(1 for _ in self.model.buffers()),
8181
desc=f'Roundpipe: Process buffers in {self.name}', leave=False):
8282
pinned_tensor = torch.empty_like(buffer.data, dtype=torch.float16 if use_fp16 and buffer.is_floating_point() else None, pin_memory=True)
8383
pinned_tensor.copy_(buffer.data)
8484
buffer.data = pinned_tensor
85-
buffer.data_cpu = pinned_tensor # type: ignore[attr-defined]
85+
buffer.data_cpu = pinned_tensor # pyright: ignore[reportAttributeAccessIssue]
8686

8787
self.RoundPipe_initialized: bool = True
8888

@@ -157,7 +157,7 @@ def forward(self, *args: Any,
157157
tag = backward_schedule_simulator.get_next_tag()
158158
for context in reversed(run_context):
159159
tag, output_require_grad_idx, *output_require_grad \
160-
= RoundPipeMicrobatchBackward.apply(context, batch, tag, *context.flatten_inputs[0]) # type: ignore
160+
= RoundPipeMicrobatchBackward.apply(context, batch, tag, *context.flatten_inputs[0]) # pyright: ignore[reportGeneralTypeIssues]
161161
for idx, item in zip(output_require_grad_idx, output_require_grad):
162162
batch.flatten_states[context.microbatch_id][idx] = item
163163
backward_schedule_simulator.update_current_tag(tag)
@@ -166,7 +166,7 @@ def forward(self, *args: Any,
166166
# ensuring gradients to be calculated even if inputs do not require grad.
167167
all_inputs = [item for batch_context in run_context
168168
for item in batch_context.flatten_inputs[0]]
169-
output_require_grad_idx, *output_require_grad = RoundPipeBatchedBackward.apply(run_context, batch, gradient_anchor, *all_inputs) # type: ignore
169+
output_require_grad_idx, *output_require_grad = RoundPipeBatchedBackward.apply(run_context, batch, gradient_anchor, *all_inputs) # pyright: ignore[reportGeneralTypeIssues]
170170
for (batch_idx, idx), item in zip(output_require_grad_idx, output_require_grad):
171171
batch.flatten_states[batch_idx][idx] = item
172172

@@ -207,7 +207,7 @@ def train_iter(self, input_args: Tuple[Any, ...] = (),
207207
context.input_backward_events = batch.backward_events[batch_idx]
208208

209209
all_inputs = [item for batch_input in batch.flatten_states for item in batch_input]
210-
input_backward_handle: torch.Tensor = RoundPipeInputBackward.apply(run_context, *all_inputs) # type: ignore
210+
input_backward_handle: torch.Tensor = RoundPipeInputBackward.apply(run_context, *all_inputs) # pyright: ignore[reportAssignmentType]
211211

212212
for layer_group_id in range(len(execute_plan.fwd_plan)):
213213
device = get_next_device()
@@ -225,7 +225,9 @@ def train_iter(self, input_args: Tuple[Any, ...] = (),
225225
if isinstance(batch.loss_list[0], torch.Tensor):
226226
loss = torch.zeros_like(batch.loss_list[0], device=torch.device('cpu'))
227227
for batch_loss in batch.loss_list:
228-
loss = loss + batch_loss.cpu() # type: ignore[reportOperatorIssue]
228+
assert isinstance(batch_loss, torch.Tensor), \
229+
"Inconsistent loss types across microbatches."
230+
loss = loss + batch_loss.cpu()
229231
else:
230232
loss = [torch.zeros_like(t, device=torch.device('cpu')) for t in batch.loss_list[0]]
231233
for batch_loss in batch.loss_list:

RoundPipe/RunConfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Runtime configuration objects shared across RoundPipe components."""
22

3-
from beartype.typing import * # type: ignore[reportWildcardImportFromLibrary]
3+
from beartype.typing import * # pyright: ignore[reportWildcardImportFromLibrary]
44
from beartype import beartype
55

66
import torch

RoundPipe/batch.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
avg_reducer: Predefined reducer that averages scalar losses across microbatches.
1010
"""
1111

12-
from beartype.typing import * # type: ignore[reportWildcardImportFromLibrary]
12+
from beartype.typing import * # pyright: ignore[reportWildcardImportFromLibrary]
1313
import warnings
1414

1515
import torch
@@ -90,14 +90,14 @@ def get_avg_reducer_args() -> Tuple[torch.Tensor, Callable[[torch.Tensor, torch.
9090
a reducer callable that updates the running average.
9191
"""
9292
init_val = torch.tensor(0)
93-
init_val.roundpipe_avg_reducer_sum = torch.tensor(0) # type: ignore[reportAttributeAccessIssue]
94-
init_val.roundpipe_avg_reducer_count = 0 # type: ignore[reportAttributeAccessIssue]
93+
init_val.roundpipe_avg_reducer_sum = torch.tensor(0) # pyright: ignore[reportAttributeAccessIssue]
94+
init_val.roundpipe_avg_reducer_count = 0 # pyright: ignore[reportAttributeAccessIssue]
9595
def reduce(reduced_val: torch.Tensor, new_val: torch.Tensor) -> torch.Tensor:
96-
val_sum = reduced_val.roundpipe_avg_reducer_sum + new_val # type: ignore[reportAttributeAccessIssue]
97-
val_count = reduced_val.roundpipe_avg_reducer_count + 1 # type: ignore[reportAttributeAccessIssue]
96+
val_sum = reduced_val.roundpipe_avg_reducer_sum + new_val # pyright: ignore[reportAttributeAccessIssue]
97+
val_count = reduced_val.roundpipe_avg_reducer_count + 1 # pyright: ignore[reportAttributeAccessIssue]
9898
new_reduced = val_sum / val_count
99-
new_reduced.roundpipe_avg_reducer_sum = val_sum # type: ignore[reportAttributeAccessIssue]
100-
new_reduced.roundpipe_avg_reducer_count = val_count # type: ignore[reportAttributeAccessIssue]
99+
new_reduced.roundpipe_avg_reducer_sum = val_sum # pyright: ignore[reportAttributeAccessIssue]
100+
new_reduced.roundpipe_avg_reducer_count = val_count # pyright: ignore[reportAttributeAccessIssue]
101101
return new_reduced
102102
return init_val, reduce
103103
avg_reducer: _CustomReducer = _CustomReducer(*get_avg_reducer_args())
@@ -153,7 +153,7 @@ def __init__(self, args: Tuple, kwargs: Dict[str, Any],
153153
for batch_idx, args_kwargs in enumerate(zip(args_list, kwargs_list)):
154154
forward_event: Set[torch.cuda.Event] = set()
155155
backward_event: Set[torch.cuda.Event] = set()
156-
cpu_tensor_backward_event: torch.cuda.Event = torch.cuda.Event() # type: ignore[reportAssignmentType]
156+
cpu_tensor_backward_event: torch.cuda.Event = torch.cuda.Event() # pyright: ignore[reportAssignmentType]
157157
flatten_input, flatten_spec = tree_flatten(args_kwargs)
158158
for idx, item in enumerate(flatten_input):
159159
if isinstance(item, torch.Tensor):

RoundPipe/device.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
cur_device: Index tracking the next device to schedule work on.
66
"""
77

8-
from beartype.typing import * # type: ignore[reportWildcardImport]
8+
from beartype.typing import * # pyright: ignore[reportWildcardImportFromLibrary]
99
from enum import Enum
1010
import threading
1111
import itertools
@@ -142,10 +142,10 @@ def __init__(self, id: int, device: torch.device):
142142
self.id: int = id
143143
self.device: torch.device = device
144144

145-
self.param_upstream: torch.cuda.Stream = torch.cuda.Stream(device) # type: ignore[reportAttributeAccessIssue]
146-
self.upstream: torch.cuda.Stream = torch.cuda.Stream(device) # type: ignore[reportAttributeAccessIssue]
145+
self.param_upstream: torch.cuda.Stream = torch.cuda.Stream(device) # pyright: ignore[reportAttributeAccessIssue]
146+
self.upstream: torch.cuda.Stream = torch.cuda.Stream(device) # pyright: ignore[reportAttributeAccessIssue]
147147
self.compute_stream: torch.cuda.Stream = torch.cuda.default_stream(self.device)
148-
self.downstream: torch.cuda.Stream = torch.cuda.Stream(device) # type: ignore[reportAttributeAccessIssue]
148+
self.downstream: torch.cuda.Stream = torch.cuda.Stream(device) # pyright: ignore[reportAttributeAccessIssue]
149149
self.mem_manager: InterStreamMemManager = InterStreamMemManager(
150150
self.param_upstream, self.upstream, self.compute_stream, self.downstream
151151
)
@@ -174,7 +174,7 @@ def mark_upload(self) -> None:
174174
Returns:
175175
The recorded event is appended to ``upload_mark``.
176176
"""
177-
event: torch.cuda.Event = torch.cuda.Event() # type: ignore[reportAttributeAccessIssue]
177+
event: torch.cuda.Event = torch.cuda.Event() # pyright: ignore[reportAssignmentType]
178178
with torch.cuda.stream(self.upstream):
179179
event.record()
180180
self.upload_mark.append(event)

RoundPipe/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
to their corresponding wrapper module paths.
1010
"""
1111

12-
from beartype.typing import * # type: ignore[reportWildcardImportFromLibrary]
12+
from beartype.typing import * # pyright: ignore[reportWildcardImportFromLibrary]
1313
import importlib
1414

1515
from ..RoundPipe import RoundPipe

RoundPipe/models/function.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from beartype.typing import * # type: ignore[reportWildcardImportFromLibrary]
1+
from beartype.typing import * # pyright: ignore[reportWildcardImportFromLibrary]
22
import types
33
import math
44

@@ -28,7 +28,7 @@ def forward(ctx: Any, logits: torch.Tensor, labels: torch.Tensor,
2828
return loss
2929

3030
@staticmethod
31-
def backward(ctx: Any, grad_loss: torch.Tensor) -> Tuple[Optional[torch.Tensor], ...]: # type: ignore[override]
31+
def backward(ctx: Any, grad_loss: torch.Tensor) -> Tuple[Optional[torch.Tensor], ...]: # pyright: ignore[reportIncompatibleMethodOverride]
3232
logits, labels, num_items_in_batch = ctx.saved_tensors
3333
grad_logits = torch.empty_like(logits)
3434

RoundPipe/models/qwen3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from beartype.typing import * # type: ignore[reportWildcardImportFromLibrary]
1+
from beartype.typing import * # pyright: ignore[reportWildcardImportFromLibrary]
22
import warnings
33

44
import torch
@@ -24,7 +24,7 @@ def forward(
2424
attention_mask: Optional[torch.Tensor] = None,
2525
position_ids: Optional[torch.Tensor] = None,
2626
past_key_values: Optional[Any] = None,
27-
inputs_embeds: Optional[torch.Tensor] = None, # type: ignore[reportRedeclaration]
27+
inputs_embeds: Optional[torch.Tensor] = None, # pyright: ignore[reportRedeclaration]
2828
labels: Optional[torch.Tensor] = None,
2929
use_cache: Optional[bool] = None,
3030
cache_position: Optional[torch.Tensor] = None,

RoundPipe/profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
PROFILER_TYPE: Type of profiler detected from environment variables.
55
"""
66

7-
from beartype.typing import * # type: ignore[reportWildcardImportFromLibrary]
7+
from beartype.typing import * # pyright: ignore[reportWildcardImportFromLibrary]
88

99
import os
1010
import contextlib

0 commit comments

Comments
 (0)