Giter Site home page Giter Site logo

openmined / syft.js Goto Github PK

View Code? Open in Web Editor NEW
147.0 26.0 57.0 19.61 MB

The official Syft worker for Web and Node, built in Javascript

License: Apache License 2.0

JavaScript 96.81% Shell 0.11% Python 3.08%
deep-learning privacy typescript javascript syft hacktoberfest

syft.js's Introduction

syft.js logo

Build codecov npm GitHub OpenCollective

All Contributors

Syft.js

Syft.js is the β€œweb” part of the OpenMined's open-source ecosystem for federated learning, which currently spans across web, iOS, Android, and servers/IoT.

Syft.js has following core features:

  • πŸ› οΈ Integration with PyGrid federated learning API.
  • βš™οΈ Training and inference of any PySyft model written in PyTorch or TensorFlow.
  • πŸ‘€ Allows all data to stay on the user's device.
  • πŸ”’ Support for secure multi-party computation and secure aggregation protocols using peer-to-peer WebRTC connections (in progress).

The library is built on top of TensorFlow.js.

There are a variety of additional privacy-preserving protections that may be applied, including differential privacy, muliti-party computation, and secure aggregation.

If you want to know how scalable federated systems are built, Towards Federated Learning at Scale is a fantastic introduction!

Installation

Note that syft.js needs Tensorflow.js library as peer dependency.

If you're using a package manager like NPM:

npm install --save @openmined/syft.js @tensorflow/tfjs-core

Or if Yarn is your cup of tea:

yarn add @openmined/syft.js @tensorflow/tfjs-core

If you're not using a package manager, you will be able to include Syft.js within a <script> tag. In this case library classes will be available under syft global object.

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@openmined/syft.js@latest/dist/index.min.js"></script>

<script type="text/javascript">
  // Create syft worker
  const worker = syft.Syft({...});
  ...
</script>

Quick Start

As a developer, there are few steps to building your own secure federated learning system upon the OpenMined infrastructure:

  1. πŸ€– Develop ML model and training procedure (aka Plan in PySyft terminology) using PySyft.
  2. 🌎 Host model and Plans on PyGrid, which will deal with all the federated learning components of your pipeline.
  3. πŸŽ‰ Execute the training on the variety of end-user devices using the client library (syft.js, SwiftSyft, KotlinSyft, PySyft).
  4. πŸ”’ Securely aggregate trained user models in PyGrid.

πŸ““ The entire workflow and process is described in greater detail in the Web & Mobile Federated Learning project roadmap.

Syft.js provides minimalistic API to communicate with federated learning PyGrid endpoints and execute PySyft's Plans in a browser. The federated learning cycle implemented with syft.js would contain following steps:

  • Register into training cycle on PyGrid.
  • Download required model and Plans from PyGrid.
  • Execute the Plan with given model parameters and local user's data (multiple times) to create better model.
  • Submit difference between original and trained model parameters for aggregation.

These steps can be expressed in the following code:

import * as tf from '@tensorflow/tfjs-core';
import { Syft } from '@openmined/syft.js';

const gridUrl = 'ws://pygrid.myserver.com:5000';
const modelName = 'my-model';
const modelVersion = '1.0.0';

// if the model is protected with authentication token (optional)
const authToken = '...';

const worker = new Syft({ gridUrl, verbose: true });
const job = await worker.newJob({ modelName, modelVersion, authToken });
job.request();

