Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Fix demos and models #461

Merged
merged 9 commits into from
Dec 23, 2017
Merged

Fix demos and models #461

merged 9 commits into from
Dec 23, 2017

Conversation

dsmilkov
Copy link
Contributor

@dsmilkov dsmilkov commented Dec 22, 2017

  • Update and fix all demos and docs to use global math, available in 0.3.15.
  • Also update all models to use 0.3.15. In addition, make sure that models with peerDependency don't include the peer in their bundle.
  • Update documentation

After this PR is submitted, I will increase the version number of each model (and make sure consumers of that model use the new version) and publish an npm package for each model.

This change is Reviewable

@dsmilkov dsmilkov requested a review from nsthorat December 23, 2017 13:24
@dsmilkov dsmilkov changed the title NOT READY: Fix demos Fix demos and models Dec 23, 2017
@nsthorat
Copy link
Contributor

:lgtm_strong:


Reviewed 23 of 27 files at r1, 19 of 19 files at r2, 19 of 19 files at r3.
Review status: all files reviewed at latest revision, 21 unresolved discussions.


demos/util.ts, line 21 at r3 (raw file):

export function isWebGLSupported(): boolean {
  return ENV.getBackend('webgl') != null;

if you're using ENV, you can just use the WEBGL_VERSION directly


demos/benchmarks/batchnormalization3d_benchmark.ts, line 32 at r3 (raw file):

      });
    }
    const math = new NDArrayMath('cpu', false);

safeMode


demos/benchmarks/batchnormalization3d_benchmark.ts, line 52 at r3 (raw file):

export class BatchNormalization3DGPUBenchmark implements BenchmarkTest {
  async run(size: number) {
    const math = new NDArrayMath('webgl', false);

safeMode


demos/benchmarks/benchmark_util.ts, line 6 at r3 (raw file):

export async function warmupAndBenchmarkGPU(
    math: NDArrayMath, benchmark: () => NDArray): Promise<number> {
  // Warmup.

no need to warmup now that you upload immediately.


demos/benchmarks/matmul_benchmarks.ts, line 31 at r3 (raw file):

      });
    }
    const math = new NDArrayMath('cpu', false);

safeMode


demos/benchmarks/matmul_benchmarks.ts, line 46 at r3 (raw file):

export class MatmulGPUBenchmark implements BenchmarkTest {
  async run(size: number): Promise<number> {
    const math = new NDArrayMath('webgl', false);

safeMode


demos/benchmarks/pool_benchmarks.ts, line 61 at r3 (raw file):

  run(size: number, option: string,
      params: PoolBenchmarkParams): Promise<number> {
    const math = new NDArrayMath('cpu', false);

safeMode


demos/benchmarks/pool_benchmarks.ts, line 87 at r3 (raw file):

  async run(size: number, option: string, params: PoolBenchmarkParams):
      Promise<number> {
    const math = new NDArrayMath('webgl', false);

safeMode


demos/benchmarks/reduction_ops_benchmark.ts, line 45 at r3 (raw file):

export class ReductionOpsCPUBenchmark implements BenchmarkTest {
  async run(size: number, option: string): Promise<number> {
    const math = new NDArrayMath('cpu', false);

safeMode


demos/benchmarks/reduction_ops_benchmark.ts, line 62 at r3 (raw file):

export class ReductionOpsGPUBenchmark implements BenchmarkTest {
  async run(size: number, option: string) {
    const math = new NDArrayMath('webgl', false);

safeMode


demos/benchmarks/unary_ops_benchmark.ts, line 65 at r3 (raw file):

export class UnaryOpsCPUBenchmark implements BenchmarkTest {
  async run(size: number, option: string): Promise<number> {
    const math = new NDArrayMath('cpu', false);

safeMode


demos/benchmarks/unary_ops_benchmark.ts, line 82 at r3 (raw file):

export class UnaryOpsGPUBenchmark implements BenchmarkTest {
  async run(size: number, option: string) {
    const math = new NDArrayMath('webgl', false);

safeMode


demos/complementary-color-prediction/complementary-color-prediction.ts, line 160 at r3 (raw file):

    const rawInputs = new Array(exampleCount);
    const oldMath = ENV.math;
    const math = new NDArrayMath('cpu', false);

safeMode


demos/fast-style-transfer/fast-style-transfer.ts, line 263 at r3 (raw file):

}

function renderToCanvas(a: Array3D, canvas: HTMLCanvasElement) {

why revert to this approach? The other one is much faster for live style transfer which we want to get out the door.


demos/imagenet/imagenet.ts, line 107 at r3 (raw file):

    this.gpgpu = new GPGPUContext(gl);
    this.backend = new MathBackendWebGL(this.gpgpu);
    this.math = new NDArrayMath(this.backend, false);

safeMode


demos/latent-space-explorer/App.vue, line 152 at r3 (raw file):

          .join(',');
        history.replaceState(undefined, undefined, hashStr);
        });

indentation is off here - use await instead of .then and you wont have to fix indentation


demos/ml_beginners/ml_beginners.ts, line 68 at r3 (raw file):

      // something random.
      let result: NDArray = session.eval(y, [{tensor: x, data: Scalar.new(4)}]);
      console.log(result.shape);

remove result.shape here for consistency


demos/ml_beginners/ml_beginners.ts, line 69 at r3 (raw file):

      let result: NDArray = session.eval(y, [{tensor: x, data: Scalar.new(4)}]);
      console.log(result.shape);
      console.log(result.getValues());

use dataSync


demos/nn-art/cppn.ts, line 77 at r3 (raw file):

    this.gpgpu = new GPGPUContext(gl);
    this.backend = new MathBackendWebGL(this.gpgpu);
    this.math = new NDArrayMath(this.backend, false);

safeMode


demos/teachable_gaming/teachable_gaming.ts, line 210 at r3 (raw file):

    const gpgpu = new GPGPUContext(gl);
    const backend = new MathBackendWebGL(gpgpu);
    this.math = new NDArrayMath(backend, false);

safeMode


models/squeezenet/squeezenet.ts, line 190 at r3 (raw file):

  }

  private topK(values: Float32Array, k: number):

fine to keep this on CPU but maybe move it to a models/util.ts since we use this everywhere


Comments from Reviewable

@dsmilkov
Copy link
Contributor Author

Thanks for the awesome fast review!


Reviewed 20 of 27 files at r1, 2 of 19 files at r2.
Review status: all files reviewed at latest revision, 21 unresolved discussions, all commit checks successful.


demos/util.ts, line 21 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

if you're using ENV, you can just use the WEBGL_VERSION directly

Done.


demos/benchmarks/batchnormalization3d_benchmark.ts, line 32 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/benchmarks/batchnormalization3d_benchmark.ts, line 52 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/benchmarks/benchmark_util.ts, line 6 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

no need to warmup now that you upload immediately.

still need warmup for the shader programs to compile


demos/benchmarks/matmul_benchmarks.ts, line 31 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/benchmarks/matmul_benchmarks.ts, line 46 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/benchmarks/pool_benchmarks.ts, line 61 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/benchmarks/pool_benchmarks.ts, line 87 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/benchmarks/reduction_ops_benchmark.ts, line 45 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/benchmarks/reduction_ops_benchmark.ts, line 62 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/benchmarks/unary_ops_benchmark.ts, line 65 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/benchmarks/unary_ops_benchmark.ts, line 82 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/complementary-color-prediction/complementary-color-prediction.ts, line 160 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/fast-style-transfer/fast-style-transfer.ts, line 263 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

why revert to this approach? The other one is much faster for live style transfer which we want to get out the door.

It was the very first demo I tried to fix, thus reverting to canvas pixel copying.
This demo made me expose getTexture() method on MathBackendWebgl and export it to the public api.

After exposing those methods, I left this demo since I felt we should convert when we actually do live. By then, maybe we find a better way to attach to the canvas


demos/imagenet/imagenet.ts, line 107 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/latent-space-explorer/App.vue, line 152 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

indentation is off here - use await instead of .then and you wont have to fix indentation

Fixed indentation. Can't use await here since it's not TypeScript, it's es6 in a .vue file and the build setup relies on typescript to compile away async/await.


demos/ml_beginners/ml_beginners.ts, line 68 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

remove result.shape here for consistency

Done.


demos/ml_beginners/ml_beginners.ts, line 69 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

use dataSync

Done.


demos/nn-art/cppn.ts, line 77 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


demos/teachable_gaming/teachable_gaming.ts, line 210 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

safeMode

Done.


models/squeezenet/squeezenet.ts, line 190 at r3 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

fine to keep this on CPU but maybe move it to a models/util.ts since we use this everywhere

Done.


Comments from Reviewable

@dsmilkov dsmilkov merged commit 0555416 into master Dec 23, 2017
@dsmilkov dsmilkov deleted the fix-demos branch December 23, 2017 17:09
const oldMath = ENV.math;
const safeMode = false;
const math = new NDArrayMath('cpu', safeMode);
ENV.setMath(math);
Copy link

@rwieruch rwieruch Dec 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello there. I got a bit confused when I saw this change.

Why are we using for the following computations the CPU, but set the math context in the end of this class method to the old math reference (GPU?) again? Furthermore, the old math reference is a new math object and not this.math from the class. In addition, the NDArrayMath is used again even though it should be deprecated?

Looking at it without being into it, it seems like a temporary workaround?

rwieruch added a commit to javascript-machine-learning/color-accessibility-neural-network-deeplearnjs that referenced this pull request Dec 28, 2017
rwieruch added a commit to javascript-machine-learning/mnist-neural-network-deeplearnjs that referenced this pull request Dec 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants