-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change scale transformation of IAF and add debugging patches
- Loading branch information
Showing
5 changed files
with
99 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Index: lib/python3.8/site-packages/tensorflow_probability/python/math/generic.py | ||
IDEA additional info: | ||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | ||
<+>UTF-8 | ||
=================================================================== | ||
--- lib/python3.8/site-packages/tensorflow_probability/python/math/generic.py (date 1614119717126) | ||
+++ lib/python3.8/site-packages/tensorflow_probability/python/math/generic.py (date 1614119717126) | ||
@@ -656,10 +656,19 @@ | ||
logcosh = abs_x + tf.math.softplus(-2 * abs_x) - np.log(2).astype( | ||
numpy_dtype) | ||
bound = 45. * np.power(np.finfo(numpy_dtype).tiny, 1 / 6.) | ||
- return tf.where( | ||
+ try: | ||
+ res = tf.where( | ||
abs_x <= bound, | ||
tf.math.exp(tf.math.log(abs_x) + tf.math.log1p(-tf.square(abs_x) / 6.)), | ||
logcosh) | ||
+ except tf.errors.InvalidArgumentError: | ||
+ tf.debugging.disable_check_numerics() | ||
+ res = tf.where( | ||
+ abs_x <= bound, | ||
+ tf.math.exp(tf.math.log(abs_x) + tf.math.log1p(-tf.square(abs_x) / 6.)), | ||
+ logcosh) | ||
+ tf.debugging.enable_check_numerics(stack_height_limit=50, path_length_limit=50) | ||
+ return res | ||
|
||
|
||
def _log_cosh_jvp(primals, tangents): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Index: lib/python3.8/site-packages/tensorflow_probability/python/bijectors/sigmoid.py | ||
IDEA additional info: | ||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | ||
<+>UTF-8 | ||
=================================================================== | ||
--- lib/python3.8/site-packages/tensorflow_probability/python/bijectors/sigmoid.py (date 1613231204680) | ||
+++ lib/python3.8/site-packages/tensorflow_probability/python/bijectors/sigmoid.py (date 1613231204680) | ||
@@ -44,7 +44,13 @@ | ||
cutoff = -20 | ||
else: | ||
cutoff = -9 | ||
- return tf.where(x < cutoff, tf.exp(x), tf.math.sigmoid(x)) | ||
+ try: | ||
+ res = tf.where(x < cutoff, tf.exp(x), tf.math.sigmoid(x)) | ||
+ except tf.errors.InvalidArgumentError: | ||
+ tf.debugging.disable_check_numerics() | ||
+ res = tf.where(x < cutoff, tf.exp(x), tf.math.sigmoid(x)) | ||
+ tf.debugging.enable_check_numerics(stack_height_limit=50, path_length_limit=50) | ||
+ return res | ||
|
||
@tf.custom_gradient | ||
def _stable_grad_softplus(x): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Index: lib/python3.8/site-packages/tensorflow_probability/python/bijectors/softplus.py | ||
IDEA additional info: | ||
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP | ||
<+>UTF-8 | ||
=================================================================== | ||
--- lib/python3.8/site-packages/tensorflow_probability/python/bijectors/softplus.py (date 1614198880654) | ||
+++ lib/python3.8/site-packages/tensorflow_probability/python/bijectors/softplus.py (date 1614198880654) | ||
@@ -50,11 +50,22 @@ | ||
else: | ||
cutoff = -9 | ||
|
||
- y = tf.where(x < cutoff, tf.math.log1p(tf.exp(x)), tf.nn.softplus(x)) | ||
+ try: | ||
+ y = tf.where(x < cutoff, tf.math.log1p(tf.exp(x)), tf.nn.softplus(x)) | ||
+ except tf.errors.InvalidArgumentError: | ||
+ tf.debugging.disable_check_numerics() | ||
+ y = tf.where(x < cutoff, tf.math.log1p(tf.exp(x)), tf.nn.softplus(x)) | ||
+ tf.debugging.enable_check_numerics(stack_height_limit=50, path_length_limit=50) | ||
|
||
def grad_fn(dy): | ||
- return dy * tf.where(x < cutoff, tf.exp(x), tf.nn.sigmoid(x)) | ||
- | ||
+ try: | ||
+ res = tf.where(x < cutoff, tf.exp(x), tf.nn.sigmoid(x)) | ||
+ except tf.errors.InvalidArgumentError: | ||
+ tf.debugging.disable_check_numerics() | ||
+ res = tf.where(x < cutoff, tf.exp(x), tf.nn.sigmoid(x)) | ||
+ tf.debugging.enable_check_numerics(stack_height_limit=50, | ||
+ path_length_limit=50) | ||
+ return dy * res | ||
return y, grad_fn | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters