Skip to content

Commit 45bb344

Browse files
Merge pull request #71 from OpenMined/vvm/update-serde
Update serde, fix with-node example
2 parents e1e30fb + e5964f6 commit 45bb344

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

examples/with-grid/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939

4040
<title>syft.js Example</title>
4141

42-
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.2.5/dist/tf.min.js"></script>
42+
<!-- NOTE: TFJS version must match with one in package-lock.json -->
43+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.5.1/dist/tf.min.js"></script>
4344
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
4445
</head>
4546
<body>
@@ -71,7 +72,7 @@ <h1>syft.js/grid.js testing</h1>
7172
>.
7273
</p>
7374
<input type="text" id="grid-server" value="ws://localhost:3000" />
74-
<input type="text" id="protocol" value="5259950754" />
75+
<input type="text" id="protocol" value="50801316202" />
7576
<button id="connect">Connect to grid.js server</button>
7677
<div id="app">
7778
<button id="disconnect">Disconnect</button>

jest-globals.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
global.tf = {
2-
tensor: (value, shape, type) => {
3-
console.log('Created a tensor!', value, shape, type);
4-
},
5-
add: jest.fn(),
6-
abs: jest.fn()
7-
};
1+
import * as tf from '@tensorflow/tfjs';
2+
const tensor = tf.tensor;
3+
jest.spyOn(tf, 'tensor').mockImplementation((values, shape, dtype) => {
4+
let t = tensor(values, shape, dtype);
5+
// override id to always return same value
6+
Object.defineProperty(t, 'id', {
7+
value: 42
8+
});
9+
return t;
10+
});

src/_helpers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TorchTensor } from './types/torch';
22
import PointerTensor from './types/pointer-tensor';
33
import { CANNOT_FIND_COMMAND } from './_errors';
4+
import * as tf from '@tensorflow/tfjs';
45

56
export const pickTensors = tree => {
67
const objects = {};

src/serde.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export const detail = data => {
8888
[proto['torch.Size']]: d => new TorchSize(d),
8989
[proto['syft.messaging.plan.plan.Plan']]: d => new Plan(...d.map(i => parse(i))),
9090
[proto['syft.messaging.plan.state.State']]: d => new State(...d.map(i => parse(i))),
91-
[proto['syft.messaging.plan.procedure.Procedure']]: d => new Procedure(d[0].map(i => parse(i)), ...d.slice(1).map(i => parse(i))),
91+
[proto['syft.messaging.plan.procedure.Procedure']]: d => new Procedure(...d.map(i => parse(i))),
9292
[proto['syft.messaging.protocol.Protocol']]: d => new Protocol(...d.map(i => parse(i))),
9393
[proto['syft.generic.pointers.pointer_tensor.PointerTensor']]: d => new PointerTensor(...d.map(i => parse(i))),
9494
[proto['syft.messaging.message.Message']]: d => new Message(...d.map(i => parse(i))),

src/types/torch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { default as proto } from '../proto';
2+
import * as tf from '@tensorflow/tfjs';
23

34
export class TorchTensor {
45
constructor(id, bin, chain, gradChain, tags, description, serializer) {

0 commit comments

Comments
 (0)