Skip to content

remove dist-import in node & layers #1956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
"clang-format": "~1.2.4",
"chalk": "~2.4.2",
"shelljs": "~0.8.3",
"tslint": "^5.11.0",
"ts-node": "~4.1.0",
"typescript": "3.5.3"
},
1 change: 1 addition & 0 deletions tfjs-automl/src/img_classification_test.ts
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@

import * as tf from '@tensorflow/tfjs-core';
import {Tensor3D, test_util} from '@tensorflow/tfjs-core';
// tslint:disable-next-line:no-imports-from-dist
import {BROWSER_ENVS, describeWithFlags} from '@tensorflow/tfjs-core/dist/jasmine_util';

import * as automl from './index';
1 change: 1 addition & 0 deletions tfjs-automl/src/test_browser.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
* =============================================================================
*/

// tslint:disable-next-line:no-imports-from-dist
import {setTestEnvs} from '@tensorflow/tfjs-core/dist/jasmine_util';

// Run browser tests againts both the cpu and webgl backends.
1 change: 1 addition & 0 deletions tfjs-automl/src/test_node.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
* =============================================================================
*/

// tslint:disable-next-line:no-imports-from-dist
import {setTestEnvs} from '@tensorflow/tfjs-core/dist/jasmine_util';

// tslint:disable-next-line:no-require-imports
1 change: 1 addition & 0 deletions tfjs-backend-nodegl/src/run_tests.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
*/

// We import index.ts so that the Node backend gets registered.
// tslint:disable-next-line:no-imports-from-dist
import * as jasmine_util from '@tensorflow/tfjs-core/dist/jasmine_util';
import * as tf from '@tensorflow/tfjs-core';

1 change: 1 addition & 0 deletions tfjs-backend-wasm/src/index_test.ts
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@

import * as tf from '@tensorflow/tfjs-core';
import {test_util} from '@tensorflow/tfjs-core';
// tslint:disable-next-line:no-imports-from-dist
import {ALL_ENVS, describeWithFlags} from '@tensorflow/tfjs-core/dist/jasmine_util';

import {BackendWasm} from './index';
2 changes: 2 additions & 0 deletions tfjs-backend-wasm/src/setup_test.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
* =============================================================================
*/

// tslint:disable-next-line:no-imports-from-dist
import {setTestEnvs} from '@tensorflow/tfjs-core/dist/jasmine_util';

setTestEnvs([{name: 'test-wasm', backendName: 'wasm', isDataSync: true}]);
@@ -70,4 +71,5 @@ env.specFilter = spec => {
};

// Import and run all the tests from core.
// tslint:disable-next-line:no-imports-from-dist
import '@tensorflow/tfjs-core/dist/tests';
2 changes: 2 additions & 0 deletions tfjs-backend-webgpu/src/setup_test.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
* =============================================================================
*/

// tslint:disable-next-line:no-imports-from-dist
import {setTestEnvs} from '@tensorflow/tfjs-core/dist/jasmine_util';

