Skip to content

Commit 4c31871

Browse files
committed
add lora assignment tests
1 parent 96a3b78 commit 4c31871

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

Tests/Runtime/TestLLM.cs

+51
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,57 @@
1010

1111
namespace LLMUnityTests
1212
{
13+
public class TestLLMLoras
14+
{
15+
[Test]
16+
public void TestLLMLorasAssign()
17+
{
18+
GameObject gameObject = new GameObject();
19+
gameObject.SetActive(false);
20+
LLM llm = gameObject.AddComponent<LLM>();
21+
22+
string lora1 = "/tmp/lala";
23+
string lora2Rel = "test/lala";
24+
string lora2 = LLMUnitySetup.GetAssetPath(lora2Rel);
25+
LLMUnitySetup.CreateEmptyFile(lora1);
26+
LLMUnitySetup.CreateEmptyFile(lora2);
27+
28+
llm.AddLora(lora1);
29+
llm.AddLora(lora2);
30+
Assert.AreEqual(llm.lora, lora1 + " " + lora2);
31+
Assert.AreEqual(llm.loraWeights, "1 1");
32+
33+
llm.RemoveLoras();
34+
Assert.AreEqual(llm.lora, "");
35+
Assert.AreEqual(llm.loraWeights, "");
36+
37+
llm.AddLora(lora1, 0.8f);
38+
llm.AddLora(lora2Rel, 0.9f);
39+
Assert.AreEqual(llm.lora, lora1 + " " + lora2);
40+
Assert.AreEqual(llm.loraWeights, "0.8 0.9");
41+
42+
llm.SetLoraScale(lora2Rel, 0.7f);
43+
Assert.AreEqual(llm.lora, lora1 + " " + lora2);
44+
Assert.AreEqual(llm.loraWeights, "0.8 0.7");
45+
46+
llm.RemoveLora(lora2Rel);
47+
Assert.AreEqual(llm.lora, lora1);
48+
Assert.AreEqual(llm.loraWeights, "0.8");
49+
50+
llm.AddLora(lora2Rel);
51+
llm.SetLoraScale(lora2Rel, 0.5f);
52+
Assert.AreEqual(llm.lora, lora1 + " " + lora2);
53+
Assert.AreEqual(llm.loraWeights, "0.8 0.5");
54+
55+
llm.SetLoraScale(lora2, 0.1f);
56+
Assert.AreEqual(llm.lora, lora1 + " " + lora2);
57+
Assert.AreEqual(llm.loraWeights, "0.8 0.1");
58+
59+
File.Delete(lora1);
60+
File.Delete(lora2);
61+
}
62+
}
63+
1364
public class TestLLM
1465
{
1566
protected static string modelUrl = "https://huggingface.co/afrideva/smol_llama-220M-openhermes-GGUF/resolve/main/smol_llama-220m-openhermes.q4_k_m.gguf?download=true";

0 commit comments

Comments
 (0)