-
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
28 changed files
with
742 additions
and
385 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
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
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
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,42 @@ | ||
import { List } from "immutable"; | ||
|
||
export interface ValidationMetrics { | ||
accuracy: number; | ||
loss: number; | ||
} | ||
|
||
export interface BatchLogs { | ||
accuracy: number; | ||
loss: number; | ||
memoryUsage: number; // GB | ||
} | ||
|
||
export class EpochLogs { | ||
public readonly batches: List<BatchLogs>; | ||
|
||
constructor( | ||
batches: Iterable<BatchLogs>, | ||
public readonly validation?: ValidationMetrics, | ||
) { | ||
this.batches = List(batches); | ||
} | ||
|
||
get training(): Record<"accuracy" | "loss", number> { | ||
const sum = this.batches.reduce( | ||
(acc, batch) => ({ | ||
accuracy: acc.accuracy + batch.accuracy, | ||
loss: acc.loss + batch.loss, | ||
}), | ||
{ loss: 0, accuracy: 0 }, | ||
); | ||
|
||
return { | ||
accuracy: sum.accuracy / this.batches.size, | ||
loss: sum.loss / this.batches.size, | ||
}; | ||
} | ||
|
||
get peakMemory(): number { | ||
return this.batches.map((batch) => batch.memoryUsage).max() ?? 0; | ||
} | ||
} |
Oops, something went wrong.