Skip to content

Commit

Permalink
Add disk or memory kv buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
tjake committed Jun 16, 2024
1 parent ad9183a commit 35ffb08
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void pchunk(int offset, int length, BiIntConsumer action) {
PhysicalCoreExecutor.instance.get().execute(() -> IntStream.range(0, fsplits)
.parallel()
.forEach(i -> action.accept(
offset + (i * fchunkSize), fremainder > 0 ? fchunkSize + fremainder : fchunkSize)));
offset + (i * fchunkSize), fremainder > 0 && i == fsplits - 1 ? fchunkSize + fremainder : fchunkSize)));
}

public static void softMax(AbstractTensor x, int offset, int length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ private Pair<RandomAccessFile, AbstractTensor> makeKvBuffer(UUID session) {
} else {
s = TensorShape.of(rawShape);
}
Preconditions.checkArgument(model.getConfig().workingDirectory().isPresent());

// If we don't have a working directory, just use a FloatBufferTensor
if (model.getConfig().workingDirectory().isEmpty()) {
return Pair.create(null, new FloatBufferTensor(s));
}

// Otherwise, create a file-backed tensor
try {
RandomAccessFile raf = new RandomAccessFile(
Paths.get(model.getConfig().workingDirectory().get().toString(), session.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void MistralRun() throws Exception {
Config c = om.readValue(new File(modelPrefix + "/config.json"), LlamaConfig.class);
LlamaModel model = new LlamaModel(c, weights, tokenizer, DType.F32, DType.I8, Optional.empty());
String prompt = "Simply put, the theory of relativity states that";
model.generate(UUID.randomUUID(), prompt, 0.7f, 256, false, makeOutHandler());
model.generate(UUID.randomUUID(), prompt, 0.7f, 64, false, makeOutHandler());
}
}

Expand Down

0 comments on commit 35ffb08

Please sign in to comment.