setTestEnvs([{
@@ -119,4 +120,5 @@ env.specFilter = spec => {
};

// Import and run all the tests from core.
// tslint:disable-next-line:no-imports-from-dist
import '@tensorflow/tfjs-core/dist/tests';
1 change: 1 addition & 0 deletions tfjs-backend-webgpu/src/test_util.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
* =============================================================================
*/

// tslint:disable-next-line:no-imports-from-dist
import {ALL_ENVS, describeWithFlags, TestEnv} from '@tensorflow/tfjs-core/dist/jasmine_util';

export function describeWebGPU(name: string, tests: (env: TestEnv) => void) {
3 changes: 2 additions & 1 deletion tfjs-converter/scripts/test_snippets.ts
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@
* =============================================================================
*/
import * as tfc from '@tensorflow/tfjs-core';
import {parseAndEvaluateSnippets} from '@tensorflow/tfjs-core/dist/scripts/test_snippets/util';

import {parseAndEvaluateSnippets} from '@tensorflow/tfjs-core/scripts/test_snippets/util';

import * as tfconv from '../src/index';

2 changes: 1 addition & 1 deletion tfjs-core/src/backends/backend_util.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ export * from '../ops/axis_util';
export * from '../ops/broadcast_util';
export * from '../ops/concat_util';
export * from '../ops/conv_util';
export {Activation} from '../ops/fused_util';
export {Activation, FusedBatchMatMulConfig} from '../ops/fused_util';

export {BackendValues, TypedArray, upcastType, PixelData} from '../types';
export {MemoryInfo, TimingInfo} from '../engine';
2 changes: 1 addition & 1 deletion tfjs-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ export {Optimizer} from './optimizers/optimizer';
export {RMSPropOptimizer} from './optimizers/rmsprop_optimizer';
export {SGDOptimizer} from './optimizers/sgd_optimizer';
export {Scalar, Tensor, Tensor1D, Tensor2D, Tensor3D, Tensor4D, Tensor5D, TensorBuffer, variable, Variable} from './tensor';
export {GradSaveFunc, NamedTensorMap, TensorContainer, TensorContainerArray, TensorContainerObject} from './tensor_types';
export {GradSaveFunc, NamedTensor, NamedTensorMap, TensorContainer, TensorContainerArray, TensorContainerObject} from './tensor_types';
export {DataType, DataTypeMap, DataValues, Rank, RecursiveArray, ShapeMap, TensorLike} from './types';

export * from './ops/ops';
1 change: 1 addition & 0 deletions tfjs-data/src/test_node.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
* =============================================================================
*/

// tslint:disable-next-line:no-imports-from-dist
import {setTestEnvs} from '@tensorflow/tfjs-core/dist/jasmine_util';

// tslint:disable-next-line:no-require-imports
1 change: 1 addition & 0 deletions tfjs-data/src/util/test_utils.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
* =============================================================================
*/

// tslint:disable-next-line:no-imports-from-dist
import {ALL_ENVS, BROWSER_ENVS, describeWithFlags, NODE_ENVS, registerTestEnv} from '@tensorflow/tfjs-core/dist/jasmine_util';

// Provide fake video stream
3 changes: 1 addition & 2 deletions tfjs-layers/src/engine/training.ts
Original file line number Diff line number Diff line change
@@ -11,8 +11,7 @@
/* Original Source: engine/training.py */

import * as tfc from '@tensorflow/tfjs-core';
import {io, ModelPredictConfig as ModelPredictArgs, NamedTensorMap, Optimizer, Scalar, scalar, serialization, Tensor, Tensor1D, tensor1d, util} from '@tensorflow/tfjs-core';
import {NamedTensor} from '@tensorflow/tfjs-core/dist/tensor_types';
import {io, ModelPredictConfig as ModelPredictArgs, NamedTensor, NamedTensorMap, Optimizer, Scalar, scalar, serialization, Tensor, Tensor1D, tensor1d, util} from '@tensorflow/tfjs-core';

import * as K from '../backend/tfjs_backend';
import {History, ModelLoggingVerbosity} from '../base_callbacks';
3 changes: 1 addition & 2 deletions tfjs-layers/src/models.ts
Original file line number Diff line number Diff line change
@@ -10,8 +10,7 @@

/* Original source keras/models.py */

import {dispose, io, NamedTensorMap, Optimizer, Scalar, serialization, Tensor, util} from '@tensorflow/tfjs-core';
import {NamedTensor} from '@tensorflow/tfjs-core/dist/tensor_types';
import {dispose, io, NamedTensor, NamedTensorMap, Optimizer, Scalar, serialization, Tensor, util} from '@tensorflow/tfjs-core';

import {getUid} from './backend/state';
import {History} from './base_callbacks';
6 changes: 3 additions & 3 deletions tfjs-layers/src/models_test.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@
*/

import {DataType, ENV, io, memory, ones, randomNormal, Scalar, scalar, serialization, sum, Tensor, tensor1d, tensor2d, tensor3d, train, zeros} from '@tensorflow/tfjs-core';
import {ConfigDict} from '@tensorflow/tfjs-core/dist/serialization';

import {LayersModel} from './engine/training';
import * as tfl from './index';
@@ -534,8 +533,9 @@ describeMathCPU('modelFromJSON', () => {
'backend': 'tensorflow'
};
const model =
deserialize(convertPythonicToTs(modelTopology) as ConfigDict) as
LayersModel;
deserialize(
convertPythonicToTs(modelTopology) as serialization.ConfigDict
) as LayersModel;

expect(model.name.indexOf('BarSequential123')).toEqual(0);
expect(model.inputs.length).toEqual(1);
1 change: 1 addition & 0 deletions tfjs-layers/src/utils/test_utils.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
*/

import {memory, Tensor, test_util, util} from '@tensorflow/tfjs-core';
// tslint:disable-next-line:no-imports-from-dist
import {ALL_ENVS, describeWithFlags, registerTestEnv} from '@tensorflow/tfjs-core/dist/jasmine_util';
import {ValueError} from '../errors';

7 changes: 3 additions & 4 deletions tfjs-node/src/io/file_system_test.ts
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@

import * as tfc from '@tensorflow/tfjs-core';
import * as tfl from '@tensorflow/tfjs-layers';
import {expectArraysClose} from '@tensorflow/tfjs-core/dist/test_util';
import * as fs from 'fs';
import * as path from 'path';
import * as rimraf from 'rimraf';
@@ -224,7 +223,7 @@ describe('File system IOHandler', () => {
dtype: 'float32',
}
]);
expectArraysClose(
tfc.test_util.expectArraysClose(
new Float32Array(modelArtifacts.weightData),
new Float32Array([-1.1, -3.3, -3.3, -7.7]));
done();
@@ -347,7 +346,7 @@ describe('File system IOHandler', () => {
new NodeFileSystem([`${modelPath}`, `${modelManifestJSONPath}`]);
handler.load()
.then(modelArtifacts => {
expectArraysClose(
tfc.test_util.expectArraysClose(
new Uint8Array(modelArtifacts.modelTopology as ArrayBuffer),
new Uint8Array(modelData));
expect(modelArtifacts.weightSpecs).toEqual([
@@ -362,7 +361,7 @@ describe('File system IOHandler', () => {
dtype: 'float32',
}
]);
expectArraysClose(
tfc.test_util.expectArraysClose(
new Float32Array(modelArtifacts.weightData),
new Float32Array([-1.1, -3.3, -3.3, -7.7]));
done();
18 changes: 11 additions & 7 deletions tfjs-node/src/nodejs_kernel_backend.ts
Original file line number Diff line number Diff line change
@@ -15,19 +15,20 @@
* =============================================================================
*/

import {BackendTimingInfo, DataMover, DataType, fill, KernelBackend, ones, Rank, rsqrt, Scalar, scalar, ShapeMap, Tensor, Tensor1D, tensor1d, Tensor2D, tensor2d, Tensor3D, tensor3d, Tensor4D, tidy, util} from '@tensorflow/tfjs-core';
import {EPSILON_FLOAT32} from '@tensorflow/tfjs-core/dist/backends/backend';
import {Conv2DInfo, Conv3DInfo} from '@tensorflow/tfjs-core/dist/ops/conv_util';
import {BackendTimingInfo, backend_util, DataMover, DataType, fill, KernelBackend, ones, Rank, rsqrt, Scalar, scalar, ShapeMap, Tensor, Tensor1D, tensor1d, Tensor2D, tensor2d, Tensor3D, tensor3d, Tensor4D, Tensor5D, tidy, util} from '@tensorflow/tfjs-core';
import * as tfc from '@tensorflow/tfjs-core';

import {Activation, FusedBatchMatMulConfig} from '@tensorflow/tfjs-core/dist/ops/fused_util';
import {Tensor5D} from '@tensorflow/tfjs-core/dist/tensor';
import {BackendValues, upcastType} from '@tensorflow/tfjs-core/dist/types';
import {isNullOrUndefined, isArray} from 'util';

import {Int64Scalar} from './int64_tensors';
import {TensorMetadata, TFEOpAttr, TFJSBinding} from './tfjs_binding';

type Activation = backend_util.Activation;
type BackendValues = backend_util.BackendValues;
type Conv2DInfo = backend_util.Conv2DInfo;
type Conv3DInfo = backend_util.Conv3DInfo;
type FusedBatchMatMulConfig = backend_util.FusedBatchMatMulConfig;

type TensorInfo = {
shape: number[],
dtype: number,
@@ -37,6 +38,9 @@ type TensorInfo = {

interface DataId {}

const { upcastType } = backend_util;
const EPSILON_FLOAT32 = 1e-7;

export class NodeJSKernelBackend extends KernelBackend {
binding: TFJSBinding;
isGPUPackage: boolean;
@@ -2028,4 +2032,4 @@ export function ensureTensorflowBackend() {
tfc.getBackend() === 'tensorflow',
() => `Expect the current backend to be "tensorflow", but got "${
tfc.getBackend()}"`);
}
}
7 changes: 3 additions & 4 deletions tfjs-node/src/nodejs_kernel_backend_test.ts
Original file line number Diff line number Diff line change
@@ -16,18 +16,17 @@
*/

import * as tf from '@tensorflow/tfjs-core';
import {Tensor5D} from '@tensorflow/tfjs-core/dist/tensor';
import {expectArraysClose} from '@tensorflow/tfjs-core/dist/test_util';
import {Tensor5D} from '@tensorflow/tfjs-core';

import {createTensorsTypeOpAttr, createTypeOpAttr, ensureTensorflowBackend, getTFDType, nodeBackend, NodeJSKernelBackend} from './nodejs_kernel_backend';

describe('delayed upload', () => {
it('should handle data before op execution', async () => {
const t = tf.tensor1d([1, 2, 3]);
expectArraysClose(await t.data(), [1, 2, 3]);
tf.test_util.expectArraysClose(await t.data(), [1, 2, 3]);

const r = t.add(tf.tensor1d([4, 5, 6]));
expectArraysClose(await r.data(), [5, 7, 9]);
tf.test_util.expectArraysClose(await r.data(), [5, 7, 9]);
});

it('Should not cache tensors in the tensor map for device support. ', () => {
1 change: 1 addition & 0 deletions tfjs-node/src/run_tests.ts
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@

// We import index.ts so that the Node backend gets registered.
import './index';
// tslint:disable-next-line:no-imports-from-dist
import * as jasmine_util from '@tensorflow/tfjs-core/dist/jasmine_util';
import {nodeBackend} from './nodejs_kernel_backend';

3 changes: 2 additions & 1 deletion tfjs-node/src/tfjs_binding.ts
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@
* =============================================================================
*/

import {BackendValues} from '@tensorflow/tfjs-core/dist/types';
import {backend_util} from '@tensorflow/tfjs-core';
type BackendValues = backend_util.BackendValues;

export declare class TensorMetadata {
id: number;
2 changes: 1 addition & 1 deletion tfjs-react-native/yarn.lock
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
resolved "https://registry.yarnpkg.com/@react-native-community/async-storage/-/async-storage-1.5.1.tgz#c496b4969eea5b91da1a5919a611046360b0c51f"
integrity sha512-Ssfx2uLYPnsuqIvDCuUOEZT6jh5AVy0U0mr2eHxNO2Syor1nfOrR/n4hTOFcBWc1wamDTGCqo+UHJpxURVXd2Q==

"@tensorflow/tfjs-core@^1.2.8":
"@tensorflow/tfjs-core@>=1.2.8":
version "1.2.8"
resolved "https://registry.yarnpkg.com/@tensorflow/tfjs-core/-/tfjs-core-1.2.8.tgz#d6873b88522f8cf25d34c10afd095866578d7d92"
integrity sha512-lWV4vAnXAAmahXpCWBwdGGW9HO6iNw9pUeVYih7pDXeJahMk3OJs6SgjRNhwn+ldsGwRoorR0/RHg0yNLmqWxQ==
2 changes: 1 addition & 1 deletion tfjs-vis/src/show/history.ts
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
* =============================================================================
*/

import {Logs} from '@tensorflow/tfjs-layers/dist/logs';
import {Logs} from '@tensorflow/tfjs-layers/src/logs';

import {linechart} from '../render/linechart';
import {getDrawArea, nextFrame} from '../render/render_utils';
2 changes: 2 additions & 0 deletions tfjs-vis/src/show/model.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,8 @@
*/

import * as tf from '@tensorflow/tfjs';

// tslint:disable-next-line:no-imports-from-dist
import {Layer} from '@tensorflow/tfjs-layers/dist/engine/topology';

import {histogram} from '../render/histogram';
2 changes: 2 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": ["tslint-no-circular-imports"],
"rulesDirectory": ".tslint",
"rules": {
"array-type": [true, "array-simple"],
"arrow-return-shorthand": true,
@@ -37,6 +38,7 @@
"no-debugger": true,
"no-default-export": true,
"no-inferrable-types": true,
"no-imports-from-dist": true,
"no-namespace": [true, "allow-declarations"],
"no-reference": true,
"no-require-imports": true,
Loading