Skip to content

Refactor factory into separate config parser and unified create_dsp() construction path#227

Open
jfsantos wants to merge 4 commits intosdatkinson:mainfrom
jfsantos:feature/config-refactor
Open

Refactor factory into separate config parser and unified create_dsp() construction path#227
jfsantos wants to merge 4 commits intosdatkinson:mainfrom
jfsantos:feature/config-refactor

Conversation

@jfsantos
Copy link
Contributor

Add typed config structs (LinearConfig, LSTMConfig, ConvNetConfig, WaveNetConfig) and parse_config_json() functions per architecture. Introduce ModelConfig variant, ModelMetadata, and create_dsp() for unified model construction independent of JSON parsing. Refactor get_dsp() to use the new unified path. Register Linear factory (was previously missing).

This is being done in order to support parsers for formats other than JSON more easily. Those parsers should NOT be a part of Core, at least for now. I will be creating a separate repo for the binary .namb format that leverages this refactor if it gets merged.

Developed with support and sponsorship from TONE3000

Add typed config structs (LinearConfig, LSTMConfig, ConvNetConfig,
WaveNetConfig) and parse_config_json() functions per architecture.
Introduce ModelConfig variant, ModelMetadata, and create_dsp() for
unified model construction independent of JSON parsing. Refactor
get_dsp() to use the new unified path. Register Linear factory
(was previously missing).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Owner

@sdatkinson sdatkinson left a comment

Choose a reason for hiding this comment

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

This is pretty slick overall!

The big problem, however, is that it seems to kill the registry pattern that makes this library extensible with new architectures?

Perhaps I owe you a test that compile-time registers a new "test" architecture. Let me do that so that the requirement is more clear.

Otherwise, very cool!

NAM/get_dsp.cpp Outdated
Copy link
Owner

Choose a reason for hiding this comment

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

[C] It appears that the registry doesn't work anymore with this?

If I have another repo with a new NAM architecture, it won't get picked up anymore.

{
std::string version;
double sample_rate = -1.0;
std::optional<double> loudness;
Copy link
Owner

Choose a reason for hiding this comment

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

I do like this <3

Copy link
Owner

Choose a reason for hiding this comment

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

[C] Can this be added to by code outside of this repo?

NAM/wavenet.cpp Outdated
Copy link
Owner

Choose a reason for hiding this comment

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

Claude seems to have thrashed the comments, which is making it hard for my eyes to see the changes. Can you revert those?

I think this is correct but

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@sdatkinson
Copy link
Owner

Try merging #231 in. If that test still passes, then I think my concerns would be allayed.

João Felipe Santos added 3 commits February 17, 2026 18:24
  ModelConfig is now an abstract class with a virtual create() method
  instead of a std::variant over built-in config types. Each architecture's
  config struct inherits from ModelConfig and implements create().

  A single ConfigParserRegistry maps architecture names to parser functions
  that return unique_ptr<ModelConfig>. Both built-in architectures (via
  ConfigParserHelper) and external ones (via factory::Helper, which now
  wraps into FactoryConfig) register in the same registry. This can be
  refactored such that we only have ConfigParserHelper, but I wanted to
  keep the API backwards-compatible.
@jfsantos
Copy link
Contributor Author

I updated the machinery to work similarly to how it worked before with a common registry for both internal and external models (the only difference being that the registry is now for parsers and not full-on constructors). Merged with #231 (tests now pass), added missing comments back.

Something I just thought could be done is register parsers with a format (e.g. register_parser(".nam", function_pointer_to_json_parser))... or we could just have an external application replace the parser with a parser for their own format instead. I did not add this here yet as I wanted to hear your thoughts about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments