Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@ public static List<Integer> generateTokensGPULlama(Model model, State state, int
// Pre-validate the max tokens to avoid checking in the loop
int actualMaxTokens = Math.min(maxTokens > 0 ? maxTokens : model.configuration().contextLength(), model.configuration().contextLength());

// Preallocate with expected capacity to avoid resizing
List<Integer> generatedTokens = new ArrayList<>(Math.min(256, actualMaxTokens - promptTokens.size())); // Conservative estimate
// Preallocate with expected capacity to avoid resizing. Clamp at 0: when the
// prompt is longer than the token budget (actualMaxTokens), the difference is
// negative and would throw IllegalArgumentException("Illegal Capacity").
Comment on lines +288 to +290
List<Integer> generatedTokens = new ArrayList<>(Math.max(0, Math.min(256, actualMaxTokens - promptTokens.size()))); // Conservative estimate

// === Token Generation Loop ===
int currentToken = state.latestToken;
Expand Down Expand Up @@ -373,8 +375,10 @@ public static List<Integer> generateTokensGPUQwen3(Model model, State state, int
// Pre-validate the max tokens to avoid checking in the loop
int actualMaxTokens = Math.min(maxTokens > 0 ? maxTokens : model.configuration().contextLength(), model.configuration().contextLength());

// Preallocate with expected capacity to avoid resizing
List<Integer> generatedTokens = new ArrayList<>(Math.min(256, actualMaxTokens - promptTokens.size())); // Conservative estimate
// Preallocate with expected capacity to avoid resizing. Clamp at 0: when the
// prompt is longer than the token budget (actualMaxTokens), the difference is
// negative and would throw IllegalArgumentException("Illegal Capacity").
Comment on lines +378 to +380
List<Integer> generatedTokens = new ArrayList<>(Math.max(0, Math.min(256, actualMaxTokens - promptTokens.size()))); // Conservative estimate
Comment on lines +378 to +381

// Initialize token variables
int currentToken = state.latestToken; // BOS?
Expand Down