Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Accuracy from cross_entropy in causal_lm.py::CrossEntropyLossMetrics #983

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

apivovarov
Copy link
Contributor

@apivovarov apivovarov commented Feb 12, 2025

PR Description:

This PR updates the accuracy calculation in causal_lm.py::CrossEntropyLossMetrics to use the value stored in loss_dict["accuracy"] instead of recomputing it. The key changes include:

  • Removing redundant accuracy computation in causal_lm.py.
  • Ensuring loss_dict["accuracy"] is used directly in CrossEntropyLossMetrics.
  • Updating the documentation in loss.py to clearly describe the accuracy computation method.
  • These changes improve code clarity and maintain consistency across the loss computation functions.

The following models already use loss_dict["accuracy"] from loss.py::cross_entropy() function

  • axlearn/audio/decoder_asr.py::LASDecoderModel::forward
  • axlearn/common/encoder_decoder.py::EncoderDecoderModel::forward (via _metrics)

Testing

Test command uses config fuji-test-v3, jax_backend is gpu

mkdir -p /tmp/gpt_c4_test
python3 -m axlearn.common.launch_trainer_main \
  --module=text.gpt.c4_trainer \
  --config=fuji-test-v3 \
  --trainer_dir=/tmp/gpt_c4_test\
  --data_dir=gs://axlearn-public/tensorflow_datasets \
  --jax_backend=gpu

tensorboard --logdir=train_train

pre-commit

$ pre-commit run --files $(git diff --name-only HEAD~1)
Check Yaml...........................................(no files to check)Skipped
Fix End of Files.........................................................Passed
Trim Trailing Whitespace.................................................Passed
black....................................................................Passed
isort....................................................................Passed
pylint...................................................................Passed

pytype

$ pytype -j auto $(git diff --name-only HEAD~1) 
Success: no errors found

@apivovarov apivovarov requested review from ruomingp, markblee and a team as code owners February 12, 2025 01:07
Copy link
Contributor

@markblee markblee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I wonder if XLA is smart enough to optimize it away (but it looks cleaner in any case).

@apivovarov
Copy link
Contributor Author

Hey Mark, thank you for reviewing and approving this PR!
Just wanted to check if there's anything else needed to merge it.
@markblee

@markblee
Copy link
Contributor

I'll need to run some internal tests before I can merge it -- hopefully soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants