Skip to content

Commit bc374f1

Browse files
committed
Merge branch 'main' of github.com:Borklet-Labs/axlearn into jax_py3.12_nightly
2 parents 034266d + dffc513 commit bc374f1

154 files changed

Lines changed: 4196 additions & 690 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/config.yml

Lines changed: 0 additions & 79 deletions
This file was deleted.

.pylintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ disable=abstract-method,
111111
no-member, # Config objects use dynamic members generated by attrs.
112112
no-name-in-module,
113113
no-self-use,
114+
not-callable,
114115
nonzero-method,
115116
oct-method,
116117
old-division,
@@ -163,6 +164,8 @@ disable=abstract-method,
163164
xrange-builtin,
164165
zip-builtin-not-iterating,
165166

167+
# Increase default from 5 to 9
168+
max-positional-arguments=9
166169

167170
[REPORTS]
168171

axlearn/audio/decoder_asr.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from axlearn.common.layers import Embedding, Linear
3636
from axlearn.common.logit_modifiers import LogitsToLogitsFn
3737
from axlearn.common.loss import cross_entropy
38-
from axlearn.common.metrics import WeightedScalar
38+
from axlearn.common.metrics import WeightedSummary
3939
from axlearn.common.module import Module, child_context
4040
from axlearn.common.rnn import BaseRNNCell, LSTMCell
4141
from axlearn.common.transducer import Transducer, log_probs_from_blank_and_tokens
@@ -238,7 +238,7 @@ def beam_search_decode(
238238

239239
def _input_stats_summaries(
240240
self, input_batch: Nested[Tensor], *, target_paddings: Tensor, is_valid_example: Tensor
241-
) -> dict[str, Union[WeightedScalar, Tensor]]:
241+
) -> dict[str, Union[WeightedSummary, Tensor]]:
242242
"""Computes input lengths stats.
243243
244244
Args:
@@ -258,13 +258,13 @@ def _input_stats_summaries(
258258
total_num_examples = jnp.maximum(is_valid_example.sum(), 1.0)
259259
total_num_frames = jnp.maximum(jnp.size(input_batch["paddings"]), 1)
260260
input_stats = {
261-
"input_stats/average_target_length": WeightedScalar(
261+
"input_stats/average_target_length": WeightedSummary(
262262
total_target_lengths / total_num_examples, total_num_examples
263263
),
264-
"input_stats/average_source_length": WeightedScalar(
264+
"input_stats/average_source_length": WeightedSummary(
265265
total_source_lengths / total_num_examples, total_num_examples
266266
),
267-
"input_stats/frame_packing_efficiency": WeightedScalar(
267+
"input_stats/frame_packing_efficiency": WeightedSummary(
268268
total_source_lengths / total_num_frames, total_num_frames
269269
),
270270
}
@@ -324,7 +324,7 @@ def _loss_summaries(
324324
per_example_weight: Tensor,
325325
paddings: Tensor,
326326
target_paddings: Tensor,
327-
) -> dict[str, Union[WeightedScalar, Tensor]]:
327+
) -> dict[str, Union[WeightedSummary, Tensor]]:
328328
valid_frame_mask = (1.0 - paddings) * per_example_weight[:, None]
329329
valid_label_mask = (1.0 - target_paddings) * per_example_weight[:, None]
330330

@@ -336,17 +336,17 @@ def _loss_summaries(
336336

337337
ret_dict = {}
338338
# 1. loss/example_weight
339-
ret_dict["loss/example_weight"] = WeightedScalar(jnp.mean(per_example_weight), batch_size)
339+
ret_dict["loss/example_weight"] = WeightedSummary(jnp.mean(per_example_weight), batch_size)
340340
# 2. loss/ctc_loss
341-
ret_dict["loss/ctc_loss"] = WeightedScalar(
341+
ret_dict["loss/ctc_loss"] = WeightedSummary(
342342
total_ctc_loss / jnp.maximum(per_example_weight.sum(), 1),
343343
jnp.maximum(per_example_weight.sum(), 1),
344344
)
345345
# 3. loss/invalid_seq_percent, per_frame_ctc_loss, per_label_ctc_loss
346346
invalid_example_percent = 1.0 - jnp.sum(per_example_weight) / batch_size
347347
ret_dict["loss/invalid_seq_percent"] = invalid_example_percent
348-
ret_dict["loss/per_frame_ctc_loss"] = WeightedScalar(per_frame_loss, num_valid_frames)
349-
ret_dict["loss/per_label_ctc_loss"] = WeightedScalar(per_label_loss, num_valid_labels)
348+
ret_dict["loss/per_frame_ctc_loss"] = WeightedSummary(per_frame_loss, num_valid_frames)
349+
ret_dict["loss/per_label_ctc_loss"] = WeightedSummary(per_label_loss, num_valid_labels)
350350

351351
return ret_dict
352352

@@ -896,11 +896,11 @@ def forward(self, input_batch: Nested[Tensor]) -> tuple[Tensor, Nested[Tensor]]:
896896

897897
self.add_summary(
898898
"loss/example_weight",
899-
WeightedScalar(jnp.mean(per_example_weight), per_example_weight.shape[0]),
899+
WeightedSummary(jnp.mean(per_example_weight), per_example_weight.shape[0]),
900900
)
901901
self.add_summary(
902902
"loss/rnnt_loss",
903-
WeightedScalar(loss, jnp.maximum(1, per_example_weight.sum())),
903+
WeightedSummary(loss, jnp.maximum(1, per_example_weight.sum())),
904904
)
905905
return loss, aux_outputs
906906

@@ -1013,7 +1013,7 @@ def tokens_to_scores(
10131013

10141014
return tokens_to_scores
10151015

1016-
def beam_search_decode(
1016+
def beam_search_decode( # pytype: disable=signature-mismatch
10171017
self,
10181018
input_batch: Nested[Tensor],
10191019
num_decodes: int,
@@ -1198,9 +1198,9 @@ def forward(self, input_batch: Nested[Tensor]) -> tuple[Tensor, Nested[Tensor]]:
11981198
# Number of valid tokens per example.
11991199
per_example_weight = jnp.sum(live_targets, axis=-1)
12001200
num_targets = per_example_weight.sum()
1201-
self.add_summary("loss", WeightedScalar(loss, num_targets))
1202-
self.add_summary("perplexity", WeightedScalar(jnp.exp(loss), num_targets))
1203-
self.add_summary("token_accuracy", WeightedScalar(loss_dict["accuracy"], num_targets))
1201+
self.add_summary("loss", WeightedSummary(loss, num_targets))
1202+
self.add_summary("perplexity", WeightedSummary(jnp.exp(loss), num_targets))
1203+
self.add_summary("token_accuracy", WeightedSummary(loss_dict["accuracy"], num_targets))
12041204
return loss, dict(per_example_loss=per_example_loss, per_example_weight=per_example_weight)
12051205

12061206
def _compute_attention_logit_biases(
@@ -1225,7 +1225,7 @@ def _validate_decode_batch(self, input_batch: Nested[Tensor]):
12251225
if "prefix" not in input_batch:
12261226
raise ValueError("Input batch is expected to contain `prefix`.")
12271227

1228-
def beam_search_decode(
1228+
def beam_search_decode( # pytype: disable=signature-mismatch
12291229
self,
12301230
input_batch: Nested[Tensor],
12311231
num_decodes: int,

axlearn/audio/decoder_asr_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from axlearn.common.decoder import _scores_from_logits
3131
from axlearn.common.decoding import NEG_INF
3232
from axlearn.common.logit_modifiers import top_k_logits
33-
from axlearn.common.metrics import WeightedScalar
33+
from axlearn.common.metrics import WeightedSummary
3434
from axlearn.common.module import Module
3535
from axlearn.common.module import functional as F
3636
from axlearn.common.param_converter import as_torch_tensor
@@ -522,7 +522,7 @@ def jit_forward(input_batch):
522522
assert_allclose(np.sum(ref_per_example_loss) / np.sum(per_example_weight), loss)
523523

524524
def _check_summary(
525-
self, summary_collection: dict[str, Any], name: str, value: Union[Tensor, WeightedScalar]
525+
self, summary_collection: dict[str, Any], name: str, value: Union[Tensor, WeightedSummary]
526526
):
527527
self.assertIn(name, summary_collection)
528528
msg = f"mismatch in {name}: {summary_collection[name]} vs {value}"
@@ -570,8 +570,8 @@ def test_forward_summary(self):
570570
)
571571
summaries = output_collections.summaries
572572
# 6 out of 8 examples are valid, therefore the average example weight is 0.75
573-
self._check_summary(summaries, "loss/example_weight", WeightedScalar(0.75, 8))
574-
self._check_summary(summaries, "loss/ctc_loss", WeightedScalar(6972.135, 6))
573+
self._check_summary(summaries, "loss/example_weight", WeightedSummary(0.75, 8))
574+
self._check_summary(summaries, "loss/ctc_loss", WeightedSummary(6972.135, 6))
575575
self._check_summary(summaries, "loss/invalid_seq_percent", 0.25)
576576
total_ctc_loss = summaries["loss/ctc_loss"].weight * summaries["loss/ctc_loss"].mean
577577
num_valid_frames = jnp.sum(safe_not(paddings) * per_example_weight[:, None])
@@ -580,28 +580,28 @@ def test_forward_summary(self):
580580
self._check_summary(
581581
summaries,
582582
"loss/per_frame_ctc_loss",
583-
WeightedScalar(total_ctc_loss / num_valid_frames, num_valid_frames),
583+
WeightedSummary(total_ctc_loss / num_valid_frames, num_valid_frames),
584584
)
585585
self._check_summary(
586586
summaries,
587587
"loss/per_label_ctc_loss",
588-
WeightedScalar(total_ctc_loss / num_valid_labels, num_valid_labels),
588+
WeightedSummary(total_ctc_loss / num_valid_labels, num_valid_labels),
589589
)
590590

591591
self._check_summary(
592592
summaries,
593593
"input_stats/average_target_length",
594-
WeightedScalar(num_valid_labels / num_valid_examples, num_valid_examples),
594+
WeightedSummary(num_valid_labels / num_valid_examples, num_valid_examples),
595595
)
596596
self._check_summary(
597597
summaries,
598598
"input_stats/average_source_length",
599-
WeightedScalar(num_valid_frames / num_valid_examples, num_valid_examples),
599+
WeightedSummary(num_valid_frames / num_valid_examples, num_valid_examples),
600600
)
601601
self._check_summary(
602602
summaries,
603603
"input_stats/frame_packing_efficiency",
604-
WeightedScalar(num_valid_frames / paddings.size, paddings.size),
604+
WeightedSummary(num_valid_frames / paddings.size, paddings.size),
605605
)
606606

607607
def _check_paddings(self, outputs: DecodeOutputs, *, blank_id: int):

axlearn/audio/evaler_asr.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
config_for_function,
2828
)
2929
from axlearn.common.evaler import ModelSummaryAccumulator
30-
from axlearn.common.metrics import WeightedScalar
30+
from axlearn.common.metrics import WeightedSummary
3131
from axlearn.common.module import Module
3232
from axlearn.common.utils import Nested, Tensor, replicate_to_local_data
3333

@@ -225,17 +225,17 @@ def _compute_word_error_rate(
225225
# TODO(zhiyunlu): investigate whether we should keep empty references.
226226
self._metric_accumulator.update(
227227
{
228-
"word_errors/wer": WeightedScalar(metrics.num_total / denom, num_words),
229-
"word_errors/deletions": WeightedScalar(
228+
"word_errors/wer": WeightedSummary(metrics.num_total / denom, num_words),
229+
"word_errors/deletions": WeightedSummary(
230230
metrics.num_deletions / denom, num_words
231231
),
232-
"word_errors/insertions": WeightedScalar(
232+
"word_errors/insertions": WeightedSummary(
233233
metrics.num_insertions / denom, num_words
234234
),
235-
"word_errors/substitutions": WeightedScalar(
235+
"word_errors/substitutions": WeightedSummary(
236236
metrics.num_substitutions / denom, num_words
237237
),
238-
"word_errors/sentence_accuracy": WeightedScalar(
238+
"word_errors/sentence_accuracy": WeightedSummary(
239239
int(metrics.num_total == 0), int(num_words > 0)
240240
),
241241
}

0 commit comments

Comments
 (0)