Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[BUG] Hardtanh ignores min_val/max_val from the .nam config

Open Beginner friendly
#342 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, python, pytorch
Domain
backend

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-modeler main @ 0072676419): nam/models/_activations.py, lines ~253–258, exports
    if 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.cpp maps "Hardtanh" to the parameterless singleton ActivationHardTanh (clamp to ±1); min_val/max_val are only parsed for LeakyHardtanh.

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sdatkinson/NeuralAmpModelerCore

All issues in sdatkinson/NeuralAmpModelerCore

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.