Draft
Perf: batch all_reduce, replace deprecated torch.inverse, optimize hot-path numpy ops, enable pin_memory#1
Conversation
… torch.linalg.inv, optimize find_closest_ind, add pin_memory, use F.pad, replace np.digitize with np.searchsorted Co-authored-by: xukechun <48900301+xukechun@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Identify and suggest improvements to slow code
Perf: batch all_reduce, replace deprecated torch.inverse, optimize hot-path numpy ops, enable pin_memory
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Targeted performance improvements across training loop, data loading, and matrix operations.
Distributed training
reduce_metrics: Singledist.all_reduceon a stacked tensor instead of N separate calls — eliminates N-1 unnecessary synchronization barriers per invocationreduce_metricsnow only called at save/log intervals; per-iteration printing uses local averagesData loading
pin_memory=Trueon all DataLoaders — enables async CPU→GPU transfer paired with existingnon_blocking=Trueinpreprocess_data()Deprecated API replacement
torch.inverse()→torch.linalg.inv()across 5 files (11 callsites) — deprecated since PyTorch 1.9,linalg.invis better optimized on modern CUDA backendsNumPy hot-path optimization
find_closest_ind: Replace 25-linenp.digitize+ 3 mask branches + concatenation with 5-line vectorizednp.searchsorted+np.clip:np.digitize→np.searchsortedinalign.pyandensemble.py—digitizewrapssearchsortedinternallyTransform object overhead
pad2square: Replace per-callv2.Pad()construction with directF.pad, with reshape handling for 6D+ tensors in replicate mode📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.