job.on('accepted', async ({ model, clientConfig }) => {
  const batchSize = clientConfig.batch_size;
  const lr = clientConfig.lr;

  // Load data.
  const [data, target] = LOAD_DATA();
  const batches = MAKE_BATCHES(data, target, batchSize);

  // Load model parameters.
  let modelParams = model.params.map((p) => p.clone());

  // Main training loop.
  for (let [dataBatch, targetBatch] of batches) {
    // NOTE: this is just one possible example.
    // Plan name (e.g. 'training_plan'), its input arguments and outputs depends on FL configuration and actual Plan implementation.
    let updatedModelParams = await job.plans['training_plan'].execute(
      job.worker,
      dataBatch,
      targetBatch,
      batchSize,
      lr,
      ...modelParams
    );

    // Use updated model params in the next iteration.
    for (let i = 0; i < modelParams.length; i++) {
      modelParams[i].dispose();
      modelParams[i] = updatedModelParams[i];
    }
  }

  // Calculate & send model diff.
  const modelDiff = await model.createSerializedDiff(modelParams);
  await job.report(modelDiff);
});

job.on('rejected', ({ timeout }) => {
  // Handle the job rejection, e.g. re-try after timeout.
});

job.on('error', (err) => {
  // Handle errors.
});

Model Training API

The Plan execution and Model training can be implemented easier using training helper that will do training loop for you (model, batch size, etc. are automatically taken from Job):

  // Main training loop.
  const training = job.train('training_plan', {
    inputs: [/* ... */],
    outputs: [/* ... */],
    data,
    target,
  });

  training.on('end', async () => {
      // Calculate & send model diff.
      const modelDiff = await model.createSerializedDiff(modelParams);
      await job.report(modelDiff);
  });

inputs and outputs need to be specified using PlanInputSpec and PlanOutputSpec and need to match with Plan's arguments and outputs. For example, if the Plan has following arguments and outputs:

loss, accuracy, modelParams1, modelParams2, modelParams3, modelParams4 = 
    plan(dataBatch, targetBatch, batchSize, lr, modelParams1, modelParams2, modelParams3, modelParams4)

Corresponding inputs, outputs in job.train will be:

const inputs = [
    new PlanInputSpec(PlanInputSpec.TYPE_DATA),
    new PlanInputSpec(PlanInputSpec.TYPE_TARGET),
    new PlanInputSpec(PlanInputSpec.TYPE_BATCH_SIZE),
    new PlanInputSpec(PlanInputSpec.TYPE_CLIENT_CONFIG_PARAM, 'lr'),
    new PlanInputSpec(PlanInputSpec.TYPE_MODEL_PARAM, 'param1', 0),
    new PlanInputSpec(PlanInputSpec.TYPE_MODEL_PARAM, 'param2', 1),
    new PlanInputSpec(PlanInputSpec.TYPE_MODEL_PARAM, 'param3', 2),
    new PlanInputSpec(PlanInputSpec.TYPE_MODEL_PARAM, 'param4', 3),
];

const outputs = [
    new PlanOutputSpec(PlanOutputSpec.TYPE_LOSS),
    new PlanOutputSpec(PlanOutputSpec.TYPE_METRIC, 'accuracy'),
    new PlanOutputSpec(PlanOutputSpec.TYPE_MODEL_PARAM, 'param1', 0),
    new PlanOutputSpec(PlanOutputSpec.TYPE_MODEL_PARAM, 'param2', 1),
    new PlanOutputSpec(PlanOutputSpec.TYPE_MODEL_PARAM, 'param3', 2),
    new PlanOutputSpec(PlanOutputSpec.TYPE_MODEL_PARAM, 'param4', 3),
];

Stop & Resume

PlanTrainer allows stopping and resuming the training using stop and resume methods:

  // Main training loop.
  const training = job.train('training_plan', {
    inputs: [/* ... */],
    outputs: [/* ... */],
    data,
    target,
  });

  training.on('start', () => {
    // training is started!
  });

  training.on('stop', () => {
    // training is stopped!
  });

  document.getElementById('stop-button').onclick = () => {
    training.stop();
  };

  document.getElementById('resume-button').onclick = () => {
    training.resume();
  };

Checkpointing

stop method returns current training state as PlanTrainerCheckpoint object, which can be serialized to JSON to restored from JSON later to continue the training:

