Instructions to use nvidia/Cosmos3-Edge-FP8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Cosmos
How to use nvidia/Cosmos3-Edge-FP8 with Cosmos:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Commit ·
5ee4fdd
1
Parent(s): 5f1f58b
docs: enable ModelOpt FP8 for Diffusers (#3)
Browse files- docs: enable ModelOpt FP8 for Diffusers (b3af554762f228c412a93530806f8cadb9b56917)
Co-authored-by: Yiming Zhao <ConstBob@users.noreply.huggingface.co>
README.md
CHANGED
|
@@ -650,6 +650,7 @@ uv pip install \
|
|
| 650 |
huggingface_hub \
|
| 651 |
imageio \
|
| 652 |
imageio-ffmpeg \
|
|
|
|
| 653 |
torch \
|
| 654 |
torchvision \
|
| 655 |
transformers
|
|
@@ -659,23 +660,32 @@ uv pip install \
|
|
| 659 |
|
| 660 |
The examples use the inputs in this repository's `assets/` directory. Run them from the model repository root.
|
| 661 |
|
|
|
|
|
|
|
| 662 |
##### Image to video generation
|
| 663 |
|
| 664 |
```python
|
| 665 |
import json
|
| 666 |
from pathlib import Path
|
| 667 |
|
|
|
|
| 668 |
import torch
|
| 669 |
from diffusers import Cosmos3OmniPipeline
|
| 670 |
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
|
| 671 |
from diffusers.utils import export_to_video, load_image
|
|
|
|
|
|
|
| 672 |
|
| 673 |
# Read the JSON-upsampled positive and negative prompts.
|
| 674 |
json_prompt = json.loads(Path("assets/example_i2v_prompt.json").read_text())
|
| 675 |
negative_prompt = json.loads(Path("assets/negative_prompt.json").read_text())
|
| 676 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 677 |
pipe = Cosmos3OmniPipeline.from_pretrained(
|
| 678 |
-
|
| 679 |
torch_dtype=torch.bfloat16,
|
| 680 |
enable_safety_checker=True,
|
| 681 |
)
|
|
@@ -724,17 +734,24 @@ This two-chunk UMI rollout conditions the first chunk on `assets/example_action_
|
|
| 724 |
import json
|
| 725 |
from pathlib import Path
|
| 726 |
|
|
|
|
| 727 |
import torch
|
| 728 |
from diffusers import Cosmos3OmniPipeline, CosmosActionCondition
|
| 729 |
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
|
| 730 |
from diffusers.utils import export_to_video, load_image
|
|
|
|
|
|
|
| 731 |
|
| 732 |
action_spec = json.loads(Path("assets/example_action_fd_umi_action_chunks.json").read_text())
|
| 733 |
output_dir = Path("assets/diffusers_outputs")
|
| 734 |
output_dir.mkdir(parents=True, exist_ok=True)
|
| 735 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 736 |
pipe = Cosmos3OmniPipeline.from_pretrained(
|
| 737 |
-
|
| 738 |
torch_dtype=torch.bfloat16,
|
| 739 |
enable_safety_checker=True,
|
| 740 |
)
|
|
@@ -793,10 +810,13 @@ This example predicts the 60-step, 9-D AV action sequence that connects each 61-
|
|
| 793 |
import json
|
| 794 |
from pathlib import Path
|
| 795 |
|
|
|
|
| 796 |
import torch
|
| 797 |
from diffusers import Cosmos3OmniPipeline, CosmosActionCondition
|
| 798 |
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
|
| 799 |
from diffusers.utils import load_video
|
|
|
|
|
|
|
| 800 |
|
| 801 |
input_videos = {
|
| 802 |
"av_inverse_0": Path("assets/example_action_id_av_0_input.mp4"),
|
|
@@ -805,8 +825,12 @@ input_videos = {
|
|
| 805 |
output_dir = Path("assets/diffusers_outputs")
|
| 806 |
output_dir.mkdir(parents=True, exist_ok=True)
|
| 807 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 808 |
pipe = Cosmos3OmniPipeline.from_pretrained(
|
| 809 |
-
|
| 810 |
torch_dtype=torch.bfloat16,
|
| 811 |
enable_safety_checker=True,
|
| 812 |
)
|
|
|
|
| 650 |
huggingface_hub \
|
| 651 |
imageio \
|
| 652 |
imageio-ffmpeg \
|
| 653 |
+
nvidia-modelopt==0.44.0 \
|
| 654 |
torch \
|
| 655 |
torchvision \
|
| 656 |
transformers
|
|
|
|
| 660 |
|
| 661 |
The examples use the inputs in this repository's `assets/` directory. Run them from the model repository root.
|
| 662 |
|
| 663 |
+
Enable ModelOpt checkpoint restoration before loading each pipeline. The explicit `hf_hub_download` ensures `transformer/modelopt_state.pth` is present even though it is not included in Diffusers' default Hub download allowlist.
|
| 664 |
+
|
| 665 |
##### Image to video generation
|
| 666 |
|
| 667 |
```python
|
| 668 |
import json
|
| 669 |
from pathlib import Path
|
| 670 |
|
| 671 |
+
import modelopt.torch.quantization.backends.fp8_per_tensor_gemm # noqa: F401
|
| 672 |
import torch
|
| 673 |
from diffusers import Cosmos3OmniPipeline
|
| 674 |
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
|
| 675 |
from diffusers.utils import export_to_video, load_image
|
| 676 |
+
from huggingface_hub import hf_hub_download
|
| 677 |
+
from modelopt.torch.opt import enable_huggingface_checkpointing
|
| 678 |
|
| 679 |
# Read the JSON-upsampled positive and negative prompts.
|
| 680 |
json_prompt = json.loads(Path("assets/example_i2v_prompt.json").read_text())
|
| 681 |
negative_prompt = json.loads(Path("assets/negative_prompt.json").read_text())
|
| 682 |
|
| 683 |
+
model_id = "nvidia/Cosmos3-Edge-FP8"
|
| 684 |
+
enable_huggingface_checkpointing()
|
| 685 |
+
hf_hub_download(repo_id=model_id, filename="transformer/modelopt_state.pth")
|
| 686 |
+
|
| 687 |
pipe = Cosmos3OmniPipeline.from_pretrained(
|
| 688 |
+
model_id,
|
| 689 |
torch_dtype=torch.bfloat16,
|
| 690 |
enable_safety_checker=True,
|
| 691 |
)
|
|
|
|
| 734 |
import json
|
| 735 |
from pathlib import Path
|
| 736 |
|
| 737 |
+
import modelopt.torch.quantization.backends.fp8_per_tensor_gemm # noqa: F401
|
| 738 |
import torch
|
| 739 |
from diffusers import Cosmos3OmniPipeline, CosmosActionCondition
|
| 740 |
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
|
| 741 |
from diffusers.utils import export_to_video, load_image
|
| 742 |
+
from huggingface_hub import hf_hub_download
|
| 743 |
+
from modelopt.torch.opt import enable_huggingface_checkpointing
|
| 744 |
|
| 745 |
action_spec = json.loads(Path("assets/example_action_fd_umi_action_chunks.json").read_text())
|
| 746 |
output_dir = Path("assets/diffusers_outputs")
|
| 747 |
output_dir.mkdir(parents=True, exist_ok=True)
|
| 748 |
|
| 749 |
+
model_id = "nvidia/Cosmos3-Edge-FP8"
|
| 750 |
+
enable_huggingface_checkpointing()
|
| 751 |
+
hf_hub_download(repo_id=model_id, filename="transformer/modelopt_state.pth")
|
| 752 |
+
|
| 753 |
pipe = Cosmos3OmniPipeline.from_pretrained(
|
| 754 |
+
model_id,
|
| 755 |
torch_dtype=torch.bfloat16,
|
| 756 |
enable_safety_checker=True,
|
| 757 |
)
|
|
|
|
| 810 |
import json
|
| 811 |
from pathlib import Path
|
| 812 |
|
| 813 |
+
import modelopt.torch.quantization.backends.fp8_per_tensor_gemm # noqa: F401
|
| 814 |
import torch
|
| 815 |
from diffusers import Cosmos3OmniPipeline, CosmosActionCondition
|
| 816 |
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
|
| 817 |
from diffusers.utils import load_video
|
| 818 |
+
from huggingface_hub import hf_hub_download
|
| 819 |
+
from modelopt.torch.opt import enable_huggingface_checkpointing
|
| 820 |
|
| 821 |
input_videos = {
|
| 822 |
"av_inverse_0": Path("assets/example_action_id_av_0_input.mp4"),
|
|
|
|
| 825 |
output_dir = Path("assets/diffusers_outputs")
|
| 826 |
output_dir.mkdir(parents=True, exist_ok=True)
|
| 827 |
|
| 828 |
+
model_id = "nvidia/Cosmos3-Edge-FP8"
|
| 829 |
+
enable_huggingface_checkpointing()
|
| 830 |
+
hf_hub_download(repo_id=model_id, filename="transformer/modelopt_state.pth")
|
| 831 |
+
|
| 832 |
pipe = Cosmos3OmniPipeline.from_pretrained(
|
| 833 |
+
model_id,
|
| 834 |
torch_dtype=torch.bfloat16,
|
| 835 |
enable_safety_checker=True,
|
| 836 |
)
|