Skip to content

Commit 706490b

Browse files
authored
TextLLMRunner test. (#12731)
Summary: . Reviewed By: mergennachin Differential Revision: D77436559
1 parent d5a7f33 commit 706490b

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
import ExecuTorchLLM
10+
import XCTest
11+
12+
struct SpecialTokens {
13+
static let kSpecialTokensSize = 256
14+
15+
static func defaultSpecialTokens() -> [String] {
16+
var tokens = [
17+
"<|begin_of_text|>",
18+
"<|end_of_text|>",
19+
"<|reserved_special_token_0|>",
20+
"<|reserved_special_token_1|>",
21+
"<|finetune_right_pad_id|>",
22+
"<|step_id|>",
23+
"<|start_header_id|>",
24+
"<|end_header_id|>",
25+
"<|eom_id|>",
26+
"<|eot_id|>",
27+
"<|python_tag|>"
28+
]
29+
var reservedIndex = 2
30+
while tokens.count < kSpecialTokensSize {
31+
tokens.append("<|reserved_special_token_\(reservedIndex)|>")
32+
reservedIndex += 1
33+
}
34+
return tokens
35+
}
36+
}
37+
38+
class TextLLMRunnerTest: XCTestCase {
39+
func test() {
40+
let bundle = Bundle(for: type(of: self))
41+
guard let modelPath = bundle.path(forResource: "llama3_2-1B", ofType: "pte"),
42+
let tokenizerPath = bundle.path(forResource: "tokenizer", ofType: "model") else {
43+
XCTFail("Couldn't find model or tokenizer files")
44+
return
45+
}
46+
let runner = TextLLMRunner(modelPath: modelPath, tokenizerPath: tokenizerPath, specialTokens: SpecialTokens.defaultSpecialTokens())
47+
var text = ""
48+
49+
do {
50+
try runner.generate("hello", sequenceLength: 2) { token in
51+
text += token
52+
}
53+
} catch {
54+
XCTFail("Failed to generate text with error \(error)")
55+
}
56+
XCTAssertEqual("hello,", text.lowercased())
57+
}
58+
}

0 commit comments

Comments
 (0)