Skip to content

Commit caa7d91

Browse files
h-joorecml authors
authored andcommitted
Internal change
PiperOrigin-RevId: 941084384
1 parent 40dd352 commit caa7d91

14 files changed

Lines changed: 53 additions & 53 deletions

File tree

recml/core/metrics/confusion_metrics.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def compute(self) -> float | Sequence[float]:
8383
precision_ = _np_divide_no_nan(
8484
self.true_positives, self.true_positives + self.false_positives
8585
)
86-
return _maybe_squeeze(precision_)
86+
return _maybe_squeeze(precision_) # pyrefly: ignore[bad-return]
8787

8888

8989
class Recall(ConfusionMetric):
@@ -93,7 +93,7 @@ def compute(self) -> float | Sequence[float]:
9393
recall_ = _np_divide_no_nan(
9494
self.true_positives, self.true_positives + self.false_negatives
9595
)
96-
return _maybe_squeeze(recall_)
96+
return _maybe_squeeze(recall_) # pyrefly: ignore[bad-return]
9797

9898

9999
class FBeta(ConfusionMetric):
@@ -145,7 +145,7 @@ def compute(self) -> float | Sequence[float]:
145145
recall_ = _np_divide_no_nan(
146146
self.true_positives, self.true_positives + self.false_negatives
147147
)
148-
return _maybe_squeeze(
148+
return _maybe_squeeze( # pyrefly: ignore[bad-return]
149149
_np_divide_no_nan(
150150
np.multiply(precision_, recall_) * (self.beta + 1.0),
151151
np.multiply(precision_, self.beta) + recall_,
@@ -174,7 +174,7 @@ def from_model_output(
174174
predictions=y_pred,
175175
labels=y_true,
176176
weights=weights,
177-
thresholds=default_thresholds(num_thresholds),
177+
thresholds=default_thresholds(num_thresholds), # pyrefly: ignore[bad-argument-type]
178178
)
179179
return cls(
180180
true_positives=tp,
@@ -237,7 +237,7 @@ def compute(self) -> float:
237237
self.false_positives, self.false_positives + self.true_negatives
238238
)
239239
# We negate the integral because the thresholds are in ascending order.
240-
return -np.trapezoid(tp_rate, fp_rate)
240+
return -np.trapezoid(tp_rate, fp_rate) # pyrefly: ignore[bad-return]
241241

242242

243243
class PrecisionAtRecall(ConfusionMetric):
@@ -261,7 +261,7 @@ def from_model_output(
261261
predictions=y_pred,
262262
labels=y_true,
263263
weights=weights,
264-
thresholds=default_thresholds(num_thresholds),
264+
thresholds=default_thresholds(num_thresholds), # pyrefly: ignore[bad-argument-type]
265265
)
266266
return cls(
267267
true_positives=tp,
@@ -593,7 +593,7 @@ def _estimate_confusion_matrix(thresholds: jt.Scalar) -> tuple[
593593

594594
return jnp.sum(tp), jnp.sum(tn), jnp.sum(fp), jnp.sum(fn)
595595

596-
thresholds = jnp.asarray(thresholds, dtype=jnp.float32)
596+
thresholds = jnp.asarray(thresholds, dtype=jnp.float32) # pyrefly: ignore[bad-assignment]
597597
return jax.vmap(_estimate_confusion_matrix)(thresholds)
598598

599599

recml/core/metrics/reduction_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def from_fun(cls, fun: Callable[..., Any], **kwargs) -> type[Self]:
3939
base_cls = cls
4040
bound_kwargs = kwargs
4141

42-
class _FromFun(cls):
42+
class _FromFun(cls): # pyrefly: ignore[invalid-inheritance]
4343
"""A reduction metric that is computed from a function."""
4444

4545
@classmethod

recml/core/metrics/tools.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def compute_and_log_scalars(
112112
for k, v in scalars.items()
113113
if not isinstance(metrics[k], base_metrics.ScalarMetric)
114114
}
115-
self._writer.write_scalars(step, non_reported_scalars)
115+
self._writer.write_scalars(step, non_reported_scalars) # pyrefly: ignore[bad-argument-type]
116116
self._writer.flush()
117117

118118
return scalars
@@ -133,7 +133,7 @@ def merge_metrics(
133133
merged_metrics = {}
134134
for k in [*a.keys(), *b.keys()]:
135135
if k in a and k in b:
136-
merged_metrics[k] = a[k].merge(b[k])
136+
merged_metrics[k] = a[k].merge(b[k]) # pyrefly: ignore[bad-argument-type]
137137
elif k in a:
138138
merged_metrics[k] = a[k]
139139
elif k in b:
@@ -156,4 +156,4 @@ def _localize_and_log_scalars(
156156
) -> None:
157157
"""Localizes the metrics from device to host and logs scalars."""
158158
scalar_metrics = jax.tree.map(_localize, scalar_metrics)
159-
summary_writer.write_scalars(step, compute_metrics(scalar_metrics))
159+
summary_writer.write_scalars(step, compute_metrics(scalar_metrics)) # pyrefly: ignore[bad-argument-type]

recml/core/ops/hstu_ops.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _apply_mask(
139139
# need to keep into account the current shard along Q sequence.
140140

141141
if k_in_lanes:
142-
assert q_sequence_ref.shape == (bq, NUM_LANES)
142+
assert q_sequence_ref.shape == (bq, NUM_LANES) # pyrefly: ignore[missing-attribute]
143143

144144
k_sequence = k_offset + jax.lax.broadcasted_iota(
145145
jnp.int32, (bq, k_slice.size), 1
@@ -148,15 +148,15 @@ def _apply_mask(
148148
repeats, rem = divmod(k_slice.size, NUM_LANES)
149149
assert rem == 0
150150
q_sequence = jnp.tile(
151-
q_sequence_ref[...], (1, repeats)
151+
q_sequence_ref[...], (1, repeats) # pyrefly: ignore[unsupported-operation]
152152
) # [bq, k_slice.size]
153153
else:
154-
assert q_sequence_ref.shape == (NUM_SUBLANES, bq)
154+
assert q_sequence_ref.shape == (NUM_SUBLANES, bq) # pyrefly: ignore[missing-attribute]
155155

156156
k_sequence = k_offset + jax.lax.broadcasted_iota(
157157
jnp.int32, (k_slice.size, bq), 0
158158
)
159-
q_sequence = q_sequence_ref[:1, :] # [1, bq]
159+
q_sequence = q_sequence_ref[:1, :] # [1, bq] # pyrefly: ignore[unsupported-operation]
160160
q_sequence = jnp.broadcast_to(q_sequence, (k_slice.size, bq))
161161

162162
assert q_sequence.shape == k_sequence.shape
@@ -244,7 +244,7 @@ def body(kv_compute_index, _):
244244
q_sequence_ref=q_sequence_ref,
245245
q_segment_ids_ref=q_segment_ids_ref,
246246
kv_segment_ids_ref=kv_segment_ids_ref,
247-
k_slice=slice_k,
247+
k_slice=slice_k, # pyrefly: ignore[bad-argument-type]
248248
# When the iteration space is shrunk (for local attention for example),
249249
# the kv_index program_id does not correspond to the actual coordinates
250250
# of the KV data. Make sure to use the 'unshrunk' index (coming from the
@@ -479,7 +479,7 @@ def body(i, _):
479479
q_sequence_ref,
480480
q_segment_ids_ref,
481481
kv_segment_ids_ref,
482-
k_slice=slice_k,
482+
k_slice=slice_k, # pyrefly: ignore[bad-argument-type]
483483
k_offset=j * bkv + i * bkv_compute,
484484
bq=bq,
485485
k_in_lanes=False,

recml/core/training/core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ def get_iterators(
161161
"""Creates and unpacks the datasets returned by the task."""
162162
if isinstance(datasets, (iterator.Iterator, tf.data.Dataset)):
163163
if isinstance(datasets, tf.data.Dataset):
164-
datasets = iterator.TFDatasetIterator(datasets)
165-
return datasets, {}
164+
datasets = iterator.TFDatasetIterator(datasets) # pyrefly: ignore[bad-assignment]
165+
return datasets, {} # pyrefly: ignore[bad-return]
166166
elif not isinstance(datasets, tuple) and len(datasets) != 2:
167167
raise ValueError(
168168
"Expected `datasets` to be a single dataset or a tuple of training"
@@ -195,7 +195,7 @@ def get_iterators(
195195

196196
if all(isinstance(v, tf.data.Dataset) for v in eval_datasets.values()):
197197
eval_datasets = {
198-
k: iterator.TFDatasetIterator(v) for k, v in eval_datasets.items()
198+
k: iterator.TFDatasetIterator(v) for k, v in eval_datasets.items() # pyrefly: ignore[bad-argument-type]
199199
}
200200

201201
if not all(isinstance(v, iterator.Iterator) for v in eval_datasets.values()):

recml/core/training/jax_trainer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def update(self, *, grads: PyTree, **kwargs) -> Self:
265265
tvars_ = dict(zip(self.tvars_paths, self.tvars))
266266
updates, new_opt_state = self.tx.update(grads_, self.opt_state, tvars_)
267267
new_tvars_ = optax.apply_updates(tvars_, updates)
268-
new_tvars = [new_tvars_[path] for path in self.tvars_paths]
268+
new_tvars = [new_tvars_[path] for path in self.tvars_paths] # pyrefly: ignore[bad-index]
269269
return self.replace(
270270
step=self.step + 1,
271271
tvars=new_tvars,
@@ -881,7 +881,7 @@ def _name(prefix: str, key: str) -> str:
881881
def _add_optimizer_metrics(opt_state: optax.OptState, prefix: str):
882882
if isinstance(opt_state, optax.MultiTransformState):
883883
for name, inner_state in opt_state.inner_states.items():
884-
_add_optimizer_metrics(inner_state, _name(prefix, name))
884+
_add_optimizer_metrics(inner_state, _name(prefix, name)) # pyrefly: ignore[bad-argument-type]
885885
elif isinstance(
886886
opt_state,
887887
(optax.InjectStatefulHyperparamsState, optax.InjectHyperparamsState),
@@ -892,7 +892,7 @@ def _add_optimizer_metrics(opt_state: optax.OptState, prefix: str):
892892
and np.prod(hparam.shape) == 1
893893
):
894894
metrics[f"optimizer/{_name(prefix, key)}"] = base_metrics.scalar(
895-
hparam
895+
hparam # pyrefly: ignore[bad-argument-type]
896896
)
897897
elif isinstance(opt_state, (list, tuple)):
898898
for opt_state in opt_state:

recml/core/training/keras_trainer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def train_callbacks(self) -> list[keras.callbacks.Callback]:
184184
),
185185
]
186186

187-
return callbacks
187+
return callbacks # pyrefly: ignore[bad-return]
188188

189189
return [
190190
keras.callbacks.TensorBoard(
@@ -310,7 +310,7 @@ def evaluate(self, task: KerasTask) -> core.Logs:
310310
return_dict=True,
311311
)
312312
epoch_dt = time.time() - epoch_start_time
313-
steps_per_second = self._steps_per_eval / epoch_dt
313+
steps_per_second = self._steps_per_eval / epoch_dt # pyrefly: ignore[unsupported-operation]
314314
val_logs = {"val_" + k: v for k, v in history.items()}
315315
val_logs["val_steps_per_second"] = steps_per_second
316316
tb_cbk.on_epoch_end(0, val_logs)
@@ -439,7 +439,7 @@ def on_test_begin(self, logs: Mapping[str, Any] | None = None):
439439
f" {psutil.Process().memory_info().rss / 1024 ** 2:.1f} MB"
440440
)
441441
epoch_dt = time.time() - epoch_start_time
442-
steps_per_second = self._steps_per_eval / epoch_dt
442+
steps_per_second = self._steps_per_eval / epoch_dt # pyrefly: ignore[unsupported-operation]
443443

444444
val_logs = {"val_" + k: v for k, v in history.items()}
445445
val_logs["val_steps_per_second"] = steps_per_second

recml/core/training/partitioning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def partition_init(
248248
specs = nn.get_partition_spec(abstract_state)
249249

250250
if self.rules is not None:
251-
specs = nn.logical_to_mesh(specs, self.rules)
251+
specs = nn.logical_to_mesh(specs, self.rules) # pyrefly: ignore[bad-argument-type]
252252

253253
state_sharding = jax.tree.map(
254254
lambda x: jax.sharding.NamedSharding(self.mesh, x), specs

recml/core/utils/keras_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def restore_keras_checkpoint(
332332
# TODO(aahil): Look into converging the logic here with the checkpointing
333333
# logic in KerasOrbaxCheckpointManagerV2.
334334
checkpointer = ocp.Checkpointer(
335-
ocp.CompositeCheckpointHandler(**{
335+
ocp.CompositeCheckpointHandler(**{ # pyrefly: ignore[bad-argument-type]
336336
STATE_CHECKPOINT_KEY: ocp.handlers.PyTreeCheckpointHandler(
337337
restore_concurrent_gb=96,
338338
),
@@ -360,7 +360,7 @@ def restore_keras_checkpoint(
360360
var._value = restored_var # pylint: disable=protected-access
361361

362362
if restore_model_epoch:
363-
model._initial_epoch = epoch + 1 # pylint: disable=protected-access
363+
model._initial_epoch = epoch + 1 # pylint: disable=protected-access # pyrefly: ignore[unsupported-operation]
364364
if restore_optimizer_vars and not restore_iterations:
365365
model.optimizer.iterations.assign(0)
366366

@@ -380,7 +380,7 @@ def load_keras_model_config(
380380

381381
json_checkpointer = ocp.Checkpointer(
382382
ocp.CompositeCheckpointHandler(
383-
**{CONFIG_CHECKPOINT_KEY: ocp.handlers.JsonCheckpointHandler()}
383+
**{CONFIG_CHECKPOINT_KEY: ocp.handlers.JsonCheckpointHandler()} # pyrefly: ignore[bad-argument-type]
384384
)
385385
)
386386
cfg = json_checkpointer.restore(
@@ -633,7 +633,7 @@ def restore_keras_model(
633633
)
634634

635635
checkpointer = ocp.Checkpointer(
636-
ocp.CompositeCheckpointHandler(**{
636+
ocp.CompositeCheckpointHandler(**{ # pyrefly: ignore[bad-argument-type]
637637
ORBAX_CHECKPOINT_DEFAULT_KEY: ocp.handlers.PyTreeCheckpointHandler()
638638
})
639639
)

recml/examples/DLRM_HSTU/contextual_interleave_preprocessor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def __call__(
140140
# Prepend contextual embeddings
141141
if self._max_contextual_seq_len > 0:
142142
output_seq_embeddings = jnp.concatenate(
143-
[contextual_embeddings, output_seq_embeddings], axis=1
143+
[contextual_embeddings, output_seq_embeddings], axis=1 # pyrefly: ignore[bad-argument-type]
144144
)
145145
contextual_mask = jnp.ones(
146146
(batch_size, self._max_contextual_seq_len), dtype=jnp.bool_

0 commit comments

Comments
 (0)