Get the index corresponding to the given batch_id Args: batch_id: The batch_id to look up Returns: The index corresponding to the batch_id, or add new key if not found
(self, batch_id)
| 466 | del self.index_to_batch_id[key] |
| 467 | |
| 468 | def get_index_by_batch_id(self, batch_id): |
| 469 | """ |
| 470 | Get the index corresponding to the given batch_id |
| 471 | |
| 472 | Args: |
| 473 | batch_id: The batch_id to look up |
| 474 | |
| 475 | Returns: |
| 476 | The index corresponding to the batch_id, or add new key if not found |
| 477 | """ |
| 478 | for index, bid in self.index_to_batch_id.items(): |
| 479 | if bid == batch_id: |
| 480 | return index |
| 481 | if batch_id in self.index_to_batch_id: |
| 482 | # In PD reordering, some req_idx that are no longer used will be removed and |
| 483 | # the remaining requests will be re-sorted by index. |
| 484 | # |
| 485 | # If req_idx = 2 was removed in the previous step and request 12 later occupied |
| 486 | # slot 2 (i.e. {2: 12}), inserting a new request with req_id = 2 may overwrite |
| 487 | # the existing request (req_idx = 12), leading to incorrect behavior. |
| 488 | # |
| 489 | # To avoid index collision, we always assign a new slot using the current length |
| 490 | # as the new index, instead of reusing a previously freed req_idx. |
| 491 | self.index_to_batch_id[len(self.index_to_batch_id)] = batch_id |
| 492 | else: |
| 493 | self.index_to_batch_id[batch_id] = batch_id |
| 494 | return batch_id |
| 495 | |
| 496 | def reset_share_inputs(self): |
| 497 | """ |
no test coverage detected