Commit 0d2ed94
perf: optimize LogprobsProcessor._update_prompt_logprobs iteration
This commit optimizes the loop iteration in LogprobsProcessor._update_prompt_logprobs() to reduce redundant operations and improve performance.
**Problem:**
The original implementation used range-based iteration with repeated list indexing:
- token_ids[pos], prompt_logprobs[pos], prompt_token_ranks[pos] required 3 index operations per iteration
- offset and offset_end were calculated even when decoded_tokens was None
- Less Pythonic code structure
**Solution:**
1. Use enumerate(zip(...)) to iterate through lists directly, eliminating repeated indexing
2. Only calculate offset when decoded_tokens is not None
3. Remove unnecessary offset_end variable
**Performance Impact:**
- Eliminates 3 list index operations per iteration
- Avoids arithmetic when decoded_tokens is None
- Micro-optimization that adds up for large num_prompt_tokens
Signed-off-by: Mohammad Othman <[email protected]>1 parent 6d17974 commit 0d2ed94
1 file changed
+12
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
142 | 144 | | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
151 | 153 | | |
152 | | - | |
153 | | - | |
| 154 | + | |
| 155 | + | |
154 | 156 | | |
155 | | - | |
| 157 | + | |
156 | 158 | | |
157 | 159 | | |
158 | 160 | | |
| |||
179 | 181 | | |
180 | 182 | | |
181 | 183 | | |
182 | | - | |
| 184 | + | |
0 commit comments