Skip to content

Commit

Permalink
*: bump deps
Browse files Browse the repository at this point in the history
  • Loading branch information
tharvik committed Feb 17, 2025
1 parent e14e03f commit d635230
Show file tree
Hide file tree
Showing 17 changed files with 265 additions and 273 deletions.
1 change: 0 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"dependencies": {
"server": "*",
"@epfml/discojs-node": "*",
"immutable": "4",
"tslib": "2"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion cli/src/benchmark_gpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ async function main(args: Required<CLIArguments>): Promise<void> {
for (let i = 0; i < iterations; i++) {
const timeStart = performance.now()
for (let n = 0; n < maxNewTokens; n++) {
const next: number = (await model.predict(List.of(tokens))).first();
const next = (await model.predict(List.of(tokens))).first();
if (next === undefined) throw new Error("empty prediction");
tokens = tokens.push(next)
}
inferenceTime += performance.now() - timeStart
Expand Down
5 changes: 2 additions & 3 deletions cli/src/train_gpt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ async function main(): Promise<void> {

const maxNewTokens = 14
for (let n = 0; n < maxNewTokens; n++) {
const next: number = (await model.predict(
List.of(tokens), { seed })
).first();
const next = (await model.predict(List.of(tokens), { seed })).first();
if (next === undefined) throw new Error("empty prediction");
tokens = tokens.push(next)
}
const generation = tokenizer.decode(tokens.toArray(), { skip_special_tokens: true })
Expand Down
3 changes: 1 addition & 2 deletions discojs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@
"@epfml/isomorphic-wrtc": "1",
"@jimp/core": "1",
"@jimp/plugin-resize": "1",
"@msgpack/msgpack": "^3.0.0-beta2",
"@msgpack/msgpack": "<3.0.0-beta5",
"@tensorflow/tfjs": "4",
"@xenova/transformers": "2",
"immutable": "4",
"isomorphic-ws": "5",
"simple-peer": "9",
"tslib": "2",
Expand Down
2 changes: 1 addition & 1 deletion discojs/src/aggregator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ AGGREGATORS.forEach(([name, Aggregator]) =>
Map(
network
.entrySeq()
.zip(Range(1312))
.zip(Range(1312, Number.POSITIVE_INFINITY))
.map(([[id, agg], ws]) => [
id,
[agg, WeightsContainer.of([ws])],
Expand Down
3 changes: 2 additions & 1 deletion discojs/src/client/decentralized/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ export class Peer {

return Seq.Indexed([firstChunk])
.concat(
Range(1 as ChunkID).zip(tail)
Range(1 as ChunkID, Number.POSITIVE_INFINITY)
.zip(tail)
.map(([id, raw]) => {
const chunk = Buffer.alloc(HEADER_SIZE + raw.length)
chunk.writeUint16BE(messageID)
Expand Down
8 changes: 7 additions & 1 deletion discojs/src/client/federated/federated_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export class FederatedClient extends Client {
* @returns the new global weights sent by the server
*/
override async onRoundEndCommunication(weights: WeightsContainer): Promise<WeightsContainer> {
if (this._ownId === undefined)
throw new Error("no received ID from server");
if (this.aggregationResult === undefined) {
throw new Error("local aggregation result was not set");
}
Expand All @@ -138,7 +140,11 @@ export class FederatedClient extends Client {
this.saveAndEmit("updating model")
// Send our local contribution to the server
// and receive the server global update for this round as an answer to our contribution
const payloadToServer: WeightsContainer = this.aggregator.makePayloads(weights).first()
const payloadToServer = this.aggregator
.makePayloads(weights)
.get(SERVER_NODE_ID);
if (payloadToServer === undefined)
throw new Error("aggregator didn't make a payload for the server");
const msg: messages.SendPayload = {
type: type.SendPayload,
payload: await serialization.weights.encode(payloadToServer),
Expand Down
2 changes: 1 addition & 1 deletion discojs/src/dataset/dataset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe("dataset", () => {
it("zips with non-async iterable", async () => {
const dataset = new Dataset([1, 2, 3]);

const zipped = dataset.zip(Range());
const zipped = dataset.zip(Range(0, Number.POSITIVE_INFINITY));

expect(await arrayFromAsync(zipped)).to.have.deep.ordered.members([
[1, 0],
Expand Down
17 changes: 11 additions & 6 deletions discojs/src/models/gpt/gpt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ describe("gpt-tfjs", function () {

const data = "Lorem ipsum dolor sit";
const dataTokens = processing.tokenize(tokenizer, data);
const lastToken = dataTokens.last();
if (lastToken === undefined) throw new Error("no token generated");
const seed = 42
const dataset = new Dataset<DataFormat.ModelEncoded["text"]>(
[[dataTokens.pop(), dataTokens.last()]]
).repeat().batch(8);
const dataset = new Dataset<DataFormat.ModelEncoded["text"]>([
[dataTokens.pop(), lastToken],
])
.repeat()
.batch(8);

const model = new GPT({
modelType: "gpt-nano",
Expand All @@ -34,9 +38,10 @@ describe("gpt-tfjs", function () {
const input = "Lorem ipsum dolor";
const inputTokens = processing.tokenize(tokenizer, data);

const outputToken: number = (
await model.predict(List.of(inputTokens), { seed })
).first();
const outputToken = (
await model.predict(List.of(inputTokens), { seed })
).first();
if (outputToken === undefined) throw new Error("empty prediction");
const output = tokenizer.decode([outputToken]);

expect(input + output).equal(data); // Assert that the model completes 'Lorem ipsum dolor' with 'sit'
Expand Down
5 changes: 3 additions & 2 deletions discojs/src/models/tfjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ export class TFJS<D extends "image" | "tabular"> extends Model<D> {
validationDataset?: Dataset<Batched<DataFormat.ModelEncoded[D]>>,
): AsyncGenerator<BatchLogs, EpochLogs> {
let batchesLogs = List<BatchLogs>();
for await (const [batch, batchNumber] of trainingDataset.zip(Range())) {

for await (const [batch, batchNumber] of trainingDataset.zip(
Range(0, Number.POSITIVE_INFINITY),
)) {
const batchLogs = {
batch: batchNumber,
...(await this.#runBatch(batch)),
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/wikitext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ async function main(): Promise<void> {
// Predict a few tokens
const numberOfTokens = 10;
for (let i = 0; i < numberOfTokens; i++) {
const next: number = (await model.predict(List.of(tokens))).first();
const next = (await model.predict(List.of(tokens))).first();
if (next === undefined) throw new Error("no prediction");
tokens = tokens.push(next)
}
console.log(tokenizer.decode(tokens.toArray()));
Expand Down
Loading

0 comments on commit d635230

Please sign in to comment.