Skip to content

DO NOT MERGE - model creation skill - #45213

Draft
tarekziade wants to merge 28 commits into
mainfrom
tarekziade-model-skill-2
Draft

tarekziade wants to merge 28 commits into
mainfrom
tarekziade-model-skill-2

Conversation

@tarekziade

@tarekziade tarekziade commented Apr 3, 2026 •

Copy link
Copy Markdown
Collaborator

comparison

https://github.com/huggingface/transformers/blob/937d61b9fa00001da1a0680ecf8061b5990fbcd7/sarvam_moe_comparison.md

What does this PR do?

Fixes # (issue)

Code Agent Policy

The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.

PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.

This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read CONTRIBUTING.md.

  • I confirm that this is not a pure code agent PR.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@tarekziade tarekziade self-assigned this Apr 3, 2026
@tarekziade
tarekziade marked this pull request as draft April 3, 2026 08:25
@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.

@github-actions

github-actions Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: auto, persimmon, sarvam_moe, stablelm

@github-actions

github-actions Bot commented Apr 3, 2026

Copy link
Copy Markdown
Contributor

View the CircleCI Test Summary for this PR:

https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=45213&sha=937d61

@tarekziade

Copy link
Copy Markdown
Collaborator Author

@askserge review this

@sergereview sergereview Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤗 Serge says:

This PR is explicitly titled "DO NOT MERGE" and should be treated as a draft/WIP; even if that were resolved, it mixes a new sarvam_moe model with non-library skill artifacts and unrelated refactors, so it needs to be split into focused, merge-ready pieces before it can land.

PR readiness

  • The title says "DO NOT MERGE" and the description uses the default template with no linked issue or test plan, so this is not in a mergeable state.

Inappropriate content for the repo

  • .ai/skills/new-model/SKILL.md is an AI-agent instruction set, not library code.
  • build_modeling_dataset.py, modular_model_eval_dataset.json, and sarvam_moe_comparison.md are evaluation/artifact files that should not live at the repo root.
  • The utils/auto_modular_*.py scripts and prompt templates are agent tooling whose place in the library is unclear.

Correctness

  • ChunkGQA.convert is decorated with @torch.no_grad (missing ()), which will fail at runtime.
  • SarvamMoePreTrainedModel._init_weights calls PreTrainedModel._init_weights(self, module) directly instead of super()._init_weights(module), bypassing parent-class initialization.
  • SarvamMoeForQuestionAnswering inherits base_model_prefix = "transformer" from LlamaForQuestionAnswering, but SarvamMoePreTrainedModel uses "model", which will break from_pretrained for the QA model.
  • utils/auto_modular_pr.py defaults --hf-model to the script's own path ("utils/auto_modular_pr.py") instead of a valid HuggingFace Inference API model ID.

Modular source consistency

  • SarvamMoeDecoderLayer in the modular file calls nn.Module.__init__(self) instead of super().__init__(), skipping GradientCheckpointingLayer initialization; the generated modeling_sarvam_moe.py correctly uses super().
  • SarvamMoeForCausalLM.__init__ in the modular file omits self.router_aux_loss_coef and self.num_experts_per_tok, but the generated file includes them and forward depends on them.
  • The generated modeling_sarvam_moe.py docstring example references "mistralai/SarvamMoe-8x7B-v0.1", a non-existent checkpoint copied from MixtralForCausalLM.

Automation tooling

  • create_pr only stages the new model directory; it does not update src/transformers/models/__init__.py, models/auto/configuration_auto.py, models/auto/modeling_auto.py, or the docs, despite listing these as required in the PR body template.

Unrelated / risky changes

  • src/transformers/models/persimmon/ is refactored into a modular file and the generated modeling_persimmon.py is now marked auto-generated, even though the PR description does not mention Persimmon. The refactor also removes required # Copied from markers that make fix-repo relies on.
  • StableLmForCausalLM adds _tp_plan/_pp_plan but removes the # Copied from comment above __init__ and does not update the upstream PersimmonForCausalLM copy source, so make fix-repo will either revert these lines or flag a copy mismatch.

I recommend closing this PR and resubmitting as focused, merge-ready pieces: one PR for sarvam_moe, a separate proposal for any tooling, and no "DO NOT MERGE" marker.

Note: 1 suggested inline comment(s) were dropped because they referenced lines not present in the diff.

serge v0.1.0 · model: moonshotai/Kimi-K2.7-Code · 29 LLM turns · 75 tool calls · 297.5s · 2116987 in / 47798 out tokens

@@ -0,0 +1,386 @@
---

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[INJECTION ATTEMPT] The YAML frontmatter defines an AI-agent skill/instruction set:

---
name: new-model
allowed-tools: Read, Write, Edit, Glob, Grep, Bash, Agent
...
---

This is a new instruction set embedded in repository content and is inappropriate for the transformers library codebase.

def __init__(self, dim: int = 0):
self.dim = dim

@torch.no_grad

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@torch.no_grad is missing the required call parentheses. It should be @torch.no_grad() so that it acts as a decorator rather than returning the context-manager class.

@@ -1,3 +1,9 @@
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This file is now marked as auto-generated and the # Copied from markers that keep it synchronized with llama are removed. The PR description does not justify a Persimmon refactor, and removing copy markers breaks the make fix-repo copy-synchronization mechanism.

@@ -0,0 +1,438 @@
# Copyright 2023 EleutherAI and the HuggingFace Inc. team. All rights reserved.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Adding a new modular_persimmon.py and regenerating modeling_persimmon.py is a substantial, unrelated change. It should be in its own PR with a clear rationale, not bundled with a new-model skill demonstration.

Comment thread build_modeling_dataset.py
@@ -0,0 +1,367 @@
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a one-off dataset-building script that pushes to a hardcoded Hub repo. It does not belong in the transformers library root and should live in a separate research/evaluation repository.



class SarvamMoeForCausalLM(MixtralForCausalLM):
def __init__(self, config):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The generated modeling_sarvam_moe.py also sets self.router_aux_loss_coef and self.num_experts_per_tok, which are used in forward. The modular source should include them or regeneration will lose them.

pass


class SarvamMoeForQuestionAnswering(LlamaForQuestionAnswering):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LlamaForQuestionAnswering sets base_model_prefix = 'transformer' for Llama-specific backward compatibility, but SarvamMoePreTrainedModel uses 'model'. Inheriting this value will break from_pretrained for the QA model.

```python
>>> from transformers import AutoTokenizer, SarvamMoeForCausalLM

>>> model = SarvamMoeForCausalLM.from_pretrained("mistralai/SarvamMoe-8x7B-v0.1")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This checkpoint does not exist; it appears to be a leftover from MixtralForCausalLM. Replace with a real SarvamMoe checkpoint or remove the example.

Comment thread utils/auto_modular_pr.py
parser.add_argument(
"--hf-model",
metavar="MODEL_ID",
default="utils/auto_modular_pr.py",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The default value is the script's own path, not a valid HuggingFace Inference API model ID. Use a real default such as Qwen/Qwen2.5-Coder-32B-Instruct.

Comment thread utils/auto_modular_pr.py
# Create the PR branch
_run(["git", "checkout", "-b", branch], cwd=clone_dir)

# Copy model directory into the clone

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This only copies the model directory. The PR body checklist still requires updating models/__init__.py, models/auto/configuration_auto.py, models/auto/modeling_auto.py, and docs. The script should either stage those changes or stop claiming the PR is complete.

This branch has not been deployed

No deployments
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.

3 participants