Skip to content

Conversation

ajcasagrande
Copy link
Contributor

@ajcasagrande ajcasagrande commented Sep 26, 2025

Tip

--fixed-schedule-speedup <float>

Specifies a scaling factor to apply to the timestamps in the fixed schedule. For example, a value of 2.0 will make the schedule run twice as fast, while a value of 0.5 will make it run half as fast.

Summary by CodeRabbit

  • New Features
    • Added an optional speedup factor for fixed schedules to accelerate or slow execution. Configure via CLI flag --fixed-schedule-speedup (float > 0); defaults to no scaling. Applies uniformly to schedule timestamps and works with both auto and manual offsets. Past timestamps still execute immediately.
  • Tests
    • Expanded coverage for speedup behavior: time-scale calculation, execution timing under various offsets, negative/identical timestamps, and edge cases. Validates correctness of scheduling metadata during scaled execution.

Copy link

coderabbitai bot commented Sep 26, 2025

Walkthrough

Adds a new fixed_schedule_speedup option threaded from InputDefaults through InputConfig and TimingManagerConfig into FixedScheduleStrategy, which scales fixed-schedule timestamp offsets during wait calculations. Test suite expanded to cover speedup behavior across default, auto/manual offsets, and edge cases.

Changes

Cohort / File(s) Summary
Defaults
aiperf/common/config/config_defaults.py
Added FIXED_SCHEDULE_SPEEDUP = None to InputDefaults.
Input configuration
aiperf/common/config/input_config.py
Introduced public field `fixed_schedule_speedup: float
Timing manager config
aiperf/timing/config.py
Added `fixed_schedule_speedup: float
Fixed schedule strategy logic
aiperf/timing/fixed_schedule_strategy.py
Implemented time scaling: _time_scale derived from config.fixed_schedule_speedup (default 1.0). Wait duration now uses scaled timestamp offset before subtracting elapsed time. No other control-flow changes.
Tests
tests/timing_manager/test_fixed_schedule_strategy.py
Extended helper to accept speedup; passed into TimingManagerConfig. Added tests for time-scale calculation, execution timing under speedups, auto/manual offsets, negative timestamps, and edge cases.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor User
    participant CLI as CLI / InputConfig
    participant TMC as TimingManagerConfig
    participant FSS as FixedScheduleStrategy
    participant CLK as Clock
    participant CM as CreditManager

    User->>CLI: Set --fixed-schedule-speedup (float | None)
    CLI->>TMC: from_user_config(input.fixed_schedule_speedup)
    TMC->>FSS: Initialize with fixed_schedule_speedup
    Note over FSS: _time_scale = speedup or 1.0

    loop For each schedule timestamp
        FSS->>CLK: Now()
        CLK-->>FSS: t_now
        Note right of FSS: scaled_offset = (ts - schedule_zero_ms) / _time_scale
        FSS->>FSS: wait_ms = scaled_offset - (t_now - start_ms)
        alt wait_ms > 0
            FSS->>CLK: Sleep(wait_ms)
            CLK-->>FSS: Wakes
        else wait_ms <= 0
            Note over FSS: Execute immediately
        end
        FSS->>CM: Request credit
        CM-->>FSS: Grant/deny
        FSS->>FSS: Proceed / drop based on credit
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I tweaked the ticks with nimble paws,
A speedup switch to bend time’s laws—
Faster hops or gentle creep,
Schedules wake or softly sleep.
With clocks in sync and credits due,
I race the wind—then pause on cue. ⏱️🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely describes the addition of the new CLI parameter for scaling the load generator by naming the feature and parameter explicitly, which aligns with the primary change in the pull request.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ajc/time-scale

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b14d24 and 7c84bf0.