const checkpoint = await training.stop();
const checkpointJson = await checkpoint.toJSON();
const checkpointJsonString = JSON.stringify(checkpointJson);
localStorage.setItem('checkpoint', checkpointJsonString);

// ... checkpoint can survive page reload ...

const checkpointJsonString = localStorage.getItem('checkpoint');
const checkpointJson = JSON.parse(checkpointJsonString);
const checkpoint = PlanTrainerCheckpoint.fromJSON(worker, checkpointJson);
    
// Main training loop.
const training = job.train('training_plan', {
  // Pass checkpoint into train method to resume from it
  // NOTE: checkpoint doesn't store Plan and training data, these still need to be supplied
  checkpoint,
  inputs: [/* ... */],
  outputs: [/* ... */],
  data,
  target,
});

Checkpoint can be created directly from PlanTrainer object using createCheckpoint method and applied back using applyCheckpoint:

const checkpoint = training.createCheckpoint();
// ...
training.applyCheckpoint(checkpoint);
training.resume();

Dataset / DataLoader API

One way to provide training data into PlanTrainer is to prepare and pass data and target parameters as plain tf.Tensor's. Another way is to use Dataset and DataLoader classes, which are simplified version of PyTorch's implementation.

Dataset class needs to be extended to implement element-wise access to the data. Resulting dataset is used with DataLoader that handles shuffling and batching of dataset elements.
The DataLoader can passed as data parameter into the PlanTrainer.

class MyDataset extends data.Dataset {
  
  constructor() {
    super();
    // this.data = ...;
    // this.target = ...;
  }

  getItem(index) {
    return [
      this.data[index],
      this.target[index]
    ];
  }

  get length() {
    return this.data.length;
  }
}

const dataset = new MyDataset();
const dl = new DataLoader({dataset, batchSize: 64, shuffle: true});

// Use with PlanTrainer
const training = job.train('training_plan', {
    inputs: [/* ... */],
    outputs: [/* ... */],
    data: dl
});

// Or use with custom training loop
for (const [data, target] of dl) {
  // ...
}

MNIST example has implementation of MNIST dataset based on Dataset class and DataLoader usage and additionally introduces data transformations using Transform.

API Documentation

See API Documentation for complete reference.

Running the Demo App

The β€œHello World” syft.js demo is MNIST training example located in examples/mnist folder. It demonstrates how a simple neural net model created in PySyft can be trained in a browser and the result of training averaged from multiple federated learning participants.

syft.js MNIST demo animation

Running the demo is multi-stage and multi-component process (as the federated learning itself).

Below are example instructions that assume you want to put everything under ~/fl-demo folder.

Installation

It is recommended that you install python packages in separate virtualenv or conda environment, e.g.:

virtualenv -p python3 syft
source syft/bin/activate

or

conda create -n syft python=3.7
conda activate syft

Now, you will need to install following packages:

  • PySyft. Follow PySyft installation guide to install the latest 0.2.x branch of PySyft.

  • PyGrid. Follow PyGrid documentation to install the latest dev branch of PyGrid.

  • Syft.js with MNIST demo. Check out the latest dev branch of syft.js with MNIST demo app included:

    cd ~/fl-demo
    git clone https://github.com/OpenMined/syft.js
    cd syft.js
    npm install
    cd examples/mnist
    npm install

Seeding the Model & Plan

Syft.js connects to PyGrid to pick up the model and training Plan. For the demo to work, we need to populate that data into PyGrid.

Run PyGrid Node

See Getting Started for details. It is possible to start PyGrid Node using docker or using console script.

We assume you don't need to change default PyGrid Node configuration and it listens on the localhost:5000. If you need to use different host/port, PyGrid URL will need to be adjusted accordingly in further steps.

Create Model & Plan

After PyGrid is running, the next step is to create the model and training plan and host them in PyGrid. MNIST example jupyter notebooks guide you through this process.

Fire up jupyter notebook in PyGrid root folder:

cd ~/fl-demo/PyGrid
jupyter notebook --notebook-dir=$(pwd)

In the console, you should see URL you should open, or the browser will open automatically. After this, navigate to examples/model-centric and run the first notebook. At this point, you can pull down the model and training plan with syft.js. However, if you'd like to see how to execute the plan using the PySyft FL worker, try running the second notebook.

PyGrid Node Clean-up

In case you need to reset PyGrid Node database to blank state, stop the process with Ctrl+C and remove databaseGateway.db file in PyGrid. Or, if you used docker-compose, stop and re-start it using docker-compose up --force-recreate command.

Starting the Demo

Finally, we got to the browser part of the demo:

cd ~/fl-demo/syft.js/examples/mnist
npm start

This should start development server and open localhost:8080 in the browser. Assuming PyGrid URL, MNIST model name and version were not modified in previous steps, just press β€œStart FL Worker”.

You should see following in dev console:

  • Syft.js registers into training cycle on PyGrid and gets configuration, Plan, and the model.
  • App loads MNIST dataset and executes the training plan with each data batch. Charts are updated during this process, and you should see the training loss going down and the accuracy going up.
  • After the training is complete, model diff is submitted to PyGrid.

If β€œKeep making cycle requests” is checked, the whole cycle process is repeated until PyGrid tells worker that model training is complete.

Compatibility

PySyft

Syft.js has been tested with PySyft 0.2.7

PyGrid

Syft.js has been tested with the latest version of PyGrid on master.

Tensorflow.js

Syft.js was tested with Tensorflow.js v1.2.5.

Browser Support

Syft.js was tested with Chrome and Firefox browsers.

Support

For support in using this library, please join the #lib_syftjs Slack channel. If you’d like to follow along with any code changes to the library, please join the #code_syftjs Slack channel. Click here to join our Slack community!

Contributing

Please check open issues as a starting point.

Bug reports and feature suggestions are welcomed as well.

The workflow is usual for github, the master branch is considered stable and the dev branch is actively under development:

  1. Star, fork, and clone the syft.js repository.
  2. Create a new branch for changes from dev.
  3. Push changes to this branch.
  4. Submit a PR to OpenMined/syft.js.
  5. PR is reviewed and accepted.

Read the contribution guide as a good starting place. Additionally, we welcome you to the slack for queries related to the library and contribution in general. The Slack channel #lib_syftjs is specific to syft.js development. See you there!

Contributors

These people were integral part of the efforts to bring syft.js to fruition and in its active development.


Patrick Cason

πŸ€” πŸ’» 🎨 πŸ“– πŸ’Ό

Vova Manannikov

πŸ’» πŸ“– ⚠️

Mike Nolan

πŸ’»

Ravikant Singh

πŸ’» ⚠️ πŸ“–

varun khare

πŸ’»

Pedro EspΓ­ndula

πŸ“–

JosΓ© Benardi de Souza Nunes

⚠️

Tajinder Singh

πŸ’»

License

Apache License 2.0

syft.js's People

Contributors

adgelbfish avatar allcontributors[bot] avatar benardi avatar cereallarceny avatar dependabot[bot] avatar harshgrandeur avatar iamtrask avatar johndoe12312 avatar k105la avatar lucaslopes avatar matthew-mcateer avatar nahuakang avatar nolski avatar pedroespindula avatar prtfw avatar rajeshhegde avatar rav1kantsingh avatar shoniko avatar tanaygahlot avatar thefirebanks avatar tisd avatar tsingh2k15 avatar veena-v-g avatar vkkhare avatar vvmnnnkv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

syft.js's Issues

Improve build system

We need to allow for the Syft.js build system to be compiled and usable (via NPM install). Currently the package is published here: https://www.npmjs.com/package/syft.js. We need to be able to include it in the following formats:

Methods of importing

ES6/7 import:

import syft from 'syft.js';

Require:

