Skip to content

[EIEX-885] Add log support using new Neutron flow#20145

Open
irtrukhina wants to merge 1 commit into
pytorch:mainfrom
nxp-upstream:feature/EIEX-885-add-log-support-using-new-neutron-flow
Open

[EIEX-885] Add log support using new Neutron flow#20145
irtrukhina wants to merge 1 commit into
pytorch:mainfrom
nxp-upstream:feature/EIEX-885-add-log-support-using-new-neutron-flow

Conversation

@irtrukhina

@irtrukhina irtrukhina commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

NXP backend: Enable aten.log with new Neutron flow.

Test plan

Tests provided.

cc @robert-kalmar @JakeStevens @digantdesai @rascani

@pytorch-bot

pytorch-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/20145

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures, 1 Cancelled Job

As of commit 99747d3 with merge base 2759ef1 (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOB - The following job was cancelled. Please retry:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 9, 2026
@linux-foundation-easycla

Copy link
Copy Markdown

CLA Not Signed

@robert-kalmar robert-kalmar added module: nxp Issues related to NXP Neutron NPU delegation and code under backends/nxp/ release notes: nxp Changes to the NXP Neutron backend delegate labels Jun 9, 2026
# Use 256 elements so that, after quantization to uint8, the input can
# cover the full discrete range [0, 255].
# The dataset is generated as a linear float ramp and later quantized,
# which effectively exercises all uint8 values.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: uint8 -> int8 (2 occurrences)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don’t want to use int8 or the range [-128, 127] for values from a log input—it doesn’t look right to me. Is it OK if I remove both uint8 references but keep the [0, 255] range?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't understand. What do you mean you don't want to use int8?
Our quantizer always quantizes to int8 (not uint8 as your comment suggests), so the quantized values are always in the range [-128, 127]. It's not about choice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Mathematically, you cannot calculate a log for input values ≤ 0. It doesn’t seem correct to mentioned negative inputs in this log test.

@MartinPavella MartinPavella Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Your comment in code and my comments in this thread are talking about quantized data. Our quantizer quantizes to int8 whether we like it or not.
This quantized data corresponds to real float data, that is not effected by the quantization type. The quantized value -42 can correspond to the float value 3.14, which is perfectly fine for the log.

Also, with the "full range" dataset you are using, you are also testing with the float value 0.0 (it likely corresponds to the quantized value -128). This is because the zero_point data type is equal to the quantization datatype, so the float 0.0 is always representable precisely using quantized values. So you are using an invalid log input anyway. I'm guessing the output is NaN for that particular input value.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In this case, I agree with you :) I will fix it.
Sorry for the misunderstanding. I was still thinking about the numbers processed on board, but not in the high-level framework.
Thank you for the clarification.

Comment on lines +34 to +59
class ConvBlocksWithLogModule(torch.nn.Module):
def __init__(self, conv_in_channels: int = 3):
super().__init__()
self.block1 = torch.nn.Sequential(
torch.nn.Conv2d(
in_channels=conv_in_channels,
out_channels=3,
kernel_size=(2, 2),
stride=(2, 2),
),
torch.nn.ReLU(),
)
self.block2 = torch.nn.Sequential(
torch.nn.Conv2d(
in_channels=conv_in_channels,
out_channels=10,
kernel_size=(2, 2),
stride=(2, 2),
),
torch.nn.ReLU(),
)

def forward(self, x):
x = self.block1(x)
x = x.clamp_min(1e-6).log()
return self.block2(x)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No change needed here, but such a complex test model is counterproductive. We prefer simple models (1 to 3 ops at most) which focus on some specific case as efficiently as possible. Here fore example, the Relu, Clamp and Relu have no effect on the testing conditions, but they make the test more complex and on lines 88-89, the test may require changes if the support for the related ops is modified (e.g. Vasek's Conv PR is merged).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If the convolution is changed to support batch sizes greater than 1, this test will fail. I was inspired by the abs operator, and this test is based on it. However, I would prefer to remove it completely, if it is acceptable to have just one test for the log.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sure, you can remove this test and keep only 1 (convolution and node formats don't affect the log operator). Just make sure the other test uses the use_qat fixture (to test both PTQ and QAT). And also parametrizing the input shape (to test with at least a couple of different shapes and ranks) wouldn't hurt.

return self.block2(x)


class TestLog:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add a test using QAT. (All operators should have at least 1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, will add

equal to `high`, with increments depending on the total number of elements.
"""

def __init__(self, num_samples=2, low=0.0, high=1.0):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: Perhaps it would be more useful to have the default range include negative values (for example if we want to use this to test relu/prelu/...). How about -1 to 1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok for me. Will change

Comment thread backends/nxp/tests/dataset_creator.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: nxp Issues related to NXP Neutron NPU delegation and code under backends/nxp/ release notes: nxp Changes to the NXP Neutron backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants