From 207530bbb5b8394c4c968622d6a0e8815fa0c420 Mon Sep 17 00:00:00 2001 From: Steven Atkinson Date: Mon, 27 Apr 2026 18:58:53 -0700 Subject: [PATCH 1/2] [BUGFIX] Avoid prewarming container slimmable model when SetSlimmableSize doesn't change which model is active. --- NAM/container.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/NAM/container.cpp b/NAM/container.cpp index 8442e17..8d6b6fe 100644 --- a/NAM/container.cpp +++ b/NAM/container.cpp @@ -69,18 +69,25 @@ void ContainerModel::Reset(const double sampleRate, const int maxBufferSize) void ContainerModel::SetSlimmableSize(const double val) { - _active_index = _submodels.size() - 1; + auto active_index = _submodels.size() - 1; for (size_t i = 0; i < _submodels.size(); ++i) { if (val < _submodels[i].max_value) { - _active_index = i; + active_index = i; break; } } - + if (active_index == _active_index) // No change to active model, so nothing to do + { + return; + } + // Setting _active_index puts the model in the RT path, so prewarm before doing that const double sr = mHaveExternalSampleRate ? mExternalSampleRate : mExpectedSampleRate; - _active_model().ResetAndPrewarm(sr, GetMaxBufferSize()); + _submodels[active_index].model->ResetAndPrewarm(sr, GetMaxBufferSize()); + + // Finally set when we're ready: + _active_index = active_index; } // ============================================================================= From ddcbc55bd20f660160aa4e286368aa034e6bd24a Mon Sep 17 00:00:00 2001 From: Steven Atkinson Date: Mon, 27 Apr 2026 19:16:21 -0700 Subject: [PATCH 2/2] [TEST] Ensure consistent model state before processing in test_container Added calls to ResetAndPrewarm in test_container_default_is_max_size to guarantee that both predictions start from the same model state, enhancing test reliability. --- tools/test/test_container.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/test/test_container.cpp b/tools/test/test_container.cpp index 993c906..ea18c62 100644 --- a/tools/test/test_container.cpp +++ b/tools/test/test_container.cpp @@ -314,6 +314,8 @@ void test_container_default_is_max_size() NAM_SAMPLE* in_ptr = input.data(); NAM_SAMPLE* out_ptr; + // Ensure both predictions start from identical model state. + dsp->ResetAndPrewarm(sample_rate, buffer_size); // Process with default (should be max size) out_ptr = out_default.data(); dsp->process(&in_ptr, &out_ptr, buffer_size); @@ -322,6 +324,7 @@ void test_container_default_is_max_size() auto* slimmable = dynamic_cast(dsp.get()); assert(slimmable != nullptr); slimmable->SetSlimmableSize(1.0); + dsp->ResetAndPrewarm(sample_rate, buffer_size); out_ptr = out_max.data(); dsp->process(&in_ptr, &out_ptr, buffer_size);