@epfml/discojs-node 2.1.2-p20240507140056.0 → 2.1.2-p20240515132210.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # @epfml/discojs-node
2
+
3
+ Decentralized & federated privacy-preserving ML training in TypeScript.
4
+
5
+ This is the node-specific library of the Disco.js project,
6
+ offering some helpers.
7
+ You probably want to also use [`discojs`](../discojs).
@@ -0,0 +1,3 @@
1
+ import { models } from '@epfml/discojs';
2
+ export declare function saveModelToDisk(model: models.Model, modelFolder: string, modelFileName: string): Promise<void>;
3
+ export declare function loadModelFromDisk(modelPath: string): Promise<models.Model>;
@@ -0,0 +1,16 @@
1
+ import fs from 'node:fs/promises';
2
+ import { serialization } from '@epfml/discojs';
3
+ export async function saveModelToDisk(model, modelFolder, modelFileName) {
4
+ try {
5
+ await fs.access(modelFolder);
6
+ }
7
+ catch {
8
+ await fs.mkdir(modelFolder);
9
+ }
10
+ const encoded = await serialization.model.encode(model);
11
+ await fs.writeFile(`${modelFolder}/${modelFileName}`, encoded);
12
+ }
13
+ export async function loadModelFromDisk(modelPath) {
14
+ const content = await fs.readFile(modelPath);
15
+ return await serialization.model.decode(content);
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@epfml/discojs-node",
3
- "version": "2.1.2-p20240507140056.0",
3
+ "version": "2.1.2-p20240515132210.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",