Skip to content

Commit f015a49

Browse files
committed
Simplify the nextTick trick
1 parent a56c790 commit f015a49

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

llm.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'node:fs'
22
import path from 'node:path'
3+
import nextTick from 'tick-promise'
34
import {core as mx, nn} from '@frost-beta/mlx'
45

56
import {Model} from './model.js'
@@ -52,11 +53,8 @@ export async function* step(promptTokens, model, topP = 1, temperature = 1) {
5253
const [token, prob] = mx.tidy(() => forward(tokens))
5354
tokens = [token]
5455
// Yield the result in the next tick of loop, so GC can get a chance to run.
55-
// TODO(zcbenz): Use the async API after this MLX issue is solved:
56-
// https://github.com/ml-explore/mlx/issues/1251
57-
yield await new Promise((resolve) => {
58-
process.nextTick(() => resolve([token, prob]))
59-
})
56+
await nextTick()
57+
yield [token, prob]
6058
}
6159
}
6260

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
},
1818
"dependencies": {
1919
"@frost-beta/mlx": "0.0.11",
20-
"@lenml/tokenizers": "1.0.2"
20+
"@lenml/tokenizers": "1.0.2",
21+
"tick-promise": "1.0.0"
2122
}
2223
}

0 commit comments

Comments
 (0)