Skip to content

Fix SDOH dataclass init - #1209

Open
fbonc wants to merge 2 commits into
sunlabuiuc:masterfrom
fbonc:fix-sdoh-dataclass-init
Open

Fix SDOH dataclass init#1209
fbonc wants to merge 2 commits into
sunlabuiuc:masterfrom
fbonc:fix-sdoh-dataclass-init

Conversation

@fbonc

@fbonc fbonc commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

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.

@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 fbonc changed the title Fix sdoh dataclass init Fix SDOH dataclass init Aug 27, 2026
@fbonc
fbonc force-pushed the fix-sdoh-dataclass-init branch from e67378b to 7a65c8e Compare August 27, 2026 04:55
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.

1 participant