Use TypeScript path mapping to specify paths between monorepo packages. This allows editors to correctly "go to definition" across packages, and ensures they reference the .ts file instead of .d.ts.
According to the ESModule standard, properties of modules are immutable. TypeScript 4 will enforce this rule. This in particular affects tests for executors in tfjs-converter, in which we often spy on tfOps.
This PR removes all instances of spyOn(tfOps,...) and replaces them with a separate spyOps mock / fake which is passed to the executeOp function.
It also removes spying on the io module in graph_model_test.ts.
This PR was part of the larger TS4 upgrade PR (#6346, #5561), but I'm splitting that PR into pieces that can be merged while we're still using TS3 because it's too large to keep up-to-date.
This PR also bumps lib to es2019 in the root tsconfig to allow using Object.fromEntries. This shouldn't affect the code we ship since it's still compiled to the es2017 target.
Note that this PR does not bump TypeScript to version 4. It leaves it at 3.
* Make ts_library tsconfig.json extend root tsconfig
* Remove tsetse settings from main tsconfig
* Remove baseUrl and paths from ts_library tsconfig
* Revert "Remove baseUrl and paths from ts_library tsconfig"
Reverted since this PR should not change the tsconfig behavior (although I don't really think this change does affect behavior).
This reverts commit 2a72331b1c.
* Lint bazel
This PR adds Bazel BUILD targets for tfjs-core and tfjs-backend-cpu. The following commands can invoke the new Bazel targets. Yarn rules have not been added for them since Bazel not the default way to build yet.
- `yarn bazel build //tfjs-core:tfjs-core_lib` compiles tfjs-core.
- `yarn bazel test //tfjs-core:tfjs-core_test` tests tfjs-core with a headless browser.
- `yarn bazel run //tfjs-core:tfjs-core_test` launches tfjs-core tests in a browser and waits for human interaction.
- `yarn bazel test //tfjs-core:browserstack_tfjs-core_test` tests tfjs-core on BrowserStack. Only Chrome on MacOS is enabled at the moment. This test requires that `BROWSERSTACK_USERNAME` and `BROWSERSTACK_KEY` are set in your environment.
- `yarn bazel run //tfjs-core:browserstack_tfjs-core_test` (theoretically) launches tfjs-core tests in a BrowserStack session for debugging and waits for you to connect before running the tests. I haven't been able to test this yet since I can't seem to get an interactive session to start (probably due to network issues).
Currently, these build targets use esbuild for bundling since it was the easiest to set up. We will probably use Rollup for some cases e.g. to support es5. Targets for publishing to npm (i.e. `pkg_npm`) are not yet written.
This PR also sets up Bazel CI tests. CI tests use a Bazel query to find what targets should be tested, so any Bazel target with `tag = ["ci"]` will be tested in CI. Bazel remote caching is now working, so we run all the tests on every commit and let Bazel figure out what actually needs to be run.
FEATURE
INTERNAL
Enable incremental builds in the root tsconfig.json to increase build speed during development. For example, running `yarn build` in tfjs-backend-cpu takes ~43 seconds without incremental builds and ~30 seconds with incremental builds (after the first build).
Co-authored-by: Ping Yu <4018+pyu10055@users.noreply.github.com>
DEV
This makes the directory structure align with the NPM package structure more closely.
This has the added effect of making syncing to google3 much saner (one BUILD rule for each of the top-level NPM packages).
DOC
- Remove the doc decorator in favor of a jsdoc annotation. This removes complexity and stack traces.
- Remove classes for ops as they can now be floating functions.
- `op` now takes a dictionary mapping function name to the method, allowing op callers to use the sugar `const pad = op({pad_});`, attaching a name to the returned op function as well as naming the scope.
Verified no change in number of symbols exported:
```
Found:
7 headings
29 subheadings
173 methods
```
Corresponding doc generator change: https://github.com/tensorflow/tfjs-website/pull/180
Corresponding layers change: https://github.com/tensorflow/tfjs-layers/pull/267
Add `@operation` decorator that wraps the method in a math.scope(methodName, () => {}). This helps annotate all ops, track them (in debug mode) and significantly reduce chances of memory leaks.
Also migrate more math ops to global namespace:
- compare (less, greater, equal etc)
- min/max/minimum/maximum/argMin/argMax/argMaxEquals
- transpose
- Replace npm with yarn
- Remove bower as a dependency (yarn handles it)
- Add tsconfig.json in demos/, so demos compile separately
- Update base tsconfig.json to not compile demos (15% faster compile time)
- Make all tsconfig.json files extend from the base tsconfig.json to avoid repetition
- move @types/polymer and tone-piano deps to demos
- update typescript compiler from 2.5.3 to 2.6.1
This change does the following:
* Renames TopKImageClassifier => KNNImageClassifier
* Puts a package.json in each of the models (squeezenet and knn-image-classifier). These each now have `tsconfig.json`s, and `package.json`s. SqueezeNet has a `demo.html` (I'll file a bug for somebody in OSS to finish the other model to add a demo).
* Puts a package.json in `demos/`. This allows us to make demos depend on the public API of `deeplearn` as well as on the public API of any models they may use, like `deeplearn-squeezenet`.
* Converts benchmarks to use the public API. This means we test against the `NDArrayMath` layer, which greatly simplifies the tests. We always run a warmup query, so shader compilation time is not an issue.
* Removes `logSumExp` benchmark file. It's already benchmarked in reduction ops.
* Calls initializeGPU from the constructor of the SqueezeNet model. This is because when we load standalone versions of both SqueezeNet and deeplearn together, the global state about GPU initialization is not shared. Once we decouple NDArray from storage mechanism, this should go away. `initializeGPU` is exported in this PR: https://github.com/PAIR-code/deeplearnjs/pull/306
* For some reason, the linter is now complaning about performance_rnn adding three numbers.. I had to cast them, but VSCode didn't seem to have the problem. Really bizarre.
Notes:
* `./scripts/watch-demo` works as it did previously.
* `npm run prep` now also runs `npm install` in the demos directory.
* Think of `package.json`s as BUILD rules in Bazel.
* migrate addScaledMat and conv2d to logical sampling and improve shader compiler
* fix conv2d zero paddig and make the project build
* migrate rest of conv shaders to logical
* replace zero pad with if
* migrate pool ops
* address review comments