📒 Files selected for processing (5)
  • aiperf/common/config/config_defaults.py (1 hunks)
  • aiperf/common/config/input_config.py (1 hunks)
  • aiperf/timing/config.py (2 hunks)
  • aiperf/timing/fixed_schedule_strategy.py (2 hunks)
  • tests/timing_manager/test_fixed_schedule_strategy.py (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-24T23:02:10.982Z
Learnt from: the-david-oy
PR: ai-dynamo/aiperf#295
File: aiperf/timing/request_cancellation_strategy.py:28-31
Timestamp: 2025-09-24T23:02:10.982Z
Learning: In aiperf, the request_cancellation_rate and request_cancellation_delay configuration fields are defined with explicit float type annotations (not Optional[float]) and default to 0.0 from LoadGeneratorDefaults with Pydantic Field constraints, so they cannot be None and don't require defensive None-handling.

Applied to files:

  • aiperf/timing/config.py
📚 Learning: 2025-09-24T23:02:10.982Z
Learnt from: the-david-oy
PR: ai-dynamo/aiperf#295
File: aiperf/timing/request_cancellation_strategy.py:28-31
Timestamp: 2025-09-24T23:02:10.982Z
Learning: In aiperf, the request_cancellation_rate and request_cancellation_delay configuration fields are defined with explicit float type annotations and default to 0.0 from LoadGeneratorDefaults, so they cannot be None and don't require defensive None-handling.

Applied to files:

  • aiperf/timing/config.py
🧬 Code graph analysis (3)
aiperf/common/config/input_config.py (2)
aiperf/common/config/cli_parameter.py (1)
  • CLIParameter (10-19)
aiperf/common/config/config_defaults.py (1)
  • InputDefaults (41-54)
aiperf/timing/config.py (1)
aiperf/common/config/config_defaults.py (1)
  • InputDefaults (41-54)
tests/timing_manager/test_fixed_schedule_strategy.py (4)
aiperf/timing/fixed_schedule_strategy.py (2)
  • FixedScheduleStrategy (20-123)
  • _execute_single_phase (83-123)
aiperf/timing/config.py (1)
  • TimingManagerConfig (13-52)
tests/timing_manager/conftest.py (1)
  • MockCreditManager (74-203)
tests/utils/time_traveler.py (3)
  • time_traveler (114-125)
  • TimeTraveler (20-110)
  • sleeps_for (92-110)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build (ubuntu-latest, 3.10)
🔇 Additional comments (13)
aiperf/timing/config.py (2)

28-28: LGTM!

The new field is properly configured with the correct type annotation and default value from InputDefaults.FIXED_SCHEDULE_SPEEDUP.


49-49: LGTM!

The field is correctly threaded through from user_config.input.fixed_schedule_speedup, maintaining consistency with the existing pattern used for other fixed schedule configuration options.

aiperf/common/config/config_defaults.py (1)

50-50: LGTM!

The default value is consistently placed with other fixed schedule defaults and follows the existing naming convention.

aiperf/timing/fixed_schedule_strategy.py (2)

94-99: LGTM!

The time scaling is correctly applied to the offset calculation. The scaled offset is computed before subtracting the elapsed time, which properly implements the speedup functionality while preserving the existing timing logic.


38-38: Approve time scale calculation. Verified that 1/(config.fixed_schedule_speedup or 1.0) yields correct inverse scaling and fallback behavior across all tested speedup values.

aiperf/common/config/input_config.py (1)

181-194: LGTM!

The field definition follows the established pattern with proper type annotation, Pydantic validation constraint gt=0 to ensure positive values only, clear documentation, and CLI parameter configuration. The validation constraint correctly prevents zero and negative speedup values.

Based on web search results, the gt=0 validation ensures that speedup values must be greater than 0, raising a 'greater_than' error if not met.

tests/timing_manager/test_fixed_schedule_strategy.py (7)

42-42: LGTM!

The helper method signature is properly extended to include the optional speedup parameter, and it's correctly passed through to TimingManagerConfig.model_construct.

Also applies to: 49-49


200-224: LGTM!

The test correctly verifies that the time scale calculation matches expected values for various speedup scenarios, including the default case when speedup is None.


225-267: LGTM!

The test properly validates that speedup affects execution timing as expected, testing multiple scenarios including edge cases like all timestamps at the same time.


268-294: LGTM!

The test correctly verifies speedup behavior with auto offset timestamps, ensuring the interaction between these two features works as expected.


295-321: LGTM!

The test properly validates speedup behavior with manual offset, confirming the feature works correctly across different offset modes.


322-343: LGTM!

The test correctly handles the edge case of negative timestamps (past events), ensuring they execute immediately regardless of speedup settings.


344-361: LGTM!

The test validates edge cases for extreme speedup values, ensuring the time scale calculation works correctly for both very small and very large speedup values.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

codecov bot commented Sep 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

),
] = InputDefaults.FIXED_SCHEDULE_END_OFFSET

# NEW AIPerf Option
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Instead of calling it 'New AIPerf Option,' maybe we could add a descriptive comment about the option itself? Since this option won’t stay 'new' for long. :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The description itself is in the data right below it. I was mostly using as a way to track features that do not have GenAI-Perf equivalents for tracking feature parity. I think maybe it is safe to remove these comments, and just use the ones inside the alias portions

Copy link
Member

Choose a reason for hiding this comment

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

Removing also sounds good to me.
Thank you @ajcasagrande

@pytest.mark.parametrize(
"speedup,schedule",
[
# 2x faster - should take half the time
Copy link
Member

Choose a reason for hiding this comment

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

Some of additional tests I can think of:

  1. speedup = 0.0
    Looks like there’s no test for this. That case would hit base_duration_sec / speedup and cause a div-by-zero.

  2. speedup < 0
    Negative values aren’t tested. That produces a negative time_scale (effectively time going backwards). It’s unclear whether the intended behavior is to error out or actually “rewind” the schedule.

  3. Extreme floating-point cases
    You’ve got tests at 0.001 and 1000.0, but nothing near the edges of floating-point behavior. Something like 1e-9 (super slow) or 1e9 (super fast) could trigger precision issues.

  4. Uneven schedules
    All the current tests use evenly spaced timestamps. A case like (0, "a"), (1, "b"), (1000, "c") would check whether scaling compresses or stretches things as expected.

  5. Overlap after scaling
    With a large speedup (say 1000x), two nearby events could collapse into the same timestamp after rounding. Right now tests assume spacing survives scaling.
    Do we want to add some checks around this and warn user about this?

  6. Very large timestamps
    Something like (10**9, "conv1") could overflow ints or lose precision once scaled. No test covers that edge case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ganeshku1 I can look into adding these, but some of them would more be config tests:

  1. speedup = 0.0
    Looks like there’s no test for this. That case would hit base_duration_sec / speedup and cause a div-by-zero.

not possible, as config option is specified as gt=0. Also the speedup calculation takes those into account time_scale = 1 / (speedup or 1), but can look at adding tests for the config

  1. speedup < 0
    Negative values aren’t tested. That produces a negative time_scale (effectively time going backwards). It’s unclear whether the intended behavior is to error out or actually “rewind” the schedule.

Again, not possible due to gt=0, but can look at adding tests for the config

  1. Extreme floating-point cases
    You’ve got tests at 0.001 and 1000.0, but nothing near the edges of floating-point behavior. Something like 1e-9 (super slow) or 1e9 (super fast) could trigger precision issues.

  2. Uneven schedules
    All the current tests use evenly spaced timestamps. A case like (0, "a"), (1, "b"), (1000, "c") would check whether scaling compresses or stretches things as expected.

👍

  1. Overlap after scaling
    With a large speedup (say 1000x), two nearby events could collapse into the same timestamp after rounding. Right now tests assume spacing survives scaling.
    Do we want to add some checks around this and warn user about this?

Hmm, this might be a good point, as I do the scaling afterwards during the sleep. Will need to check.

  1. Very large timestamps
    Something like (10**9, "conv1") could overflow ints or lose precision once scaled. No test covers that edge case.

Worth checking.

@the-david-oy
Copy link
Contributor

Maybe we can reuse --conversation-turn-delay-ratio for this? It seems like it's doing the same thing except for fixed schedule. We can rename the option if needed.

Note that that option was configured to 2x if the ratio was 2, .5x if the ratio was .5. If this does the inverse, then it should be made the same for both options.

@ajcasagrande
Copy link
Contributor Author

ajcasagrande commented Sep 26, 2025

@the-david-oy that flag is not hooked up in main branch. Looks like you have a commit adding parts of its usage.

Edit: Looked at the GAP implementation, looks like it affects the delays between turns in input files as well. Not sure best way to combine these fields. As this field is for fixed timestamps, but it would likely want to be applied to delays as well. So maybe a new cli option that replaces both?

Edit: Also, I am in favor of using speedup style vs time-scale (naming whatever, talking about concept in general), as 2 meaning faster is more user-friendly and understandable than 0.5.

@the-david-oy
Copy link
Contributor

@the-david-oy that flag is not hooked up in main branch. Looks like you have a commit adding parts of its usage.

Edit: Looked at the GAP implementation, looks like it affects the delays between turns in input files as well. Not sure best way to combine these fields. As this field is for fixed timestamps, but it would likely want to be applied to delays as well. So maybe a new cli option that replaces both?

Edit: Also, I am in favor of using speedup style vs time-scale (naming whatever, talking about concept in general), as 2 meaning faster is more user-friendly and understandable than 0.5.

That's fine. I think this feature wasn't heavily used, so we can probably update any users who were using this.

Yeah, I can create a PR to get it merged to main sooner if it'd be useful. The flag already exists on main but isn't hooked up to do anything.

Fixed timestamps and delays should be mutually exclusive. The only place they wouldn't be is if we wanted to allow the first request to have a fixed timestamp + subsequent requests to have delays, which is a valid albeit niche use case that we do not support today. The previous feedback we had was that we had too many CLI flags, so I wanted to mention this here since it seems like two flags that have significant overlap for most use cases.

@ajcasagrande
Copy link
Contributor Author

The only place they wouldn't be is if we wanted to allow the first request to have a fixed timestamp + subsequent requests to have delays, which is a valid albeit niche use case that we do not support today.

Yeah thats what I had in mind with regards to them working together.

The previous feedback we had was that we had too many CLI flags, so I wanted to mention this here since it seems like two flags that have significant overlap for most use cases.

agreed

@ajcasagrande ajcasagrande marked this pull request as draft September 26, 2025 19:59
@ajcasagrande ajcasagrande removed the request for review from debermudez September 26, 2025 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants