Skip to content

[CI] Allow single file tests to run as fast tests - #14324

Merged
DN6 merged 15 commits into
mainfrom
single-file-test-update
Aug 19, 2026
Merged

DN6 merged 15 commits into
mainfrom
single-file-test-update

Conversation

@DN6

@DN6 DN6 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

We've had trouble running single file testing with fast tests for a while because creating a dummy checkpoint for models in their original format is non-trivial. In this PR, we leverage the fact that the hub allows downloading safetensors metadata via
HfApi().parse_safetensors_file_metadata. This includes information about the checkpoint keys, which we can use to build a dummy state dict with empty tensors on meta device. The primary thing we want to test with single file loading is the loading and conversion step, and we can use these dummy checkpoints for that purpose.

To run a check on whether converted parameters match 1:1 would still require downloading a real checkpoints, so we move just that test to nightly.

Also added coverage for models that support single file loading that were missed during the first test refactor pass.

Fixes # (issue)

Before submitting

  • Did you use an AI agent (Claude Code, Codex, Cursor, etc.) to help with this PR? If so:
    • Did you read the Coding with AI agents guide?
    • Did you run the self-review skill on the diff?
    • Did you share the final self-review notes in the PR description or a comment?
  • Did you read the contributor guideline?
  • Did you read our philosophy doc? (important for complex PRs)
  • 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?
  • Are you the author (or part of the team) of the model/pipeline (only applicable for model/pipeline related PRs)?

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.

@DN6
DN6 requested a review from sayakpaul July 29, 2026 16:41
@github-actions github-actions Bot added size/L PR with diff > 200 LOC tests single-file labels Jul 29, 2026
@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.

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

Really nice!

import torch
from huggingface_hub import hf_hub_download, snapshot_download
from accelerate import init_empty_weights

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.

Maybe we don't need init_empty_weights() here and we could just use with torch.device("meta")?

)
assert model_single_file.dtype == dtype, f"Expected dtype {dtype}, got {model_single_file.dtype}"

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.

Should it resemble

for name, param in model.named_parameters():
if any(module_to_keep_in_fp32 in name.split(".") for module_to_keep_in_fp32 in fp32_modules):
assert param.dtype == torch.float32, f"Parameter {name} should be float32 but got {param.dtype}"
else:
assert param.dtype == torch.float16, f"Parameter {name} should be float16 but got {param.dtype}"
?

@github-actions github-actions Bot added documentation Improvements or additions to documentation models utils CI labels Aug 14, 2026

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

Thanks! Just a few nits. Additionally, it would helpful to briefly summarize what's being tested (fast) in the single file test suite to get a quick idea. Optional though.

Comment thread .github/workflows/pr_tests.yml Outdated
Comment on lines +196 to +197
env:
HF_TOKEN: ""

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.

What is going here? IMO, it's better to scope the token to the steps where it's needed.

| `flash_varlen` | [FlashAttention](https://github.com/Dao-AILab/flash-attention) | Variable length FlashAttention |
| `flash_varlen_hub` | [FlashAttention](https://github.com/Dao-AILab/flash-attention) | Variable length FlashAttention from kernels |
| `aiter` | [AI Tensor Engine for ROCm](https://github.com/ROCm/aiter) | FlashAttention for AMD ROCm |
| `aiter_fa2_hub` | [AI Tensor Engine for ROCm](https://github.com/ROCm/aiter) | FlashAttention-2 for AMD ROCm from kernels |

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.

Seems unrelated but okay.

Comment on lines -757 to +771
target_key = "model.diffusion_model.patch_embedding.weight"
prefix = "model.diffusion_model."
else:
target_key = "patch_embedding.weight"
prefix = ""

target_key = f"{prefix}patch_embedding.weight"

if CHECKPOINT_KEY_NAMES["wan_vace"] in checkpoint:
if f"{prefix}{CHECKPOINT_KEY_NAMES['wan_vace']}" in checkpoint:

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.

Did these come about during writing the tests being added in this PR?

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.

Yup. VACE auto config loading wasn't working for models with keys prefixed with model.diffusion_model.

if torch.distributed.is_available():
import torch.distributed._functional_collectives as funcol

from ..utils import (

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.

Seems completely unrelated.

Comment thread tests/models/testing_utils/single_file.py Outdated
model = self.model_class.from_config(self.pretrained_model_name_or_path, **self.pretrained_model_kwargs)

config = model.config
model_single_file = self.model_class.from_single_file(self.get_dummy_single_file_state_dict(), device="meta")

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.

Curious. We're doing torch.empty with a meta device in get_dummy_single_file_state_dict(). Do we still need to pass "meta" here?

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.

torch.empty still allocates CPU memory. Setting to meta device avoids that.

# See the License for the specific language governing permissions and
# limitations under the License.

import functools

@sayakpaul sayakpaul Aug 18, 2026 •

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.

Also from the PR description:

To run a check on whether converted parameters match 1:1 would still require downloading a real checkpoints, so we move just that test to nightly.

Here I am guessing we want to test if the from_single_file() path and the respective from_pretrained() path lead to the same results? But I didn't see any such tests. Maybe I am missing something. Which test did you refer to here? from_pretrained() params and from_single_file() params match with one another?

Edit: nevermind. I think you referred to test_single_file_model_parameters().

@github-actions github-actions Bot removed documentation Improvements or additions to documentation models utils labels Aug 18, 2026
# Conflicts:
#	tests/models/transformers/test_models_transformer_sd3.py
@DN6
DN6 merged commit aeda394 into main Aug 19, 2026
18 of 20 checks passed
@DN6
DN6 deleted the single-file-test-update branch August 19, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants