Repository navigation
[CI] Allow single file tests to run as fast tests - #14324
Conversation
|
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. |
| import torch | ||
| from huggingface_hub import hf_hub_download, snapshot_download | ||
| from accelerate import init_empty_weights |
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
Should it resemble
diffusers/tests/models/testing_utils/common.py
Lines 519 to 523 in 3c46892
… FlashAttention (drop `aiter` dependency) (#14436) Use Hub kernel Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
sayakpaul
left a comment
There was a problem hiding this comment.
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.
| env: | ||
| HF_TOKEN: "" |
There was a problem hiding this comment.
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 | |
| 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: |
There was a problem hiding this comment.
Did these come about during writing the tests being added in this PR?
There was a problem hiding this comment.
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 ( |
| 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") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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().
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
# Conflicts: # tests/models/transformers/test_models_transformer_sd3.py
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
self-reviewskill on the diff?documentation guidelines, and
here are tips on formatting docstrings.
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.