TensorFlow Source

This commit is contained in:
Brenden Harrell committed 2021-05-25 09:14:13 -05:00
1 parent cab277cf2c
commit e1791c2630
38 files changed
+198246

No files matched your search

@@ -0,0 +1,18 @@
/**
* @license
* Copyright 2021 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).tf=e.tf||{})}(this,(function(e){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(e,t){return e(t={exports:{}},t.exports),t.exports}var r=function(e){return e&&e.Math==Math&&e},a=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof t&&t)||function(){return this}()||Function("return this")(),i=function(e){try{return!!e()}catch(e){return!0}},o=!i((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),s={}.propertyIsEnumerable,u=Object.getOwnPropertyDescriptor,l={f:u&&!s.call({1:2},1)?function(e){var t=u(this,e);return!!t&&t.enumerable}:s},c=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},p={}.toString,h=function(e){return p.call(e).slice(8,-1)},f="".split,d=i((function(){return!Object("z").propertyIsEnumerable(0)}))?function(e){return"String"==h(e)?f.call(e,""):Object(e)}:Object,m=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e},v=function(e){return d(m(e))},g=function(e){return"object"==typeof e?null!==e:"function"==typeof e},y=function(e,t){if(!g(e))return e;var n,r;if(t&&"function"==typeof(n=e.toString)&&!g(r=n.call(e)))return r;if("function"==typeof(n=e.valueOf)&&!g(r=n.call(e)))return r;if(!t&&"function"==typeof(n=e.toString)&&!g(r=n.call(e)))return r;throw TypeError("Can't convert object to primitive value")},b={}.hasOwnProperty,x=function(e,t){return b.call(e,t)},w=a.document,k=g(w)&&g(w.createElement),N=function(e){return k?w.createElement(e):{}},I=!o&&!i((function(){return 7!=Object.defineProperty(N("div"),"a",{get:function(){return 7}}).a})),S=Object.getOwnPropertyDescriptor,T={f:o?S:function(e,t){if(e=v(e),t=y(t,!0),I)try{return S(e,t)}catch(e){}if(x(e,t))return c(!l.f.call(e,t),e[t])}},C=function(e){if(!g(e))throw TypeError(String(e)+" is not an object");return e},E=Object.defineProperty,R={f:o?E:function(e,t,n){if(C(e),t=y(t,!0),C(n),I)try{return E(e,t,n)}catch(e){}if("get"in n||"set"in n)throw TypeError("Accessors not supported");return"value"in n&&(e[t]=n.value),e}},A=o?function(e,t,n){return R.f(e,t,c(1,n))}:function(e,t,n){return e[t]=n,e},F=function(e,t){try{A(a,e,t)}catch(n){a[e]=t}return t},_="__core-js_shared__",D=a[_]||F(_,{}),O=Function.toString;"function"!=typeof D.inspectSource&&(D.inspectSource=function(e){return O.call(e)});var M,L,z,P=D.inspectSource,B=a.WeakMap,W="function"==typeof B&&/native code/.test(P(B)),V=n((function(e){(e.exports=function(e,t){return D[e]||(D[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.9.1",mode:"global",copyright:"© 2021 Denis Pushkarev (zloirock.ru)"})})),U=0,G=Math.random(),j=function(e){return"Symbol("+String(void 0===e?"":e)+")_"+(++U+G).toString(36)},H=V("keys"),q=function(e){return H[e]||(H[e]=j(e))},K={},X=a.WeakMap;if(W){var Y=D.state||(D.state=new X),J=Y.get,Z=Y.has,Q=Y.set;M=function(e,t){return t.facade=e,Q.call(Y,e,t),t},L=function(e){return J.call(Y,e)||{}},z=function(e){return Z.call(Y,e)}}else{var $=q("state");K[$]=!0,M=function(e,t){return t.facade=e,A(e,$,t),t},L=function(e){return x(e,$)?e[$]:{}},z=function(e){return x(e,$)}}var ee,te,ne={set:M,get:L,has:z,enforce:function(e){return z(e)?L(e):M(e,{})},getterFor:function(e){return function(t){var n;if(!g(t)||(n=L(t)).type!==e)throw TypeError("Incompatible receiver, "+e+" required");return n}}},re=n((function(e){var t=ne.get,n=ne.enforce,r=String(String).split("String");(e.exports=function(e,t,i,o){var s,u=!!o&&!!o.unsafe,l=!!o&&!!o.enumerable,c=!!o&&!!o.noTargetGet;"function"==typeof i&&("string"!=typeof t||x(i,"name")||A(i,"name",t),(s=n(i)).source||(s.source=r.join("string"==typeof t?t:""))),e!==a?(u?!c&&e[t]&&(l=!0):delete e[t],l?e[t]=i:A(e,t,i)):l?e[t]=i:F(t,i)})(Function.prototype,"toString",(function(){return"function"==typeof this&&t(this).source||P(this)}))})),ae=a,ie=function(e){return"function"==typeof e?e:void 0},oe=function(e,t){return arguments.length<2?ie(ae[e])||ie(a[e]):ae[e]&&ae[e][t]||a[e]&&a[e][t]},se=Math.ceil,ue=Math.floor,le=function(e){return isNaN(e=+e)?0:(e>0?ue:se)(e)},ce=Math.min,pe=function(e){return e>0?ce(le(e),9007199254740991):0},he=Math.max,fe=Math.min,de=function(e,t){var n=le(e);return n<0?he(n+t,0):fe(n,t)},me=function(e){return function(t,n,r){var a,i=v(t),o=pe(i.length),s=de(r,o);if(e&&n!=n){for(;o>s;)if((a=i[s++])!=a)return!0}else for(;o>s;s++)if((e||s in i)&&i[s]===n)return e||s||0;return!e&&-1}},ve={includes:me(!0),indexOf:me(!1)},ge=ve.indexOf,ye=function(e,t){var n,r=v(e),a=0,i=[];for(n in r)!x(K,n)&&x(r,n)&&i.push(n);for(;t.length>a;)x(r,n=t[a++])&&(~ge(i,n)||i.push(n));return i},be=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],xe=be.Line truncated
//# sourceMappingURL=tf.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"tf.min.js","sources":["../node_modules/core-js/internals/global.js","../node_modules/core-js/internals/fails.js","../node_modules/core-js/internals/descriptors.js","../node_modules/core-js/internals/object-property-is-enumerable.js","../node_modules/core-js/internals/create-property-descriptor.js","../node_modules/core-js/internals/classof-raw.js","../node_modules/core-js/internals/indexed-object.js","../node_modules/core-js/internals/require-object-coercible.js","../node_modules/core-js/internals/to-indexed-object.js","../node_modules/core-js/internals/is-object.js","../node_modules/core-js/internals/to-primitive.js","../node_modules/core-js/internals/has.js","../node_modules/core-js/internals/document-create-element.js","../node_modules/core-js/internals/ie8-dom-define.js","../node_modules/core-js/internals/object-get-own-property-descriptor.js","../node_modules/core-js/internals/an-object.js","../node_modules/core-js/internals/object-define-property.js","../node_modules/core-js/internals/create-non-enumerable-property.js","../node_modules/core-js/internals/set-global.js","../node_modules/core-js/internals/shared-store.js","../node_modules/core-js/internals/inspect-source.js","../node_modules/core-js/internals/internal-state.js","../node_modules/core-js/internals/native-weak-map.js","../node_modules/core-js/internals/shared.js","../node_modules/core-js/internals/uid.js","../node_modules/core-js/internals/shared-key.js","../node_modules/core-js/internals/hidden-keys.js","../node_modules/core-js/internals/engine-v8-version.js","../node_modules/core-js/internals/redefine.js","../node_modules/core-js/internals/path.js","../node_modules/core-js/internals/get-built-in.js","../node_modules/core-js/internals/to-integer.js","../node_modules/core-js/internals/to-length.js","../node_modules/core-js/internals/to-absolute-index.js","../node_modules/core-js/internals/array-includes.js","../node_modules/core-js/internals/object-keys-internal.js","../node_modules/core-js/internals/enum-bug-keys.js","../node_modules/core-js/internals/object-get-own-property-names.js","../node_modules/core-js/internals/object-get-own-property-symbols.js","../node_modules/core-js/internals/own-keys.js","../node_modules/core-js/internals/copy-constructor-properties.js","../node_modules/core-js/internals/is-forced.js","../node_modules/core-js/internals/export.js","../node_modules/core-js/internals/engine-is-node.js","../node_modules/core-js/internals/engine-user-agent.js","../node_modules/core-js/internals/object-create.js","../node_modules/core-js/internals/native-symbol.js","../node_modules/core-js/internals/use-symbol-as-uid.js","../node_modules/core-js/internals/is-array.js","../node_modules/core-js/internals/to-object.js","../node_modules/core-js/internals/object-keys.js","../node_modules/core-js/internals/object-define-properties.js","../node_modules/core-js/internals/html.js","../node_modules/core-js/internals/object-get-own-property-names-external.js","../node_modules/core-js/internals/well-known-symbol.js","../node_modules/core-js/internals/well-known-symbol-wrapped.js","../node_modules/core-js/internals/define-well-known-symbol.js","../node_modules/core-js/internals/set-to-string-tag.js","../node_modules/core-js/internals/a-function.js","../node_modules/core-js/internals/function-bind-context.js","../node_modules/core-js/internals/array-species-create.js","../node_modules/core-js/internals/array-iteration.js","../node_modules/core-js/modules/es.symbol.js","../node_modules/core-js/modules/es.symbol.async-iterator.js","../node_modules/core-js/modules/es.symbol.description.js","../node_modules/core-js/modules/es.symbol.has-instance.js","../node_modules/core-js/modules/es.symbol.is-concat-spreadable.js","../node_modules/core-js/modules/es.symbol.iterator.js","../node_modules/core-js/modules/es.symbol.match.js","../node_modules/core-js/modules/es.symbol.match-all.js","../node_modules/core-js/modules/es.symbol.replace.js","../node_modules/core-js/modules/es.symbol.search.js","../node_modules/core-js/modules/es.symbol.species.js","../node_modules/core-js/modules/es.symbol.split.js","../node_modules/core-js/modules/es.symbol.to-primitive.js","../node_modules/core-js/modules/es.symbol.to-string-tag.js","../node_modules/core-js/modules/es.symbol.unscopables.js","../node_modules/core-js/internals/correct-prototype-getter.js","../node_modules/core-js/internals/object-get-prototype-of.js","../node_modules/core-js/internals/a-possible-prototype.js","../node_modules/core-js/internals/object-set-prototype-of.js","../node_modules/core-js/internals/iterators.js","../node_modules/core-js/internals/is-array-iterator-method.js","../node_modules/core-js/internals/to-string-tag-support.js","../node_modules/core-js/internals/classof.js","../node_modules/core-js/internals/get-iterator-method.js","../node_modules/core-js/internals/iterator-close.js","../node_modules/core-js/internals/iterate.js","../node_modules/core-js/modules/es.aggreLine truncated
@@ -0,0 +1 @@
{"version":3,"file":"tf.fesm.min.js","sources":["../node_modules/@tensorflow/tfjs-core/dist/backends/backend.js","../node_modules/@tensorflow/tfjs-core/dist/util_base.js","../node_modules/@tensorflow/tfjs-core/dist/environment.js","../node_modules/@tensorflow/tfjs-core/dist/global_util.js","../node_modules/@tensorflow/tfjs-core/dist/kernel_names.js","../node_modules/@tensorflow/tfjs-core/dist/kernel_registry.js","../node_modules/@tensorflow/tfjs-core/dist/util.js","../node_modules/@tensorflow/tfjs-core/dist/profiler.js","../node_modules/@tensorflow/tfjs-core/dist/tensor_format.js","../node_modules/@tensorflow/tfjs-core/dist/tensor.js","../node_modules/@tensorflow/tfjs-core/dist/types.js","../node_modules/@tensorflow/tfjs-core/dist/tensor_util.js","../node_modules/@tensorflow/tfjs-core/dist/engine.js","../node_modules/@tensorflow/tfjs-core/dist/tape.js","../node_modules/@tensorflow/tfjs-core/dist/device_util.js","../node_modules/@tensorflow/tfjs-core/dist/flags.js","../node_modules/@tensorflow/tfjs-core/dist/tensor_util_env.js","../node_modules/@tensorflow/tfjs-core/dist/ops/operation.js","../node_modules/@tensorflow/tfjs-core/dist/ops/complex.js","../node_modules/@tensorflow/tfjs-core/dist/ops/tensor_ops_util.js","../node_modules/@tensorflow/tfjs-core/dist/ops/tensor.js","../node_modules/@tensorflow/tfjs-core/dist/io/types.js","../node_modules/@tensorflow/tfjs-core/dist/io/io_utils.js","../node_modules/@tensorflow/tfjs-core/dist/io/router_registry.js","../node_modules/@tensorflow/tfjs-core/dist/io/indexed_db.js","../node_modules/@tensorflow/tfjs-core/dist/io/local_storage.js","../node_modules/@tensorflow/tfjs-core/dist/io/model_management.js","../node_modules/@tensorflow/tfjs-core/dist/platforms/platform_browser.js","../node_modules/@tensorflow/tfjs-core/dist/platforms/platform_node.js","../node_modules/@tensorflow/tfjs-core/dist/ops/buffer.js","../node_modules/@tensorflow/tfjs-core/dist/ops/cast.js","../node_modules/@tensorflow/tfjs-core/dist/ops/clone.js","../node_modules/@tensorflow/tfjs-core/dist/ops/print.js","../node_modules/@tensorflow/tfjs-core/dist/base_side_effects.js","../node_modules/@tensorflow/tfjs-core/dist/io/browser_files.js","../node_modules/@tensorflow/tfjs-core/dist/io/progress.js","../node_modules/@tensorflow/tfjs-core/dist/io/weights_loader.js","../node_modules/@tensorflow/tfjs-core/dist/io/http.js","../node_modules/@tensorflow/tfjs-core/dist/io/passthrough.js","../node_modules/@tensorflow/tfjs-core/dist/ops/mat_mul.js","../node_modules/@tensorflow/tfjs-core/dist/ops/one_hot.js","../node_modules/@tensorflow/tfjs-core/dist/ops/transpose.js","../node_modules/@tensorflow/tfjs-core/dist/ops/confusion_matrix.js","../node_modules/@tensorflow/tfjs-core/dist/ops/tensor3d.js","../node_modules/@tensorflow/tfjs-core/dist/ops/browser.js","../node_modules/@tensorflow/tfjs-core/dist/ops/gather_nd_util.js","../node_modules/@tensorflow/tfjs-core/dist/ops/scatter_nd_util.js","../node_modules/@tensorflow/tfjs-core/dist/ops/slice_util.js","../node_modules/@tensorflow/tfjs-core/dist/serialization.js","../node_modules/@tensorflow/tfjs-core/dist/test_util.js","../node_modules/@tensorflow/tfjs-core/dist/version.js","../node_modules/@tensorflow/tfjs-core/dist/globals.js","../node_modules/@tensorflow/tfjs-core/dist/ops/add.js","../node_modules/@tensorflow/tfjs-core/dist/ops/floorDiv.js","../node_modules/@tensorflow/tfjs-core/dist/ops/div.js","../node_modules/@tensorflow/tfjs-core/dist/ops/mul.js","../node_modules/@tensorflow/tfjs-core/dist/ops/abs.js","../node_modules/@tensorflow/tfjs-core/dist/ops/acos.js","../node_modules/@tensorflow/tfjs-core/dist/ops/acosh.js","../node_modules/@tensorflow/tfjs-core/dist/ops/add_n.js","../node_modules/@tensorflow/tfjs-core/dist/ops/all.js","../node_modules/@tensorflow/tfjs-core/dist/ops/any.js","../node_modules/@tensorflow/tfjs-core/dist/ops/arg_max.js","../node_modules/@tensorflow/tfjs-core/dist/ops/arg_min.js","../node_modules/@tensorflow/tfjs-core/dist/ops/asin.js","../node_modules/@tensorflow/tfjs-core/dist/ops/asinh.js","../node_modules/@tensorflow/tfjs-core/dist/ops/atan.js","../node_modules/@tensorflow/tfjs-core/dist/ops/atan2.js","../node_modules/@tensorflow/tfjs-core/dist/ops/atanh.js","../node_modules/@tensorflow/tfjs-core/dist/ops/conv_util.js","../node_modules/@tensorflow/tfjs-core/dist/ops/reshape.js","../node_modules/@tensorflow/tfjs-core/dist/ops/avg_pool.js","../node_modules/@tensorflow/tfjs-core/dist/ops/avg_pool_3d.js","../node_modules/@tensorflow/tfjs-core/dist/ops/concat.js","../node_modules/@tensorflow/tfjs-core/dist/ops/sigmoid.js","../node_modules/@tensorflow/tfjs-core/dist/ops/slice.js","../node_modules/@tensorflow/tfjs-core/dist/ops/tanh.js","../node_modules/@tensorflow/tfjs-core/dist/ops/basic_lstm_cell.js","../node_modules/@tensorflow/tfjs-core/dist/ops/batch_to_space_nd.js","../node_modules/@tensorflow/tfjs-core/dist/ops/batchnorm.js","../node_modules/@tensorflow/tfjs-core/dist/ops/batchnorm_util.js","../node_modules/@tensorflow/tfjs-core/dist/oLine truncated
File diff suppressed because it is too large. Load diff
@@ -0,0 +1 @@
{"version":3,"file":"tf.js","sources":["../node_modules/core-js/internals/global.js","../node_modules/core-js/internals/fails.js","../node_modules/core-js/internals/descriptors.js","../node_modules/core-js/internals/object-property-is-enumerable.js","../node_modules/core-js/internals/create-property-descriptor.js","../node_modules/core-js/internals/classof-raw.js","../node_modules/core-js/internals/indexed-object.js","../node_modules/core-js/internals/require-object-coercible.js","../node_modules/core-js/internals/to-indexed-object.js","../node_modules/core-js/internals/is-object.js","../node_modules/core-js/internals/to-primitive.js","../node_modules/core-js/internals/has.js","../node_modules/core-js/internals/document-create-element.js","../node_modules/core-js/internals/ie8-dom-define.js","../node_modules/core-js/internals/object-get-own-property-descriptor.js","../node_modules/core-js/internals/an-object.js","../node_modules/core-js/internals/object-define-property.js","../node_modules/core-js/internals/create-non-enumerable-property.js","../node_modules/core-js/internals/set-global.js","../node_modules/core-js/internals/shared-store.js","../node_modules/core-js/internals/inspect-source.js","../node_modules/core-js/internals/native-weak-map.js","../node_modules/core-js/internals/is-pure.js","../node_modules/core-js/internals/shared.js","../node_modules/core-js/internals/uid.js","../node_modules/core-js/internals/shared-key.js","../node_modules/core-js/internals/hidden-keys.js","../node_modules/core-js/internals/internal-state.js","../node_modules/core-js/internals/redefine.js","../node_modules/core-js/internals/path.js","../node_modules/core-js/internals/get-built-in.js","../node_modules/core-js/internals/to-integer.js","../node_modules/core-js/internals/to-length.js","../node_modules/core-js/internals/to-absolute-index.js","../node_modules/core-js/internals/array-includes.js","../node_modules/core-js/internals/object-keys-internal.js","../node_modules/core-js/internals/enum-bug-keys.js","../node_modules/core-js/internals/object-get-own-property-names.js","../node_modules/core-js/internals/object-get-own-property-symbols.js","../node_modules/core-js/internals/own-keys.js","../node_modules/core-js/internals/copy-constructor-properties.js","../node_modules/core-js/internals/is-forced.js","../node_modules/core-js/internals/export.js","../node_modules/core-js/internals/engine-is-node.js","../node_modules/core-js/internals/engine-user-agent.js","../node_modules/core-js/internals/engine-v8-version.js","../node_modules/core-js/internals/native-symbol.js","../node_modules/core-js/internals/use-symbol-as-uid.js","../node_modules/core-js/internals/is-array.js","../node_modules/core-js/internals/to-object.js","../node_modules/core-js/internals/object-keys.js","../node_modules/core-js/internals/object-define-properties.js","../node_modules/core-js/internals/html.js","../node_modules/core-js/internals/object-create.js","../node_modules/core-js/internals/object-get-own-property-names-external.js","../node_modules/core-js/internals/well-known-symbol.js","../node_modules/core-js/internals/well-known-symbol-wrapped.js","../node_modules/core-js/internals/define-well-known-symbol.js","../node_modules/core-js/internals/set-to-string-tag.js","../node_modules/core-js/internals/a-function.js","../node_modules/core-js/internals/function-bind-context.js","../node_modules/core-js/internals/array-species-create.js","../node_modules/core-js/internals/array-iteration.js","../node_modules/core-js/modules/es.symbol.js","../node_modules/core-js/modules/es.symbol.async-iterator.js","../node_modules/core-js/modules/es.symbol.description.js","../node_modules/core-js/modules/es.symbol.has-instance.js","../node_modules/core-js/modules/es.symbol.is-concat-spreadable.js","../node_modules/core-js/modules/es.symbol.iterator.js","../node_modules/core-js/modules/es.symbol.match.js","../node_modules/core-js/modules/es.symbol.match-all.js","../node_modules/core-js/modules/es.symbol.replace.js","../node_modules/core-js/modules/es.symbol.search.js","../node_modules/core-js/modules/es.symbol.species.js","../node_modules/core-js/modules/es.symbol.split.js","../node_modules/core-js/modules/es.symbol.to-primitive.js","../node_modules/core-js/modules/es.symbol.to-string-tag.js","../node_modules/core-js/modules/es.symbol.unscopables.js","../node_modules/core-js/internals/correct-prototype-getter.js","../node_modules/core-js/internals/object-get-prototype-of.js","../node_modules/core-js/internals/a-possible-prototype.js","../node_modules/core-js/internals/object-set-prototype-of.js","../node_modules/core-js/internals/iterators.js","../node_modules/core-js/internals/is-array-iterator-method.js","../node_modules/core-js/internals/to-string-tag-support.js","../node_modules/core-js/internals/classof.js","../node_modules/core-js/internals/get-iterator-method.js","../node_modules/core-js/internals/iterator-close.js","../node_modules/core-js/internals/iterate.jsLine truncated
@@ -0,0 +1,18 @@
/**
* @license
* Copyright 2021 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).tf=e.tf||{})}(this,(function(e){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(e,t){return e(t={exports:{}},t.exports),t.exports}var r=function(e){return e&&e.Math==Math&&e},a=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof t&&t)||function(){return this}()||Function("return this")(),i=function(e){try{return!!e()}catch(e){return!0}},o=!i((function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]})),s={}.propertyIsEnumerable,u=Object.getOwnPropertyDescriptor,l={f:u&&!s.call({1:2},1)?function(e){var t=u(this,e);return!!t&&t.enumerable}:s},c=function(e,t){return{enumerable:!(1&e),configurable:!(2&e),writable:!(4&e),value:t}},p={}.toString,h=function(e){return p.call(e).slice(8,-1)},f="".split,d=i((function(){return!Object("z").propertyIsEnumerable(0)}))?function(e){return"String"==h(e)?f.call(e,""):Object(e)}:Object,m=function(e){if(null==e)throw TypeError("Can't call method on "+e);return e},v=function(e){return d(m(e))},g=function(e){return"object"==typeof e?null!==e:"function"==typeof e},y=function(e,t){if(!g(e))return e;var n,r;if(t&&"function"==typeof(n=e.toString)&&!g(r=n.call(e)))return r;if("function"==typeof(n=e.valueOf)&&!g(r=n.call(e)))return r;if(!t&&"function"==typeof(n=e.toString)&&!g(r=n.call(e)))return r;throw TypeError("Can't convert object to primitive value")},b={}.hasOwnProperty,x=function(e,t){return b.call(e,t)},w=a.document,k=g(w)&&g(w.createElement),N=function(e){return k?w.createElement(e):{}},I=!o&&!i((function(){return 7!=Object.defineProperty(N("div"),"a",{get:function(){return 7}}).a})),S=Object.getOwnPropertyDescriptor,T={f:o?S:function(e,t){if(e=v(e),t=y(t,!0),I)try{return S(e,t)}catch(e){}if(x(e,t))return c(!l.f.call(e,t),e[t])}},C=function(e){if(!g(e))throw TypeError(String(e)+" is not an object");return e},E=Object.defineProperty,R={f:o?E:function(e,t,n){if(C(e),t=y(t,!0),C(n),I)try{return E(e,t,n)}catch(e){}if("get"in n||"set"in n)throw TypeError("Accessors not supported");return"value"in n&&(e[t]=n.value),e}},A=o?function(e,t,n){return R.f(e,t,c(1,n))}:function(e,t,n){return e[t]=n,e},F=function(e,t){try{A(a,e,t)}catch(n){a[e]=t}return t},_="__core-js_shared__",D=a[_]||F(_,{}),O=Function.toString;"function"!=typeof D.inspectSource&&(D.inspectSource=function(e){return O.call(e)});var M,L,z,P=D.inspectSource,B=a.WeakMap,W="function"==typeof B&&/native code/.test(P(B)),V=n((function(e){(e.exports=function(e,t){return D[e]||(D[e]=void 0!==t?t:{})})("versions",[]).push({version:"3.9.1",mode:"global",copyright:"© 2021 Denis Pushkarev (zloirock.ru)"})})),U=0,G=Math.random(),j=function(e){return"Symbol("+String(void 0===e?"":e)+")_"+(++U+G).toString(36)},H=V("keys"),q=function(e){return H[e]||(H[e]=j(e))},K={},X=a.WeakMap;if(W){var Y=D.state||(D.state=new X),J=Y.get,Z=Y.has,Q=Y.set;M=function(e,t){return t.facade=e,Q.call(Y,e,t),t},L=function(e){return J.call(Y,e)||{}},z=function(e){return Z.call(Y,e)}}else{var $=q("state");K[$]=!0,M=function(e,t){return t.facade=e,A(e,$,t),t},L=function(e){return x(e,$)?e[$]:{}},z=function(e){return x(e,$)}}var ee,te,ne={set:M,get:L,has:z,enforce:function(e){return z(e)?L(e):M(e,{})},getterFor:function(e){return function(t){var n;if(!g(t)||(n=L(t)).type!==e)throw TypeError("Incompatible receiver, "+e+" required");return n}}},re=n((function(e){var t=ne.get,n=ne.enforce,r=String(String).split("String");(e.exports=function(e,t,i,o){var s,u=!!o&&!!o.unsafe,l=!!o&&!!o.enumerable,c=!!o&&!!o.noTargetGet;"function"==typeof i&&("string"!=typeof t||x(i,"name")||A(i,"name",t),(s=n(i)).source||(s.source=r.join("string"==typeof t?t:""))),e!==a?(u?!c&&e[t]&&(l=!0):delete e[t],l?e[t]=i:A(e,t,i)):l?e[t]=i:F(t,i)})(Function.prototype,"toString",(function(){return"function"==typeof this&&t(this).source||P(this)}))})),ae=a,ie=function(e){return"function"==typeof e?e:void 0},oe=function(e,t){return arguments.length<2?ie(ae[e])||ie(a[e]):ae[e]&&ae[e][t]||a[e]&&a[e][t]},se=Math.ceil,ue=Math.floor,le=function(e){return isNaN(e=+e)?0:(e>0?ue:se)(e)},ce=Math.min,pe=function(e){return e>0?ce(le(e),9007199254740991):0},he=Math.max,fe=Math.min,de=function(e,t){var n=le(e);return n<0?he(n+t,0):fe(n,t)},me=function(e){return function(t,n,r){var a,i=v(t),o=pe(i.length),s=de(r,o);if(e&&n!=n){for(;o>s;)if((a=i[s++])!=a)return!0}else for(;o>s;s++)if((e||s in i)&&i[s]===n)return e||s||0;return!e&&-1}},ve={includes:me(!0),indexOf:me(!1)},ge=ve.indexOf,ye=function(e,t){var n,r=v(e),a=0,i=[];for(n in r)!x(K,n)&&x(r,n)&&i.push(n);for(;t.length>a;)x(r,n=t[a++])&&(~ge(i,n)||i.push(n));return i},be=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],xe=be.Line truncated
//# sourceMappingURL=tf.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"tf.min.js","sources":["../node_modules/core-js/internals/global.js","../node_modules/core-js/internals/fails.js","../node_modules/core-js/internals/descriptors.js","../node_modules/core-js/internals/object-property-is-enumerable.js","../node_modules/core-js/internals/create-property-descriptor.js","../node_modules/core-js/internals/classof-raw.js","../node_modules/core-js/internals/indexed-object.js","../node_modules/core-js/internals/require-object-coercible.js","../node_modules/core-js/internals/to-indexed-object.js","../node_modules/core-js/internals/is-object.js","../node_modules/core-js/internals/to-primitive.js","../node_modules/core-js/internals/has.js","../node_modules/core-js/internals/document-create-element.js","../node_modules/core-js/internals/ie8-dom-define.js","../node_modules/core-js/internals/object-get-own-property-descriptor.js","../node_modules/core-js/internals/an-object.js","../node_modules/core-js/internals/object-define-property.js","../node_modules/core-js/internals/create-non-enumerable-property.js","../node_modules/core-js/internals/set-global.js","../node_modules/core-js/internals/shared-store.js","../node_modules/core-js/internals/inspect-source.js","../node_modules/core-js/internals/internal-state.js","../node_modules/core-js/internals/native-weak-map.js","../node_modules/core-js/internals/shared.js","../node_modules/core-js/internals/uid.js","../node_modules/core-js/internals/shared-key.js","../node_modules/core-js/internals/hidden-keys.js","../node_modules/core-js/internals/engine-v8-version.js","../node_modules/core-js/internals/redefine.js","../node_modules/core-js/internals/path.js","../node_modules/core-js/internals/get-built-in.js","../node_modules/core-js/internals/to-integer.js","../node_modules/core-js/internals/to-length.js","../node_modules/core-js/internals/to-absolute-index.js","../node_modules/core-js/internals/array-includes.js","../node_modules/core-js/internals/object-keys-internal.js","../node_modules/core-js/internals/enum-bug-keys.js","../node_modules/core-js/internals/object-get-own-property-names.js","../node_modules/core-js/internals/object-get-own-property-symbols.js","../node_modules/core-js/internals/own-keys.js","../node_modules/core-js/internals/copy-constructor-properties.js","../node_modules/core-js/internals/is-forced.js","../node_modules/core-js/internals/export.js","../node_modules/core-js/internals/engine-is-node.js","../node_modules/core-js/internals/engine-user-agent.js","../node_modules/core-js/internals/object-create.js","../node_modules/core-js/internals/native-symbol.js","../node_modules/core-js/internals/use-symbol-as-uid.js","../node_modules/core-js/internals/is-array.js","../node_modules/core-js/internals/to-object.js","../node_modules/core-js/internals/object-keys.js","../node_modules/core-js/internals/object-define-properties.js","../node_modules/core-js/internals/html.js","../node_modules/core-js/internals/object-get-own-property-names-external.js","../node_modules/core-js/internals/well-known-symbol.js","../node_modules/core-js/internals/well-known-symbol-wrapped.js","../node_modules/core-js/internals/define-well-known-symbol.js","../node_modules/core-js/internals/set-to-string-tag.js","../node_modules/core-js/internals/a-function.js","../node_modules/core-js/internals/function-bind-context.js","../node_modules/core-js/internals/array-species-create.js","../node_modules/core-js/internals/array-iteration.js","../node_modules/core-js/modules/es.symbol.js","../node_modules/core-js/modules/es.symbol.async-iterator.js","../node_modules/core-js/modules/es.symbol.description.js","../node_modules/core-js/modules/es.symbol.has-instance.js","../node_modules/core-js/modules/es.symbol.is-concat-spreadable.js","../node_modules/core-js/modules/es.symbol.iterator.js","../node_modules/core-js/modules/es.symbol.match.js","../node_modules/core-js/modules/es.symbol.match-all.js","../node_modules/core-js/modules/es.symbol.replace.js","../node_modules/core-js/modules/es.symbol.search.js","../node_modules/core-js/modules/es.symbol.species.js","../node_modules/core-js/modules/es.symbol.split.js","../node_modules/core-js/modules/es.symbol.to-primitive.js","../node_modules/core-js/modules/es.symbol.to-string-tag.js","../node_modules/core-js/modules/es.symbol.unscopables.js","../node_modules/core-js/internals/correct-prototype-getter.js","../node_modules/core-js/internals/object-get-prototype-of.js","../node_modules/core-js/internals/a-possible-prototype.js","../node_modules/core-js/internals/object-set-prototype-of.js","../node_modules/core-js/internals/iterators.js","../node_modules/core-js/internals/is-array-iterator-method.js","../node_modules/core-js/internals/to-string-tag-support.js","../node_modules/core-js/internals/classof.js","../node_modules/core-js/internals/get-iterator-method.js","../node_modules/core-js/internals/iterator-close.js","../node_modules/core-js/internals/iterate.js","../node_modules/core-js/modules/es.aggreLine truncated
@@ -0,0 +1 @@
{"version":3,"file":"tf.node.js","sources":["../node_modules/@tensorflow/tfjs-core/dist/kernel_names.js","../node_modules/@tensorflow/tfjs-core/dist/backends/backend.js","../node_modules/@tensorflow/tfjs-core/dist/util_base.js","../node_modules/@tensorflow/tfjs-core/dist/environment.js","../node_modules/@tensorflow/tfjs-core/dist/global_util.js","../node_modules/@tensorflow/tfjs-core/dist/kernel_registry.js","../node_modules/@tensorflow/tfjs-core/dist/util.js","../node_modules/@tensorflow/tfjs-core/dist/profiler.js","../node_modules/@tensorflow/tfjs-core/dist/tape.js","../node_modules/@tensorflow/tfjs-core/dist/tensor_format.js","../node_modules/@tensorflow/tfjs-core/dist/tensor.js","../node_modules/@tensorflow/tfjs-core/dist/types.js","../node_modules/@tensorflow/tfjs-core/dist/tensor_util.js","../node_modules/@tensorflow/tfjs-core/dist/engine.js","../node_modules/@tensorflow/tfjs-core/dist/tensor_util_env.js","../node_modules/@tensorflow/tfjs-core/dist/ops/operation.js","../node_modules/@tensorflow/tfjs-core/dist/ops/cast.js","../node_modules/@tensorflow/tfjs-core/dist/ops/mul.js","../node_modules/@tensorflow/tfjs-core/dist/ops/step.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Abs_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/floorDiv.js","../node_modules/@tensorflow/tfjs-core/dist/ops/div.js","../node_modules/@tensorflow/tfjs-core/dist/ops/neg.js","../node_modules/@tensorflow/tfjs-core/dist/ops/tensor_ops_util.js","../node_modules/@tensorflow/tfjs-core/dist/ops/scalar.js","../node_modules/@tensorflow/tfjs-core/dist/ops/sqrt.js","../node_modules/@tensorflow/tfjs-core/dist/ops/square.js","../node_modules/@tensorflow/tfjs-core/dist/ops/sub.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Acos_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Acosh_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/broadcast_util.js","../node_modules/@tensorflow/tfjs-core/dist/ops/reshape.js","../node_modules/@tensorflow/tfjs-core/dist/ops/sum.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Add_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/AddN_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/zeros_like.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/ArgMax_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/ArgMin_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Asin_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/add.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Asinh_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Atan2_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Atan_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Atanh_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/avg_pool_3d_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/AvgPool3D_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/avg_pool_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/AvgPool_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/mat_mul.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/BatchMatMul_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/space_to_batch_nd.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/BatchToSpaceND_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/BroadcastTo_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Cast_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Ceil_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/greater_equal.js","../node_modules/@tensorflow/tfjs-core/dist/ops/less_equal.js","../node_modules/@tensorflow/tfjs-core/dist/ops/logical_and.js","../node_modules/@tensorflow/tfjs-core/dist/ops/clone.js","../node_modules/@tensorflow/tfjs-core/dist/ops/broadcast_to.js","../node_modules/@tensorflow/tfjs-core/dist/ops/where.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/ClipByValue_grad.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/ComplexAbs_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/split.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Concat_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/conv2d_backprop_filter.js","../node_modules/@tensorflow/tfjs-core/dist/ops/conv2d_backprop_input.js","../node_modules/@tensorflow/tfjs-core/dist/ops/conv_util.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Conv2D_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/conv2d.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Conv2DBackpropInput_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/conv3d_backprop_filter.js","../node_modules/@tensorflow/tfjs-core/dist/ops/conv3d_backprop_input.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Conv3D_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/sin.js","../node_modules/@tensorflow/tfjs-core/dist/gradients/Cos_grad.js","../node_modules/@tensorflow/tfjs-core/dist/ops/sinh.js",Line truncated
@@ -0,0 +1,120 @@
#!/usr/bin/env node
"use strict";
/**
* @license
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Entry point for cli tool to build custom tfjs modules
*/
var fs = require("fs");
var path = require("path");
var yargs = require("yargs");
var tfjs_core_1 = require("@tensorflow/tfjs-core");
var util_1 = require("./util");
var types_1 = require("./types");
var esm_module_provider_1 = require("./esm_module_provider");
// Will be configured when loading the config file.
var moduleProvider;
var BASE_PATH = process.env.BASE_PATH || process.cwd();
var DEFAULT_CUSTOM_BUNDLE_ARGS = {
entries: [],
models: [],
kernels: [],
forwardModeOnly: true,
backends: ['cpu', 'webgl'],
moduleOptions: {},
};
var argParser = yargs.options({
config: {
description: 'Path to custom module config file.',
type: 'string',
demandOption: true
}
});
var args = argParser.argv;
function validateArgs() {
var configFilePath = args.config;
if (configFilePath == null) {
util_1.bail("Error: no config file passed");
}
configFilePath = path.resolve(BASE_PATH, configFilePath);
if (!fs.existsSync(configFilePath)) {
util_1.bail("Error: config file does not exist at " + configFilePath);
}
var config;
try {
config = JSON.parse(fs.readFileSync(configFilePath, 'utf-8'));
}
catch (error) {
util_1.bail("Error could not read/parse JSON config file. \n " + error.message);
}
if (config.outputPath == null) {
util_1.bail('Error: config must specify "outputPath" property');
}
console.log("Using custom module configuration from " + configFilePath + ".");
var finalConfig = Object.assign({}, DEFAULT_CUSTOM_BUNDLE_ARGS, config);
if (finalConfig.entries.length !== 0) {
util_1.bail('Error: config.entries not yet supported');
}
// if (finalConfig.models.length !== 0) {
// TODO validate that all these paths exist.
// bail('Error: config.models not yet supported');
// }
for (var _i = 0, _a = finalConfig.backends; _i < _a.length; _i++) {
var requestedBackend = _a[_i];
if (requestedBackend !== types_1.SupportedBackends.cpu &&
requestedBackend !== types_1.SupportedBackends.webgl &&
requestedBackend !== types_1.SupportedBackends.wasm) {
util_1.bail("Error: Unsupported backend specified '" + requestedBackend + "'");
}
}
// Normalize the paths to absolute paths.
function normalizePath(p) {
return path.resolve(BASE_PATH, p);
}
finalConfig.models = finalConfig.models.map(normalizePath);
finalConfig.entries = finalConfig.entries.map(normalizePath);
finalConfig.normalizedOutputPath = normalizePath(finalConfig.outputPath);
moduleProvider = esm_module_provider_1.getModuleProvider(finalConfig.moduleOptions);
console.log('Final Configuration', finalConfig);
return finalConfig;
}
function getKernelNamesForConfig(config) {
// Later on this will do a union of kernels from entries, models and
// kernels, (and kernels used by the converter itself) Currently we only
// support directly listing kernels. remember that this also needs to handle
// kernels used by gradients if forwardModeOnly is false.
// Ops in core that are implemented as custom ops may appear in tf.profile
// they will have __op as a suffix. These do not have corresponding backend
// kernels so we need to filter them out.
function isNotCustomOp(kernelName) {
// opSuffix value is defined in tfjs-core/src/operation.ts
// duplicating it here to avoid an export.
return !kernelName.endsWith(tfjs_core_1.OP_SCOPE_SUFFIX);
}
return config.kernels.filter(isNotCustomOp);
}
var customConfig = validateArgs();
var kernelsToInclude = getKernelNamesForConfig(customConfig);
customConfig.kernels = kernelsToInclude;
if (moduleProvider != null) {
moduleProvider.produceCustomTFJSModule(customConfig);
}
else {
throw new Error('No module provider has been initialized.');
}
//# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../tools/custom_module/cli.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;GAeG;;AAEH;;GAEG;AACH,uBAAyB;AACzB,2BAA6B;AAC7B,6BAA+B;AAE/B,mDAAsD;AAEtD,+BAA4B;AAC5B,iCAAkF;AAClF,6DAAwD;AAExD,mDAAmD;AACnD,IAAI,cAA8B,CAAC;AAEnC,IAAM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E,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,109 @@
"use strict";
/**
* @license
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
Object.defineProperty(exports, "__esModule", { value: true });
var util_1 = require("./util");
function getCustomModuleString(config, moduleProvider) {
var kernels = config.kernels, backends = config.backends, forwardModeOnly = config.forwardModeOnly, models = config.models;
var tfjs = [util_1.getPreamble()];
// A custom tfjs module
addLine(tfjs, moduleProvider.importCoreStr(forwardModeOnly));
if (models.length > 0) {
// A model.json has been passed.
addLine(tfjs, moduleProvider.importConverterStr());
}
for (var _i = 0, backends_1 = backends; _i < backends_1.length; _i++) {
var backend = backends_1[_i];
addLine(tfjs, "\n//backend = " + backend);
addLine(tfjs, moduleProvider.importBackendStr(backend));
for (var _a = 0, kernels_1 = kernels; _a < kernels_1.length; _a++) {
var kernelName = kernels_1[_a];
var kernelImport = moduleProvider.importKernelStr(kernelName, backend);
if (!moduleProvider.validateImportPath(kernelImport.importPath)) {
console.warn('WARNING:', "Import path '" + kernelImport.importPath + "' cannot be resolved. Skipping...");
continue;
}
addLine(tfjs, kernelImport.importStatement);
addLine(tfjs, registerKernelStr(kernelImport.kernelConfigId));
}
}
if (!forwardModeOnly) {
addLine(tfjs, "\n//Gradients");
for (var _b = 0, kernels_2 = kernels; _b < kernels_2.length; _b++) {
var kernelName = kernels_2[_b];
var gradImport = moduleProvider.importGradientConfigStr(kernelName);
if (!moduleProvider.validateImportPath(gradImport.importPath)) {
console.warn('WARNING:', "Import path '" + gradImport.importPath + "' cannot be resolved. Skipping...");
continue;
}
addLine(tfjs, gradImport.importStatement);
addLine(tfjs, registerGradientConfigStr(gradImport.gradConfigId));
}
}
// A custom tfjs core module for imports within tfjs packages
var core = [util_1.getPreamble()];
addLine(core, moduleProvider.importCoreStr(forwardModeOnly));
return {
core: core.join('\n'),
tfjs: tfjs.join('\n'),
};
}
exports.getCustomModuleString = getCustomModuleString;
function getCustomConverterOpsModule(ops, moduleProvider) {
var result = ['// This file is autogenerated\n'];
// Separate namespaced apis from non namespaced ones as they require a
// different export pattern that treats each namespace as a whole.
var flatOps = [];
var namespacedOps = {};
for (var _i = 0, ops_1 = ops; _i < ops_1.length; _i++) {
var opSymbol = ops_1[_i];
if (opSymbol.match(/\./)) {
var parts = opSymbol.split(/\./);
var namespace = parts[0];
var opName = parts[1];
if (namespacedOps[namespace] == null) {
namespacedOps[namespace] = [];
}
namespacedOps[namespace].push(opName);
}
else {
flatOps.push(opSymbol);
}
}
// Group the namespaced symbols by namespace
for (var _a = 0, _b = Object.keys(namespacedOps); _a < _b.length; _a++) {
var namespace = _b[_a];
var opSymbols = namespacedOps[namespace];
result.push(moduleProvider.importNamespacedOpsForConverterStr(namespace, opSymbols));
}
for (var _c = 0, flatOps_1 = flatOps; _c < flatOps_1.length; _c++) {
var opSymbol = flatOps_1[_c];
result.push(moduleProvider.importOpForConverterStr(opSymbol));
}
return result.join('\n');
}
exports.getCustomConverterOpsModule = getCustomConverterOpsModule;
function addLine(target, line) {
target.push(line);
}
function registerKernelStr(kernelConfigId) {
return "registerKernel(" + kernelConfigId + ");";
}
function registerGradientConfigStr(gradConfigId) {
return "registerGradient(" + gradConfigId + ");";
}
//# sourceMappingURL=custom_module.js.map
@@ -0,0 +1 @@
{"version":3,"file":"custom_module.js","sourceRoot":"","sources":["../../../tools/custom_module/custom_module.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;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CAAC,CAAC;QACxE,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,oCAAoC,CAAC,CAAC;QAC7D,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,oCAAoC,CAAC,CAAC;QAE7D,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,0BAA0B,CAAC,CAAC;QACnD,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,+CAA+C,CAAC,CAAC;QACxE,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,+CAA+C,CAAC,CAAC;QACxE,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,oCAAoC,CAAC,CAAC;QAC7D,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,oCAAoC,CAAC,CAAC;QAE7D,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,6CAA6C,EAAE;IACtD,IAAM,eAAe,GAAG,KAAK,CAAC;IAE9B,EAAE,CAAC,yBAAyB,EAAE;QAC5B,IAAM,MAAM,GAAG;YACb,OAAO,EAAE,CAAC,UAAU,EAAE,SAAS,CAAC;YAChC,QAAQ,EAAE,CAAC,WAAW,CAAC;YACvB,MAAM,EAAE,EAAc;YALine truncated
@@ -0,0 +1,143 @@
"use strict";
/**
* @license
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
Object.defineProperty(exports, "__esModule", { value: true });
var fs = require("fs");
var path = require("path");
var custom_module_1 = require("./custom_module");
var model_parser_1 = require("./model_parser");
var util_1 = require("./util");
function getModuleProvider(opts) {
return new ESMModuleProvider();
}
exports.getModuleProvider = getModuleProvider;
var ESMModuleProvider = /** @class */ (function () {
function ESMModuleProvider() {
}
/**
* Writes out custom tfjs module(s) to disk.
*/
ESMModuleProvider.prototype.produceCustomTFJSModule = function (config) {
var normalizedOutputPath = config.normalizedOutputPath;
var moduleStrs = custom_module_1.getCustomModuleString(config, exports.esmImportProvider);
fs.mkdirSync(normalizedOutputPath, { recursive: true });
console.log("Will write custom tfjs modules to " + normalizedOutputPath);
var customTfjsFileName = 'custom_tfjs.js';
var customTfjsCoreFileName = 'custom_tfjs_core.js';
// Write a custom module for @tensorflow/tfjs and @tensorflow/tfjs-core
fs.writeFileSync(path.join(normalizedOutputPath, customTfjsCoreFileName), moduleStrs.core);
fs.writeFileSync(path.join(normalizedOutputPath, customTfjsFileName), moduleStrs.tfjs);
// Write a custom module tfjs-core ops used by converter executors
var kernelToOps;
var mappingPath;
try {
mappingPath =
require.resolve('@tensorflow/tfjs-converter/metadata/kernel2op.json');
kernelToOps = JSON.parse(fs.readFileSync(mappingPath, 'utf-8'));
}
catch (e) {
util_1.bail("Error loading kernel to ops mapping file " + mappingPath);
}
var converterOps = model_parser_1.getOpsForConfig(config, kernelToOps);
if (converterOps.length > 0) {
var converterOpsModule = custom_module_1.getCustomConverterOpsModule(converterOps, exports.esmImportProvider);
var customConverterOpsFileName = 'custom_ops_for_converter.js';
fs.writeFileSync(path.join(normalizedOutputPath, customConverterOpsFileName), converterOpsModule);
}
};
return ESMModuleProvider;
}());
/**
* An import provider to generate custom esm modules.
*/
// Exported for tests.
exports.esmImportProvider = {
importCoreStr: function (forwardModeOnly) {
var importLines = [
"import {registerKernel} from '@tensorflow/tfjs-core/dist/base';",
"import '@tensorflow/tfjs-core/dist/base_side_effects';",
"export * from '@tensorflow/tfjs-core/dist/base';"
];
if (!forwardModeOnly) {
importLines.push("import {registerGradient} from '@tensorflow/tfjs-core/dist/base';");
}
return importLines.join('\n');
},
importConverterStr: function () {
return "export * from '@tensorflow/tfjs-converter';";
},
importBackendStr: function (backend) {
var backendPkg = getBackendPath(backend);
return "export * from '" + backendPkg + "/dist/base';";
},
importKernelStr: function (kernelName, backend) {
var backendPkg = getBackendPath(backend);
var kernelConfigId = kernelName + "_" + backend;
var importPath = backendPkg + "/dist/kernels/" + kernelName;
var importStatement = "import {" + util_1.kernelNameToVariableName(kernelName) + "Config as " + kernelConfigId + "} from '" + importPath + "';";
return { importPath: importPath, importStatement: importStatement, kernelConfigId: kernelConfigId };
},
importGradientConfigStr: function (kernelName) {
var gradConfigId = util_1.kernelNameToVariableName(kernelName) + "GradConfig";
var importPath = "@tensorflow/tfjs-core/dist/gradients/" + kernelName + "_grad";
var importStatement = "import {" + gradConfigId + "} from '" + importPath + "';";
return { importPath: importPath, importStatement: importStatement, gradConfigId: gradConfigId };
},
importOpForConverterStr: function (opSymbol) {
var opFileName = util_1.opNameToFileName(opSymbol);
return "export {" + opSymbol + "} from '@tensorflow/tfjs-core/dist/ops/" + opFileName + "';";
},
importNamespacedOpsForConverterStr: function (namespace, opSymbols) {
var result = [];
for (var _i = 0, opSymbols_1 = opSymbols; _i < opSymbols_1.length; _i++) {
var opSymbol = opSymbols_1[_i];
var opFileName = util_1.opNameToFileName(opSymbol);
var opAlias = opSymbol + "_" + namespace;
result.push("import {" + opSymbol + " as " + opAlias + "} from '@tensorflow/tfjs-core/dist/ops/" + namespace + "/" + opFileName + "';");
}
result.push("export const " + namespace + " = {");
for (var _a = 0, opSymbols_2 = opSymbols; _a < opSymbols_2.length; _a++) {
var opSymbol = opSymbols_2[_a];
var opAlias = opSymbol + "_" + namespace;
result.push("\t" + opSymbol + ": " + opAlias + ",");
}
result.push("};");
return result.join('\n');
},
validateImportPath: function (importPath) {
try {
require.resolve(importPath);
return true;
}
catch (e) {
return false;
}
}
};
function getBackendPath(backend) {
switch (backend) {
case 'cpu':
return '@tensorflow/tfjs-backend-cpu';
case 'webgl':
return '@tensorflow/tfjs-backend-webgl';
case 'wasm':
return '@tensorflow/tfjs-backend-wasm';
default:
throw new Error("Unsupported backend " + backend);
}
}
//# sourceMappingURL=esm_module_provider.js.map
@@ -0,0 +1 @@
{"version":3,"file":"esm_module_provider.js","sourceRoot":"","sources":["../../../tools/custom_module/esm_module_provider.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AAEH,uBAAyB;AACzB,2BAA6B;AAE7B,iDAAmF;AACnF,+CAA+C;AAE/C,+BAAwE;AAExE,SAAgB,iBAAiB,CAAC,IAAQ;IACxC,OAAO,IAAI,iBAAiB,EAAE,CAAC;AACjC,CAAC;AAFD,8CAEC;AAED;IAAA;IA8CA,CAAC;IA7CC;;OAEG;IACH,mDAAuB,GAAvB,UAAwB,MAA8B;QAC7C,IAAA,kDAAoB,CAAW;QAEtC,IAAM,UAAU,GAAG,qCAAqB,CAAC,MAAM,EAAE,yBAAiB,CAAC,CAAC;QAEpE,EAAE,CAAC,SAAS,CAAC,oBAAoB,EAAE,EAAC,SAAS,EAAE,IAAI,EAAC,CAAC,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,uCAAqC,oBAAsB,CAAC,CAAC;QAEzE,IAAM,kBAAkB,GAAG,gBAAgB,CAAC;QAC5C,IAAM,sBAAsB,GAAG,qBAAqB,CAAC;QAErD,uEAAuE;QACvE,EAAE,CAAC,aAAa,CACZ,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,sBAAsB,CAAC,EACvD,UAAU,CAAC,IAAI,CAAC,CAAC;QACrB,EAAE,CAAC,aAAa,CACZ,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,kBAAkB,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;QAE1E,kEAAkE;QAElE,IAAI,WAAW,CAAC;QAChB,IAAI,WAAW,CAAC;QAChB,IAAI;YACF,WAAW;gBACP,OAAO,CAAC,OAAO,CAAC,oDAAoD,CAAC,C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IAAM,QAAQ,kBAAA;YACjB,IAAM,OAAO,GAAM,QAAQ,SAAI,SAAW,CAAC;YAC3C,MAAM,CAAC,IAAI,CAAC,OAAK,QAAQ,UAAK,OAAO,MAAG,CAAC,CAAC;SAC3C;QACD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAElB,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAED,kBAAkB,EAAlB,UAAmB,UAAkB;QACnC,IAAI;YACF,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;YAC5B,OAAO,IAAI,CAAC;SACb;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,KAAK,CAAC;SACd;IACH,CAAC;CACF,CAAC;AAEF,SAAS,cAAc,CAAC,OAAyB;IAC/C,QAAQ,OAAO,EAAE;QACf,KAAK,KAAK;YACR,OAAO,8BAA8B,CAAC;QACxC,KAAK,OAAO;YACV,OAAO,gCAAgC,CAAC;QAC1C,KAAK,MAAM;YACT,OAAO,+BAA+B,CAAC;QACzC;YACE,MAAM,IAAI,KAAK,CAAC,yBAAuB,OAAS,CAAC,CAAC;KACrD;AACH,CAAC"}
@@ -0,0 +1 @@
{"version":3,"file":"esm_module_provider_test.js","sourceRoot":"","sources":["../../../tools/custom_module/esm_module_provider_test.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AAEH,6DAAwD;AAExD,QAAQ,CAAC,qBAAqB,EAAE;IAC9B,EAAE,CAAC,oCAAoC,EAAE;QACvC,IAAM,eAAe,GAAG,IAAI,CAAC;QAC7B,IAAM,GAAG,GAAG,uCAAiB,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;QAC7D,MAAM,CAAC,GAAG,CAAC,CAAC,SAAS,CACjB,gEAAgE,CAAC,CAAC;QACtE,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,SAAS,CACrB,kEAAkE,CAAC,CAAC;QACxE,MAAM,CAAC,GAAG,CAAC,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,CAAC;IAEH,EAAE,CAAC,sCAAsC,EAAE;QACzC,IAAM,GAAG,GAAG,uCAAiB,CAAC,uBAAuB,CAAC,cAAc,CAAC,CAAC;QACtE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI;QACZ,4CAA4C;QAC5C,4EAA4E,CAAC,CAAC;IACpF,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yDAAyD,EAAE;QAC5D,IAAM,GAAG,GAAG,uCAAiB,CAAC,kCAAkC,CAC5D,OAAO,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI;QACZ,4CAA4C;QAC5C,mLAGL,CAAC,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yDAAyD,EAAE;QAC5D,IAAM,GAAG,GAAG,uCAAiB,CAAC,kCAAkC,CAC5D,OAAO,EAAE,CAAC,gBAAgB,EAAE,uBAAuB,CAAC,CAAC,CAAC;QAC1D,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI;QACZ,4CAA4C;QAC5C,8WAKL,CAAC,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,75 @@
"use strict";
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
Object.defineProperty(exports, "__esModule", { value: true });
var fs = require("fs");
var util_1 = require("./util");
function getOpsForConfig(
// tslint:disable-next-line: no-any
config, kernelToOps) {
// This will return a list of ops used by the model.json(s) passed in.
var results = new Set();
var modelJson;
for (var _i = 0, _a = config.models; _i < _a.length; _i++) {
var modelJsonPath = _a[_i];
try {
modelJson = JSON.parse(fs.readFileSync(modelJsonPath, 'utf-8'));
}
catch (e) {
util_1.bail("Error loading JSON file " + modelJsonPath);
}
var ops = getOps(modelJson, kernelToOps);
ops.forEach(function (op) { return results.add(op); });
}
return Array.from(results);
}
exports.getOpsForConfig = getOpsForConfig;
function getOps(
// tslint:disable-next-line: no-any
modelJson, kernelToOp) {
var results = new Set();
var addOpsToResults = function (kernel) {
var ops = kernelToOp[kernel];
if (ops == null) {
console.warn("Kernel => Op warning: could not find op mapping for kernel " + kernel);
}
ops.forEach(function (op) {
results.add(op);
});
};
var graph = modelJson.modelTopology;
// Parse nodes
if (graph.node != null) {
graph.node.forEach(function (node) {
addOpsToResults(node.op);
});
}
// Parse functionDef nodes
if (graph.library != null && graph.library.function != null) {
graph.library.function.forEach(function (functionDef) {
var nodeDef = functionDef.nodeDef;
if (nodeDef != null) {
nodeDef.forEach(function (node) {
addOpsToResults(node.op);
});
}
});
}
return Array.from(results);
}
exports.getOps = getOps;
//# sourceMappingURL=model_parser.js.map
@@ -0,0 +1 @@
{"version":3,"file":"model_parser.js","sourceRoot":"","sources":["../../../tools/custom_module/model_parser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AAKH,uBAAyB;AAEzB,+BAA4B;AAE5B,SAAgB,eAAe;AAC3B,mCAAmC;AACnC,MAA8B,EAAE,WAAgB;IAClD,sEAAsE;IACtE,IAAM,OAAO,GAAgB,IAAI,GAAG,EAAE,CAAC;IACvC,IAAI,SAAS,CAAC;IACd,KAA4B,UAAa,EAAb,KAAA,MAAM,CAAC,MAAM,EAAb,cAAa,EAAb,IAAa,EAAE;QAAtC,IAAM,aAAa,SAAA;QACtB,IAAI;YACF,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;SACjE;QAAC,OAAO,CAAC,EAAE;YACV,WAAI,CAAC,6BAA2B,aAA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EAAC,OAAO,EAAE,EAAC,CAAC,EAAE,MAAM,EAA0B,EAAC;aACtD;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,EAAE,EAAE,MAAM;gBACV,KAAK,EAAE,CAAC,SAAS,CAAC;gBAClB,IAAI,EAAE,EAAC,IAAI,EAAE,EAAC,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAC,EAAC;aACnD;SACF;QACD,OAAO,EAAE;YACP,QAAQ,EAAE;gBACR;oBACE,SAAS,EAAE;wBACT,IAAI,EAAE,qCAAqC;wBAC3C,QAAQ,EAAE;4BACR,EAAC,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAC;4BAChE;gCACE,IAAI,EAAE,0BAA0B;gCAChC,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,QAAQ;6BACnC;4BACD,EAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAC;4BACzD,EAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,QAAQ,EAAC,EAAE;gCACpD,IAAI,EAAE,wCAAwC;gCAC9C,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,QAAQ;6BACnC;yBACF;wBACD,SAAS,EAAE,CAAC,EAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAC,CAAC;qBACnE;oBACD,OAAO,EAAE,CAAC;4BACR,IAAI,EAAE,MAAM;4BACZ,EAAE,EAAE,MAAM;4BACV,KAAK,EAAE,CAAC,aAAa,EAAE,QAAQ,CAAC;4BAChC,IAAI,EAAE,EAAC,CAAC,EAAE,EAAC,IAAI,EAAE,UAAU,CAACLine truncated
@@ -0,0 +1,25 @@
"use strict";
/**
* @license
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
Object.defineProperty(exports, "__esModule", { value: true });
var SupportedBackends;
(function (SupportedBackends) {
SupportedBackends["cpu"] = "cpu";
SupportedBackends["webgl"] = "webgl";
SupportedBackends["wasm"] = "wasm";
})(SupportedBackends = exports.SupportedBackends || (exports.SupportedBackends = {}));
//# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../tools/custom_module/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;AAEH,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IAC3B,gCAAW,CAAA;IACX,oCAAe,CAAA;IACf,kCAAa,CAAA;AACf,CAAC,EAJW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAI5B"}
@@ -0,0 +1,54 @@
#!/usr/bin/env node
"use strict";
/**
* @license
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
Object.defineProperty(exports, "__esModule", { value: true });
var chalk = require("chalk");
/**
* Normalized kernels names to the variable name used in code for the kernel
* config.
*/
function kernelNameToVariableName(kernelName) {
if (kernelName.startsWith('_')) {
// e.g. _FusedMatMulConfig
return "_" + kernelName.charAt(1).toLowerCase() + kernelName.slice(2);
}
return kernelName.charAt(0).toLowerCase() + kernelName.slice(1);
}
exports.kernelNameToVariableName = kernelNameToVariableName;
/**
* Given an op name returns the name of the file that would export that op.
*/
function opNameToFileName(opName) {
// add exceptions here.
if (opName === 'isNaN') {
return 'is_nan';
}
return opName.replace(/[A-Z]/g, function (s) { return "_" + s.toLowerCase(); });
}
exports.opNameToFileName = opNameToFileName;
function getPreamble() {
var preamble = "/**\n * @license\n * Copyright " + (new Date()).getFullYear() + " Google LLC. All Rights Reserved.\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n * =============================================================================\n */\n\n// This file is autogenerated.\n\n";
return preamble;
}
exports.getPreamble = getPreamble;
function bail(errorMsg) {
console.log(chalk.red(errorMsg));
process.exit(1);
}
exports.bail = bail;
//# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../../tools/custom_module/util.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;;;GAeG;;AAEH,6BAA+B;AAE/B;;;GAGG;AACH,SAAgB,wBAAwB,CAAC,UAAkB;IACzD,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QAC9B,0BAA0B;QAC1B,OAAO,MAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAG,CAAC;KACvE;IACD,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAND,4DAMC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,MAAc;IAC7C,uBAAuB;IACvB,IAAI,MAAM,KAAK,OAAO,EAAE;QACtB,OAAO,QAAQ,CAAC;KACjB;IACD,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAC,CAAS,IAAK,OAAA,MAAI,CAAC,CAAC,WAAW,EAAI,EAArB,CAAqB,CAAC,CAAC;AACxE,CAAC;AAND,4CAMC;AAED,SAAgB,WAAW;IACzB,IAAM,QAAQ,GAAG,oCAEJ,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,ytBAgBxC,CAAC;IACA,OAAO,QAAQ,CAAC;AAClB,CAAC;AArBD,kCAqBC;AAED,SAAgB,IAAI,CAAC,QAAgB;IACnC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAHD,oBAGC"}
@@ -0,0 +1,3 @@
/** @license See the LICENSE file. */
declare const version = "3.6.0";
export { version };
@@ -0,0 +1,5 @@
/** @license See the LICENSE file. */
// This code is auto-generated, do not modify this file!
const version = '3.6.0';
export { version };
//# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA,qCAAqC;AAErC,wDAAwD;AACxD,MAAM,OAAO,GAAG,OAAO,CAAC;AACxB,OAAO,EAAC,OAAO,EAAC,CAAC","sourcesContent":["/** @license See the LICENSE file. */\n\n// This code is auto-generated, do not modify this file!\nconst version = '3.6.0';\nexport {version};\n"]}
@@ -0,0 +1,53 @@
/**
* @license
* Copyright 2018 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import '@tensorflow/tfjs-core';
// tslint:disable-next-line: no-imports-from-dist
import '@tensorflow/tfjs-core/dist/register_all_gradients';
// tslint:disable-next-line: no-imports-from-dist
import '@tensorflow/tfjs-core/dist/public/chained_ops/register_all_chained_ops';
export * from '@tensorflow/tfjs-core';
export * from '@tensorflow/tfjs-layers';
export * from '@tensorflow/tfjs-converter';
// Export data api as tf.data
import * as data from '@tensorflow/tfjs-data';
export {data};
// Import and register backends.
import '@tensorflow/tfjs-backend-cpu';
import '@tensorflow/tfjs-backend-webgl';
// Import versions of all sub-packages.
import {version_core} from '@tensorflow/tfjs-core';
import {version_cpu} from '@tensorflow/tfjs-backend-cpu';
import {version_webgl} from '@tensorflow/tfjs-backend-webgl';
import {version_data} from '@tensorflow/tfjs-data';
import {version_layers} from '@tensorflow/tfjs-layers';
import {version_converter} from '@tensorflow/tfjs-converter';
import {version as version_union} from './version';
export const version = {
'tfjs-core': version_core,
'tfjs-backend-cpu': version_cpu,
'tfjs-backend-webgl': version_webgl,
'tfjs-data': version_data,
'tfjs-layers': version_layers,
'tfjs-converter': version_converter,
'tfjs': version_union
};
@@ -0,0 +1,21 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
// This file is used to build a union bundle that has polyfills for ES5 support.
import 'core-js/stable';
import 'regenerator-runtime/runtime';
export * from './index';
@@ -0,0 +1,5 @@
/** @license See the LICENSE file. */
// This code is auto-generated, do not modify this file!
const version = '3.6.0';
export {version};
@@ -0,0 +1,143 @@
#!/usr/bin/env node
/**
* @license
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
/**
* Entry point for cli tool to build custom tfjs modules
*/
import * as fs from 'fs';
import * as path from 'path';
import * as yargs from 'yargs';
import {OP_SCOPE_SUFFIX} from '@tensorflow/tfjs-core';
import {bail} from './util';
import {CustomTFJSBundleConfig, SupportedBackends, ModuleProvider} from './types';
import {getModuleProvider} from './esm_module_provider';
// Will be configured when loading the config file.
let moduleProvider: ModuleProvider;
const BASE_PATH = process.env.BASE_PATH || process.cwd();
const DEFAULT_CUSTOM_BUNDLE_ARGS: Partial<CustomTFJSBundleConfig> = {
entries: [],
models: [],
kernels: [],
forwardModeOnly: true,
backends: ['cpu', 'webgl'],
moduleOptions: {},
};
const argParser = yargs.options({
config: {
description: 'Path to custom module config file.',
type: 'string',
demandOption: true
}
});
const args = argParser.argv;
function validateArgs(): CustomTFJSBundleConfig {
let configFilePath = args.config;
if (configFilePath == null) {
bail(`Error: no config file passed`);
}
configFilePath = path.resolve(BASE_PATH, configFilePath);
if (!fs.existsSync(configFilePath)) {
bail(`Error: config file does not exist at ${configFilePath}`);
}
let config;
try {
config = JSON.parse(fs.readFileSync(configFilePath, 'utf-8'));
} catch (error) {
bail(`Error could not read/parse JSON config file. \n ${error.message}`);
}
if (config.outputPath == null) {
bail('Error: config must specify "outputPath" property');
}
console.log(`Using custom module configuration from ${configFilePath}.`);
const finalConfig = Object.assign({}, DEFAULT_CUSTOM_BUNDLE_ARGS, config);
if (finalConfig.entries.length !== 0) {
bail('Error: config.entries not yet supported');
}
// if (finalConfig.models.length !== 0) {
// TODO validate that all these paths exist.
// bail('Error: config.models not yet supported');
// }
for (const requestedBackend of finalConfig.backends) {
if (requestedBackend !== SupportedBackends.cpu &&
requestedBackend !== SupportedBackends.webgl &&
requestedBackend !== SupportedBackends.wasm) {
bail(`Error: Unsupported backend specified '${requestedBackend}'`);
}
}
// Normalize the paths to absolute paths.
function normalizePath(p: string) {
return path.resolve(BASE_PATH, p);
}
finalConfig.models = finalConfig.models.map(normalizePath);
finalConfig.entries = finalConfig.entries.map(normalizePath);
finalConfig.normalizedOutputPath = normalizePath(finalConfig.outputPath);
moduleProvider = getModuleProvider(finalConfig.moduleOptions);
console.log('Final Configuration', finalConfig);
return finalConfig;
}
function getKernelNamesForConfig(config: CustomTFJSBundleConfig) {
// Later on this will do a union of kernels from entries, models and
// kernels, (and kernels used by the converter itself) Currently we only
// support directly listing kernels. remember that this also needs to handle
// kernels used by gradients if forwardModeOnly is false.
// Ops in core that are implemented as custom ops may appear in tf.profile
// they will have __op as a suffix. These do not have corresponding backend
// kernels so we need to filter them out.
function isNotCustomOp(kernelName: string) {
// opSuffix value is defined in tfjs-core/src/operation.ts
// duplicating it here to avoid an export.
return !kernelName.endsWith(OP_SCOPE_SUFFIX);
}
return config.kernels.filter(isNotCustomOp);
}
const customConfig = validateArgs();
const kernelsToInclude = getKernelNamesForConfig(customConfig);
customConfig.kernels = kernelsToInclude;
if (moduleProvider != null) {
moduleProvider.produceCustomTFJSModule(customConfig);
} else {
throw new Error('No module provider has been initialized.');
}
@@ -0,0 +1,38 @@
/**
* @license
* Copyright 2020 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import * as fs from 'fs';
import * as path from 'path';
describe('CLI binary', () => {
it('should be present and executable', () => {
const packageJsonPath = path.resolve(
__dirname,
'../../package.json',
);
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
const binEntry = packageJson.bin;
expect(binEntry['tfjs-custom-module']).toBeDefined();
const toolPath = path.resolve(
path.dirname(packageJsonPath), binEntry['tfjs-custom-module']);
expect(() => {
fs.accessSync(toolPath, fs.constants.X_OK);
}).not.toThrow();
});
});
@@ -0,0 +1,126 @@
/**
* @license
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {CustomModuleFiles, CustomTFJSBundleConfig, ImportProvider} from './types';
import {getPreamble} from './util';
export function getCustomModuleString(
config: CustomTFJSBundleConfig,
moduleProvider: ImportProvider,
): CustomModuleFiles {
const {kernels, backends, forwardModeOnly, models} = config;
const tfjs: string[] = [getPreamble()];
// A custom tfjs module
addLine(tfjs, moduleProvider.importCoreStr(forwardModeOnly));
if (models.length > 0) {
// A model.json has been passed.
addLine(tfjs, moduleProvider.importConverterStr());
}
for (const backend of backends) {
addLine(tfjs, `\n//backend = ${backend}`);
addLine(tfjs, moduleProvider.importBackendStr(backend));
for (const kernelName of kernels) {
const kernelImport = moduleProvider.importKernelStr(kernelName, backend);
if (!moduleProvider.validateImportPath(kernelImport.importPath)) {
console.warn(
'WARNING:',
`Import path '${
kernelImport.importPath}' cannot be resolved. Skipping...`);
continue;
}
addLine(tfjs, kernelImport.importStatement);
addLine(tfjs, registerKernelStr(kernelImport.kernelConfigId));
}
}
if (!forwardModeOnly) {
addLine(tfjs, `\n//Gradients`);
for (const kernelName of kernels) {
const gradImport = moduleProvider.importGradientConfigStr(kernelName);
if (!moduleProvider.validateImportPath(gradImport.importPath)) {
console.warn(
'WARNING:',
`Import path '${
gradImport.importPath}' cannot be resolved. Skipping...`);
continue;
}
addLine(tfjs, gradImport.importStatement);
addLine(tfjs, registerGradientConfigStr(gradImport.gradConfigId));
}
}
// A custom tfjs core module for imports within tfjs packages
const core: string[] = [getPreamble()];
addLine(core, moduleProvider.importCoreStr(forwardModeOnly));
return {
core: core.join('\n'),
tfjs: tfjs.join('\n'),
};
}
export function getCustomConverterOpsModule(
ops: string[], moduleProvider: ImportProvider): string {
const result: string[] = ['// This file is autogenerated\n'];
// Separate namespaced apis from non namespaced ones as they require a
// different export pattern that treats each namespace as a whole.
const flatOps = [];
const namespacedOps: {[key: string]: string[]} = {};
for (const opSymbol of ops) {
if (opSymbol.match(/\./)) {
const parts = opSymbol.split(/\./);
const namespace = parts[0];
const opName = parts[1];
if (namespacedOps[namespace] == null) {
namespacedOps[namespace] = [];
}
namespacedOps[namespace].push(opName);
} else {
flatOps.push(opSymbol);
}
}
// Group the namespaced symbols by namespace
for (const namespace of Object.keys(namespacedOps)) {
const opSymbols = namespacedOps[namespace];
result.push(moduleProvider.importNamespacedOpsForConverterStr(
namespace, opSymbols));
}
for (const opSymbol of flatOps) {
result.push(moduleProvider.importOpForConverterStr(opSymbol));
}
return result.join('\n');
}
function addLine(target: string[], line: string) {
target.push(line);
}
function registerKernelStr(kernelConfigId: string) {
return `registerKernel(${kernelConfigId});`;
}
function registerGradientConfigStr(gradConfigId: string) {
return `registerGradient(${gradConfigId});`;
}
@@ -0,0 +1,276 @@
/**
* @license
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {getCustomConverterOpsModule, getCustomModuleString} from './custom_module';
import {CustomTFJSBundleConfig, ImportProvider} from './types';
const mockImportProvider: ImportProvider = {
importCoreStr: () => 'import CORE',
importConverterStr: () => 'import CONVERTER',
importBackendStr: (name: string) => `import BACKEND ${name}`,
importKernelStr: (kernelName: string, backend: string) => {
const importPath = `${
kernelName === 'Invalid' ? 'BACKEND_Invalid' : 'BACKEND'} ${backend}`;
return {
importPath,
importStatement: `import KERNEL ${kernelName} from ${importPath}`,
kernelConfigId: `${kernelName}_${backend}`
};
},
importGradientConfigStr: (kernel: string) => {
const importPath = kernel === 'Invalid' ? 'BACKEND_Invalid' : 'BACKEND';
return {
importPath,
importStatement: `import GRADIENT ${kernel} from ${importPath}`,
gradConfigId: `${kernel}_GRAD_CONFIG`,
};
},
importOpForConverterStr: (opSymbol: string) => {
return `export * from ${opSymbol}`;
},
importNamespacedOpsForConverterStr: (
namespace: string, opSymbols: string[]) => {
return `export ${opSymbols.join(',')} as ${namespace} from ${namespace}/`;
},
validateImportPath: (importPath: string) => {
return !importPath.includes('Invalid');
}
};
describe('getCustomModuleString forwardModeOnly=true', () => {
const forwardModeOnly = true;
it('one kernel, one backend', () => {
const config = {
kernels: ['MathKrnl', 'Invalid'],
backends: ['FastBcknd'],
models: [] as string[],
forwardModeOnly
};
const {tfjs, core} = getCustomModuleString(
// cast because FastBcknd is not a valid backend per the type
config as CustomTFJSBundleConfig, mockImportProvider);
expect(core).toContain('import CORE');
expect(tfjs).toContain('import CORE');
expect(tfjs).toContain('import BACKEND FastBcknd');
expect(tfjs).toContain('import KERNEL MathKrnl from BACKEND FastBcknd');
expect(tfjs).toContain('registerKernel(MathKrnl_FastBcknd)');
expect(tfjs).not.toContain('import KERNEL Invalid from BACKEND FastBcknd');
expect(tfjs).not.toContain('registerKernel(Invalid_FastBcknd)');
expect(tfjs).not.toContain('GRADIENT');
});
it('one kernel, one backend, one model', () => {
const config = {
kernels: ['MathKrnl'],
backends: ['FastBcknd'],
models: ['model1.json'],
forwardModeOnly
};
const {tfjs, core} = getCustomModuleString(
// cast because FastBcknd is not a valid backend per the type
config as CustomTFJSBundleConfig, mockImportProvider);
expect(core).toContain('import CORE');
expect(tfjs).toContain('import CORE');
expect(tfjs).toContain('import CONVERTER');
expect(tfjs).toContain('import BACKEND FastBcknd');
expect(tfjs).toContain('import KERNEL MathKrnl from BACKEND FastBcknd');
expect(tfjs).toContain('registerKernel(MathKrnl_FastBcknd)');
expect(tfjs).not.toContain('GRADIENT');
});
it('one kernel, two backend', () => {
const config = {
kernels: ['MathKrnl'],
backends: ['FastBcknd', 'SlowBcknd'],
models: [] as string[],
forwardModeOnly
};
const {tfjs} = getCustomModuleString(
// cast because the backends are not truly valid backend per the type
config as CustomTFJSBundleConfig, mockImportProvider);
expect(tfjs).toContain('import CORE');
expect(tfjs).toContain('import BACKEND FastBcknd');
expect(tfjs).toContain('import KERNEL MathKrnl from BACKEND FastBcknd');
expect(tfjs).toContain('registerKernel(MathKrnl_FastBcknd)');
expect(tfjs).toContain('import BACKEND SlowBcknd');
expect(tfjs).toContain('import KERNEL MathKrnl from BACKEND SlowBcknd');
expect(tfjs).toContain('registerKernel(MathKrnl_SlowBcknd)');
expect(tfjs).not.toContain('GRADIENT');
});
it('two kernels, one backend', () => {
const config = {
kernels: ['MathKrnl', 'MathKrn2'],
backends: ['FastBcknd'],
models: [] as string[],
forwardModeOnly
};
const {tfjs} = getCustomModuleString(
config as CustomTFJSBundleConfig, mockImportProvider);
expect(tfjs).toContain('import CORE');
expect(tfjs).toContain('import BACKEND FastBcknd');
expect(tfjs).toContain('import KERNEL MathKrnl from BACKEND FastBcknd');
expect(tfjs).toContain('import KERNEL MathKrn2 from BACKEND FastBcknd');
expect(tfjs).toContain('registerKernel(MathKrnl_FastBcknd)');
expect(tfjs).toContain('registerKernel(MathKrn2_FastBcknd)');
expect(tfjs).not.toContain('GRADIENT');
});
it('two kernels, two backends', () => {
const config = {
kernels: ['MathKrnl', 'MathKrn2'],
backends: ['FastBcknd', 'SlowBcknd'],
models: [] as string[],
forwardModeOnly
};
const {tfjs} = getCustomModuleString(
config as CustomTFJSBundleConfig, mockImportProvider);
expect(tfjs).toContain('import CORE');
expect(tfjs).toContain('import BACKEND FastBcknd');
expect(tfjs).toContain('import KERNEL MathKrnl from BACKEND FastBcknd');
expect(tfjs).toContain('import KERNEL MathKrn2 from BACKEND FastBcknd');
expect(tfjs).toContain('registerKernel(MathKrnl_FastBcknd)');
expect(tfjs).toContain('registerKernel(MathKrn2_FastBcknd)');
expect(tfjs).toContain('import BACKEND SlowBcknd');
expect(tfjs).toContain('import KERNEL MathKrnl from BACKEND SlowBcknd');
expect(tfjs).toContain('import KERNEL MathKrn2 from BACKEND SlowBcknd');
expect(tfjs).toContain('registerKernel(MathKrnl_SlowBcknd)');
expect(tfjs).toContain('registerKernel(MathKrn2_SlowBcknd)');
expect(tfjs).not.toContain('GRADIENT');
});
});
describe('getCustomModuleString forwardModeOnly=false', () => {
const forwardModeOnly = false;
it('one kernel, one backend', () => {
const config = {
kernels: ['MathKrnl', 'Invalid'],
backends: ['FastBcknd'],
models: [] as string[],
forwardModeOnly
};
const {tfjs} = getCustomModuleString(
config as CustomTFJSBundleConfig, mockImportProvider);
expect(tfjs).toContain('import CORE');
expect(tfjs).toContain('import BACKEND FastBcknd');
expect(tfjs).toContain('import KERNEL MathKrnl from BACKEND FastBcknd');
expect(tfjs).toContain('registerKernel(MathKrnl_FastBcknd)');
expect(tfjs).not.toContain('import KERNEL Invalid from BACKEND FastBcknd');
expect(tfjs).not.toContain('registerKernel(Invalid_FastBcknd)');
expect(tfjs).toContain('import GRADIENT MathKrnl');
expect(tfjs).toContain('registerGradient(MathKrnl_GRAD_CONFIG)');
expect(tfjs).not.toContain('import GRADIENT Invalid');
expect(tfjs).not.toContain('registerKernel(Invalid_GRAD_CONFIG)');
});
it('one kernel, two backend', () => {
const config = {
kernels: ['MathKrnl'],
backends: ['FastBcknd', 'SlowBcknd'],
models: [] as string[],
forwardModeOnly
};
const {tfjs} = getCustomModuleString(
config as CustomTFJSBundleConfig, mockImportProvider);
expect(tfjs).toContain('import GRADIENT MathKrnl');
expect(tfjs).toContain('registerGradient(MathKrnl_GRAD_CONFIG)');
const gradIndex = tfjs.indexOf('GRADIENT');
expect(tfjs.indexOf('GRADIENT', gradIndex + 1))
.toBe(-1, `Gradient import appears twice in:\n ${tfjs}`);
});
it('two kernels, one backend', () => {
const config = {
kernels: ['MathKrnl', 'MathKrn2'],
backends: ['FastBcknd'],
models: [] as string[],
forwardModeOnly
};
const {tfjs} = getCustomModuleString(
config as CustomTFJSBundleConfig, mockImportProvider);
expect(tfjs).toContain('import GRADIENT MathKrnl');
expect(tfjs).toContain('registerGradient(MathKrnl_GRAD_CONFIG)');
expect(tfjs).toContain('import GRADIENT MathKrn2');
expect(tfjs).toContain('registerGradient(MathKrn2_GRAD_CONFIG)');
});
it('two kernels, two backends', () => {
const config = {
kernels: ['MathKrnl', 'MathKrn2'],
backends: ['FastBcknd', 'SlowBcknd'],
models: [] as string[],
forwardModeOnly
};
const {tfjs} = getCustomModuleString(
config as CustomTFJSBundleConfig, mockImportProvider);
expect(tfjs).toContain('import GRADIENT MathKrnl');
expect(tfjs).toContain('registerGradient(MathKrnl_GRAD_CONFIG)');
expect(tfjs).toContain('import GRADIENT MathKrn2');
expect(tfjs).toContain('registerGradient(MathKrn2_GRAD_CONFIG)');
});
});
describe('getCustomConverterOpsModule', () => {
it('non namespaced ops', () => {
const result =
getCustomConverterOpsModule(['add', 'sub'], mockImportProvider);
expect(result).toContain('export * from add');
expect(result).toContain('export * from sub');
});
it('namespaced ops', () => {
const result = getCustomConverterOpsModule(
['image.resizeBilinear', 'image.resizeNearestNeighbor'],
mockImportProvider);
expect(result).toContain(
'export resizeBilinear,resizeNearestNeighbor as image from image/');
});
});
@@ -0,0 +1,123 @@
/**
* @license
* Copyright 2020 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/
import {esmImportProvider} from './esm_module_provider';
describe('ESM Module Provider', () => {
it('importCoreStr forwardModeOnly=true', () => {
const forwardModeOnly = true;
const res = esmImportProvider.importCoreStr(forwardModeOnly);
expect(res).toContain(
`import {registerKernel} from '@tensorflow/tfjs-core/dist/base'`);
expect(res).not.toContain(
`import {registerGradient} from '@tensorflow/tfjs-core/dist/base'`);
expect(res).toContain(
`import '@tensorflow/tfjs-core/dist/base_side_effects';`);
expect(res).toContain(`export * from '@tensorflow/tfjs-core/dist/base';`);
});
it('importCoreStr forwardModeOnly=false', () => {
const forwardModeOnly = false;
const res = esmImportProvider.importCoreStr(forwardModeOnly);
expect(res).toContain(
`import {registerKernel} from '@tensorflow/tfjs-core/dist/base'`);
expect(res).toContain(
`import {registerGradient} from '@tensorflow/tfjs-core/dist/base'`);
expect(res).toContain(
`import '@tensorflow/tfjs-core/dist/base_side_effects';`);
expect(res).toContain(`export * from '@tensorflow/tfjs-core/dist/base';`);
});
it('importConverterStr', () => {
const res = esmImportProvider.importConverterStr();
expect(res).toBe(`export * from '@tensorflow/tfjs-converter';`);
});
it('importBackendStr cpu', () => {
const res = esmImportProvider.importBackendStr('cpu');
expect(res).toBe(`export * from '@tensorflow/tfjs-backend-cpu/dist/base';`);
});
it('importBackendStr webgl', () => {
const res = esmImportProvider.importBackendStr('webgl');
expect(res).toBe(
`export * from '@tensorflow/tfjs-backend-webgl/dist/base';`);
});
it('importKernelStr Max cpu', () => {
const res = esmImportProvider.importKernelStr('Max', 'cpu');
expect(res.importStatement).toContain('import {maxConfig as Max_cpu}');
expect(res.importStatement)
.toContain(`from '@tensorflow/tfjs-backend-cpu/dist/kernels/Max'`);
expect(res.kernelConfigId).toBe('Max_cpu');
});
it('importGradientConfigStr Max', () => {
const res = esmImportProvider.importGradientConfigStr('Max');
expect(res.importStatement).toContain('import {maxGradConfig}');
expect(res.importStatement)
.toContain(`from '@tensorflow/tfjs-core/dist/gradients/Max_grad'`);
expect(res.gradConfigId).toBe('maxGradConfig');
});
it('importGradientConfigStr Max', () => {
const res = esmImportProvider.importGradientConfigStr('Max');
expect(res.importStatement).toContain('import {maxGradConfig}');
expect(res.importStatement)
.toContain(`from '@tensorflow/tfjs-core/dist/gradients/Max_grad'`);
expect(res.gradConfigId).toBe('maxGradConfig');
});
it('importOpForConverterStr add', () => {
const res = esmImportProvider.importOpForConverterStr('add');
expect(res).toBe(`export {add} from '@tensorflow/tfjs-core/dist/ops/add';`);
});
it('importOpForConverterStr stridedSlice', () => {
const res = esmImportProvider.importOpForConverterStr('stridedSlice');
expect(res).toBe(
// tslint:disable-next-line: max-line-length
`export {stridedSlice} from '@tensorflow/tfjs-core/dist/ops/strided_slice';`);
});
it('importNamespacedOpsForConverterStr image.resizeBilinear', () => {
const res = esmImportProvider.importNamespacedOpsForConverterStr(
'image', ['resizeBilinear']);
expect(res).toBe(
// tslint:disable-next-line: max-line-length
`import {resizeBilinear as resizeBilinear_image} from '@tensorflow/tfjs-core/dist/ops/image/resize_bilinear';
export const image = {
\tresizeBilinear: resizeBilinear_image,
};`);
});
it('importNamespacedOpsForConverterStr two ops in namespace', () => {
const res = esmImportProvider.importNamespacedOpsForConverterStr(
'image', ['resizeBilinear', 'resizeNearestNeighbor']);
expect(res).toBe(
// tslint:disable-next-line: max-line-length
`import {resizeBilinear as resizeBilinear_image} from '@tensorflow/tfjs-core/dist/ops/image/resize_bilinear';
import {resizeNearestNeighbor as resizeNearestNeighbor_image} from '@tensorflow/tfjs-core/dist/ops/image/resize_nearest_neighbor';
export const image = {
\tresizeBilinear: resizeBilinear_image,
\tresizeNearestNeighbor: resizeNearestNeighbor_image,
};`);
});
});