Skip to content

Add SAM3-LiteText#44320

Merged
vasqu merged 36 commits intohuggingface:mainfrom
NielsRogge:add_sam_3_lite_text
Apr 13, 2026
Merged

Add SAM3-LiteText#44320
vasqu merged 36 commits intohuggingface:mainfrom
NielsRogge:add_sam_3_lite_text

Conversation

@NielsRogge
Copy link
Copy Markdown
Collaborator

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


# Get tokenizer class
if self.lowercase_name in TOKENIZER_MAPPING_NAMES:
self.tokenizer_class = None
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note: have opened a separate PR for the CLI fixes here: #44334

@JavierYepez
Copy link
Copy Markdown

JavierYepez commented Mar 27, 2026

Maybe not the best practice to post this here but I'm getting an error when running
python utils/modular_model_converter.py sam3_lite_text

Converting src/transformers/models/sam3_lite_text/modular_sam3_lite_text.py to a single model single file format
multiprocessing.pool.RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/Users/javieryepez/.local/share/uv/python/cpython-3.11.14-macos-aarch64-none/lib/python3.11/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/.local/share/uv/python/cpython-3.11.14-macos-aarch64-none/lib/python3.11/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
           ^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/utils/modular_model_converter.py", line 1952, in run_converter
    converted_files = convert_modular_file(modular_file, source_library=source_library)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/utils/modular_model_converter.py", line 1908, in convert_modular_file
    for file, module in create_modules(
                        ^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/utils/modular_model_converter.py", line 1799, in create_modules
    nodes_to_add, file_type, new_imports = get_class_node_and_dependencies(modular_mapper, class_name, node, files)
                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/utils/modular_model_converter.py", line 1733, in get_class_node_and_dependencies
    updated_node = replace_class_node(mapper, node, renamed_super_class, super_class)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/utils/modular_model_converter.py", line 1084, in replace_class_node
    new_replacement_class = temp_module.visit(
                            ^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/module.py", line 89, in visit
    result = super(Module, self).visit(visitor)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/base.py", line 228, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/module.py", line 74, in _visit_and_replace_children
    body=visit_body_sequence(self, "body", self.body, visitor),
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/internal.py", line 227, in visit_body_sequence
    return tuple(visit_body_iterable(parent, fieldname, children, visitor))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/internal.py", line 193, in visit_body_iterable
    new_child = child.visit(visitor)
                ^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/base.py", line 228, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/statement.py", line 1989, in _visit_and_replace_children
    body=visit_required(self, "body", self.body, visitor),
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/internal.py", line 81, in visit_required
    result = node.visit(visitor)
             ^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/base.py", line 228, in visit
    _CSTNodeSelfT, self._visit_and_replace_children(visitor)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/statement.py", line 704, in _visit_and_replace_children
    body=visit_body_sequence(self, "body", self.body, visitor),
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/internal.py", line 227, in visit_body_sequence
    return tuple(visit_body_iterable(parent, fieldname, children, visitor))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/internal.py", line 193, in visit_body_iterable
    new_child = child.visit(visitor)
                ^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_nodes/base.py", line 237, in visit
    leave_result = visitor.on_leave(self, with_updated_children)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/.venv/lib/python3.11/site-packages/libcst/_visitors.py", line 71, in on_leave
    updated_node = leave_func(original_node, updated_node)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/utils/modular_model_converter.py", line 365, in leave_FunctionDef
    original_modeling_method_body = self.original_modeling_methods[func_name].body.body
                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
KeyError: '__init__'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/javieryepez/Documents/Projects/opensource/transformers/utils/modular_model_converter.py", line 2039, in <module>
    pool.map(partial(run_converter, source_library=args.source_library), dependency_level_files)
  File "/Users/javieryepez/.local/share/uv/python/cpython-3.11.14-macos-aarch64-none/lib/python3.11/multiprocessing/pool.py", line 367, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/javieryepez/.local/share/uv/python/cpython-3.11.14-macos-aarch64-none/lib/python3.11/multiprocessing/pool.py", line 774, in get
    raise self._value
KeyError: '__init__'

@yonigozlan yonigozlan force-pushed the add_sam_3_lite_text branch from e5a5063 to 8f35675 Compare March 30, 2026 16:59
@vasqu
Copy link
Copy Markdown
Contributor

vasqu commented Apr 2, 2026

ping me when it's ready for review 🤗 not sure atm :p

@yonigozlan
Copy link
Copy Markdown
Member

Thanks for reviewing @vasqu ! It should be ready to merge now ;)

@yonigozlan yonigozlan requested a review from vasqu April 6, 2026 20:29
Copy link
Copy Markdown
Contributor

@vasqu vasqu left a comment

Choose a reason for hiding this comment

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

Sorry, found a few other smaller things. Shouldn't be anything big (and also some repeating stuff)

Comment thread docs/source/en/model_doc/nomic_bert.md
Comment thread docs/source/en/model_doc/sam3_lite_text.md Outdated
Comment on lines +59 to +60
model = AutoModel.from_pretrained("yonigozlan/sam3-litetext-s0", device_map="auto")
processor = AutoProcessor.from_pretrained("yonigozlan/sam3-litetext-s0")
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.

Are there any plans to move these to another repo?

Comment thread docs/source/en/model_doc/sam3_lite_text.md
Comment thread src/transformers/models/auto/processing_auto.py
Comment thread src/transformers/models/sam3_lite_text/modular_sam3_lite_text.py
Comment thread tests/models/sam3_lite_text/test_modeling_sam3_lite_text.py Outdated
Comment thread tests/models/sam3_lite_text/test_modeling_sam3_lite_text.py Outdated
Comment thread tests/models/sam3_lite_text/test_modeling_sam3_lite_text.py Outdated
Comment thread tests/models/sam3_lite_text/test_modeling_sam3_lite_text.py Outdated
Copy link
Copy Markdown
Contributor

@vasqu vasqu left a comment

Choose a reason for hiding this comment

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

I'm running slow tests in a second, I really only have the last nits left

Should be mergable today or tomorrow if we are fast enough :)

Comment on lines +48 to +51
window_size (`int`, *optional*, defaults to 24):
Window size for windowed attention.
global_attn_indexes (`list[int]`, *optional*, defaults to `[7, 15, 23, 31]`):
Indexes of layers with global attention.
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.

These are for the underlying auto models ig?

Comment on lines +46 to +47
rope_theta (`float`, *optional*, defaults to 10000.0):
Base frequency for RoPE.
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.

Should not be used at all, if anything we should change default theta (which is 10_000.0 already so no need to change)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It is generated by make fix-repo

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.

I see that it is indeed needed either way for the sam vit model but we should probably refactor this a bit to follow more standard RoPE implementations cc @yonigozlan

Comment thread tests/models/auto/test_image_processing_auto.py Outdated
Comment thread progress.md Outdated
Comment thread tests/models/sam3_lite_text/test_modeling_sam3_lite_text.py Outdated
@vasqu
Copy link
Copy Markdown
Contributor

vasqu commented Apr 13, 2026

run-slow: sam3_lite_text

@github-actions
Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["models/sam3_lite_text"]
quantizations: []

@github-actions
Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN 8a21b5fc workflow commit (merge commit)
PR fe153ad8 branch commit (from PR)
main a001f344 base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

@vasqu
Copy link
Copy Markdown
Contributor

vasqu commented Apr 13, 2026

run-slow: sam3, sam3_lite_text

@github-actions
Copy link
Copy Markdown
Contributor

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

run-slow: auto, sam3, sam3_lite_text, sam3_video

@github-actions
Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["models/sam3", "models/sam3_lite_text"]
quantizations: []

@github-actions
Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN 38f4d2a3 workflow commit (merge commit)
PR ccb49029 branch commit (from PR)
main 52f2268b base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

@vasqu vasqu added this pull request to the merge queue Apr 13, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Apr 13, 2026
@vasqu vasqu added this pull request to the merge queue Apr 13, 2026
Merged via the queue into huggingface:main with commit 22278df Apr 13, 2026
29 checks passed
@yonigozlan
Copy link
Copy Markdown
Member

Nice! I'll reach out to the authors to transfer the checkpoints

sirzechs66 pushed a commit to sirzechs66/transformers that referenced this pull request Apr 18, 2026
* Fix

* First draft

* Add push-to-hub options for SAM3-LiteText conversion

* Fix SAM3-LiteText model tests and text encoder init stability

* Add LiteText ViT auto mappings and use LiteText config

* Improve conversion script

* Do not require triton

* Improve modeling

* Fix repo

* Fix repo

* Add vision model to auto mapping

* Add missing entries to auto mapping

* reverse serve.py

* simplify implementation

* fix modular

* Address review comments

* fix repo

* fix after review 2

* fix tests + repo

* Address comments

* Address comments

* Make fix-repo

* add to hub cache + fixup base sam3 as well

---------

Co-authored-by: yonigozlan <yoni.gozlan@huggingface.co>
Co-authored-by: Yoni Gozlan <74535834+yonigozlan@users.noreply.github.com>
Co-authored-by: vasqu <antonprogamer@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding SAM3-LiteText

6 participants