mistral.rs icon indicating copy to clipboard operation
mistral.rs copied to clipboard

Refactor model examples

Open EricLBuehler opened this issue 8 months ago • 2 comments

Summary

  • consolidate vision and text examples
  • use CLI args for choosing model IDs
  • remove redundant per-model demo folders
  • update documentation links

Testing

  • cargo fmt --all
  • make fmt
  • timeout 60 cargo clippy --workspace --tests --examples -- -D warnings (failed: timed out)
  • timeout 60 cargo test -p mistralrs-core -p mistralrs-quant -p mistralrs-vision (failed: timed out)

https://chatgpt.com/codex/tasks/task_e_68425ab1e4fc832283388c438c1d9a64

Summary by CodeRabbit

  • Documentation

    • Updated documentation links across multiple model guides to reference new example scripts focused on vision chat functionality.
  • New Features

    • Enhanced example scripts to support command-line arguments for model selection and image input, enabling flexible usage for both Python and Rust vision chat examples.
  • Refactor

    • Removed numerous legacy example scripts for specific models, consolidating vision model usage into a single, configurable vision chat example for both Python and Rust.
  • Chores

    • Cleaned up outdated server and client example scripts to streamline and modernize the example set.

EricLBuehler avatar Jun 06 '25 09:06 EricLBuehler

Walkthrough

This update standardizes and modernizes vision model example usage across documentation and code. It removes numerous model-specific example scripts in Python and Rust, replacing them with a single, configurable vision_chat example. Documentation links are updated to reference this unified example. The new scripts accept command-line arguments for model and image selection, enhancing flexibility.

Changes

Files/Paths Change Summary
docs/GEMMA3.md, docs/LLAMA4.md, docs/LLaVA.md, docs/MISTRAL3.md, Updated documentation links to reference vision_chat example scripts instead of model-specific scripts in HTTP server, Rust, Python.
docs/PHI3V.md, docs/PHI4MM.md, docs/QWEN2VL.md, docs/VLLAMA.md, Updated documentation to point to vision_chat.py or vision_chat/main.rs for vision model examples.
docs/VISION_MODELS.md, docs/IDEFICS2.md Updated references to Python/HTTP API examples to use vision_chat.py.
examples/python/gemma3.py, .../deepseekr1.py, .../deepseekv2.py, Deleted model-specific Python example scripts for vision and text models.
.../llama4.py, .../llama_vision.py, .../llava_next.py, .../mistral3.py, .../phi4mm.py, .../qwen2vl.py, .../smolvlm.py
examples/server/gemma3.py, .../llama4.py, .../llama_vision.py, Deleted model-specific OpenAI API client example scripts for vision models.
.../llava.py, .../llava_next.py, .../mistral3.py, .../phi4mm.py, .../qwen2vl.py
mistralrs/examples/gemma2/main.rs, .../deepseekr1/main.rs, Deleted model-specific Rust example programs for text and vision models.
.../deepseekv2/main.rs, .../gemma3/main.rs, .../llama4/main.rs,
.../llama_vision/main.rs, .../llava_next/main.rs, .../mistral3/main.rs, .../phi3v/main.rs, .../phi4mm/main.rs, .../qwen2vl/main.rs, .../smolvlm/main.rs
examples/python/plain.py Refactored to accept model ID and architecture as command-line arguments for flexible model selection.
examples/python/vision_chat.py Refactored to accept model ID, architecture, and image URL as command-line arguments; removed hardcoded values.
examples/server/vision_chat.py Refactored to accept model name and image URL as command-line arguments; simplified response printing.
mistralrs/examples/simple/main.rs Refactored to use clap for command-line parsing; allows dynamic model ID selection.
mistralrs/examples/vision_chat/main.rs Refactored to use clap for command-line parsing; allows dynamic model ID and image URL selection.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI Example (vision_chat.py/.rs)
    participant Model Runner (Python/Rust)
    participant Model

    User->>CLI Example: Run with --model-id, --arch, --image-url
    CLI Example->>Model Runner: Initialize with model-id, arch
    CLI Example->>Model Runner: Send chat completion request (with image)
    Model Runner->>Model: Process request
    Model-->>Model Runner: Generate response
    Model Runner-->>CLI Example: Return response
    CLI Example-->>User: Print response content

Possibly related PRs

  • EricLBuehler/mistral.rs#1332: Refactors the internal vision loader system by making the vision loader type optional and adding an automatic vision loader selector; related as both PRs address vision model usage, though at different layers (example/docs vs. core loader).

Poem

In the garden of code, where examples once grew,
The rabbits have tidied, and pruned what they knew.
Now one vision script, with arguments so neat,
Lets every model hop in, no need to repeat!
Documentation points true, the old files now gone—
Unified, flexible, and ready for dawn.
🐇✨

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

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

coderabbitai[bot] avatar Jun 06 '25 09:06 coderabbitai[bot]

Code Metrics Report
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 C Header                3           62           53            0            9
 CSS                     1          473          408           14           51
 Dockerfile              1           42           23           10            9
 HTML                    1           73           61            4            8
 JavaScript              7         1248          936          174          138
 JSON                   14          123          122            0            1
 Makefile                1            6            5            0            1
 Python                 87         4097         3457          161          479
 Shell                   1           63           26           18           19
 Plain Text              3         3723            0         2413         1310
 TOML                   21          695          634           10           51
 YAML                    2           21           19            2            0
-------------------------------------------------------------------------------
 Jupyter Notebooks       3            0            0            0            0
 |- Markdown             2           77           32           31           14
 |- Python               2          205          178            1           26
 (Total)                            282          210           32           40
-------------------------------------------------------------------------------
 Markdown               60         5211            0         3984         1227
 |- BASH                11          123          117            2            4
 |- JSON                 2           42           42            0            0
 |- Python               7          121          109            0           12
 |- Rust                22          757          634            1          122
 |- TOML                 2           75           63            0           12
 (Total)                           6329          965         3987         1377
-------------------------------------------------------------------------------
 Rust                  376       132481       117880         2913        11688
 |- Markdown           175         3002           29         2662          311
 (Total)                         135483       117909         5575        11999
===============================================================================
 Total                 581       148318       123624         9703        14991
===============================================================================

github-actions[bot] avatar Jun 06 '25 09:06 github-actions[bot]