Skip to content

primitive scale fix#2210

Merged
facebook-github-bot merged 1 commit into
pytorch:mainfrom
YIWENX14:export-D74446877
Jun 5, 2025
Merged

primitive scale fix#2210
facebook-github-bot merged 1 commit into
pytorch:mainfrom
YIWENX14:export-D74446877

Conversation

@YIWENX14
Copy link
Copy Markdown
Contributor

Differential Revision: D74446877

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 14, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/2210

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

✅ No Failures

As of commit 83d990d with merge base 35ffb26 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@facebook-github-bot facebook-github-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 May 14, 2025
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D74446877

@YIWENX14
Copy link
Copy Markdown
Contributor Author

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot Bot added the module: not user facing Use this tag if you don't want this PR to show up in release notes label May 14, 2025
YIWENX14 added a commit to YIWENX14/ao that referenced this pull request May 14, 2025
)

Summary: Pull Request resolved: pytorch#2210

Differential Revision: D74446877
@YIWENX14 YIWENX14 force-pushed the export-D74446877 branch from 3fc617b to 0db5fc2 Compare May 14, 2025 22:44
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D74446877

@YIWENX14 YIWENX14 force-pushed the export-D74446877 branch from 0db5fc2 to cdc082f Compare May 14, 2025 23:54
YIWENX14 added a commit to YIWENX14/ao that referenced this pull request May 14, 2025
)

Summary: Pull Request resolved: pytorch#2210

Differential Revision: D74446877
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D74446877

YIWENX14 added a commit to YIWENX14/ao that referenced this pull request May 15, 2025
)

Summary: Pull Request resolved: pytorch#2210

Differential Revision: D74446877
@YIWENX14 YIWENX14 force-pushed the export-D74446877 branch from cdc082f to fa63a56 Compare May 15, 2025 00:01
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D74446877

YIWENX14 added a commit to YIWENX14/ao that referenced this pull request May 15, 2025
)

Summary: Pull Request resolved: pytorch#2210

Differential Revision: D74446877
@YIWENX14 YIWENX14 force-pushed the export-D74446877 branch from fa63a56 to ed81130 Compare May 15, 2025 00:17
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D74446877

@drisspg drisspg requested a review from jerryzh168 May 15, 2025 00:20
else:
assert mapping_type == MappingType.ASYMMETRIC.name
scale = (max_val_pos - min_val_neg) / float(quant_max - quant_min)
scale = (max_val_pos - min_val_neg) / torch.tensor(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what if you did:
(max_val_pos - min_val_neg) / (quant_max - quant_min).to(torch.float32)

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.

Casting to float32 doesn't help the discrepancy on CPU vs GPU.

Copy link
Copy Markdown
Contributor

@drisspg drisspg May 15, 2025

Choose a reason for hiding this comment

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

Ahh sorry I see that quant_max and quant_mins are ints, why is this better than the existing? Maybe a test might be helpful

import torch
from transformer_nuggets.utils.tracing import LoggingMode
a = torch.randn(2, 3, device="cuda")
with LoggingMode():
    out = a / float(32 - 12)
    print(out)


with LoggingMode():
    out = a / torch.tensor(float(32 - 12), dtype=a.dtype, device=a.device)
    print(out)
    

Produces:

$1: f32[2, 3] = aten.div.Tensor($0, 20.0)
tensor([[-0.0313, -0.0028, -0.0344],
       [ 0.0299,  0.0099, -0.0426]], device='cuda:0')
$0: f32[] = aten.lift_fresh.default($0)
$2: f32[2, 3] = aten.div.Tensor($1, $0)
tensor([[-0.0313, -0.0028, -0.0344],
       [ 0.0299,  0.0099, -0.0426]], device='cuda:0')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Driss, the issue is "float" as in python float is actually float64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So this isn't about fixing a device but about fixing the dtype?

Copy link
Copy Markdown
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

OK, I think it's fine to merge as long as it doesn't break existing tests, there are some flexibility in these quant primitive ops since we didn't really define these very precisely

)

Summary: Pull Request resolved: pytorch#2210

Reviewed By: jainapurva

Differential Revision: D74446877
@YIWENX14 YIWENX14 force-pushed the export-D74446877 branch from ed81130 to 83d990d Compare June 5, 2025 05:35
@facebook-github-bot
Copy link
Copy Markdown
Contributor

This pull request was exported from Phabricator. Differential Revision: D74446877

@facebook-github-bot facebook-github-bot merged commit 9cd5851 into pytorch:main Jun 5, 2025
20 of 21 checks passed
liangel-02 pushed a commit that referenced this pull request Aug 25, 2025
Differential Revision: D74446877

Pull Request resolved: #2210
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. fb-exported module: not user facing Use this tag if you don't want this PR to show up in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants