Commit Graph

27 Commits

Author SHA1 Message Date
Matthew Soulanille 130a56d4d8
Add StaticRegexReplace Op (#7379) 2023-02-15 10:57:11 -08:00
Matthew Soulanille 8f0ece5161
Add path mapping to the root tsconfig (#6957)
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.
2022-10-25 17:29:37 -07:00
Matthew Soulanille ccca85464d
[converter] Avoid spying on properties of the 'tfOps' module (#6563)
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.
2022-06-28 17:06:02 -07:00
Matthew Soulanille 41202650a7
Make ts_library tsconfig.json extend root tsconfig (#6451)
* 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
2022-05-26 13:45:37 -07:00
Matthew Soulanille 441537199e
Lint Bazel packages with a central lint script (#5790)
INTERNAL
* Add global lint script

* Omit non-bazel packages from repo-wide lint

* Lint Bazel packages with a global lint script

* Fix lint errors

* [core] Remove lint script

* [cpu] Remove lint script

* [webgl] Remove lint script

* [converter] Remove tslint script

* [layers] Remove tslint script

* [tflite] Remove tslint script

* [data] Remove tslint script

* Update cloudbuild golden file tests

* [webgpu] Revert incorrect lint changes

* Add lint instructions to Bazel migration doc

* Fix lint errors

* [core] Remove circular import in platform_node

Co-authored-by: Ping Yu <4018+pyu10055@users.noreply.github.com>
2021-11-02 14:48:54 -07:00
Ping Yu 6e0bcb0cf7
uses require instead of enable esmoduleinterop flag (#5074)
BUG
* uses require instead of esmoduleinterop

* fixed lint error

* run chrome webworker test first
2021-05-14 17:33:26 -07:00
ahmedsabie 2f064d4782
Add kernel StringToHashBucketFast for CPU and WebGL backend (#5052)
FEATURE
* Add kernel StringToHashBucketFast for CPU and WebGL backend

* Remove int32 limit

* fix test failure

* fix long package import error

* add lng package to root package.json

* add types/long package

* fixed cpu and webgl test failure

* added esModuleInterop to root tsconfig

* fix tfjs-converter tests

* fix layers build

* fix tfjs rollup

* fix node tsconfig

* fix node tests

Co-authored-by: Ping Yu <4018+pyu10055@users.noreply.github.com>
2021-05-13 10:32:53 -07:00
Matthew Soulanille cc5c97b803
Build tfjs-core and tfjs-backend-cpu with Bazel (#4856)
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.
2021-04-16 14:57:58 -07:00
Matthew Elliott Soulanille d3e48d6832
Enable incremental typescript builds (#4092)
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>
2020-10-29 09:18:20 -07:00
Yannick Assogba 8c59e2b43a
Update packages to compile to ESM modules by default (#3112)
BREAKING
INTERNAL
2020-04-27 13:29:25 -04:00
Daniel Smilkov 4cb7fda922
Move rollup-plugin-visualizer from optionalDep to devDep (#1817)
INTERNAL
2019-06-26 22:39:12 -04:00
Nikhil Thorat 781f70658b
Move webgpu code to a top-level tfjs-webgpu folder. (#1797)
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).
2019-06-19 11:45:20 -04:00
Daniel Smilkov 30161740c5
add joke of the day for a failed build (#1735)
INTERNAL
2019-05-03 10:10:09 -04:00
Nikhil Thorat 9960893532
Add snippet testing on CI. (#1715)
DEV

Example failure: https://pantheon.corp.google.com/cloud-build/builds/6ee4fe0b-2c1a-4e7e-aaf9-0707f6889da3?project=learnjs-174218

Also fix errors with snippets
- Add isNaN, isFinite, isInf chaining API
- Don't ignore scripts. This allows layers to depend on this script.
2019-04-30 11:47:55 -04:00
Ann Yuan 988121926e
Add WebGPU backend. (#1676)
FEATURE
2019-04-16 13:30:16 -04:00
Yannick Assogba 8f1f8b17da
Preserve docs in npm package (#1533)
DOC
This fixes https://github.com/tensorflow/tfjs/issues/1180 and allows users to see docs in code editors like vscode.

Note that the docs are still removed from the minified bundle.
2019-02-05 11:04:14 -05:00
Nikhil Thorat f915a7ef5e
Remove the doc decorator in favor of a jsdoc annotation. (#1158)
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
2018-07-13 14:45:33 -04:00
Daniel Smilkov d8149a711f
Make es bundle and remove dist-es6/ (#1095)
Make es bundle via rollup. We also don't need dist-es6/ anymore. See https://github.com/tensorflow/tfjs/pull/413 for a similar PR in tfjs.

DEV
2018-06-11 12:59:07 -04:00
Nikhil Thorat 2780b0316c
Convert core to use rollup for bundling. (#1037)
BREAKING "tfc" => "tf" for ES5 tf-core.js bundle users.

This change does the following:
- Convert to rollup for bundling. Remove browserify.
- Use "extend: true" to extend a global "tf" object. There is now no "tfc".
- Ship es6 in a dist-es6 folder as well as es5.
- Remove models. They don't build anymore nor are they useful. We'll keep the KNN image classifier around and not unit test it just so we have the code. I'll remove this at some point in the future.

This PR goes along with:
https://github.com/tensorflow/tfjs-layers/pull/191
https://github.com/tensorflow/tfjs/pull/301

I tested with yalc across all packages, and eventually all the way to the mobilenet example in tfjs-example and everything seems to work. Using the bundles I've also used the code on the homepage to train a simple layers model (tested both union and including layers and core independently).

Hosted bundles here:
https://storage.googleapis.com/dljs-test/rollup/tf.js
https://storage.googleapis.com/dljs-test/rollup/tf.min.js
https://storage.googleapis.com/dljs-test/rollup/tf-core.js
https://storage.googleapis.com/dljs-test/rollup/tf-core.min.js
https://storage.googleapis.com/dljs-test/rollup/tf-layers.js
https://storage.googleapis.com/dljs-test/rollup/tf-layers.min.js
2018-05-17 12:53:56 -04:00
Daniel Smilkov 5c57a3a008
Add @operation decorator and migrate compare/minmax/transpose ops (#577)
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
2018-01-21 23:53:49 -05:00
Daniel Smilkov b61523ff95
Setup vuejs for demos. Add an example demo that uses vuejs (#396) 2017-11-28 21:08:25 -05:00
Daniel Smilkov 21dd65c756
Improve build system (npm -> yarn, remove bower, add demos/tsconfig.json) (#360)
- 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
2017-11-19 18:10:45 -05:00
Nikhil Thorat 6c86ec7618
Pull SqueezeNet and KNNImageClassifier out into separate npm modules. (#294)
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.
2017-11-06 19:29:42 -05:00
Daniel Smilkov 7a569b6f4f Add starter projects for Typescript and ES6 (#259) 2017-10-23 15:53:42 -04:00
Daniel Smilkov 86c61880ac Migrate conv2D and related ops to logical sampling (#52)
* 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
2017-08-17 21:34:37 -04:00
Daniel Smilkov f21337776f Remove all unused variables and enable lint rule (#26)
* remove all unused variables and enable lint rule

* revert benchmarks deletion

* further reduce unused vars using tsconfig settings
2017-08-12 06:07:54 +10:00
Daniel Smilkov 9d1d224caf initial commit 2017-08-03 13:45:13 -04:00