@@ -328,11 +328,11 @@ def _abstain_prediction_uniform(rng: np.random.Generator, n_classes: int) -> Lab
328328def _batch_test (rng : np .random .Generator , learner : Classifier , x : Tensor ) -> np .ndarray :
329329 """Test a batch of instances using the learner."""
330330 batch_size = x .shape [0 ]
331- x = x .view (batch_size , - 1 )
332331 if isinstance (learner , BatchClassifier ):
333332 x = x .to (dtype = learner .x_dtype , device = learner .device )
334333 return learner .batch_predict (x ).cpu ().numpy ()
335334 else :
335+ x = x .view (batch_size , - 1 )
336336 yb_pred = np .zeros (batch_size , dtype = int )
337337 for i in range (batch_size ):
338338 instance = Instance .from_array (learner .schema , x [i ].numpy ())
@@ -345,16 +345,16 @@ def _batch_test(rng: np.random.Generator, learner: Classifier, x: Tensor) -> np.
345345 return yb_pred
346346
347347
348- def _batch_train (learner : Classifier , x : Tensor , y : Tensor ):
348+ def _batch_train (learner : Classifier , x : Tensor , y : Tensor , x_shape : Sequence [ int ] ):
349349 """Train a batch of instances using the learner."""
350- batch_size = x .shape [0 ]
351- x = x .view (batch_size , - 1 )
350+ bs = x .shape [0 ]
352351 if isinstance (learner , BatchClassifier ):
353- x = x .to (dtype = learner .x_dtype , device = learner .device )
352+ x = x .to (dtype = learner .x_dtype , device = learner .device ). view ( bs , * x_shape )
354353 y = y .to (dtype = learner .y_dtype , device = learner .device )
355354 learner .batch_train (x , y )
356355 else :
357- for i in range (batch_size ):
356+ x = x .view (bs , - 1 )
357+ for i in range (bs ):
358358 instance = LabeledInstance .from_array (
359359 learner .schema , x [i ].numpy (), int (y [i ].item ())
360360 )
@@ -441,7 +441,7 @@ def ocl_train_eval_loop(
441441 yb : Tensor
442442 pbar .update (1 )
443443 yb_pred = _batch_test (rng , learner , xb )
444- _batch_train (learner , xb , yb )
444+ _batch_train (learner , xb , yb , learner . schema . shape )
445445
446446 for y , y_pred in zip (yb , yb_pred , strict = True ):
447447 online_eval .update (y .item (), y_pred )
0 commit comments