Skip to content

Commit 4436f7e

Browse files
authored
Updated tests model to "LLama 3.2 1B Instruct" (#983)
* Updated tests model to "LLama 3.2 1B Instruct"
1 parent 45afacc commit 4436f7e

10 files changed

Lines changed: 65 additions & 89 deletions

LLama.Unittest/BasicTest.cs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public void Dispose()
2929
[Fact]
3030
public void BasicModelProperties()
3131
{
32-
Assert.Equal(32000, _model.VocabCount);
33-
Assert.Equal(4096, _model.ContextSize);
34-
Assert.Equal(4096, _model.EmbeddingSize);
32+
Assert.Equal(128256, _model.VocabCount);
33+
Assert.Equal(131072, _model.ContextSize);
34+
Assert.Equal(2048, _model.EmbeddingSize);
3535
}
3636

3737
[Fact]
@@ -41,36 +41,32 @@ public void AdvancedModelProperties()
4141
// tests are switched to use a new model!
4242
var expected = new Dictionary<string, string>
4343
{
44-
{ "general.name", "LLaMA v2" },
44+
{ "general.name", "Llama 3.2 1B Instruct" },
4545
{ "general.architecture", "llama" },
4646
{ "general.quantization_version", "2" },
47-
{ "general.file_type", "11" },
47+
{ "general.file_type", "2" },
4848

49-
{ "llama.context_length", "4096" },
50-
{ "llama.rope.dimension_count", "128" },
51-
{ "llama.embedding_length", "4096" },
52-
{ "llama.block_count", "32" },
53-
{ "llama.feed_forward_length", "11008" },
49+
{ "llama.context_length", "131072" },
50+
{ "llama.rope.dimension_count", "64" },
51+
{ "llama.embedding_length", "2048" },
52+
{ "llama.block_count", "16" },
53+
{ "llama.feed_forward_length", "8192" },
5454
{ "llama.attention.head_count", "32" },
55-
{ "llama.attention.head_count_kv", "32" },
56-
{ "llama.attention.layer_norm_rms_epsilon", "0.000001" },
55+
{ "llama.attention.head_count_kv", "8" },
56+
{ "llama.attention.layer_norm_rms_epsilon", "0.000010" },
5757

58-
{ "tokenizer.ggml.eos_token_id", "2" },
59-
{ "tokenizer.ggml.model", "llama" },
60-
{ "tokenizer.ggml.bos_token_id", "1" },
61-
{ "tokenizer.ggml.unknown_token_id", "0" },
58+
{ "tokenizer.ggml.eos_token_id", "128009" },
59+
{ "tokenizer.ggml.model", "gpt2" },
60+
{ "tokenizer.ggml.bos_token_id", "128000" },
6261
};
6362

6463
// Print all keys
6564
foreach (var (key, value) in _model.Metadata)
6665
_testOutputHelper.WriteLine($"{key} = {value}");
6766

68-
// Check the count is equal
69-
Assert.Equal(expected.Count, _model.Metadata.Count);
70-
7167
// Check every key
72-
foreach (var (key, value) in _model.Metadata)
73-
Assert.Equal(expected[key], value);
68+
foreach (var (key, value) in expected)
69+
Assert.Equal(_model.Metadata[key], value);
7470
}
7571
}
7672
}

LLama.Unittest/Constants.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using System.Runtime.InteropServices;
1+
using System.Runtime.InteropServices;
22

33
namespace LLama.Unittest
44
{
55
internal static class Constants
66
{
7-
public static readonly string GenerativeModelPath = "Models/llama-2-7b-chat.Q3_K_S.gguf";
7+
public static readonly string GenerativeModelPath = "Models/Llama-3.2-1B-Instruct-Q4_0.gguf";
88
public static readonly string EmbeddingModelPath = "Models/all-MiniLM-L12-v2.Q8_0.gguf";
99

1010
public static readonly string LLavaModelPath = "Models/llava-v1.6-mistral-7b.Q3_K_XS.gguf";

LLama.Unittest/KernelMemory/ITextTokenizerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void GetTokens_ShouldReturnListOfTokensForInputString(string? text)
3939
var tokens = _generator!.GetTokens(text);
4040
var tokensCount = _generator.CountTokens(text);
4141

42-
var expected = " " + text; // the placement of the space corresponding to BOS will vary by model tokenizer
42+
var expected = text;
4343
var actual = string.Join("", tokens);
4444

4545
_testOutputHelper.WriteLine($"Tokens for '{text}':");
@@ -79,7 +79,7 @@ public void GetTokens_Unicode_ShouldReturnListOfTokensForInputString(string? tex
7979
var tokens = _generator!.GetTokens(text);
8080
var tokensCount = _generator.CountTokens(text);
8181

82-
var expected = " " + text; // the placement of the space corresponding to BOS will vary by model tokenizer
82+
var expected = text;
8383
var actual = string.Join("", tokens);
8484

8585
_testOutputHelper.WriteLine($"Tokens for '{text}':");

LLama.Unittest/LLama.Unittest.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
<Target Name="DownloadContentFilesInner">
3131

32-
<DownloadFile SourceUrl="https://huggingface.co/TheBloke/Llama-2-7b-Chat-GGUF/resolve/main/llama-2-7b-chat.Q3_K_S.gguf" DestinationFolder="Models" DestinationFileName="llama-2-7b-chat.Q3_K_S.gguf" SkipUnchangedFiles="true">
32+
<DownloadFile SourceUrl="https://huggingface.co/bartowski/Llama-3.2-1B-Instruct-GGUF/resolve/main/Llama-3.2-1B-Instruct-Q4_0.gguf" DestinationFolder="Models" DestinationFileName="Llama-3.2-1B-Instruct-Q4_0.gguf" SkipUnchangedFiles="true">
3333
</DownloadFile>
3434

3535
<DownloadFile SourceUrl="https://huggingface.co/cjpais/llava-1.6-mistral-7b-gguf/resolve/main/llava-v1.6-mistral-7b.Q3_K_XS.gguf" DestinationFolder="Models" DestinationFileName="llava-v1.6-mistral-7b.Q3_K_XS.gguf" SkipUnchangedFiles="true">
@@ -57,7 +57,7 @@
5757
<None Update="Models\all-MiniLM-L12-v2.Q8_0.gguf">
5858
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5959
</None>
60-
<None Update="Models\llama-2-7b-chat.Q3_K_S.gguf">
60+
<None Update="Models\Llama-3.2-1B-Instruct-Q4_0.gguf">
6161
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6262
</None>
6363
<None Update="Models\llava-v1.6-mistral-7b.Q3_K_XS.gguf">

LLama.Unittest/LLamaContextTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@ public void Dispose()
3030
public void CheckProperties()
3131
{
3232
Assert.Equal(128u, _context.ContextSize);
33-
Assert.Equal(4096, _context.EmbeddingSize);
34-
Assert.Equal(32000, _context.VocabCount);
33+
Assert.Equal(2048, _context.EmbeddingSize);
34+
Assert.Equal(128256, _context.VocabCount);
3535
}
3636

3737
[Fact]
3838
public void Tokenize()
3939
{
4040
var tokens = _context.Tokenize("The quick brown fox", true);
4141

42-
Assert.Equal(new LLamaToken[] { 1, 450, 4996, 17354, 1701, 29916 }, tokens);
42+
Assert.Equal(new LLamaToken[] { 128000, 791, 4062, 14198, 39935 }, tokens);
4343
}
4444

4545
[Fact]
4646
public void TokenizeNewline()
4747
{
4848
var tokens = _context.Tokenize("\n", false, false);
4949

50-
Assert.Equal(new LLamaToken[] { 29871, 13 }, tokens);
50+
Assert.Equal(new LLamaToken[] { 198 }, tokens);
5151
}
5252

5353
[Fact]
@@ -78,7 +78,7 @@ public void TokenizeWithoutBOS()
7878
{
7979
var tokens = _context.Tokenize("The quick brown fox", false);
8080

81-
Assert.Equal(new LLamaToken[] { 450, 4996, 17354, 1701, 29916 }, tokens);
81+
Assert.Equal(new LLamaToken[] { 791, 4062, 14198, 39935 }, tokens);
8282
}
8383

8484
[Fact]

LLama.Unittest/LLamaEmbedderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ private async Task CompareEmbeddings(string modelPath)
6060
Assert.All(cat.Zip(embeddings[0].Vector.Span.EuclideanNormalization()), e => Assert.Equal(e.First, e.Second, 0.001));
6161
Assert.All(kitten.Zip(embeddings[1].Vector.Span.EuclideanNormalization()), e => Assert.Equal(e.First, e.Second, 0.001));
6262
Assert.All(spoon.Zip(embeddings[2].Vector.Span.EuclideanNormalization()), e => Assert.Equal(e.First, e.Second, 0.001));
63-
Assert.True(embeddings.Usage?.InputTokenCount is 19 or 20);
64-
Assert.True(embeddings.Usage?.TotalTokenCount is 19 or 20);
63+
Assert.True(embeddings.Usage?.InputTokenCount is 16 or 19);
64+
Assert.True(embeddings.Usage?.TotalTokenCount is 16 or 19);
6565

6666
_testOutputHelper.WriteLine($"Cat = [{string.Join(",", cat.AsMemory().Slice(0, 7).ToArray())}...]");
6767
_testOutputHelper.WriteLine($"Kitten = [{string.Join(",", kitten.AsMemory().Slice(0, 7).ToArray())}...]");

LLama.Unittest/LLavaWeightsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using LLama.Common;
1+
using LLama.Common;
22
using LLama.Native;
33

44
namespace LLama.Unittest
@@ -14,7 +14,7 @@ public sealed class LLavaWeightTests
1414

1515
public LLavaWeightTests()
1616
{
17-
var @params = new ModelParams(Constants.GenerativeModelPath)
17+
var @params = new ModelParams(Constants.LLavaModelPath)
1818
{
1919
// Llava models requires big context
2020
ContextSize = 4096,

LLama.Unittest/Native/SafeLlamaModelHandleTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Text;
1+
using System.Text;
22
using LLama.Common;
33
using LLama.Native;
44
using LLama.Extensions;
@@ -29,7 +29,7 @@ public void MetadataValByKey_ReturnsCorrectly()
2929
var template = _model.NativeHandle.MetadataValueByKey(key);
3030
var name = Encoding.UTF8.GetStringFromSpan(template!.Value.Span);
3131

32-
const string expected = "LLaMA v2";
32+
const string expected = "Llama 3.2 1B Instruct";
3333
Assert.Equal(expected, name);
3434

3535
var metadataLookup = _model.Metadata[key];

LLama.Unittest/TemplateTests.cs

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,14 @@ public void BasicTemplate()
5555
Assert.Equal(8, templater.Count);
5656

5757
var templateResult = Encoding.UTF8.GetString(dest);
58-
const string expected = "<|im_start|>assistant\nhello<|im_end|>\n" +
59-
"<|im_start|>user\nworld<|im_end|>\n" +
60-
"<|im_start|>assistant\n" +
61-
"111<|im_end|>" +
62-
"\n<|im_start|>user\n" +
63-
"aaa<|im_end|>\n" +
64-
"<|im_start|>assistant\n" +
65-
"222<|im_end|>\n" +
66-
"<|im_start|>user\n" +
67-
"bbb<|im_end|>\n" +
68-
"<|im_start|>assistant\n" +
69-
"333<|im_end|>\n" +
70-
"<|im_start|>user\n" +
71-
"ccc<|im_end|>\n";
58+
const string expected = "<|start_header_id|>assistant<|end_header_id|>\n\nhello<|eot_id|>"
59+
+ "<|start_header_id|>user<|end_header_id|>\n\nworld<|eot_id|>"
60+
+ "<|start_header_id|>assistant<|end_header_id|>\n\n111<|eot_id|>"
61+
+ "<|start_header_id|>user<|end_header_id|>\n\naaa<|eot_id|>"
62+
+ "<|start_header_id|>assistant<|end_header_id|>\n\n222<|eot_id|>"
63+
+ "<|start_header_id|>user<|end_header_id|>\n\nbbb<|eot_id|>"
64+
+ "<|start_header_id|>assistant<|end_header_id|>\n\n333<|eot_id|>"
65+
+ "<|start_header_id|>user<|end_header_id|>\n\nccc<|eot_id|>";
7266

7367
Assert.Equal(expected, templateResult);
7468
}
@@ -136,21 +130,15 @@ public void BasicTemplateWithAddAssistant()
136130
Assert.Equal(8, templater.Count);
137131

138132
var templateResult = Encoding.UTF8.GetString(dest);
139-
const string expected = "<|im_start|>assistant\nhello<|im_end|>\n" +
140-
"<|im_start|>user\nworld<|im_end|>\n" +
141-
"<|im_start|>assistant\n" +
142-
"111<|im_end|>" +
143-
"\n<|im_start|>user\n" +
144-
"aaa<|im_end|>\n" +
145-
"<|im_start|>assistant\n" +
146-
"222<|im_end|>\n" +
147-
"<|im_start|>user\n" +
148-
"bbb<|im_end|>\n" +
149-
"<|im_start|>assistant\n" +
150-
"333<|im_end|>\n" +
151-
"<|im_start|>user\n" +
152-
"ccc<|im_end|>\n" +
153-
"<|im_start|>assistant\n";
133+
const string expected = "<|start_header_id|>assistant<|end_header_id|>\n\nhello<|eot_id|>"
134+
+ "<|start_header_id|>user<|end_header_id|>\n\nworld<|eot_id|>"
135+
+ "<|start_header_id|>assistant<|end_header_id|>\n\n111<|eot_id|>"
136+
+ "<|start_header_id|>user<|end_header_id|>\n\naaa<|eot_id|>"
137+
+ "<|start_header_id|>assistant<|end_header_id|>\n\n222<|eot_id|>"
138+
+ "<|start_header_id|>user<|end_header_id|>\n\nbbb<|eot_id|>"
139+
+ "<|start_header_id|>assistant<|end_header_id|>\n\n333<|eot_id|>"
140+
+ "<|start_header_id|>user<|end_header_id|>\n\nccc<|eot_id|>"
141+
+ "<|start_header_id|>assistant<|end_header_id|>\n\n";
154142

155143
Assert.Equal(expected, templateResult);
156144
}
@@ -252,14 +240,14 @@ public void Clear_ResetsTemplateState()
252240
var dest = templater.Apply();
253241
var templateResult = Encoding.UTF8.GetString(dest);
254242

255-
const string expectedTemplate = $"<|im_start|>user\n{userData}<|im_end|>\n";
243+
const string expectedTemplate = $"<|start_header_id|>user<|end_header_id|>\n\n{userData}<|eot_id|>";
256244
Assert.Equal(expectedTemplate, templateResult);
257245
}
258246

259247
[Fact]
260248
public void EndOTurnToken_ReturnsExpected()
261249
{
262-
Assert.Null(_model.Tokens.EndOfTurnToken);
250+
Assert.Equal("<|eot_id|>", _model.Tokens.EndOfTurnToken);
263251
}
264252

265253
[Fact]
@@ -272,7 +260,7 @@ public void EndOSpeechToken_ReturnsExpected()
272260
var eosStr = ConvertTokenToString(_model.Tokens.EOS!.Value);
273261
_output.WriteLine(eosStr ?? "null");
274262

275-
Assert.Equal("</s>", _model.Tokens.EndOfSpeechToken);
263+
Assert.Equal("<|eot_id|>", _model.Tokens.EndOfSpeechToken);
276264
}
277265

278266
private string? ConvertTokenToString(LLamaToken token)

LLama.Unittest/Transformers/PromptTemplateTransformerTests.cs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using LLama.Common;
1+
using LLama.Common;
22
using LLama.Transformers;
33

44
namespace LLama.Unittest.Transformers;
@@ -28,9 +28,7 @@ public void HistoryToText_EncodesCorrectly()
2828
Messages = [new ChatHistory.Message(AuthorRole.User, userData)]
2929
});
3030

31-
const string expected = "<|im_start|>user\n" +
32-
$"{userData}<|im_end|>\n" +
33-
"<|im_start|>assistant\n";
31+
const string expected = $"<|start_header_id|>user<|end_header_id|>\n\n{userData}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n";
3432
Assert.Equal(expected, template);
3533
}
3634

@@ -62,21 +60,15 @@ public void ToModelPrompt_FormatsCorrectly()
6260

6361
// Call once with empty array to discover length
6462
var templateResult = PromptTemplateTransformer.ToModelPrompt(templater);
65-
const string expected = "<|im_start|>assistant\nhello<|im_end|>\n" +
66-
"<|im_start|>user\nworld<|im_end|>\n" +
67-
"<|im_start|>assistant\n" +
68-
"111<|im_end|>" +
69-
"\n<|im_start|>user\n" +
70-
"aaa<|im_end|>\n" +
71-
"<|im_start|>assistant\n" +
72-
"222<|im_end|>\n" +
73-
"<|im_start|>user\n" +
74-
"bbb<|im_end|>\n" +
75-
"<|im_start|>assistant\n" +
76-
"333<|im_end|>\n" +
77-
"<|im_start|>user\n" +
78-
"ccc<|im_end|>\n" +
79-
"<|im_start|>assistant\n";
63+
const string expected = "<|start_header_id|>assistant<|end_header_id|>\n\nhello<|eot_id|>"
64+
+ "<|start_header_id|>user<|end_header_id|>\n\nworld<|eot_id|>"
65+
+ "<|start_header_id|>assistant<|end_header_id|>\n\n111<|eot_id|>"
66+
+ "<|start_header_id|>user<|end_header_id|>\n\naaa<|eot_id|>"
67+
+ "<|start_header_id|>assistant<|end_header_id|>\n\n222<|eot_id|>"
68+
+ "<|start_header_id|>user<|end_header_id|>\n\nbbb<|eot_id|>"
69+
+ "<|start_header_id|>assistant<|end_header_id|>\n\n333<|eot_id|>"
70+
+ "<|start_header_id|>user<|end_header_id|>\n\nccc<|eot_id|>"
71+
+ "<|start_header_id|>assistant<|end_header_id|>\n\n";
8072

8173
Assert.Equal(expected, templateResult);
8274
}

0 commit comments

Comments
 (0)