Merge pull request #40109 from HughKu:fix/HessiansV2
PiperOrigin-RevId: 321235946 Change-Id: Ie793bc3369fd3cae22897f50ab80bc592bee8ca7
This commit is contained in:
commit
f1405cbe46
tensorflow
@ -446,8 +446,34 @@ def HessiansV2(ys,
|
||||
gate_gradients=False,
|
||||
aggregation_method=None,
|
||||
name="hessians"):
|
||||
return hessians(ys, xs, name=name, gate_gradients=gate_gradients,
|
||||
aggregation_method=aggregation_method)
|
||||
"""Constructs the Hessian of sum of `ys` with respect to `x` in `xs`.
|
||||
|
||||
`hessians()` adds ops to the graph to output the Hessian matrix of `ys`
|
||||
with respect to `xs`. It returns a list of `Tensor` of length `len(xs)`
|
||||
where each tensor is the Hessian of `sum(ys)`.
|
||||
|
||||
HessiansV2.__doc__ = hessians.__doc__
|
||||
The Hessian is a matrix of second-order partial derivatives of a scalar
|
||||
tensor (see https://en.wikipedia.org/wiki/Hessian_matrix for more details).
|
||||
|
||||
Args:
|
||||
ys: A `Tensor` or list of tensors to be differentiated.
|
||||
xs: A `Tensor` or list of tensors to be used for differentiation.
|
||||
gate_gradients: See `gradients()` documentation for details.
|
||||
aggregation_method: See `gradients()` documentation for details.
|
||||
name: Optional name to use for grouping all the gradient ops together.
|
||||
defaults to 'hessians'.
|
||||
|
||||
Returns:
|
||||
A list of Hessian matrices of `sum(ys)` for each `x` in `xs`.
|
||||
|
||||
Raises:
|
||||
LookupError: if one of the operations between `xs` and `ys` does not
|
||||
have a registered gradient function.
|
||||
"""
|
||||
return hessians(
|
||||
ys,
|
||||
xs,
|
||||
name=name,
|
||||
colocate_gradients_with_ops=True,
|
||||
gate_gradients=gate_gradients,
|
||||
aggregation_method=aggregation_method)
|
||||
|
@ -1282,69 +1282,72 @@ class TFAPIChangeSpec(ast_edits.NoUpdateSpec):
|
||||
# Warnings that are emitted only if a specific arg is found.
|
||||
self.function_arg_warnings = {
|
||||
"tf.nn.conv1d": {
|
||||
("use_cudnn_on_gpu", 4): (
|
||||
ast_edits.WARNING,
|
||||
"use_cudnn_on_gpu has been removed, behavior is now equivalent"
|
||||
"to setting it to True."),
|
||||
("use_cudnn_on_gpu", 4):
|
||||
(ast_edits.WARNING,
|
||||
"use_cudnn_on_gpu has been removed, behavior is now equivalent"
|
||||
"to setting it to True."),
|
||||
},
|
||||
"tf.nn.conv2d": {
|
||||
("use_cudnn_on_gpu", 4): (
|
||||
ast_edits.WARNING,
|
||||
"use_cudnn_on_gpu has been removed, behavior is now equivalent"
|
||||
"to setting it to True."),
|
||||
("use_cudnn_on_gpu", 4):
|
||||
(ast_edits.WARNING,
|
||||
"use_cudnn_on_gpu has been removed, behavior is now equivalent"
|
||||
"to setting it to True."),
|
||||
},
|
||||
"tf.nn.conv2d_backprop_filter": {
|
||||
("use_cudnn_on_gpu", 5): (
|
||||
ast_edits.WARNING,
|
||||
"use_cudnn_on_gpu has been removed, behavior is now equivalent"
|
||||
"to setting it to True."),
|
||||
("use_cudnn_on_gpu", 5):
|
||||
(ast_edits.WARNING,
|
||||
"use_cudnn_on_gpu has been removed, behavior is now equivalent"
|
||||
"to setting it to True."),
|
||||
},
|
||||
"tf.nn.conv2d_backprop_input": {
|
||||
("use_cudnn_on_gpu", 5): (
|
||||
ast_edits.WARNING,
|
||||
"use_cudnn_on_gpu has been removed, behavior is now equivalent"
|
||||
"to setting it to True."),
|
||||
("use_cudnn_on_gpu", 5):
|
||||
(ast_edits.WARNING,
|
||||
"use_cudnn_on_gpu has been removed, behavior is now equivalent"
|
||||
"to setting it to True."),
|
||||
},
|
||||
"tf.gradients": {
|
||||
("colocate_gradients_with_ops", 4): (
|
||||
ast_edits.INFO,
|
||||
"tf.gradients no longer takes "
|
||||
"'colocate_gradients_with_ops' argument, it behaves as if it "
|
||||
"was set to True."),
|
||||
("colocate_gradients_with_ops", 4):
|
||||
(ast_edits.INFO, "tf.gradients no longer takes "
|
||||
"'colocate_gradients_with_ops' argument, it behaves as if it "
|
||||
"was set to True."),
|
||||
},
|
||||
"tf.hessians": {
|
||||
("colocate_gradients_with_ops", 3):
|
||||
(ast_edits.INFO, "tf.hessians no longer takes "
|
||||
"'colocate_gradients_with_ops' argument, it behaves as if it "
|
||||
"was set to True."),
|
||||
},
|
||||
"*.minimize": {
|
||||
("colocate_gradients_with_ops", 5): (
|
||||
ast_edits.INFO,
|
||||
"Optimizer.minimize no longer takes "
|
||||
"'colocate_gradients_with_ops' argument, it behaves as if it "
|
||||
"was set to True."),
|
||||
("colocate_gradients_with_ops", 5):
|
||||
(ast_edits.INFO, "Optimizer.minimize no longer takes "
|
||||
"'colocate_gradients_with_ops' argument, it behaves as if it "
|
||||
"was set to True."),
|
||||
},
|
||||
"*.compute_gradients": {
|
||||
("colocate_gradients_with_ops", 4): (
|
||||
ast_edits.INFO,
|
||||
"Optimizer.compute_gradients no "
|
||||
"longer takes 'colocate_gradients_with_ops' argument, it "
|
||||
"behaves as if it was set to True."),
|
||||
("colocate_gradients_with_ops", 4):
|
||||
(ast_edits.INFO, "Optimizer.compute_gradients no "
|
||||
"longer takes 'colocate_gradients_with_ops' argument, it "
|
||||
"behaves as if it was set to True."),
|
||||
},
|
||||
"tf.cond": {
|
||||
("strict", 3): (
|
||||
ast_edits.WARNING,
|
||||
"tf.cond no longer takes 'strict' argument, it behaves as "
|
||||
"if was set to True.")
|
||||
("strict", 3):
|
||||
(ast_edits.WARNING,
|
||||
"tf.cond no longer takes 'strict' argument, it behaves as "
|
||||
"if was set to True.")
|
||||
},
|
||||
"tf.contrib.summary.audio": {
|
||||
("family", 4): contrib_summary_family_arg_comment,
|
||||
},
|
||||
"tf.contrib.summary.create_file_writer": {
|
||||
("name", 4): (
|
||||
ast_edits.WARNING,
|
||||
"tf.contrib.summary.create_file_writer() no longer supports "
|
||||
"implicit writer re-use based on shared logdirs or resource "
|
||||
"names; this call site passed a 'name' argument that has been "
|
||||
"removed. The new tf.compat.v2.summary.create_file_writer() "
|
||||
"replacement has a 'name' parameter but the semantics are "
|
||||
"the usual ones to name the op itself and do not control "
|
||||
"writer re-use; writers must be manually re-used if desired.")
|
||||
("name", 4):
|
||||
(ast_edits.WARNING,
|
||||
"tf.contrib.summary.create_file_writer() no longer supports "
|
||||
"implicit writer re-use based on shared logdirs or resource "
|
||||
"names; this call site passed a 'name' argument that has been "
|
||||
"removed. The new tf.compat.v2.summary.create_file_writer() "
|
||||
"replacement has a 'name' parameter but the semantics are "
|
||||
"the usual ones to name the op itself and do not control "
|
||||
"writer re-use; writers must be manually re-used if desired.")
|
||||
},
|
||||
"tf.contrib.summary.generic": {
|
||||
("name", 0): (
|
||||
@ -1374,44 +1377,44 @@ class TFAPIChangeSpec(ast_edits.NoUpdateSpec):
|
||||
("family", 2): contrib_summary_family_arg_comment,
|
||||
},
|
||||
"tf.image.resize": {
|
||||
("align_corners",
|
||||
3): (ast_edits.WARNING,
|
||||
"align_corners is not supported by tf.image.resize, the new "
|
||||
"default transformation is close to what v1 provided. If you "
|
||||
"require exactly the same transformation as before, use "
|
||||
"compat.v1.image.resize."),
|
||||
("align_corners", 3):
|
||||
(ast_edits.WARNING,
|
||||
"align_corners is not supported by tf.image.resize, the new "
|
||||
"default transformation is close to what v1 provided. If you "
|
||||
"require exactly the same transformation as before, use "
|
||||
"compat.v1.image.resize."),
|
||||
},
|
||||
"tf.image.resize_bilinear": {
|
||||
("align_corners",
|
||||
2): (ast_edits.WARNING,
|
||||
"align_corners is not supported by tf.image.resize, the new "
|
||||
"default transformation is close to what v1 provided. If you "
|
||||
"require exactly the same transformation as before, use "
|
||||
"compat.v1.image.resize_bilinear."),
|
||||
("align_corners", 2):
|
||||
(ast_edits.WARNING,
|
||||
"align_corners is not supported by tf.image.resize, the new "
|
||||
"default transformation is close to what v1 provided. If you "
|
||||
"require exactly the same transformation as before, use "
|
||||
"compat.v1.image.resize_bilinear."),
|
||||
},
|
||||
"tf.image.resize_area": {
|
||||
("align_corners",
|
||||
2): (ast_edits.WARNING,
|
||||
"align_corners is not supported by tf.image.resize, the new "
|
||||
"default transformation is close to what v1 provided. If you "
|
||||
"require exactly the same transformation as before, use "
|
||||
"compat.v1.image.resize_area."),
|
||||
("align_corners", 2):
|
||||
(ast_edits.WARNING,
|
||||
"align_corners is not supported by tf.image.resize, the new "
|
||||
"default transformation is close to what v1 provided. If you "
|
||||
"require exactly the same transformation as before, use "
|
||||
"compat.v1.image.resize_area."),
|
||||
},
|
||||
"tf.image.resize_bicubic": {
|
||||
("align_corners",
|
||||
2): (ast_edits.WARNING,
|
||||
"align_corners is not supported by tf.image.resize, the new "
|
||||
"default transformation is close to what v1 provided. If you "
|
||||
"require exactly the same transformation as before, use "
|
||||
"compat.v1.image.resize_bicubic."),
|
||||
("align_corners", 2):
|
||||
(ast_edits.WARNING,
|
||||
"align_corners is not supported by tf.image.resize, the new "
|
||||
"default transformation is close to what v1 provided. If you "
|
||||
"require exactly the same transformation as before, use "
|
||||
"compat.v1.image.resize_bicubic."),
|
||||
},
|
||||
"tf.image.resize_nearest_neighbor": {
|
||||
("align_corners",
|
||||
2): (ast_edits.WARNING,
|
||||
"align_corners is not supported by tf.image.resize, the new "
|
||||
"default transformation is close to what v1 provided. If you "
|
||||
"require exactly the same transformation as before, use "
|
||||
"compat.v1.image.resize_nearest_neighbor."),
|
||||
("align_corners", 2):
|
||||
(ast_edits.WARNING,
|
||||
"align_corners is not supported by tf.image.resize, the new "
|
||||
"default transformation is close to what v1 provided. If you "
|
||||
"require exactly the same transformation as before, use "
|
||||
"compat.v1.image.resize_nearest_neighbor."),
|
||||
},
|
||||
}
|
||||
all_renames_v2.add_contrib_direct_import_support(self.function_arg_warnings)
|
||||
|
@ -1118,6 +1118,12 @@ bazel-bin/tensorflow/tools/compatibility/update/generate_v2_reorders_map
|
||||
self.assertEqual("optimizer.compute_gradients(a)\n", new_text)
|
||||
self.assertIn("Optimizer.compute_gradients no longer takes", report)
|
||||
|
||||
def testColocateGradientsWithHessians(self):
|
||||
text = "tf.hessians(ys=a, xs=b, colocate_gradients_with_ops=False)\n"
|
||||
_, report, unused_errors, new_text = self._upgrade(text)
|
||||
self.assertEqual("tf.hessians(ys=a, xs=b)\n", new_text)
|
||||
self.assertIn("tf.hessians no longer takes", report)
|
||||
|
||||
def testExportSavedModelRename(self):
|
||||
text = "self.est.export_savedmodel(path)"
|
||||
_, report, unused_errors, unused_new_text = self._upgrade(text)
|
||||
|
Loading…
Reference in New Issue
Block a user