Skip to content

Fix Metric Reporting Crash (ZeroDivisionError) using Tunix PerfTracer#3597

Draft
igorts-git wants to merge 1 commit intomainfrom
igorts/sft-tracer-timing-fix
Draft

Fix Metric Reporting Crash (ZeroDivisionError) using Tunix PerfTracer#3597
igorts-git wants to merge 1 commit intomainfrom
igorts/sft-tracer-timing-fix

Conversation

@igorts-git
Copy link
Copy Markdown
Collaborator

@igorts-git igorts-git commented Apr 7, 2026

Description

This PR fixes a ZeroDivisionError that occurred in the MaxText MetricLogger during Tunix-based SFT runs.

The Problem

As the result of Tunix PR1289. The Tunix library's internal training loop now hard-codes the step time to zero when calling the on_train_step_end hook.
The MaxText SFT hook passes the zero value to the metric_logger.
The MetricLogger divides FLOPS and tokens values by the passed zero step_time.

The Tunix change was made because the old reported step_time metric was inaccurate due to async execution. The recommended solution was to use Tunix PerfTracer, which correctly tracks the async step time.

The Fix

  1. Initialize a PerfTracer in setup_trainer_state and passes it to the PeftTrainer.
  2. Add sft_perf_export_fn to extract the peft_train_step span duration from the Tunix timeline.
  3. The training hooks now pull the step_time from the tracer.

FIXES: b/497665859.

Tests

Manual invocation of SFT training with and without the fix with Tunix installed from main/HEAD.

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/maxtext/trainers/post_train/sft/hooks.py 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@igorts-git igorts-git force-pushed the igorts/sft-tracer-timing-fix branch from 953990b to f3d4232 Compare April 7, 2026 23:22
@igorts-git igorts-git force-pushed the igorts/sft-tracer-timing-fix branch from f3d4232 to abcb6e2 Compare April 8, 2026 00:02
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.

1 participant