Skip to content

Commit 66f7a60

Browse files
Clean up comments and docs (#335)
1 parent e9dfa74 commit 66f7a60

36 files changed

+126
-126
lines changed

Applications/LLMEval/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class LLMEvaluator {
234234

235235
self.prompt = modelConfiguration.defaultPrompt
236236
self.modelInfo =
237-
"Loaded \(modelConfiguration.id). Weights: \(numParams / (1024*1024))M"
237+
"Loaded \(modelConfiguration.id). Weights: \(numParams / (1024*1024))M"
238238
loadState = .loaded(modelContainer)
239239
return modelContainer
240240

Applications/LLMEval/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ memory.
3333

3434
### Troubleshooting
3535

36-
If the program crashes with a very deep stack trace you may need to build
37-
in Release configuration. This seems to depend on the size of the model.
36+
If the program crashes with a very deep stack trace, you may need to build
37+
in Release configuration. This seems to depend on the size of the model.
3838

3939
There are a couple options:
4040

41-
- build Release
42-
- force the model evaluation to run on the main thread, e.g. using @MainActor
43-
- build `Cmlx` with optimizations by modifying `mlx/Package.swift` and adding `.unsafeOptions(["-O3"]),` around line 87
41+
- Build Release
42+
- Force the model evaluation to run on the main thread, e.g. using @MainActor
43+
- Build `Cmlx` with optimizations by modifying `mlx/Package.swift` and adding `.unsafeOptions(["-O3"]),` around line 87
4444

4545
See discussion here: https://github.com/ml-explore/mlx-swift-examples/issues/3
4646

4747
### Performance
4848

4949
Different models have difference performance characteristics. For example Gemma 2B may outperform Phi-2 in terms of tokens / second.
5050

51-
You may also find that running outside the debugger boosts performance. You can do this in Xcode by pressing cmd-opt-r and unchecking "Debug Executable".
51+
You may also find that running outside the debugger boosts performance. You can do this in Xcode by pressing cmd-opt-r and unchecking "Debug Executable".

Applications/LoRATrainingExample/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Example application that:
1010
This roughly equates to the command line example in [Tools/llm-tool](../../Tools/llm-tool) and
1111
you can read more about LoRA there.
1212

13-
This evaluates the LoRA adapted model rather than a fused model. This doesn't persist
13+
This evaluates the LoRA adapted model rather than a fused model. This doesn't persist
1414
the LoRA weights or the fused model -- it will retrain it each time the program is launched.
1515

1616
### Troubleshooting

Applications/StableDiffusionExample/ContentView.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,18 @@ class StableDiffusionEvaluator {
253253
progress = .init(title: "Preparing", current: 0, limit: 1)
254254
message = nil
255255

256-
// the parameters that control the generation of the image. See
257-
// EvaluateParameters for more information. For example adjusting
256+
// The parameters that control the generation of the image. See
257+
// EvaluateParameters for more information. For example, adjusting
258258
// the latentSize parameter will change the size of the generated
259-
// image. imageCount could be used to generate a gallery of
259+
// image. `imageCount` could be used to generate a gallery of
260260
// images at the same time.
261261
let parameters = {
262262
var p = modelFactory.configuration.defaultParameters()
263263
p.prompt = prompt
264264
p.negativePrompt = negativePrompt
265265

266-
// per measurement each step consumes memory that we want to conserve. trade
267-
// off steps (quality) for memory
266+
// Per measurement each step consumes memory that we want to conserve. Trade
267+
// off steps (quality) for memory.
268268
if modelFactory.conserveMemory {
269269
p.steps = 1
270270
}
@@ -273,33 +273,33 @@ class StableDiffusionEvaluator {
273273
}()
274274

275275
do {
276-
// note: the optionals are used to discard parts of the model
277-
// as it runs -- this is used to conserveMemory in devices
278-
// with less memory
276+
// Note: The optionals are used to discard parts of the model
277+
// as it runs. This is used to conserve memory in devices
278+
// with less memory.
279279
let container = try await modelFactory.load(reportProgress: updateProgress)
280280

281281
try await container.performTwoStage { generator in
282-
// the parameters that control the generation of the image. See
283-
// EvaluateParameters for more information. For example adjusting
284-
// the latentSize parameter will change the size of the generated
285-
// image. imageCount could be used to generate a gallery of
282+
// The parameters that control the generation of the image. See
283+
// EvaluateParameters for more information. For example adjusting
284+
// the `latentSize` parameter will change the size of the generated
285+
// image. `imageCount` could be used to generate a gallery of
286286
// images at the same time.
287287
var parameters = modelFactory.configuration.defaultParameters()
288288
parameters.prompt = prompt
289289
parameters.negativePrompt = negativePrompt
290290

291-
// per measurement each step consumes memory that we want to conserve. trade
292-
// off steps (quality) for memory
291+
// Per measurement each step consumes memory that we want to conserve. Trade
292+
// off steps (quality) for memory.
293293
if modelFactory.conserveMemory {
294294
parameters.steps = 1
295295
}
296296

297-
// generate the latent images -- this is fast as it is just generating
298-
// the graphs that will be evaluated below
297+
// Generate the latent images. This is fast as it is just generating
298+
// the graphs that will be evaluated below.
299299
let latents: DenoiseIterator? = generator.generateLatents(parameters: parameters)
300300

301-
// when conserveMemory is true this will discard the first part of
302-
// the model and just evaluate the decode portion
301+
// When conserveMemory is true this will discard the first part of
302+
// the model and just evaluate the decode portion.
303303
return (generator.detachedDecoder(), latents)
304304

305305
} second: { decoder, latents in

Applications/StableDiffusionExample/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ If you are interested in adjusting the generated images, look in
2323
Stable diffusion can run in less that 4G available memory (typically a
2424
device or computer with 6G of memory or more) in a constrained mode -- it will
2525
load and unload parts of the model as it runs and it can only perform one step
26-
of diffusion. This is configured automatically, see `modelFactory.conserveMemory`
26+
of diffusion. This is configured automatically, see `modelFactory.conserveMemory`
2727
in [ContentView.swift](ContentView.swift).
2828

2929
On a device or computer with more memory the model will be kept resident and

Libraries/Embedders/Configuration.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public enum StringOrNumber: Codable, Equatable, Sendable {
2828

2929
private class ModelTypeRegistry: @unchecked Sendable {
3030

31-
// Note: using NSLock as we have very small (just dictionary get/set)
32-
// critical sections and expect no contention. this allows the methods
31+
// Note: Using NSLock as we have very small (just dictionary get/set)
32+
// critical sections and expect no contention. This allows the methods
3333
// to remain synchronous.
3434
private let lock = NSLock()
3535

Libraries/Embedders/EmbeddingModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Tokenizers
88

99
/// Container for models that guarantees single threaded access.
1010
///
11-
/// Wrap models used by e.g. the UI in a ModelContainer. Callers can access
11+
/// Wrap models used by e.g. the UI in a ModelContainer. Callers can access
1212
/// the model and/or tokenizer:
1313
///
1414
/// ```swift
@@ -55,7 +55,7 @@ public actor ModelContainer {
5555
self.pooler = loadPooling(modelDirectory: modelDirectory) //?? Pooling(strategy: .none)
5656
}
5757

58-
/// Perform an action on the model and/or tokenizer. Callers _must_ eval any `MLXArray` before returning as
58+
/// Perform an action on the model and/or tokenizer. Callers _must_ eval any `MLXArray` before returning as
5959
/// `MLXArray` is not `Sendable`.
6060
public func perform<R>(_ action: @Sendable (EmbeddingModel, Tokenizer, Pooling) throws -> R)
6161
rethrows

Libraries/Embedders/Models.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import Foundation
44
import Hub
55

66
/// Registry of models and any overrides that go with them, e.g. prompt augmentation.
7-
/// If asked for an unknown configuration this will use the model/tokenizer as-is.
7+
/// If asked for an unknown configuration this will use the model/tokenizer as is.
88
///
9-
/// The python tokenizers have a very rich set of implementations and configuration. The
9+
/// The Python tokenizers have a very rich set of implementations and configuration. The
1010
/// swift-tokenizers code handles a good chunk of that and this is a place to augment that
1111
/// implementation, if needed.
1212
public struct ModelConfiguration: Sendable {

Libraries/MLXLLM/Documentation.docc/adding-model.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public struct YourModelConfiguration: Codable, Sendable {
3030

3131
## Create the Model Class
3232

33-
Create the model class. The top-level public class should have a
33+
Create the model class. The top-level public class should have a
3434
structure something like this:
3535

3636
```swift

Libraries/MLXLLM/Documentation.docc/using-model.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ load models, if needed.
6363
## Evaluating a Model
6464

6565
Once a model is loaded you can evaluate a prompt or series of
66-
messages. Minimally you need to prepare the user input:
66+
messages. Minimally you need to prepare the user input:
6767

6868
```swift
6969
let prompt = "Describe the image in English"
@@ -72,7 +72,7 @@ input.processing.resize = .init(width: 256, height: 256)
7272
```
7373

7474
This example shows adding some images and processing instructions -- if
75-
model accepts text only then these parts can be omitted. The inference
75+
model accepts text only then these parts can be omitted. The inference
7676
calls are the same.
7777

7878
Assuming you are using a `ModelContainer` (an actor that holds
@@ -90,7 +90,7 @@ let result = try await modelContainer.perform { [input] context in
9090
```
9191

9292
Given that `input` we can call `generate()` to produce a stream
93-
of tokens. In this example we use a `NaiveStreamingDetokenizer`
93+
of tokens. In this example we use a `NaiveStreamingDetokenizer`
9494
to assist in converting a stream of tokens into text and print it.
9595
The stream is stopped after we hit a maximum number of tokens:
9696

0 commit comments

Comments
 (0)