[BUG] Hardtanh ignores min_val/max_val from the .nam config
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start in NAM/activations.cpp, then compare the exported bounds in nam/models/_activations.py. Trace how Hardtanh configuration parameters are parsed and exercise a config with min_val=-0.5 and max_val=0.8. Done means bounded Hardtanh matches the trainer while the bare string and configs without bounds retain the current ±1 behavior.
Written by the indexing model from the issue text.
Description
Summary
Hardtanh activations ignore their min_val / max_val bounds: the core always clamps to [-1, 1]. The trainer exports Hardtanh with explicit bounds, so a model trained with torch.nn.Hardtanh(min_val, max_val) other than ±1 runs differently in the core.
Where
- Trainer (
neural-amp-modelermain@ 0072676419):nam/models/_activations.py, lines ~253–258, exportsif isinstance(module, _nn.Hardtanh): return {"type": "Hardtanh", "min_val": module.min_val, "max_val": module.max_val} - Core (
main@ 0b3d3c97b0, also v0.5.4):NAM/activations.cppmaps"Hardtanh"to the parameterless singletonActivationHardTanh(clamp to ±1);min_val/max_valare only parsed forLeakyHardtanh.
Suggested fix
When a Hardtanh config carries min_val/max_val, honour them — e.g. build a clamp with those bounds, or map it to LeakyHardtanh with min_slope = max_slope = 0 (which is exactly a clamp to [min_val, max_val]). The bare string "Hardtanh" and configs without bounds keep today's ±1 behaviour.
With that mapping, a test model using Hardtanh(min_val=-0.5, max_val=0.8) matched the trainer's PyTorch output to ~6e-8. (That same model also has an inactive layer1x1, so the ~6e-8 figure is with the fix from #341 applied as well.)
- Dominant language
- C++
- Stars
- 931
- Forks
- 178
- Avg merge
- 36m
- Merged PRs (30d)
- 4
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sdatkinson/NeuralAmpModelerCore
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sdatkinson/NeuralAmpModelerCore#328 ·
Maintainers usually reply within 1 day
-
documentation
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
sdatkinson/NeuralAmpModelerCore#305 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
sdatkinson/NeuralAmpModelerCore#304 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 76/100
sdatkinson/NeuralAmpModelerCore#341 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
sdatkinson/NeuralAmpModelerCore#327 · 1 reaction ·
Maintainers usually reply within 1 day
All issues in sdatkinson/NeuralAmpModelerCore
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
espressif/esp-matter#1867 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
cuAmpcorParameter.cpp (CPU pycuampcor) does not compile with libc++: EXIT_FAILURE is undeclaredOpen
Difficulty 1/5 Under an hour Newbie friendliness 92/100
isce-framework/isce3#387 ·
-
upstream update
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
conan-io/conan-center-index#31055 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day