[tests] add test for hotswapping + compilation on resolution changes#11825
[tests] add test for hotswapping + compilation on resolution changes#11825
Conversation
|
Cc: @StrongerXi and @anijain2305 as well. |
| new_model = self.model_class.from_pretrained(tmp_dir, device_map="auto", max_memory=max_memory) | ||
| # Making sure part of the model will actually end up offloaded | ||
| self.assertSetEqual(set(new_model.hf_device_map.values()), {0, 1}) | ||
| print(f" new_model.hf_device_map:{new_model.hf_device_map}") |
There was a problem hiding this comment.
Unrelated but hopefully okay :-)
tests/models/test_modeling_common.py
Outdated
| if different_resolutions is not None: | ||
| for height, width in self.different_shapes_for_compilation: | ||
| new_inputs_dict = self.prepare_dummy_input(height=height, width=width) | ||
| _ = model(**new_inputs_dict) | ||
| else: | ||
| output0_after = model(**inputs_dict)["sample"] | ||
| assert torch.allclose(output0_before, output0_after, atol=tol, rtol=tol) |
There was a problem hiding this comment.
We don't need assertions when testing for different shapes as that would make the test unnecessarily complicated. We just check for recompilations.
|
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. |
BenjaminBossan
left a comment
There was a problem hiding this comment.
Thanks for extending the hotswapping tests. Overall looks good, but I have some suggestions.
BenjaminBossan
left a comment
There was a problem hiding this comment.
Thanks, I learned something new about torch.compile. LGTM.
| > [!TIP] | ||
| > Move your code inside the `with torch._dynamo.config.patch(error_on_recompile=True)` context manager to detect if a model was recompiled. If a model is recompiled despite following all the steps above, please open an [issue](https://github.com/huggingface/diffusers/issues) with a reproducible example. | ||
|
|
||
| If you expect to varied resolutions during inference with this feature, then make sure set `dynamic=True` during compilation. Refer to [this document](../optimization/fp16#dynamic-shape-compilation) for more details. |
There was a problem hiding this comment.
I wonder if we should publicize use_duck_shape = False as well...
…uggingface#11825) * add resolution changes tests to hotswapping test suite. * fixes * docs * explain duck shapes * fix
What does this PR do?
As promised :)