Repository navigation
Add RunningAbsMaxSmoothQuantObserver for memory-efficient calibration (#3946) - #3946
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/3946
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 04581a1 with merge base 960f307 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| @@ -0,0 +1,249 @@ | |||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |||
There was a problem hiding this comment.
Not sure why test script is located inside package. Shouldn't we update https://github.com/pytorch/ao/blob/main/test/prototype/test_smoothquant.py instead?
There was a problem hiding this comment.
Yes, will tell Hossein to do that before merging
| return smoothing_factor, None | ||
|
|
||
|
|
||
| class RunningAbsMaxSmoothQuantObserver(torch.nn.Module): |
There was a problem hiding this comment.
Like this new logic overally, but do we actually need RunningAbsMaxSmoothQuantObserver? To me, minimal SmoothQuantObserver update (even though its bc-breaking) looks better.
Also, RunningAbsMaxSmoothQuantObserver reminds me AQT (AffineQuantizedTensor) nightmare. I am not sure if we really need abstracted notation.
There was a problem hiding this comment.
Yeah agree SmoothQuantObserver abstraction is kind of funky.
I think the best way this mess is to define a ObserverTensor class that we can then modify appropriately. That way we don't need to have SmoothQuantObserver, SmoothQuantObservedLinear and can just use a single SmoothQuantObserverTensor.
Do you know if smoothquant API is used much anywhere? The only thing that concerns me is that by default replacing SmoothQuantObserver with RunningAbsMaxSmoothQuantObserver is that we need two passes through the data for RunningAbsMaxSmoothQuantObserver, so existing workflows might fail.
We do need a way to test numerics though between SmoothQuantObserver and RunningAbsMaxSmoothQuantObserver, so even if we make RunningAbsMaxSmoothQuantObserver we'll still need to store this code somewhere. I think it's better to leave the cleanup as a follow up.
There was a problem hiding this comment.
I think the best way this mess is to define a ObserverTensor class that we can then modify appropriately. That way we don't need to have SmoothQuantObserver, SmoothQuantObservedLinear and can just use a single SmoothQuantObserverTensor.
So are you considering common observer class? More generally, quantization subclass (Float8Tensor/Int8Tensor) should not contain observer-related ops (like act_pre_scale)? Actually I was working for this topic, so it would be great if you can look into it — #3925.
There was a problem hiding this comment.
Do you know if smoothquant API is used much anywhere? The only thing that concerns me is that by default replacing SmoothQuantObserver with RunningAbsMaxSmoothQuantObserver is that we need two passes through the data for RunningAbsMaxSmoothQuantObserver, so existing workflows might fail.
Yeah I am also interested in this topic. For example, because AWQ uses greedy search
ao/torchao/prototype/awq/core.py
Lines 70 to 86 in 5045d76
, we can try better searching algorithm like binary/tenary. It's GPTQ, but I already observed tenary is 2x faster than greedy: ModelCloud/GPTQModel#2419
Wondering if you have any candidates for these numerical techniques, what about your thought?
There was a problem hiding this comment.
We do need a way to test numerics though between SmoothQuantObserver and RunningAbsMaxSmoothQuantObserver, so even if we make RunningAbsMaxSmoothQuantObserver we'll still need to store this code somewhere. I think it's better to leave the cleanup as a follow up.
I think in this early stage, we don't need multiple-configs to store all of them. Also I don't want to see RunningAbsMaxSmoothQuantObserver anywhere.
Instead, we can just run perf using https://github.com/pytorch/ao/blob/main/benchmarks/quantization/calibration_based/measure_accuracy_and_performance.sh and update minimally across AWQ/GPTQ/SmoothQuant I feel.
…pytorch#3946) Summary: Add a memory-efficient SmoothQuant observer that uses running per-channel absmax instead of storing all calibration inputs. This reduces calibration memory from O(N x features) to O(features), preventing RAM spikes and OOM kills when calibrating on large datasets. - Add RunningAbsMaxSmoothQuantObserver class in core.py - Add use_running_absmax config option to SmoothQuantConfig - Export the new observer from the module Differential Revision: D94260071
|
@claude can you fix lint please |
|
Claude finished @jcaip's task in 10m 33s —— View job Fixed lint issues
Changes madeApplied
Note: I was unable to install/run |
|
@jcaip @jerryzh168 do you have any GPU profiling e2e results for this PR? If I remember correctly, there wasn't a profiling benchmark at the time — just wanted to check if that's been added or if there are any benchmark numbers available I am missing. |
…pytorch#3946) Differential Revision: D94260071 Pull Request resolved: pytorch#3946
Summary:
Add a memory-efficient SmoothQuant observer that uses running per-channel
absmax instead of storing all calibration inputs. This reduces calibration
memory from O(N x features) to O(features), preventing RAM spikes and OOM
kills when calibrating on large datasets.
Differential Revision: D94260071