File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
extension/llm/apple/ExecuTorchLLM/__tests__ Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments