deepseek-ai/EPLB ? reverse-engineered prompt
Reverse engineered prompt
Build me a small Python utility for balancing expert parallel MoE models across GPUs.
I want a function called rebalance_experts that takes estimated expert loads, a number of redundant replicas, the number of expert groups, the number of nodes, and the number of GPUs, then returns a placement plan for each replica. It should try to keep the load spread evenly across GPUs, and when possible, keep experts from the same group on the same node so communication stays lower.
Please support two modes of planning, one that works hierarchically when the node count fits the group count nicely, and one that does a global balancing pass when that is not the case. Return the mappings in a way that is easy to use with PyTorch tensors.
If helpful, include a simple example with a small MoE layer setup and make sure the output matches the kind of placement shown in the README. Look up current docs online if you need to, but keep the implementation self contained.
Are you gonna build this?
make sure you review the code using coderabbit