Open levmckinney opened 11 months ago
Hey @levmckinney , thanks for posting!
I'm familiar with this issue, let me try to recall what's going on.
I believe what's happening is that SimpleParsing is parsing the value from str into an Enum, so in the __post_init__
, you're calling the Color constructor with a Color
instance, rather than a string.
I'll try to whip up a solution on Monday, but for now, I think you could fix it with something like:
@dataclass
class SubComponent:
color: Union[str, Color] = Color.BLUE
def __post_init__(self):
if isinstance(self.color, str):
self.color = Color(self.color)
I'm surprised though, I thought I had this issue already nailed down with my HuggingFace example / test. I guess one other approach would be to leave those HF classes as-is, but to add a custom handler for them..
I have to think about this, I'll get back to you, thanks again for posting!
Describe the bug I've really been loving using simple-parsing in my projects. It looks like you are trying to maintain compatibility with hugging faces dataclass #172. One use case I've been trying to get to work that involves this is to expose the
TrainingArguments
dataclass on the command line usingsimple-parsing
so that I don't have to manual pass all the different configuration options through. This was working great until I tried to add default arguments, at which point I started running into errors of the form:I believe this is because at some point
simple-parsing
convertsIntervalStrategy.STEP
into the string literalTo Reproduce
So you don't have to dig through hugging faces code, here is a minimal replication of what's happening.
See https://github.com/huggingface/transformers/pull/17933 for why it inherits from string
Expected behavior A clear and concise description of what you expected to happen.
Actual behavior I get errors of the form:
Here is the simplified example that replicates the basic issue without the HF stuff.
Desktop (please complete the following information):
Additional context My current understanding is that our
Enum
classColor
orIntervalStrategy
inheriting fromstr
is causing the problem. This seems to be a hack on Hugging Faces side to help with serialization see https://github.com/huggingface/transformers/pull/17933.