const syft = require('syft.js');

Script include:

<script src="/node_modules/syft.js/lib/index.js"></script>

Referencing in Javascript

const mySyft = new syft(url);

Testing sockets

We really need some test coverage around our WebSocket code. Currently, this has tests written for it, but they're definitely out of date. Let's get 100% coverage across the board and then move on to testing our WebRTC integration.

Include Tensorflow.js dependency the right way

Problem

  1. syft.js demo app throws several warnings during startup:
webgl backend was already registered. Reusing existing backend factory.
cpu backend was already registered. Reusing existing backend factory.
Platform browser has already been set. Overwriting the platform with [object Object].
syft.js/src/_helpers.js 33:6-23
"export 'hasOwnProperty' (imported as 'tf') was not found in '@tensorflow/tfjs'
  1. Unit tests display lots of warnings like these:
    console.warn node_modules/@tensorflow/tfjs-core/dist/log.js:26
      
      ============================
      Hi there οΏ½. Looks like you are running TensorFlow.js in Node.js. To speed things up dramatically, install our node backend, which binds to TensorFlow C++, by running npm i @tensorflow/tfjs-node, or npm i @t
ensorflow/tfjs-node-gpu if you have CUDA. Then call require('@tensorflow/tfjs-node'); (-gpu suffix for CUDA) at the start of your program. Visit https://github.com/tensorflow/tfjs-node for more details.
      ============================

Expected behavior

1 - It seems that TFJS library is being initialized multiple times. We prefer to produce the bundle where the library is NOT included in syft.js itself, instead it is expected to be loaded separately (like in demo app).

2 - It would be nice to suppress these warnings, or use tfjs-node specifically for unit tests to avoid them.

Unit Testing Suite

Create an initial unit testing suite, create a demo unit test, and add the command to run unit tests to the Readme.md

Write inline documentation for src/job.js

Where?

src/job.js

Who?

Any developer who wants to work on syft.js should be able to read inline documentation for this file, as well as any file in the project.

What?

We need to go "line-by-line" and create inline documentation for this file. Please try to use proper punctuation and English grammar to the best of your ability.

Additional Context

None

Write inline documentation for src/grid-api-client.js

Where?

src/grid-api-client.js

Who?

Any developer who wants to work on syft.js should be able to read inline documentation for this file, as well as any file in the project.

What?

We need to go "line-by-line" and create inline documentation for this file. Please try to use proper punctuation and English grammar to the best of your ability.

Additional Context

None

Remote Addition

In Issue #9 , we implemented functionality that allowed PySyft to send a tensor to syft.js which is saved in a local dictionary called _objects. In this issue, we want PySyft to be able to send JSON to add two tensors together (which have previously been sent to syft.js).

This json command is sent automatically when two PySyft tensors are added together.

import torch

from syft.core.hooks import TorchHook
from syft.core.workers import WebSocketWorker

hook = TorchHook(local_worker=WebSocketWorker(id=0, port=1111, verbose=True))
remote_client = WebSocketWorker(hook=hook,id=2, port=1112, is_pointer=True, verbose=True)
hook.local_worker.add_worker(remote_client)
x = torch.FloatTensor([1,2,3,4,5]).send(remote_client)
x2 = torch.FloatTensor([1,2,3,4,4]).send(remote_client)
y = x + x2

.send is the functionality that already works as of Issue #9

This command should add x and x2 together when "y = x + x2" command is executed (which sends a JSON command to syft.js)

Create an auto-generated API reference documentation

Where?

The entire project

Who?

Developers looking to implement the library in their application.

What?

We want to provide automatically generated API reference documentation to allow developers to use our library in their application to be able to read all publicly available methods and their signatures. This documentation is purely meant to be functional. It does not need to look pretty, but it does need to be very organized. Here is an example of what you should aim to reproduce.

Additional Context

  • Generate this file to the root of the project located at /API-REFERENCE.md
  • Set it to run the regeneration function on every commit and add it to the current commit
  • Add a reference to this file from the Usage section of the main readme

Test all major features

Description

We want to test all major features of the federated learning process in this repo. This includes:

  • Mocking PyGrid in order to run the test suite without the use of another server running (these endpoints will likely be what you want to mock)
  • Testing a flow with no authentication
  • Testing a flow with basic JWT authentication (failing)
  • Testing a flow with basic JWT authentication (passing)
  • Testing the acceptance of a worker in an FL cycle request
  • Testing the timeout for the re-application of an FL cycle request
  • Testing the graceful handling of an error whereby a plan or model does not exist in PyGrid from what is being requested
  • Testing the creation of one job
  • Testing the creation of multiple jobs
  • Testing that a job can be completed successfully
  • Testing that multiple jobs can be completed successfully
  • Testing that errors in a job can be caught by the onError handler and handled appropriately
  • Testing that we can successfully report a model diff to PyGrid
  • Any other related tests, or permutations of the above tests, that are required to pass for a developer to successfully use this library... in other words, be thorough and test everything you can think of that a developer might do.

Type of Test

  • Unit test (e.g. checking a loop, method, or function is working as intended)
  • Integration test (e.g. checking if a certain group or set of functionality is working as intended)
  • Regression test (e.g. checking if by adding or removing a module of code allows other systems to continue to function as intended)
  • Stress test (e.g. checking to see how well a system performs under various situations, including heavy usage)
  • Performance test (e.g. checking to see how efficient a system is as performing the intended task)
  • Other...

Expected Behavior

We expect all the above tests to pass.

Additional Context

None

Write inline documentation for src/object-registry.js

Where?

src/object-registry.js

Who?

Any developer who wants to work on syft.js should be able to read inline documentation for this file, as well as any file in the project.

What?

We need to go "line-by-line" and create inline documentation for this file. Please try to use proper punctuation and English grammar to the best of your ability.

Additional Context

None

Implement the command translation layer inside of syft.js

The Threepio project is set to replace the convertToTF() function in syft.ks. This function currently only provides rudimentary, and very naive, conversion of commands from PyTorch to TFJS. Threepio will focus on a 3-way translation for the majority of the commands in PyTorch, TensorFlow, and TFJS.

Once Threepio is in a good state, we'll want to include this library inside of syft.js to allow for plan command conversion on the fly and in any direction we choose.

The following issues must be completed first:

Create a better Readme

Based on this readme template, we should improve our readmes across all OpenMined projects.

More specifically, you should fill out the template at the minimum.

  • Don't worry about the logo, I'll get this to you.
  • Change all badges to reflect your repo, include other badges as desired, but use those at the minimum. You can generate more here: https://shields.io/
  • Change the title
  • Write a detailed description of what your library intends to accomplish. I would also advise that you provide links to the following papers: https://ai.googleblog.com/2017/04/federated-learning-collaborative.html, https://arxiv.org/pdf/1902.01046.pdf, https://research.google/pubs/pub47246/. I would also explain that the system is driven by developing a model in PySyft, hosting it in PyGrid, and then downloading it using a worker library. Be sure to also link to the other worker libraries that aren't yours, so we can cross-promote our work!
  • Fill out a list of features that your library supports. A suggested list includes: PySyft plan execution, optional third-party JWT authentication, wifi detection, charge detection, sleep/wake detection, protocols for secure aggregation (put mark this as "in progress"), and a list of environments this library is expected to work in. That's a short list, you can add or remove what you please.
  • Installation section should be updated and specify the appropriate package manager (with a link to our deployment page on that package manager)
  • Usage section should be comprised of the implementation code for the MNIST example. Make sure to clean these up first. I've created an issue for this elsewhere - do that one first.
  • Fill out some basic contributing information to tell people how to run your library locally, what the local development instructions are, etc.
  • Fill out the list of contributors from All Contributors. Build this into your workflow and expect to use their Github issue commands in the future to make adding people to the readme easier.

[syft.js] Handle large messages in data channel

Data channel is limited to a certain size (depending on the browser) with the safe max value of around 16kb.
Update webrtc.js's sendMessage to handle large binary messages, such as protobuf blobs.

This involves:

  • Split large messages into parts
  • Basic protocol for split data, like header and number of parts (+ we don't need to split small messages)
  • Control of bufferedAmount
  • Concat on the other side and error checking

Example:
https://webrtc.github.io/samples/src/content/datachannel/datatransfer/

Add a stopping method that stops the training process in syft.js

We need to have a stopping method that will terminate the current job in question. Reasons for stopping training could be any of the following:

  • The user wanted to... like they clicked a "stop" button
  • The plan has an error and can't execute
  • The user started using their device again
  • The device loses wifi
  • The device loses active charging
  • Or perhaps most importantly... if the model isn't really going anywhere (the error rate isn't going down)

At this point, we should stop and notify the user with some sort of message.

Demo Website

In a folder "demo", create a demo website which imports syft.js and executes a function contained within syft.js. This website obviously won't do much yet (except import a library) but the idea is that it will eventually grow into our Federated Learning App.

Deserialize JSON string into new tensor class

if you have a javascript variable

message = {"torch_type": "torch.FloatTensor", "data": [1.0, 2.0, 3.0, 4.0, 5.0], "id": 1476041248, "owners": [0], "is_pointer": false}

We want a new javascript function called "receive_tensor" which will convert that JSON message into this object with all the attributes contained in the dictionary.

This object should have exactly 1 method "add" which can add two of these objects together. For example...

var x = receive_obj(message)
var y = x.add(x)

Add bandwidth and Internet connectivity test in syft.js

We need to have some sort of way to run a basic bandwidth and Internet connectivity test in syft.js so that we may submit these values to PyGrid. This allows PyGrid to properly select candidates for pooling based on internet connection speed.

We must determine the average ping, upload speed, and download speed of the device and report these values to PyGrid.

Migrate all Serde tests to use live data from grid.js seed generator

The syft.js project could use a lot of help refining our current test suite.

Currently, all of our tests for Serde in Javascript run based on strings that we occasionally copy and paste from PySyft. However, these strings are now incredibly out of date and we're finding a lot of problems as the PySyft team changes things periodically. We need to figure out some sort of way to utilize the grid.js seed file generator (maybe by building one of our own in syft.js?) to automate the creation of these Serde simplified strings. In theory, this would notify us every time syft.js becomes out of date with PySyft... aka, insanely helpful.

This issue is a bit non-descript, so if you're interested in helping to write tests, please contact me (@cereallarceny) on Slack and I'll get you started!

Don't send WEBRTC_PEER_LEFT twice

I believe we're already sending this message from grid.js. We should only send it once - I would imagine that grid.js is the best place to send this from, rather than from the client.

Travis Support for Unit Tests

In Issue #11 , we created a basic Unit Testing Suite... in this issue, we want to support automated unit testing using Travis (with integration to Github) so that all submitted pull requests get tested automatically.

This should also include a travis build badge on the Readme.

Add eslint support

We need help adding ESLint to syft.js so that we can more readily detect style issues in our code. Ideally, all configs would be set to error so that we have failing tests until the code is properly written.

This issue is a bit non-descript, so if you're interested in helping configuring ESLint properly, please contact me (@cereallarceny) on Slack and I'll get you started!

Add Typescript definitions

https://stackoverflow.com/questions/53710368/how-do-i-add-typescript-types-to-a-javascript-module-without-switching-to-typesc

We're not planning on writing syft.js in Typescript, but it would be great to have Typescript definitions so that others may use this project within a TS environment, or allowing for better IDE integration with typing. Adding support for Typescript definitions here should also include tests to be written to prove that data being provided is of a certain type and nothing else. πŸ˜„

Clean up MNIST example

Description

The MNIST example currently in the project could use some minor improvements. We need to do the following:

  • Remove references to grid.js
  • Remove references to "with-grid" and make everything labeled "MNIST"
  • Remove the current description and replace it with something describing the demo:

This is a demonstration of how to use syft.js with PyGrid to train a plan on local data in the browser.

Are you interested in working on this improvement yourself?

Additional Context

None

Migrate syft.js to use Protobuf classes

We need to add the following Protobuf classes to syft.js as they are completed:

Deserialize from protobuf:

  • Plan
  • State
  • Operation
  • ObjectMessage
  • Placeholder
  • TorchTensor
  • TorchParameter
  • Protocol (old one)
  • PromiseTensor (not implemented in PySyft yet)
  • PointerTensor
  • ... more to be defined

Serialize to protobuf:

  • Plan
  • State
  • Operation
  • ObjectMessage
  • Placeholder
  • TorchTensor
  • TorchParameter
  • Protocol (old one)
  • PromiseTensor (not implemented in PySyft yet)
  • PointerTensor
  • ... more to be defined

Test syft.js main file

The syft.js project could use a lot of help refining our current test suite.

We need to test the syft.js file as it currently stands. This issue is a bit non-descript, so if you're interested in helping to write tests, please contact me (@cereallarceny) on Slack and I'll get you started!

Convert Logger class to be a singleton

Right now, we have the Logger class as a class that you can create, but then you have to pass it around the library, or instantiate a new version each time. It would be a lot easier to convert this to be a singleton class. This would allow us to "instantiate" the Logger class multiple times, but only have one true reference to the first one we created. This also has a huge added benefit of not having to pass the original Logger instance (located in the syft.js file) around to each of the other files... annoying!

This is a really good first issue, any takers?

Testing WebRTC

We cannot complete this until we have fully tested Sockets - reference #47

Either way, we need 100% test coverage on WebRTC. This is notoriously difficult to test as it relies on passing tests from our Socket integration as well. They're co-dependent. Separately, testing WebRTC relies on realistic mocking of a WebRTC environment... which is... hard.

Here's some next steps on reading materials:

Add gpu.js as a dependency

In the long run, we will very likely want to use a separate tensor library for all our javascript tensor operation needs. The first one we'd like to evaluate is gpu.js (http://gpu.rocks/). So, to start, this issue is to import that library in as a dependency.

Create an example with a Webpack build

We need to create an identical example to the simple-example folder inside of examples. This will include the ability to load the library in via a build system like Webpack rather than a <script> tag. This shows a "real-world" version of how the library would be used.

Save Tensors in a dict locally

In Issue #8, we built functionality that allowed us to send a tensor from PySyft to syft.js and print it to the console. In this issue, we want to instead save that tensor to a dictionary with a unique ID (specified by the "id" attribute sent with the tensor). This dictionary should be called _objects.

Execute plans in syft.js

As of now, syft.js is entirely protocol based. Now that we have a new roadmap, we must shift focus to the execution of training plans. This will require initially translating a training plan's list of operations into operations that can be executed in TFJS. This work will be done for us by using Threepio.

Currently, the code we have in syft.js actually runs plans somewhat well, but they're always wrapped in a protocol. This old plan execution code will need to be migrated over after we develop the new API structure in syft.js (#87).

Create syft.js tensor using PySyft over Web Sockets

This project combines: #6 and #7 . #6 is about being able to translate JSON messages into tensors. #7 is about being able to receive JSON messages from PySyft.

In this issue, we want to glue #6 and #7 together by being able to receive a JSON message from PySyft and initialize a tensor locally (logging it to the console)

Bring ESLint and testing suite to pass

We currently have a failing testing suite because of the addition of ESLint to our codebase. Please fix all ESLint related issues and do your best to bring our codebase up to speed with tests.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.