Skip to content

Add extensible VLM processor loading rules - #565

Merged
davidkoski merged 2 commits into
ml-explore:mainfrom
aleroot:allow_external_code_to_configure_model_loading
Aug 24, 2026
Merged

davidkoski merged 2 commits into
ml-explore:mainfrom
aleroot:allow_external_code_to_configure_model_loading

Conversation

@aleroot

@aleroot aleroot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

Fixes #547.

External model packages could register their models and processors, but could not control how processor metadata was loaded. This forced model-specific fixes to be hard-coded inside VLMModelFactory.

This PR introduces a public processor-loading resolver registry. External packages can now:

  • Provide processor configuration when it is missing from a model repository.
  • Correct an incorrectly declared processor type.
  • Override built-in behavior without modifying MLXVLM.

Existing Qwen3.5, Mistral3, and Gemma4 special cases now use the same public mechanism. Repository configuration files remain authoritative, and fallbacks are only evaluated when those files are absent.

Checklist

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

@aleroot

aleroot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

This PR Action check is failing because 1441444 targeting Xcode 27 beta 5 while the hosted xcode-27 runner is still on beta 4. It now affects every PR tested against main.
@davidkoski, would you like me to open a temporary revert PR and reapply the change once GitHub upgrades the hosted runner, or should we treat integration_build_xcode27 as non-blocking until then?

@davidkoski

Copy link
Copy Markdown
Member

We can just treat the xcode27 as non-blocking for now (I will just verify that it is the expected error).


Some repositories omit processor metadata, or declare a generic processor that is not the
right implementation for their model type. An external model package can handle either case
without changing `VLMModelFactory`:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is curious that there are several VLMs in this situation and no LLMs.

`processor_config.json` always wins over a generated fallback. Processor type resolution is
applied afterward and can supply a missing `processor_class` or correct an incorrect one.
For isolated applications and tests, pass a separate
`VLMProcessorLoadingRegistry` to `VLMModelFactory` instead of registering globally.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

/// `preprocessor_config.json` nor `processor_config.json` exists. Processor type resolvers are
/// consulted after a configuration has been selected, so they can supply missing metadata or
/// correct metadata shipped by a checkpoint.
public protocol VLMProcessorLoadingResolver: Sendable {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great -- if we need more hooks we can easily add more methods with nil-returning defaults in the future.

@davidkoski davidkoski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks awesome! Thank you!

@davidkoski
davidkoski merged commit 60985ee into ml-explore:main Aug 24, 2026
2 of 3 checks passed
djandrewgibbons pushed a commit to djandrewgibbons/mlx-swift-lm that referenced this pull request Sep 1, 2026
* Add extensible VLM processor loading rules
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.

allow external code to configure model loading

2 participants