Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Added support for 'Tensor.clipped(min:max:)' and its VJP. #361

Merged
merged 2 commits into from
Jul 14, 2019

Conversation

eaplatanios
Copy link
Contributor

No description provided.

@Shashi456
Copy link
Contributor

I guess after this PR, a lot of layers can be updated to avoid certain values beyond bounds. Like its done in keras.

@eaplatanios
Copy link
Contributor Author

I guess after this PR, a lot of layers can be updated to avoid certain values beyond bounds. Like its done in keras.

Could you give examples of some of these layers in Keras? I'm curious to see where they clip implicitly.

@eaplatanios eaplatanios changed the title Added support for 'Tensor.clipping(min:max:)' and its VJP. Added support for 'Tensor.clipped(min:max:)' and its VJP. Jul 14, 2019
@eaplatanios eaplatanios merged commit 33b3b5b into tensorflow:master Jul 14, 2019
@rxwei
Copy link
Contributor

rxwei commented Jul 14, 2019

I feel the tensor-scalar and scalar-tensor overloads are not quite necessary and may not set a good example to follow for future APIs. Say, if some API has three 0-D tensor parameters (e.g. batch norm), would we want to write all 6 combinations of scalars parameters and tensor parameters?

@eaplatanios
Copy link
Contributor Author

I agree. Would it be possible to make Scalar: TensorFlowScalar implicitly convertible to Tensor<Scalar>?

@rxwei
Copy link
Contributor

rxwei commented Jul 14, 2019

No, implicit conversion is generally not possible in Swift except for literals. However, scalar literal conversion for Tensor has been very problematic.

@eaplatanios
Copy link
Contributor Author

What is it that makes it problematic? Is it too inefficient for the type checker?

@rxwei
Copy link
Contributor

rxwei commented Jul 14, 2019

Type checking ambiguity. s + t is possible where s is a scalar and t is a tensor, but if you make tensor also expressible by literal, the type checker won't know which overload you are calling for an expression like 3 + x (scalar-tensor or tensor-tensor).

@eaplatanios
Copy link
Contributor Author

Can we not impose a hierarchy on the literal conversion rules?

@rxwei
Copy link
Contributor

rxwei commented Jul 14, 2019

What do you mean exactly?

@rxwei
Copy link
Contributor

rxwei commented Jul 14, 2019

Type checking precedence changes generally need to be an evolution proposal.

@eaplatanios
Copy link
Contributor Author

Yes that would need an evolution proposal indeed. We could go for something even more powerful and support implicit type conversions using something like this:

@implicitConversion(precedence: ...)
func _<Scalar: TensorFlowScalar>(_ value: Scalar) -> Tensor<Scalar> {
  ...
}

Do you think something like this could potentially go through evolution? Also, how time consuming would it be support something like this in the compiler?

@eaplatanios
Copy link
Contributor Author

Note that this would be separate from how literals are handled.

@rxwei
Copy link
Contributor

rxwei commented Jul 14, 2019

This would be highly unlikely. I would suggest asking a question on the Swift evolution forum about it.

@eaplatanios
Copy link
Contributor Author

Started a discussion thread here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants