Skip to content

Conversation

@tafsiri
Copy link
Contributor

@tafsiri tafsiri commented Mar 19, 2020

Strawman PR for discussion:

This PR modularises the clone op. But does so differently to how most ops will be modularised. There are three distinct things here:

  1. The kernel and gradient registration is done within the op file and the kernel name and interface are not in kernel_names.ts. This is done under the assumption that we don't expect backends to need to implement clone (and thus do not list it in the kernel_names file). It is also done under the assumption that we always want clone available in tfjs/tfjs-core.
  2. It does not add a chained op augmentor for clone. This is under a hunch that we will want some subset of ops to always be on tensor. To my eye this includes things like cast, reshape, buffer, as2D, as3D, asType, etc (but we can make a list if we agree with this hunch with the goal of keeping it as small as possible). These would remain on the backend interface / opHandler mechanism. This is primarily with an eye to developer ergonomics (including internal code).
  3. It registers a backend agnostic kernels.

To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.


This change is Reviewable

@tafsiri tafsiri marked this pull request as ready for review March 20, 2020 14:55
Copy link
Contributor

@dsmilkov dsmilkov left a comment

Choose a reason for hiding this comment

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

This all looks good to me. I agree with 2. It would be great to keep some chaining methods for dev ergonomics. Also wait for Nikhil. We can also sync on GVC if needed.

Reviewed 4 of 4 files at r1.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @annxingyuan, @dsmilkov, @nsthorat, and @tafsiri)


tfjs-core/src/kernel_registry.ts, line 93 at r1 (raw file):

    kernelName: string, backendName: string): KernelConfig {
  const key = makeKey(kernelName, backendName);
  if (kernelRegistry.has(key)) {

just an observation: this means that a backend could, technically, later overwrite clone with a backend-specific implementation. my first impression is that this is fine, but something to think about.


tfjs-core/src/ops/clone.ts, line 46 at r1 (raw file):

export const clone = op({clone_});

/**

either tie the jsdoc to a function/class/variable or use regular comment.

Copy link
Contributor

@nsthorat nsthorat left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @annxingyuan, @dsmilkov, @nsthorat, and @tafsiri)


tfjs-core/src/kernel_registry.ts, line 93 at r1 (raw file):

Previously, dsmilkov (Daniel Smilkov) wrote…

just an observation: this means that a backend could, technically, later overwrite clone with a backend-specific implementation. my first impression is that this is fine, but something to think about.

I think that's the only point, right? If that wasn't the case, it shouldn't be a kernel at all.


tfjs-core/src/ops/clone.ts, line 39 at r1 (raw file):

 */
/** @doc {heading: 'Tensors', subheading: 'Creation'} */
function clone_<T extends Tensor>(x: T|TensorLike): T {

any idea how many ops are gonna be like this?

something to think about: IMO duplicating this code in each backend simplifies the mental model significantly, rather than having a default implementation and an override. Plus, where the code lives is now confusing. FromPixels already is confusing because of that.


tfjs-core/src/ops/clone.ts, line 55 at r1 (raw file):

const cloneKernelConfig: KernelConfig = {
  kernelName: Clone,
  backendName: BACKEND_AGNOSTIC,  // this is a backend agnostic kernel

nit: remove this comment, the code is clear


tfjs-core/src/ops/clone.ts, line 62 at r1 (raw file):

};

const cloneGradientConfig: GradConfig = {

shouldn't this be in a separate file in gradients?

@tafsiri tafsiri requested review from dsmilkov and nsthorat March 20, 2020 20:57
Copy link
Contributor Author

@tafsiri tafsiri left a comment

Choose a reason for hiding this comment

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

updated this PR based on GVC discussion.

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @annxingyuan, @dsmilkov, and @nsthorat)


tfjs-core/src/kernel_registry.ts, line 93 at r1 (raw file):

Previously, nsthorat (Nikhil Thorat) wrote…

I think that's the only point, right? If that wasn't the case, it shouldn't be a kernel at all.

Removed backend agnostic kernel support

Copy link
Contributor

@nsthorat nsthorat left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 4 files at r1, 5 of 5 files at r2.
Reviewable status: :shipit: complete! 2 of 1 approvals obtained (waiting on @annxingyuan, @dsmilkov, and @nsthorat)

Copy link
Contributor

@dsmilkov dsmilkov left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 5 files at r2.
Reviewable status: :shipit: complete! 2 of 1 approvals obtained (waiting on @annxingyuan and @dsmilkov)

@tafsiri tafsiri merged commit 42b2f49 into master Mar 23, 2020
@tafsiri tafsiri deleted the mod-clone-op branch March 23, 2020 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants