Skip to content

[maxtext] improve profiling in decode #1863

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

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion MaxText/decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,19 @@ def main(argv: Sequence[str]) -> None:
decode_state = engine.insert(prefill_result_list[i], decode_state, slot=i)

# Generate
prof_deactivated = False
steps = range(config.max_prefill_predict_length, config.max_target_length)
sampled_tokens_list.append(_batch_first_result_token(first_token_list, batch_size))
for i in steps:
rng, rng_generate = jax.random.split(rng)
with jax.profiler.StepTraceAnnotation("generate", step=i):
decode_state, sampled_tokens = engine.generate(params, decode_state, rng=rng_generate)

# Automatically deactivate profiler after profiler_steps steps
if i > config.max_prefill_predict_length + config.profiler_steps:
prof.deactivate(blocking_object=sampled_tokens)
prof_deactivated = True

sampled_tokens_list.append(sampled_tokens)

# Get results
Expand All @@ -176,7 +183,10 @@ def main(argv: Sequence[str]) -> None:
), f"generated text mismatch {output=}, {config.autoregressive_decode_assert=}"

# Deactivate profiler
prof.deactivate()
if not prof_deactivated:
prof.deactivate(blocking_object=output)

prof.post_process()

def _validate_config(config):
assert config.load_full_state_path == "", (
Expand Down
3 changes: 3 additions & 0 deletions MaxText/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,6 @@ def should_activate_periodic_profile(self, step):

def should_deactivate_periodic_profile(self, step):
return self.profile_period > 0 and (step - self.finished_initial_profile_step) % self.profile_period == 0

def post_process(self):
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

The plan is to fill this in later, right?

Loading