+
Skip to content

Conversation

Weili-0234
Copy link

@Weili-0234 Weili-0234 commented Jul 27, 2025

This PR adds custom_models/__init__.py to ensure proper model registration with AutoConfig and AutoModelForCausalLM
Also updates train.sh to explicitly import custom_models when parsing the model name (used in wandb run name)

related issue: #35

Summary by CodeRabbit

  • Documentation

    • Updated the instructions for adding custom models, clarifying the need to import new models and configure their exposure in the initialization file.
  • New Features

    • Introduced an initialization file for custom models, ensuring only specified models are publicly available.
  • Chores

    • Adjusted the training script to import custom models, improving compatibility with custom configurations.

Copy link

coderabbitai bot commented Jul 27, 2025

Walkthrough

A new step was added to the README for custom model integration, instructing users to update custom_models/__init__.py to import and expose their models. The custom_models/__init__.py file was created to import the sba module and set __all__. The train.sh script now imports custom_models in its model type extraction step.

Changes

File(s) Change Summary
README.md Added step to guide users to import and expose custom models in custom_models/__init__.py.
custom_models/init.py Created file; imports sba and sets __all__ = ["sba"].
train.sh Modified Python snippet to import custom_models when extracting model type from config.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

A hop, a skip, a custom model’s leap—
Now __init__.py keeps exports neat.
The README guides with wisdom new,
While train.sh learns what models do.
With every tweak, our warren grows,
As code and carrots both compose! 🥕

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
README.md (1)

485-491: Step 3 vs Step 6 duplicate the same instruction – collapse them for clarity

Step 3 already tells users to “Register your models in __init__.py”.
Step 6 repeats the same requirement, which can confuse first-time readers.

Consider merging the bullets or re-ordering:

3. Edit `custom_models/__init__.py`:
   - `from . import my_model`
   - set `__all__ = ["my_model"]`

Keeps the checklist concise and avoids readers missing one of the two steps.

train.sh (1)

69-70: Python one-liner can drop the extra jq dependency

Since the sole purpose is to obtain model_type, do it directly in Python and avoid the jq pipe (makes the script portable to systems without jq):

-model=$(
-  python -c "import fla, sys, custom_models; from transformers import AutoConfig; print(AutoConfig.from_pretrained(sys.argv[1]).to_json_string())" "$config" | jq -r '.model_type'
-)
+model=$(
+  python - <<'PY' "$config"
+import sys, custom_models  # noqa: F401 – import for side-effect registration
+from transformers import AutoConfig
+print(AutoConfig.from_pretrained(sys.argv[1]).model_type)
+PY
+)

No behavioural change, but one fewer external dependency and slightly simpler.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8684660 and ea99aff.

📒 Files selected for processing (3)
  • README.md (1 hunks)
  • custom_models/__init__.py (1 hunks)
  • train.sh (1 hunks)

Comment on lines +1 to +3
from . import sba

__all__ = ["sba"]
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Import fails hard if ‘sba’ is absent – make registration resilient / configurable

__init__.py eagerly imports sba, raising ModuleNotFoundError the moment a user removes or renames that directory.
Given the README now tells users to edit this file for their own models, a safer pattern is to:

  1. Gate the import in a try/except and emit a clear error message, or
  2. Provide a minimal lazy-import helper that looks up modules listed in __all__ only when accessed.

This prevents a broken install/run‐time experience when someone forgets to adjust the import while experimenting.

-from . import sba
-
-__all__ = ["sba"]
+import importlib
+import warnings
+
+__all__ = ["sba"]  # update this list for your own modules
+
+def __getattr__(name):
+    if name in __all__:
+        try:
+            module = importlib.import_module(f".{name}", __name__)
+            globals()[name] = module
+            return module
+        except ModuleNotFoundError:
+            raise ImportError(
+                f"custom_models: requested sub-module '{name}' not found – "
+                "did you forget to create/rename it?"
+            )
+    raise AttributeError(name)

Keeps side-effects minimal and offers a clearer failure mode.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from . import sba
__all__ = ["sba"]
import importlib
import warnings
__all__ = ["sba"] # update this list for your own modules
def __getattr__(name):
if name in __all__:
try:
module = importlib.import_module(f".{name}", __name__)
globals()[name] = module
return module
except ModuleNotFoundError:
raise ImportError(
f"custom_models: requested sub-module '{name}' not found – "
"did you forget to create/rename it?"
)
raise AttributeError(name)
🤖 Prompt for AI Agents
In custom_models/__init__.py at lines 1 to 3, the current eager import of 'sba'
causes a ModuleNotFoundError if 'sba' is missing. To fix this, wrap the import
of 'sba' in a try/except block that catches ImportError and logs a clear,
user-friendly error message explaining the missing module. Alternatively,
implement a lazy-import mechanism that only imports modules listed in __all__
when they are accessed, preventing immediate import failures and improving
resilience when users modify the models.

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

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载