Skip to content

Add Sapiens2 Model - #45919

Merged
guarin merged 201 commits into
huggingface:mainfrom
guarin:add-sapiens2
Jun 3, 2026
Merged

guarin merged 201 commits into
huggingface:mainfrom
guarin:add-sapiens2

Conversation

@guarin

@guarin guarin commented May 12, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

  • Adds the new Sapiens2 model from Meta

There is an open PR for the original Sapiens model (v1) from 2024: #33167 I started from scratch for v2 as it supersedes the old version.

Sapiens2 repo: https://github.com/facebookresearch/sapiens2

TODO before merge

  • Drop cv2 dependency?
  • Re-use pose pre- and post-processing from ViTPose where possible
  • Update docs
  • Tidy up all docstrings
  • Once config is settled, create PR to hub with model and processor configs
  • Add flip test?
  • Handle num_first_full_attention_layers and num_last_full_attention_layers
  • Check layer inits
  • Double check output formats for all tasks
  • Add test for composite
  • Check config.layer_norm_eps and config.apply_layernorm

Open PRs on the hub:

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.

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

@molbap molbap left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice! Left a small initial review

Comment thread docs/source/en/model_doc/sapiens2.md Resolved
Comment thread src/transformers/conversion_mapping.py Resolved
@guarin

guarin commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

run-slow: auto, sapiens2

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

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

models: ["models/auto", "models/sapiens2"]
quantizations: []

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN 902bf705 workflow commit (merge commit)
PR f5eb93a0 branch commit (from PR)
main 31637182 base commit (on main)

⚠️ Model CI failed to report results

The test failure analysis could not be completed. Please check the workflow run for details.

@guarin

guarin commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

run-slow: auto, sapiens2

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

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

models: ["models/auto", "models/sapiens2"]
quantizations: []

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN 7316ffa9 workflow commit (merge commit)
PR 54cdcacd branch commit (from PR)
main a46a7325 base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

@guarin
guarin added this pull request to the merge queue Jun 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 3, 2026
@guarin

guarin commented Jun 3, 2026

Copy link
Copy Markdown
Member Author

run-slow: auto, sapiens2

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

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

run-slow: auto, sapiens2

1 similar comment
@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

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

run-slow: auto, sapiens2

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

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

models: ["models/auto", "models/sapiens2"]
quantizations: []

@github-actions

github-actions Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN 0d3d550d workflow commit (merge commit)
PR b1a6041c branch commit (from PR)
main 595721c4 base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

@guarin
guarin added this pull request to the merge queue Jun 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 3, 2026
@guarin
guarin added this pull request to the merge queue Jun 3, 2026
Merged via the queue into huggingface:main with commit e820678 Jun 3, 2026
119 checks passed
@guarin
guarin deleted the add-sapiens2 branch June 3, 2026 10:22
khushali9 pushed a commit to khushali9/transformers that referenced this pull request Jun 8, 2026
* Add sapiens2

* Add attention

* Add todo

* Update norm

* fix-repo

* Amend

* Fix tests

* Update license

* Fix docstrings

* Add backbone test

* Fix rescale

* Add checkpoint conversion

* Add expected logits

* Remove unused class definitions

* Default to bf16 for rope

* Update layer_norm_eps

* Update test

* Update rope and test

* Format

* Handle layernorm

* Add layer_types

* Update image loading in test

* Add docs

* Update config attributes

* Add semantic segmentation

* Update logits for 1024x768

* Update logits for 1024x768

* Update seg conversion

* Update seg inference tests

* Add segmentation docs

* Add masks preprocessing

* Move head args to config

* Add pose head

* Add pose mapping

* Add pose image processing

* Update test inference configs

* Fix test

* Update test configs

* Update expected heatmap size

* Fix pose processing

* Add to ignore_non_auto

* Fix test

* Format

* Update kv group handling

* Update conv layer

* Remove pose head

* Deduplicate image processing code

* Fix modeling

* Fix mapping

* Move image processing to top

* Remove todo

* Add normal estimation

* Fix normal

* Add normal test logits

* Remove original_sizes

* Add pointmap estimation

* Update pointmap tests

* Refactor scale head

* Adjust tol

* Cleanup

* Add matting

* Update tests

* Move comment

* Fix head inits

* Refactor heads

* Fix test

* Speed up tests

* Fix test

* More test cleanup

* Add cuddn.deterministic = True

* Add matting tests

* Use num_key_value_heads_per_layer

* Cleanup tests

* Cleanup docstrings

* Cleanup docstrings

* Update docs

* Add flip_pairs

* Remove check

* Remove todos

* Add matting composite

* Add flip test

* Add matting background test

* Fix test

* Fix test

* Simplify rope

* Fix test

* Try replace periods with inv_freq

* Try replace periods with inv_freq

* Inherit from DINOv3RopePositionEmbedding

* Fix rope dtype

* Fix rope

* Update docs

* Use revision in tests

* Remove default head configs

* Update automodels

* Fix pose bbox output

* Add target_sizes to post_process_pose_estimation

* Fix docs

* Format

* Add flip_pairs to config

* Use dinov3 rope

* Fix

* Fix

* Remove cv2 dependency from processing

* Remove np dependency from processing

* Cleanup

* Batch pose pre- and post-processing

* Fix tests

* Fix pose bbox postprocessing

* Cleanup

* Batch crop_and_resize

* Add outputs_flipped

* Return normals as dict

* Return dict from pointmaps

* Cleanup

* Update docs

* Remove cxcywh in function names

* Clarify boxes shapes

* Cleanup hessian computation

* Cleanup processor inheritance

* Cleanup processor inheritance

* Rename Matting to ImageMatting following VitMatte

* Inherit vitpose output

* Cleanup

* Use LlamaRMSNorm

* Merge conv layers

* Merge PixelShuffle

* Merge heads

* Refactor final layer

* Add head_scale_final_input_size to config

* Rename to model

* Cleanup _init_weights

* Remove post_init()

* Cleanup tests

* Add head_config

* Speed up postprocessors

* Add flip_pairs to config

* Fix head config docstring

* Add head config to docs

* Cleanup

* Add auto models

* Use analytical hessian solution

* Rename boxes

* Update mask_token handling

* Update config

* Update configs

* Update docs

* Cleanup patch size handling

* Use hfoption

* Cleanup var names

* Fix auto

* Fix automodel

* Adress review

* Cleanup docs

* Cleanup scale_final_input_size init

* Add spacing

* Cleanup

* Remove layer_norm_eps and apply_layernorm from config

* Update Sapiens2ConvLayer

* Add decorators for task model forward again

* Update docs

* Cleanup boxes

* Remove last_hidden_state from backbone output

* Remove redundant test

* Added PPOCRV5ServerDetConvBatchnormLayer again

* Remove revision

* Remove hopper expectation in tests

* Fix DataParallel forward

* Ignore missing mask token

* Update publish date

* fix: Upload test images to hf-internal-testing
stevhliu pushed a commit to stevhliu/transformers that referenced this pull request Jul 30, 2026
* Add sapiens2

* Add attention

* Add todo

* Update norm

* fix-repo

* Amend

* Fix tests

* Update license

* Fix docstrings

* Add backbone test

* Fix rescale

* Add checkpoint conversion

* Add expected logits

* Remove unused class definitions

* Default to bf16 for rope

* Update layer_norm_eps

* Update test

* Update rope and test

* Format

* Handle layernorm

* Add layer_types

* Update image loading in test

* Add docs

* Update config attributes

* Add semantic segmentation

* Update logits for 1024x768

* Update logits for 1024x768

* Update seg conversion

* Update seg inference tests

* Add segmentation docs

* Add masks preprocessing

* Move head args to config

* Add pose head

* Add pose mapping

* Add pose image processing

* Update test inference configs

* Fix test

* Update test configs

* Update expected heatmap size

* Fix pose processing

* Add to ignore_non_auto

* Fix test

* Format

* Update kv group handling

* Update conv layer

* Remove pose head

* Deduplicate image processing code

* Fix modeling

* Fix mapping

* Move image processing to top

* Remove todo

* Add normal estimation

* Fix normal

* Add normal test logits

* Remove original_sizes

* Add pointmap estimation

* Update pointmap tests

* Refactor scale head

* Adjust tol

* Cleanup

* Add matting

* Update tests

* Move comment

* Fix head inits

* Refactor heads

* Fix test

* Speed up tests

* Fix test

* More test cleanup

* Add cuddn.deterministic = True

* Add matting tests

* Use num_key_value_heads_per_layer

* Cleanup tests

* Cleanup docstrings

* Cleanup docstrings

* Update docs

* Add flip_pairs

* Remove check

* Remove todos

* Add matting composite

* Add flip test

* Add matting background test

* Fix test

* Fix test

* Simplify rope

* Fix test

* Try replace periods with inv_freq

* Try replace periods with inv_freq

* Inherit from DINOv3RopePositionEmbedding

* Fix rope dtype

* Fix rope

* Update docs

* Use revision in tests

* Remove default head configs

* Update automodels

* Fix pose bbox output

* Add target_sizes to post_process_pose_estimation

* Fix docs

* Format

* Add flip_pairs to config

* Use dinov3 rope

* Fix

* Fix

* Remove cv2 dependency from processing

* Remove np dependency from processing

* Cleanup

* Batch pose pre- and post-processing

* Fix tests

* Fix pose bbox postprocessing

* Cleanup

* Batch crop_and_resize

* Add outputs_flipped

* Return normals as dict

* Return dict from pointmaps

* Cleanup

* Update docs

* Remove cxcywh in function names

* Clarify boxes shapes

* Cleanup hessian computation

* Cleanup processor inheritance

* Cleanup processor inheritance

* Rename Matting to ImageMatting following VitMatte

* Inherit vitpose output

* Cleanup

* Use LlamaRMSNorm

* Merge conv layers

* Merge PixelShuffle

* Merge heads

* Refactor final layer

* Add head_scale_final_input_size to config

* Rename to model

* Cleanup _init_weights

* Remove post_init()

* Cleanup tests

* Add head_config

* Speed up postprocessors

* Add flip_pairs to config

* Fix head config docstring

* Add head config to docs

* Cleanup

* Add auto models

* Use analytical hessian solution

* Rename boxes

* Update mask_token handling

* Update config

* Update configs

* Update docs

* Cleanup patch size handling

* Use hfoption

* Cleanup var names

* Fix auto

* Fix automodel

* Adress review

* Cleanup docs

* Cleanup scale_final_input_size init

* Add spacing

* Cleanup

* Remove layer_norm_eps and apply_layernorm from config

* Update Sapiens2ConvLayer

* Add decorators for task model forward again

* Update docs

* Cleanup boxes

* Remove last_hidden_state from backbone output

* Remove redundant test

* Added PPOCRV5ServerDetConvBatchnormLayer again

* Remove revision

* Remove hopper expectation in tests

* Fix DataParallel forward

* Ignore missing mask token

* Update publish date

* fix: Upload test images to hf-internal-testing
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.

6 participants