Skip to content

[docs] static model rules#45232

Merged
ydshieh merged 3 commits intohuggingface:mainfrom
stevhliu:static-model-rules
Apr 8, 2026
Merged

[docs] static model rules#45232
ydshieh merged 3 commits intohuggingface:mainfrom
stevhliu:static-model-rules

Conversation

@stevhliu
Copy link
Copy Markdown
Member

@stevhliu stevhliu commented Apr 3, 2026

adds docs for static model rules so model contributors are aware of expectations

I wonder if it wouldn't make sense to auto generate that portion of the doc automatically

added from @tarekziade feedback:

  • reformats format_rule_details() to output Markdown that gets inserted directly in the docs
  • adds a check_modeling_rules_doc.py util that checks rules.toml and uses format_rule_details() to generate the ## Rules reference section
  • adds util to make check-repo and make fix-repo to catch any drifts and automatically regenerate the docs if a rule is added or removed from rules.toml

@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@stevhliu stevhliu requested review from tarekziade and vasqu April 3, 2026 22:54
Copy link
Copy Markdown
Collaborator

@tarekziade tarekziade left a comment

Choose a reason for hiding this comment

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

nice!
when we your run mlinter --rule you get a documentation snippet, very similar to your doc for each rule. See also --list-rules.

I wonder if it wouldn't make sense to auto generate that portion of the doc automatically

@stevhliu
Copy link
Copy Markdown
Member Author

stevhliu commented Apr 6, 2026

oh good idea!

i think it'd be clearer and easier to scan if we combined the bad_example and good_example fields with a single diff field for each rule in rules.toml. wdyt?

@tarekziade
Copy link
Copy Markdown
Collaborator

oh good idea!

i think it'd be clearer and easier to scan if we combined the bad_example and good_example fields with a single diff field for each rule in rules.toml. wdyt?

Could you show me an example of what you have in mind? would that be a reorg in the toml or in how the CLI outputs it?

@stevhliu
Copy link
Copy Markdown
Member Author

stevhliu commented Apr 6, 2026

i was thinking a reorg in rules.toml to something like:

[rules.TRF001.explanation]
what_it_does = "Checks naming consistency between <Model>PreTrainedModel and config_class."
why_bad = "Mismatched config_class can break loading, auto classes, and developer expectations."
diff = '''
   class AcmePreTrainedModel(PreTrainedModel):
-  config_class = NanoConfig
+  config_class = AcmeConfig
'''

@tarekziade
Copy link
Copy Markdown
Collaborator

i was thinking a reorg in rules.toml to something like:

[rules.TRF001.explanation]
what_it_does = "Checks naming consistency between <Model>PreTrainedModel and config_class."
why_bad = "Mismatched config_class can break loading, auto classes, and developer expectations."
diff = '''
   class AcmePreTrainedModel(PreTrainedModel):
-  config_class = NanoConfig
+  config_class = AcmeConfig
'''

nice! +1 to do this.

Copy link
Copy Markdown
Collaborator

@tarekziade tarekziade left a comment

Choose a reason for hiding this comment

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

super nice addition, thanks!

@stevhliu stevhliu enabled auto-merge April 7, 2026 18:22
@stevhliu stevhliu disabled auto-merge April 7, 2026 18:22
@stevhliu
Copy link
Copy Markdown
Member Author

stevhliu commented Apr 7, 2026

do you have permissions to merge for me @tarekziade? i don't think the required failing test is related here

@tarekziade
Copy link
Copy Markdown
Collaborator

I don't have the perms. cc @ydshieh

@ydshieh ydshieh merged commit dd6e8c5 into huggingface:main Apr 8, 2026
17 of 19 checks passed
@stevhliu stevhliu deleted the static-model-rules branch April 8, 2026 15:06
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.

4 participants