You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/llm/run-on-ios.md
+146-8Lines changed: 146 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,17 +80,22 @@ do {
80
80
81
81
#### Generating
82
82
83
-
Generate up to a given number of tokens from an initial prompt. The callback block is invoked once per token as it’s produced.
83
+
Generate tokens from an initial prompt, configured with an `ExecuTorchLLMConfig` object. The callback block is invoked once per token as it’s produced.
BOOL success = [runner generate:@"Once upon a time"
89
-
sequenceLength:50
90
-
withTokenCallback:^(NSString *token) {
91
-
NSLog(@"Generated token: %@", token);
92
-
}
93
-
error:&error];
93
+
BOOL success = [runner generateWithPrompt:@"Once upon a time"
94
+
config:config
95
+
tokenCallback:^(NSString *token) {
96
+
NSLog(@"Generated token: %@", token);
97
+
}
98
+
error:&error];
94
99
if (!success) {
95
100
NSLog(@"Generation failed: %@", error);
96
101
}
@@ -99,7 +104,10 @@ if (!success) {
99
104
Swift:
100
105
```swift
101
106
do {
102
-
try runner.generate("Once upon a time", sequenceLength: 50) { token in
107
+
try runner.generate("Once upon a time", Config {
108
+
$0.temperature = 0.8
109
+
$0.sequenceLength = 2048
110
+
}) { token in
103
111
print("Generated token:", token)
104
112
}
105
113
} catch {
@@ -121,6 +129,136 @@ Swift:
121
129
runner.stop()
122
130
```
123
131
132
+
#### Resetting
133
+
134
+
To clear the prefilled tokens from the KV cache and reset generation stats, call:
135
+
136
+
Objective-C:
137
+
```objectivec
138
+
[runner reset];
139
+
```
140
+
141
+
Swift:
142
+
```swift
143
+
runner.reset()
144
+
```
145
+
146
+
### MultimodalRunner
147
+
148
+
The `ExecuTorchLLMMultimodalRunner` class (bridged to Swift as `MultimodalRunner`) provides an interface for loading and running multimodal models that can accept a sequence of text, image, and audio inputs.
149
+
150
+
#### Multimodal Inputs
151
+
152
+
Inputs are provided as an array of `ExecuTorchLLMMultimodalInput` (or `MultimodalInput` in Swift). You can create inputs from String for text, `ExecuTorchLLMImage` for images (`Image` in Swift), and `ExecuTorchLLMAudio` for audio features (`Audio`) in Swift.
153
+
154
+
Objective-C:
155
+
```objectivec
156
+
ExecuTorchLLMMultimodalInput *textInput = [ExecuTorchLLMMultimodalInput inputWithText:@"What's in this image?"];
The stop and reset methods for `MultimodalRunner` behave identically to those on `TextRunner`.
261
+
124
262
## Demo
125
263
126
264
Get hands-on with our [etLLM iOS Demo App](https://github.com/meta-pytorch/executorch-examples/tree/main/llm/apple) to see the LLM runtime APIs in action.
0 commit comments