Skip to content

Add Custom Traffic Pattern benchmark - #263

Closed
x41lakazam wants to merge 14 commits into
ai-dynamo:mainfrom
x41lakazam:main
Closed

x41lakazam wants to merge 14 commits into
ai-dynamo:mainfrom
x41lakazam:main

Conversation

@x41lakazam

@x41lakazam x41lakazam commented May 7, 2025 •

Copy link
Copy Markdown
Contributor

CTPerftest - Custom Traffic Performance Test Implementation

Overview

Benchmark tool to measure the performance of customizable traffic patterns, where each rank sends a custom message size to every other rank (can be 0).

The purpose of such a benchmark is to simulate asymetric traffic flow, like the KV caches transfers flow in a disaggregated inference system.

Such a pattern is defined using a transfer matrix, i.e a matrix where cell [i.j] defines the size of the message sent by rank i to rank j.

The following benchmarks are available:

  • Sequential CT Perftest: Benchmark the performance of a continuum of traffic patterns one after the other, before running each pattern, all the ranks involved in the pattern do a barrier, then optionally sleep a given amount of time, and then run the pattern and measure the execution time.

The PR also introduce a tool script to generate the matrices that would simulate a flow of KV cache transfer, in tools/inference_workload_matgen.py.

Implementation Details

  • ct_perftest/sequential_custom_traffic_perftest.py implements Sequential CT Perftest
  • Utilizes common utilities from ct_perftest/utils.py and ct_perftest/dist_utils.py for distributed testing support
  • Command-line interface extensions in ct_perftest/cli.py for test configuration
  • ct_perftest/common.py defines an abstraction for NixlBuffers
  • tools/inference_workload_matgen.py - Small script to generate transfer matrices of KV transfers, with very basic computation simulation, the output of this script will be a lot of matrices and a metadata.yaml file that can be directly fed to Sequential CT Benchmark.

Sequential CT Perftest

Reports

Sequential CT Perftest reports the total latency per matrix execution, along with their latency when ran isolated, which can be used to evaluate how good the network react to congestion. The report is both saved as a JSON file (controlled by the --json-output-path parameter) and displayed in stdout as:

  Transfer size (GB)    Latency (ms)    Isolated Latency (ms)    Num Senders
--------------------  --------------  -----------------------  -------------
         4.945               35.047                   35.421              4
         3.230               21.152                   21.800              4
         1.104                8.222                    8.280              4
         ...                 ...                         ...             ...
         0.129                2.147                    2.386              4

Usage

Tests can be defined using YAML configuration files.

CT Perftest define a single traffic pattern, as well as number of iterations and warmup iterations:

iters: 50
warmup_iters: 10
traffic_pattern:
  matrix_file: "/path/to/matrix.txt"
  shards: 1
  mem_type: "cuda"
  xfer_op: "WRITE"

Sequential CT Perftest configuration defines a sequence of traffic patterns:

traffic_patterns:
- matrix_file: /swgwork/eshukrun/nixl/tools/perf/run/llama-405b/prefill_tp_4_decode_tp_8/matrices/matrix_0.txt
  metadata:
    isl: 38328
  sleep_before_launch_sec: 16.480753057792
- matrix_file: /swgwork/eshukrun/nixl/tools/perf/run/llama-405b/prefill_tp_4_decode_tp_8/matrices/matrix_1.txt
  metadata:
    isl: 25034
  sleep_before_launch_sec: 71.875102179328

traffic_patterns can contain multiple elements that run sequentially. See TrafficPattern in common.py for default values.

  • matrix_file: The file containing the matrix, the matrix cells should be separated by whitespaces and contain either a number of bytes as integer or use a standard unit like K, M and G.
  • shards: Number of chunks the buffer has to be sharded into.
  • mem_type: For now support only cuda, but it should follow nixl memory types
  • xfer_op: xfer operation, can be READ or WRITE
  • sleep_before_launch_sec: number of seconds to sleep before running this traffic pattern, can be used for example to simulate computation.

Example of a matrix file:

0 0 1M 1M
0 0 1M 1M
0 0 0 5K
0 0 0 5K

Usage

Install requirements

pip install -r requirements.txt

Optionally, generate matrices using the inference_workload_matgen.py script

python inference_workload_matgen.py generate \
    --num-user-requests 10 \
    --num-prefill-nodes 16 \
    --num-decode-nodes 16 \
    --prefill-tp 8 \
    --prefill-pp 1 \
    --prefill-cp 1 \
    --decode-tp 8 \
    --decode-pp 1 \
    --decode-cp 1 \
    --results-dir $PWD/matrices \
    --model llama-405b

Run the test using the CLI:

python cli.py sequential-ct-perftest ./matrices/metadata.yaml --verify-buffers --json-output-path ./results.json
# Or with slurm
srun <params> python cli.py sequential-ct-perftest ./matrices/metadata.yaml --verify-buffers --json-output-path ./results.json

Next Steps

  • Support more memory types

Known Issues

  • The nixl xfer preparation currently takes a lot of time (the _prepare_tp() method).

@copy-pr-bot

copy-pr-bot Bot commented May 7, 2025

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions

github-actions Bot commented May 7, 2025

Copy link
Copy Markdown

👋 Hi x41lakazam! Thank you for contributing to ai-dynamo/nixl.

Your PR reviewers will review your contribution then trigger the CI to test your changes.

🚀

@yosefe

yosefe commented May 7, 2025

Copy link
Copy Markdown
Contributor

@x41lakazam thanks for the contribution!
Can you pls add running the new benchmark to CI scripts?

@sb17v sb17v left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR!
Please check the pre-commit hook failure and fix the formatting errors. Initial comments are included.

Comment thread benchmark/ct_perftest/requirements.txt Outdated
Comment thread benchmark/tools/inference_workload_matgen.py Outdated
Comment thread benchmark/tools/inference_workload_matgen.py
Comment thread benchmark/ct_perftest/common.py Outdated
)
)

self.reg_descs = nixl_agent.get_reg_descs(self.bufs, mem_type=mem_type)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of registering all individual sharded chunks, can we check if chunks are contiguous and register the entire region? We could time this part and compare the difference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The whole point is to simulate sharded bufs

Comment thread benchmark/ct_perftest/common.py Outdated
)

self.reg_descs = nixl_agent.get_reg_descs(self.bufs, mem_type=mem_type)
self.xfer_descs = nixl_agent.get_xfer_descs(self.bufs, mem_type=mem_type)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It will also be better to time this part.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Isn't this supposed to happen in parallel of the KV computation ?

Comment on lines +56 to +63
def _share_md(self) -> None:
"""Share agent metadata between all ranks. (Need to be run after registering buffers)"""
md = self.nixl_agent.get_agent_metadata()
mds = dist_utils.allgather_obj(md)
for other_rank, metadata in enumerate(mds):
if other_rank == self.my_rank:
continue
self.nixl_agent.add_remote_agent(metadata)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@sb17v @aranadive This part takes a really really long time (sometimes 20 mins), is it the good way to do it ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@x41lakazam, How many ranks are you using?
The steps look good to me.
Do you have the split time measurement for:

  • get_agent_metadata
  • allgather
  • individual and loop measurement for add_remote_agent

@aranadive

Copy link
Copy Markdown
Contributor

@x41lakazam please fix pre-commit issues

@aranadive

Copy link
Copy Markdown
Contributor

Next steps for this PR:
CTP will be divided into 3 parts and combined with current KVBench and made NIXLKVBench.py. We cant merge this as-is and will require some fix ups.

New Runner - Run either CTP/KVBench
Model Parameters Input - merged with what KVBench has
Workload Matrix Generator - merged as is
CTP Runner - merged as is

@aranadive will look at creating a new skeleton merge PR.

@aranadive

Copy link
Copy Markdown
Contributor

This is merged with PR #433.

@aranadive aranadive closed this Jul 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants