real: T tokens, kTop experts each, `groups_req` distinct experts in all (capped at kTop * T, floored at kTop). Expert j is forced onto token j % T so that every group has at least one entry; the rest of each token's picks are random.
| 160 | // Expert j is forced onto token j % T so that every group has at least one entry; the rest of each token's picks are |
| 161 | // random. |
| 162 | Window build_real(int T, int groups_req, std::mt19937& rng) { |
| 163 | Window w; |
| 164 | const int G = std::min(std::max(groups_req, kTop), kTop * T); |
| 165 | std::vector<std::vector<int>> picks((size_t) G); |
| 166 | for (int k = 0; k < T; ++k) { |
| 167 | std::vector<char> in((size_t) G, 0); |
| 168 | int cnt = 0; |
| 169 | for (int j = k; j < G; j += T) { in[(size_t) j] = 1; ++cnt; } |
| 170 | std::vector<int> rest; |
| 171 | for (int j = 0; j < G; ++j) |
| 172 | if (!in[(size_t) j]) rest.push_back(j); |
| 173 | std::shuffle(rest.begin(), rest.end(), rng); |
| 174 | for (size_t i = 0; cnt < kTop; ++i, ++cnt) in[(size_t) rest[i]] = 1; |
| 175 | for (int j = 0; j < G; ++j) |
| 176 | if (in[(size_t) j]) picks[(size_t) j].push_back(k); |
| 177 | } |
| 178 | w.groups = G; |
| 179 | w.start.push_back(0); |
| 180 | for (int g = 0; g < G; ++g) { |
| 181 | for (int k : picks[(size_t) g]) { |
| 182 | w.tok.push_back(k); |
| 183 | w.dst.push_back((int32_t) w.dst.size()); |
| 184 | } |
| 185 | w.start.push_back((int32_t) w.dst.size()); |
| 186 | } |
| 187 | w.entries = (int) w.dst.size(); |
| 188 | return w; |
| 189 | } |
| 190 | // single: kTop T groups of one entry each (token g % T) |
| 191 | Window build_single(int T) { |
| 192 | Window w; |