Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the max tokens based on the model and fix temp for now #77

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
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 @@ -15,6 +15,7 @@
*/
package com.github.tjake.jlama.model.functions;

import com.github.tjake.jlama.safetensors.Config;
import com.github.tjake.jlama.safetensors.prompt.PromptContext;
import com.github.tjake.jlama.safetensors.prompt.PromptSupport;
import com.github.tjake.jlama.safetensors.prompt.ToolCall;
Expand Down Expand Up @@ -163,6 +164,8 @@ default Map<String, Float> classify(String input, PoolingType poolingType) {
throw new UnsupportedOperationException("Classification not supported by this model");
}

Config getConfig();

Tokenizer getTokenizer();

Optional<PromptSupport> promptSupport();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2170,8 +2170,18 @@ public void accumulate(AbstractTensor aBatch, AbstractTensor bBatch, int offset,
throw new UnsupportedOperationException();
}
break;
case BF16:
switch (vectorType) {
case AVX_512:
case AVX_256:
accumulateF32BF16_256((FloatBufferTensor) a, (BFloat16BufferTensor) b, offset, limit);
break;
default:
throw new UnsupportedOperationException();
}
break;
default:
throw new UnsupportedOperationException();
throw new UnsupportedOperationException("F32 => " + b.dType());
}
break;
case BF16:
Expand Down Expand Up @@ -2244,6 +2254,31 @@ void accumulateF32Q4_256(FloatBufferTensor a, Q4ByteBufferTensor b, int offset,
}
}

void accumulateF32BF16_256(FloatBufferTensor a, BFloat16BufferTensor b, int offset, int limit) {
int upperBound = offset + FloatVector.SPECIES_256.loopBound(limit);

int i = offset;
for (; i < upperBound; i += FloatVector.SPECIES_256.length()) {

// F32
var af = a.getVector(FloatVector.SPECIES_256, 0, i);

// Convert BF16 to F32
var bf = b.getVector(ShortVector.SPECIES_128, 0, i)
.convertShape(VectorOperators.S2I, IntVector.SPECIES_256, 0)
.lanewise(VectorOperators.LSHL, BF16_BYTE_SHIFT_256)
.reinterpretAsFloats();

var res = af.add(bf);
a.intoTensor(res, 0, i);
}

// tail
for (; i < offset + limit; i++) {
a.set(a.get(0, i) + b.get(0, i), 0, i);
}
}

void accumulateBF16_256(BFloat16BufferTensor a, BFloat16BufferTensor b, int offset, int limit) {
int upperBound = offset + FloatVector.SPECIES_256.loopBound(limit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ Object createChatCompletion(@RequestHeader Map<String, String> headers, @Valid @
}
}

float temperature = request.getTemperature() == null ? 0.3f : request.getTemperature().floatValue();
int maxTokens = request.getMaxTokens() == null ? 1024 : request.getMaxTokens();
float temperature = 0.3f;
int maxTokens = request.getMaxTokens() == null ? model.getConfig().contextLength : request.getMaxTokens();

logger.info("Generating completion for session {} with temperature {} and max tokens {}", sessionId, temperature, maxTokens);
AtomicInteger index = new AtomicInteger(0);
if (request.getStream() != null && request.getStream()) {
SseEmitter emitter = new SseEmitter(-1L);
Expand Down Expand Up @@ -139,11 +140,9 @@ Object createChatCompletion(@RequestHeader Map<String, String> headers, @Valid @

emitter.complete();

logger.info(
"Stats: {} ms/tok (prompt), {} ms/tok (gen)",
Math.round(r.promptTimeMs / (double) r.promptTokens),
Math.round(r.generateTimeMs / (double) r.generatedTokens)
);
logger.info("{} tokens/s (prompt), {} tokens/s (gen)",
Math.round(r.promptTokens / (double) (r.promptTimeMs / 1000f)),
Math.round(r.generatedTokens / (double) (r.generateTimeMs / 1000f)));

} catch (IOException e) {
emitter.completeWithError(e);
Expand Down
Loading