[go: nahoru, domu]

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

[TOSA] Fix tfl.transpose_conv legalization when layer has bias #61493

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tom-arm
Copy link
Contributor
@tom-arm tom-arm commented Aug 7, 2023

This PR fixes the legalization of tfl.transpose_conv in the case where the layer has a non-zero bias.

* Legalization now handles cases where the layer has a bias
@google-ml-butler google-ml-butler bot added the size:M CL Change Size: Medium label Aug 7, 2023
@google-ml-butler google-ml-butler bot added the awaiting review Pull request awaiting review label Aug 8, 2023
@gbaned gbaned added this to Assigned Reviewer in PR Queue via automation Aug 16, 2023
@gbaned
Copy link
Contributor
gbaned commented Aug 24, 2023

Hi @rsuderman Can you please review this PR ? Thank you!

Copy link
Member
@jpienaar jpienaar left a comment

Choose a reason for hiding this comment

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

Looks good in general, small changes and then can approve.

@@ -1618,6 +1619,23 @@ LogicalResult ConvertTFLTransposeConvOp::matchAndRewrite(
bool output_is_qtype =
output_type.getElementType().isa<mlir::quant::QuantizedType>();

const bool has_bias = !(!tfl_conv_op.getBias() ||
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this

tfl_conv_op.getBias() && !isa(tfl_conv_op.getBias().getType())

? (it reads slightly easier to me than the double negative)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes agreed, this is done

if (has_bias) {
RankedTensorType bias_type =
dyn_cast<RankedTensorType>(tfl_conv_op.getBias().getType());
bool bias_is_qtype =
Copy link
Member

Choose a reason for hiding this comment

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

Prefer to use free functions here (isa<...>(X) instead of X.isa<...>), see MLIR deprecation page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, free functions are used across the whole function for consistency

if (input_is_qtype != bias_is_qtype) {
return rewriter.notifyMatchFailure(
op,
"input/bias tensor should "
Copy link
Member

Choose a reason for hiding this comment

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

Formatting here seems weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have left this as is for now, as there are instances of this function being used with this formatting across the file. But do let know if this needs looking at again before it can be merged!

std::optional<Value> zero_bias;
if (input_is_qtype) {
uint32_t input_bits =
dyn_cast<mlir::quant::QuantizedType>(input_type.getElementType())
Copy link
Member

Choose a reason for hiding this comment

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

cast - if its dyn_cast without checking if none followed by dereference, then cast gives better error message/cheaper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

.getStorageTypeIntegralWidth();

if (input_bits == 16 && weight_bits == 8) {
SmallVector<APInt> vec(output_channel, APInt(48, 0, true));
Copy link
Member

Choose a reason for hiding this comment

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

Could you add comment here on the 48 bits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a comment for this

@tom-arm
Copy link
Contributor Author
tom-arm commented Oct 12, 2023

Thank you for the review @jpienaar, I have posted replies to your comments.

@gbaned gbaned requested a review from jpienaar October 13, 2023 03:28
@gbaned
Copy link
Contributor
gbaned commented Nov 3, 2023

Hi @jpienaar, Can you please review this PR ? Thank you!

@tom-arm
Copy link
Contributor Author
tom-arm commented Nov 30, 2023

Hi @jpienaar, could you review this PR please? Thanks!

@gbaned
Copy link
Contributor
gbaned commented Dec 15, 2023

Hi @jpienaar, Can you please review this PR ? Thank you!

1 similar comment
@gbaned
Copy link
Contributor
gbaned commented Dec 29, 2023

Hi @jpienaar, Can you please review this PR ? Thank you!

@tom-arm
Copy link
Contributor Author
tom-arm commented Jan 23, 2024

Hi @jpienaar, could you review this PR please? Thanks!

@gbaned gbaned requested review from rdzhabarov and removed request for rsuderman February 9, 2024 06:55
@tom-arm
Copy link
Contributor Author
tom-arm commented Feb 26, 2024

Hi @rdzhabarov, can you review this PR please? Thanks!

@gbaned
Copy link
Contributor
gbaned commented Mar 8, 2024

Hi @jpienaar, Can you please review this PR ? Thank you!

@tom-arm
Copy link
Contributor Author
tom-arm commented Mar 21, 2024

Hey @jpienaar, could you review this PR please? Many thanks!

@tom-arm
Copy link
Contributor Author
tom-arm commented Apr 15, 2024

Hey @jpienaar, could you review this PR please? Thanks in advance!

@gbaned
Copy link
Contributor
gbaned commented Apr 26, 2024

Hi @tom-arm Can you please resolve conflicts? Thank you!

@gbaned gbaned added stat:awaiting response Status - Awaiting response from author and removed awaiting review Pull request awaiting review labels Apr 26, 2024
Copy link

This PR is stale because it has been open for 14 days with no activity. It will be closed if no further activity occurs. Thank you.

@github-actions github-actions bot added the stale This label marks the issue/pr stale - to be closed automatically if no activity label May 11, 2024
* Fixed merge conflicts in legalize_tfl.cc
@github-actions github-actions bot removed the stat:awaiting response Status - Awaiting response from author label May 14, 2024
@tom-arm
Copy link
Contributor Author
tom-arm commented May 14, 2024

Hi @gbaned, the conflict is fixed now. It would be good to get this reviewed if possible

@google-ml-butler google-ml-butler bot removed the stale This label marks the issue/pr stale - to be closed automatically if no activity label May 14, 2024
@gbaned
Copy link
Contributor
gbaned commented May 29, 2024

Hi @jpienaar, Can you please review this PR ? Thank you!

@gbaned gbaned added the awaiting review Pull request awaiting review label May 29, 2024
@gbaned
Copy link
Contributor
gbaned commented Jun 7, 2024

Hi @jpienaar, Can you please review this PR ? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review Pull request awaiting review size:M CL Change Size: Medium
Projects
PR Queue
  
Assigned Reviewer
Development

Successfully merging this pull request may close these issues.

None yet

3 participants