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]
44from beartype import beartype
55import traceback
66import 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 :
0 commit comments