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

fix tf.nn.{conv2d,convolution} substitution #1275

Merged
merged 2 commits into from
Nov 24, 2024
Merged

fix tf.nn.{conv2d,convolution} substitution #1275

merged 2 commits into from
Nov 24, 2024

Conversation

irenaby
Copy link
Collaborator

@irenaby irenaby commented Nov 24, 2024

Pull Request Description:

Fixed tf conv substitution to handle attrs with default values that were not passed explicitly, and convert tf-specific format to keras compatible values.

Checklist before requesting a review:

  • I set the appropriate labels on the pull request.
  • I have added/updated the release note draft (if necessary).
  • I have updated the documentation to reflect my changes (if necessary).
  • All function and files are well documented.
  • All function and classes have type hints.
  • There is a licenses in all file.
  • The function and variable names are informative.
  • I have checked for code duplications.
  • I have added new unittest (if necessary).

@irenaby irenaby marked this pull request as ready for review November 24, 2024 09:17
Copy link
Collaborator

@elad-c elad-c left a comment

Choose a reason for hiding this comment

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

Add PR description

if b is None:
conv_fw_attr[USE_BIAS] = False
else:
weights[BIAS] = b

data_format = conv_func_node.op_call_kwargs.get(DATA_FORMAT, 'NHWC')
conv_fw_attr['data_format'] = {'NHWC': 'channels_last', 'NCHW': 'channels_first'}[data_format]
Copy link
Collaborator

Choose a reason for hiding this comment

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

use constants from the keras constants

"""
v = node.op_call_kwargs.get(key)
if v is None:
return 1, 1
Copy link
Collaborator

Choose a reason for hiding this comment

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

this way you assume the defaults. why not return None?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's intentional. None wouldn't do, we need to fill in an explicit default. This method is specific to tf stride & dilation

@@ -54,6 +54,8 @@ def compare(self, quantized_model, float_model, input_x=None, quantization_info=
y = float_model.predict(input_x)
y_hat = quantized_model.predict(input_x)
self.unit_test.assertTrue(y.shape == y_hat.shape, msg=f'out shape is not as expected!')
# FIXME this doesn't test anything, the number of quantized convs in the network is exactly 0. Even if it
Copy link
Collaborator

Choose a reason for hiding this comment

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

then why not remove it?

self.unit_test.assertTrue(len(layer.weights) == 2,msg=f'fail Bias should appear in weights!!')


class FuncConv2DCollapsingTest(FourConv2DCollapsingTest):
Copy link
Collaborator

Choose a reason for hiding this comment

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

These tests seem redunant, as the there's no difference between these tests and the ones for Conv2D layer. wht not just test the substitution of these layers to Conv2D?

@irenaby irenaby changed the title fix tf.nn.{conv2,convolution} substitution fix tf.nn.{conv2d,convolution} substitution Nov 24, 2024
@irenaby irenaby merged commit efd3310 into main Nov 24, 2024
42 checks passed
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.

2 participants