-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
discojs/model: expose batch generator
- Loading branch information
Showing
11 changed files
with
341 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export async function get_return_value<T>( | ||
iter: AsyncIterator<unknown, T>, | ||
): Promise<T> { | ||
for (;;) { | ||
const v = await iter.next(); | ||
if (!v.done) continue; | ||
return v.value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { List } from "immutable"; | ||
|
||
export interface BatchLogs { | ||
batch: number; // first batch is zero | ||
accuracy: number; | ||
loss: number; | ||
memoryUsage: number; // GB | ||
} | ||
|
||
export class EpochLogs { | ||
public readonly batches: List<BatchLogs>; | ||
|
||
constructor( | ||
public readonly epoch: number, // first epoch is zero | ||
batches: Iterable<BatchLogs>, | ||
public readonly validation?: Record<"accuracy" | "loss", number>, | ||
) { | ||
this.batches = List(batches); | ||
} | ||
|
||
get training(): Record<"accuracy" | "loss", number> { | ||
return this.batches.reduce( | ||
(acc, batch) => ({ | ||
accuracy: acc.accuracy + batch.accuracy, | ||
loss: acc.loss + batch.loss, | ||
}), | ||
{ loss: 0, accuracy: 0 }, | ||
); | ||
} | ||
|
||
get peakMemory(): number { | ||
return this.batches.map((batch) => batch.memoryUsage).max() ?? 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.