Fix SDOH dataclass init - #1209
Open
fbonc wants to merge 2 commits into
Open
Conversation
@DataClass on an nn.Module subclass generated an __init__ that never called nn.Module.__init__, leaving the module without _parameters/_modules and unusable as a torch model. Replace with an explicit __init__ that calls super().__init__().
fbonc
force-pushed
the
fix-sdoh-dataclass-init
branch
from
August 27, 2026 04:55
e67378b to
7a65c8e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
SdohClassifier was decorated with @DataClass while subclassing BaseModel, which is an nn.Module. The dataclass-generated __init__ replaces BaseModel.__init__ and never calls nn.Module.__init__, so the module's internal state (_parameters, _modules, _buffers) is never created. As a result the object cannot behave as a torch module: parameters(), .to(), .eval(), and submodule assignment all raise, and @DataClass also makes the instance unhashable. The class's own docstring example (SdohClassifier()) yields an unusable object.
Fix
Removed the @DataClass decorator and the field(...) declarations, replacing them with an explicit __init__ that calls super().__init__(dataset=None) and assigns api_key, base_model_id, and adapter_model_id. Passing dataset=None is correct here because this is an LLM-based classifier that is not trained against a SampleDataset; BaseModel handles a falsy dataset by leaving feature/label keys empty. Removed the now-unused dataclass imports.
Notes
Added regression test test_is_initialized_nn_module in tests/core/test_sdoh.py asserting nn.Module state is initialized.