Skip to content

feat: add optimization for buffer transformation - #2

Open
Lin-xs wants to merge 5 commits into
mainfrom
feat/buffer-opt
Open

Lin-xs wants to merge 5 commits into
mainfrom
feat/buffer-opt

Conversation

@Lin-xs

@Lin-xs Lin-xs commented May 11, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

Signed-off-by: Lin-xs <1833080950@qq.com>
Copilot AI review requested due to automatic review settings May 11, 2026 03:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a buffered/batched optimizer-tensor transfer path to reduce per-tensor communication overhead during resharding, and adds extra runtime instrumentation (timings + per-peer byte stats). It also updates the E2E demo script and checkpoint output path behavior to align with the new logging/measurement workflow.

Changes:

  • Batch/pack multiple optimizer tensor slices per peer into a single uint8 buffer and transfer via batch_isend_irecv, with added timing instrumentation.
  • Track communication bytes by peer (send/recv breakdown) and print per-rank stage timing + traffic summaries.
  • Update demo/run and checkpoint save path behavior (logging layout, SAVE_PATH usage).

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
run_e2e_demo.sh Updates demo launch configuration, logging layout, and adds post-processing.
elastic_megatron/transfer/transfer.py Implements batched/packed P2P transfers and adds detailed timers.
elastic_megatron/transfer/communicator.py Adds per-peer send/recv byte accounting and returns structured comm stats.
elastic_megatron/elastic_manager.py Collects/prints per-rank transfer stage timings and send/recv stats.
elastic_megatron/megatron_manager/training_state.py Adds model_only option to weight sync; changes default checkpoint base directory logic.
elastic_megatron/megatron_manager/megatron_state.py Adds (currently commented) memory/parallel-state debug helpers.
elastic_megatron/resharding/virtual_param.py Adds import and debug comments around reshard-plan generation/caching.
elastic_megatron/resharding/util.py Improves string formatting for range types (but introduces duplicate __str__).
elastic_megatron/resharding/resharding_tp.py Adds illustrative comments for TP scale up/down mapping.
elastic_megatron/resharding/resharding_metadata.py Adds clarifying comments in layer index update.
elastic_megatron/resharding/resharding_dp.py Adds clarifying docstrings/comments for DP bucket distribution helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread run_e2e_demo.sh Outdated
Comment on lines +7 to +18
BASE_PATH=/mnt/public/yuanqwang/flextrain
MEGATRON_PATH=/mnt/public/yuanqwang/flextrain/Megatron-LM-011
export PYTHONPATH="${BASE_PATH}/ElasticMegatron:${MEGATRON_PATH}"
export TORCH_NCCL_AVOID_RECORD_STREAMS=1

export OMP_NUM_THREADS=8
export CUDA_DEVICE_MAX_CONNECTIONS=1

TP=${TP:-1}
PP=${PP:-1}
export CUDA_VISIBLE_DEVICES="0"
CONFIG_PY=/mnt/public/yuanqwang/flextrain/Megatron-LM-011/megatron/training/set_config.py
TP=$(python ${CONFIG_PY} tp)
PP=$(python ${CONFIG_PY} pp)
# export CUDA_VISIBLE_DEVICES="0"
Comment thread run_e2e_demo.sh Outdated
Comment on lines +32 to +33
export MODEL_SIZE=${MODEL_SIZE:-"tiny"}
export MODEL_SIZE=$(python ${CONFIG_PY} model_size)
Comment thread run_e2e_demo.sh
Comment on lines +63 to +67
if [ "${NODE_RANK}" -eq 0 ]; then
time_prefix=$(TZ='UTC-8' date +%Y%m%d-%H%M%S)
printf '%s\n' "${time_prefix}" > "${rendezvous_file}"
else
until [ -s "${rendezvous_file}" ]; do sleep 1; done
Comment thread run_e2e_demo.sh Outdated
Comment on lines +211 to +213
if [ $NODE_RANK == 0 ]; then
python /mnt/public/yuanqwang/flextrain/testcode/load_log.py $LOG_PATH | tee -a ${LOG_PATH}
fi No newline at end of file
Comment thread elastic_megatron/transfer/transfer.py Outdated
Comment on lines +653 to +654
use_block_and_print = False

Comment thread elastic_megatron/elastic_manager.py Outdated


obj_list = [None] * torch.distributed.get_world_size(group=union_world_group)
torch.distributed.all_gather_object(obj_list, local_comm_info)
Comment on lines +131 to +141
def get_communication_bytes(self) -> CommunicationBytes:
"""Get the communication bytes(GB) and reset the communication bytes to 0"""
communication_bytes = self._communication_bytes
communication_bytes_send = self._communication_bytes_send
communication_bytes_recv = self._communication_bytes_recv
self._communication_bytes = 0
return communication_bytes / (1024**3)
self._communication_bytes_send = defaultdict(int)
self._communication_bytes_recv = defaultdict(int)
return CommunicationBytes(
communication_bytes_send, communication_bytes_recv, communication_bytes
)
Comment on lines 348 to 354
if save_path is None:
cwd = pathlib.Path.cwd()
cwd = pathlib.Path(os.environ["SAVE_PATH"])
save_dir = (
cwd.parent
/ "ElasticMegatron"
/ "tools"
cwd
/ "ckpt"
/ ("before_reshard" if is_before_reshard else "after_reshard")
)
Comment thread elastic_megatron/resharding/util.py Resolved
from copy import deepcopy
from typing import Tuple
import torch
from megatron.core import parallel_state
@i-Taozi
i-Taozi self-requested a review May 11, 2026 03:36
Lin-xs added 4 commits May 13, 2026 15:08
Signed-off-by: Lin-xs <1833080950@qq.com>
Signed-off-by: Lin-xs <1833080950@qq.com>
Signed-off-by: Lin-xs <1833080950@qq.com>
Signed-off-by: Lin-xs <1833080950@qq.com>
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