accelerate
accelerate copied to clipboard
Optimize the time complexity of get_balanced_memory
When loading very large MoE models it stalls here; I found this part has O(n^2) complexity. If you convert it to a set, it can be reduced to O(n).
https://github.com/huggingface/accelerate/blob/8b493524c8630dc2eb85ac18906fdcf642eae805/src/accelerate/utils/modeling.py#L1043-L1045
Hey @Jintao-Huang! You're very right, that's definitely a free lunch. I opened a PR to push that small fix, run tests and benchmark to see what speedup this allows on real-world scenarios! Feel free to review (/stamp), very much looking for your feedback :) Thanks!