Skip to content
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

Pass Variable Length Argument To Old Function Call #366

Merged
merged 5 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion smdebug/tensorflow/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def get_layer_call_fn(layer: tf.keras.layers.Layer) -> Callable[[tf.Tensor], tf.

def call(inputs, *args, **kwargs) -> tf.Tensor:
layer_input = inputs
layer_output = old_call_fn(inputs)
layer_output = old_call_fn(inputs, *args, **kwargs)
vandanavk marked this conversation as resolved.
Show resolved Hide resolved
for hook in layer._hooks:
hook_result = hook(inputs, layer_input=layer_input, layer_output=layer_output)
if hook_result is not None:
Expand Down
12 changes: 11 additions & 1 deletion tests/tensorflow2/test_model_subclassing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ def __init__(self):
self.conv1 = Conv2D(
32, 3, activation="relu", kernel_initializer=tf.keras.initializers.GlorotNormal(seed=12)
)
self.original_call = self.conv1.call

def new_call(inputs, *args, **kwargs):
# Since we use layer wrapper we need to assert if these parameters
# are actually being passed into the original call fn
assert kwargs["input_one"] == 1
kwargs.pop("input_one")
vandanavk marked this conversation as resolved.
Show resolved Hide resolved
return self.original_call(inputs, *args, **kwargs)

self.conv1.call = new_call
self.conv0 = Conv2D(
32, 3, activation="relu", kernel_initializer=tf.keras.initializers.GlorotNormal(seed=12)
)
Expand All @@ -26,7 +36,7 @@ def __init__(self):
def first(self, x):
with tf.name_scope("first"):
tf.print("mymodel.first")
x = self.conv1(x)
x = self.conv1(x, input_one=1)
# x = self.bn(x)
vandanavk marked this conversation as resolved.
Show resolved Hide resolved
return self.flatten(x)

Expand Down