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
Return a function instead of calling it (in safe_eval) #16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tried
x = QConv2D(64, (3, 3), strides=(2,2), kernel_quantizer=binary_tanh, bias_quantizer=quantized_bits(4,0,1), name="conv2d_1_m", activation="hard_sigmoid")(x)
x = QActivation("hard_sigmoid")(x)
Does it work?
@@ -83,4 +83,7 @@ def safe_eval(eval_str, op_dict, *params, **kwparams): # pylint: disable=invali | |||
if len(function_split) == 2 or args or kwargs: | |||
return quantizer(*args, **kwargs) | |||
else: | |||
return quantizer() | |||
if isinstance(quantizer, type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add comment here, something like "check the quantizer is a class"
I tried, but if i understand correctly, this is not how quantizers are intended to be used. The first |
Since the PR is for "If quantizer is a function (like binary_tanh or hard_sigmoid, used as activations), ...", I just want to try whether it can be used in activation inside a qkeras layers and QActivation layer directly. |
Using |
put this PR into internal system review. |
Is there anything else I should do for this PR? |
sorry about the late. no for now. I am waiting for feedback from another googler (required by the internal flow). |
PiperOrigin-RevId: 295783821 Change-Id: I0c541eaabe348ca5d9422be18d3877ef1206ce6d
PiperOrigin-RevId: 295783821 Change-Id: I0c541eaabe348ca5d9422be18d3877ef1206ce6d
If quantizer is a function (like
binary_tanh
orhard_sigmoid
, used as activations),safe_eval
would try to make an instance of it and fail. This was due to the change introduced in #12. We should check if quantizer is class to be instantiated before being called or a function ready to be called.