Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: setting model_diagram to False after initialization #296

Conversation

BenjaminBossan
Copy link
Collaborator

Resolves #292

When setting model_card.model_diagram = False, the rendered model card should not contain the model diagram. For more explanation, see the issue.

The issue is not resolved for the case that a user doesn't use the skops template, because it means we don't know where they put the model diagram and can thus not disable it after they set model_card.model_diagram = False. The corresponding test is marked to xfail.

The test suite has been extended to cover more cases around the use of custom templates in conjunction with the model diagram.

Resolves skops-dev#292

When setting model_card.model_diagram = False, the rendered model card
should not contain the model diagram. For more explanation, see the
issue.
@BenjaminBossan
Copy link
Collaborator Author

Ready for review @skops-dev/maintainers

Copy link
Member

@adrinjalali adrinjalali left a comment

Choose a reason for hiding this comment

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

Fixing the comment, I think would also make this PR fix #292

Comment on lines 723 to 727
# If we use the skops template, we know what section to add or remove
# when model_diagram changes values. If not, we don't know and thus need
# to skip this step.
if self.template != Templates.skops.value:
return
Copy link
Member

Choose a reason for hiding this comment

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

instead of this, we can raise and say that we don't know what to do about this.

Copy link
Member

@adrinjalali adrinjalali Feb 28, 2023

Choose a reason for hiding this comment

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

As in, instead of returning here, we could raise an error, and if we do, then this PR can be considered to fully fixing the original issue IMO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot about this PR, hence the late reply :)

I changed the code to raise an error here, with a hopefully useful error message for the user.

This is still not solving the whole problem though. We have test_setting_model_diagram_false_other_section, which is still xfailing. The problem is that even with a skops template, if the user adds a model diagram to a different section, since we don't store that section name, we cannot remove it later on. For that, I see two possible solutions, but I don't like either:

  1. Don't allow users to add a model diagram to a different section when they have the skops template (why would they need it twice?) -- but should we really disallow it?
  2. We remember where we put stuff, e.g. saving an attribute _section_name_of_model_diagram, but that seems to be overly complex for such a niche error.

WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

So this makes me realize maybe our abstraction is a bit the issue. We're trying to handle metadata related to the template, but not stored in the template. One way to fix this, would be to allow users to set attributes on the template, such as "collapsed/expanded" for each section. We can still accept a dictionary as a template, but if the template extends the dictionary and includes such information, we apply them to the rendered readme. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree that this smells of incorrect abstraction. But I'm not sure if the proposed solution is the right one. Right now, the template is used to prefill the model card, not anything more. Let's assume we would allow users, as you suggest, to set "collapsed/expanded" on the template. If they use the template that way, and later add a new section, how would they control if that section is collapsed? As it's not in the template, they would have to set it on the card. Now there are two different ways to achieve the same thing.

I think the problem in the discussed case is the conflict between flexibility&customization vs predefined sections. To accommodate the former, we have to allow 0, 1, or multiple model diagrams anywhere in the card. For the latter, we have to assume there either is or isn't a model diagram, and it always sits in the same place. I don't have a good proposal to resolve that conflict.

Regarding this specific problem, it might be better to not have a model_diagram=True/False argument on Card at all. Instead, just never create it automatically, and if I need it, I have to call model_card.add_model_plot(section_name) (the section_name argument would be optional with the skops template). If I don't want it anymore, I call model_card.delete(section_name). IMO that is much cleaner, but it's breaking BC.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with most of what you say. Here's another solution:

  • don't treat model diagram as a special case. Create a [sub]section for it, and put the diagram content there.
  • we don't have to remove the arg from init, but we can make it be model_diagram=True/None/section name
  • if the user wants to hide the model diagram, they should hide the section

The semantics of the following code becomes:

card = Card(..., model_diagram=None) # don't add the diagram yet
card.add_model_diagram(section_name) # now add the diagram
card.select(section_name).hidden = True # hide the model diagram

Is that better?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sounds doable. For clarification:

if the user wants to hide the model diagram, they should hide the section

Is your suggestion that if the user sets model_card.model_diagram = False, we should try to make it invisible (this PR) or just do nothing (status quo)?

Copy link
Member

Choose a reason for hiding this comment

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

We can remove the boolean model_diagram from the object. The object would either not have it at all, or if it does, it'd be the Section object.

@BenjaminBossan
Copy link
Collaborator Author

Fixing the comment, I think would also make this PR fix #292

Ah, sorry, I don't follow. Is this referring to your other remark:

instead of this, we can raise and say that we don't know what to do about this.

?

That's better than just ignoring it, especially if the error message can
guide the user to the right solution.

Also, early return in setter in case the value stays the same.
BenjaminBossan added a commit to BenjaminBossan/skops that referenced this pull request Mar 9, 2023
As discussed in skops-dev#296, instead of dealing with the issue what should
happen if the user sets model_card.model_diagram = False after
initializing with True, just remove the attribute from the Card class.
This way, there cannot be the false impression that the diagram can be
removed from the card by setting the attribute to False.

If users really need to remove the model diagram after enabling it at
first, they can just delete the corresponding section (or make it
invisible).

On top of that, a feature was added that passing a str to model_diagram
will use that str as the section name. Previously, always the default
section would be used (for skops template) or no section added (for
custom templates).
@BenjaminBossan
Copy link
Collaborator Author

Closing in favor of #314

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.

BUG: After setting model_diagram=False on instantiated model card, the diagram is still shown
2 participants