Skip to content

Commit 4aad7f9

Browse files
authored
Merge pull request kherud#35 from cestella/cstella/fix_build
Fixing build and defaulting models.home
2 parents 4b3e051 + aeb38c6 commit 4aad7f9

File tree

7 files changed

+22
-6
lines changed

7 files changed

+22
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ build
3030
hs_err_pid*
3131
replay_pid*
3232

33+
models/*.gguf
3334
src/main/cpp/de_kherud_llama_*.h
3435
src/main/resources/**/*.so
3536
src/main/resources/**/*.dylib

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ There are multiple [examples](src/test/java/examples). Make sure to set `model.h
2525
```bash
2626
mvn exec:java -Dexec.mainClass="examples.MainExample" -Dmodel.home="/path/to/models" -Dmodel.name="codellama-13b.Q5_K_M.gguf"
2727
```
28+
Note: if your model is in the `models` directory, then you can ommit the `-Dmodel.home` property.
2829

29-
You can also run some integration tests, which will automatically download a model to `model.home`:
30+
You can also run some integration tests, which will automatically download a model to the `models` directory:
3031

3132
```bash
32-
mvn verify -Dmodel.home=/path/to/models
33+
mvn verify
3334
```
3435

3536
### No Setup required

build-args.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ else()
44
set(LLAMA_METAL_DEFAULT OFF)
55
endif()
66

7+
# general
8+
option(LLAMA_NATIVE "llama: enable -march=native flag" ON)
9+
710
# instruction set specific
811
if (LLAMA_NATIVE)
912
set(INS_ENB OFF)
@@ -633,4 +636,4 @@ if (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
633636
endif()
634637
if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
635638
add_compile_definitions(_BSD_SOURCE)
636-
endif()
639+
endif()

models/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Local Model Directory
2+
This directory contains models which will be automatically downloaded
3+
for use in java-llama.cpp's unit tests.

pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
<junit.version>4.13.1</junit.version>
4949
<test.plugin.version>3.2.3</test.plugin.version>
5050
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
51-
<integration.test.model>mistral-7b-instruct-v0.2.Q5_K_S.gguf</integration.test.model>
51+
<model.home>${project.basedir}/models</model.home>
52+
<integration.test.model>mistral-7b-instruct-v0.2.Q2_K.gguf</integration.test.model>
5253
<integration.test.model.url>https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.2-GGUF/resolve/main/${integration.test.model}</integration.test.model.url>
5354
</properties>
5455

@@ -110,6 +111,7 @@
110111
<systemPropertyVariables>
111112
<propertyName>model.home</propertyName>
112113
<integration.test.model>${integration.test.model}</integration.test.model>
114+
<model.home>${model.home}</model.home>
113115
</systemPropertyVariables>
114116
</configuration>
115117
<executions>

src/test/java/de/kherud/llama/LlamaModelIT.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public void testGenerateGrammar() {
8686
String output = sb.toString();
8787

8888
Assert.assertTrue(output.matches("[ab]+"));
89-
Assert.assertEquals(nPredict, model.encode(output).length);
89+
int generated = model.encode(output).length;
90+
Assert.assertTrue(generated > 0 && generated <= nPredict);
9091
}
9192

9293
@Test
@@ -126,7 +127,8 @@ public void testCompleteGrammar() {
126127
.setNPredict(nPredict);
127128
String output = model.complete("", params);
128129
Assert.assertTrue(output.matches("[ab]+"));
129-
Assert.assertEquals(nPredict, model.encode(output).length);
130+
int generated = model.encode(output).length;
131+
Assert.assertTrue(generated > 0 && generated <= nPredict);
130132
}
131133

132134
@Test

src/test/java/de/kherud/llama/ModelResolver.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.kherud.llama;
22

3+
import java.io.File;
34
import java.nio.file.Paths;
45

56

@@ -22,6 +23,9 @@ public enum ModelResolver {
2223
public String resolve() {
2324
String ret = System.getProperty(systemPropertyName);
2425
if(ret == null) {
26+
if(new File("models").exists()) {
27+
return "models";
28+
}
2529
throw new IllegalArgumentException(String.format(errorMessage, systemPropertyName));
2630
}
2731
return ret;

0 commit comments

Comments
 (0)