NeverMore0123 commited on
Commit
9ff0e10
·
1 Parent(s): f94301b

add download model and how to use

Browse files
Files changed (3) hide show
  1. README.md +35 -0
  2. download_autoregressive.py +3 -34
  3. video2world_hf.py +3 -4
README.md CHANGED
@@ -1,3 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  ![Cosmos Logo](assets/cosmos-logo.png)
3
 
 
1
+ ## How to Use
2
+
3
+ '''python
4
+ from transformers import AutoModel
5
+
6
+ model = AutoModel.from_pretrained(
7
+ "NeverMore0123/AutoregressiveVideo2WorldGeneration",
8
+ cache_dir="./cache",
9
+ trust_remote_code=True,
10
+
11
+ input_type = "text_and_image",
12
+ num_input_frames = 1,
13
+ prompt = "A video recorded from a moving vehicle's perspective, capturing roads, buildings, landscapes, and changing weather and lighting conditions." ,
14
+ input_image_or_video_path = "AutoregressiveVideo2WorldGeneration/cosmos1/models/autoregressive/assets/v1p0/input.jpg",
15
+ video_save_name = "diffusion_decoder_image_output",
16
+ ar_model_dir = "Cosmos-1.0-Autoregressive-5B-Video2World",
17
+
18
+ # input_type = "text_and_video",
19
+ # num_input_frames = 9,
20
+ # prompt = "A video recorded from a moving vehicle's perspective, capturing roads, buildings, landscapes, and changing weather and lighting conditions." ,
21
+ # input_image_or_video_path = "AutoregressiveVideo2WorldGeneration/cosmos1/models/autoregressive/assets/v1p0/input.mp4",
22
+ # video_save_name = "diffusion_decoder_video_output",
23
+
24
+ # turn on offloading on a low GPU memory machine:
25
+ disable_diffusion_decoder=False,
26
+ offload_guardrail_models=True,
27
+ offload_diffusion_decoder=True,
28
+ offload_network=True,
29
+ offload_tokenizer=True,
30
+ offload_text_encoder_model=True,
31
+ )
32
+
33
+ model()
34
+ '''
35
+
36
 
37
  ![Cosmos Logo](assets/cosmos-logo.png)
38
 
download_autoregressive.py CHANGED
@@ -18,34 +18,7 @@ from pathlib import Path
18
 
19
  from huggingface_hub import snapshot_download
20
 
21
-
22
- def parse_args():
23
- parser = argparse.ArgumentParser(description="Download NVIDIA Cosmos-1.0 Autoregressive models from Hugging Face")
24
- parser.add_argument(
25
- "--model_sizes",
26
- nargs="*",
27
- default=[
28
- "4B",
29
- "5B",
30
- ], # Download all by default
31
- choices=["4B", "5B", "12B", "13B"],
32
- help="Which model sizes to download. Possible values: 4B, 5B, 12B, 13B.",
33
- )
34
- parser.add_argument(
35
- "--cosmos_version",
36
- type=str,
37
- default="1.0",
38
- choices=["1.0"],
39
- help="Which version of Cosmos to download. Only 1.0 is available at the moment.",
40
- )
41
- parser.add_argument(
42
- "--checkpoint_dir", type=str, default="checkpoints", help="Directory to save the downloaded checkpoints."
43
- )
44
- args = parser.parse_args()
45
- return args
46
-
47
-
48
- def main(args):
49
  ORG_NAME = "nvidia"
50
 
51
  # Mapping from size argument to Hugging Face repository name
@@ -65,13 +38,13 @@ def main(args):
65
  ]
66
 
67
  # Create local checkpoints folder
68
- checkpoints_dir = Path(args.checkpoint_dir)
69
  checkpoints_dir.mkdir(parents=True, exist_ok=True)
70
 
71
  download_kwargs = dict(allow_patterns=["README.md", "model.pt", "config.json", "*.jit"])
72
 
73
  # Download the requested Autoregressive models
74
- for size in args.model_sizes:
75
  model_name = model_map[size]
76
  repo_id = f"{ORG_NAME}/{model_name}"
77
  local_dir = checkpoints_dir.joinpath(model_name)
@@ -99,7 +72,3 @@ def main(args):
99
  local_dir_use_symlinks=False,
100
  )
101
 
102
-
103
- if __name__ == "__main__":
104
- args = parse_args()
105
- main(args)
 
18
 
19
  from huggingface_hub import snapshot_download
20
 
21
+ def main(model_sizes, checkpoint_dir="checkpoints"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  ORG_NAME = "nvidia"
23
 
24
  # Mapping from size argument to Hugging Face repository name
 
38
  ]
39
 
40
  # Create local checkpoints folder
41
+ checkpoints_dir = Path(checkpoint_dir)
42
  checkpoints_dir.mkdir(parents=True, exist_ok=True)
43
 
44
  download_kwargs = dict(allow_patterns=["README.md", "model.pt", "config.json", "*.jit"])
45
 
46
  # Download the requested Autoregressive models
47
+ for size in model_sizes:
48
  model_name = model_map[size]
49
  repo_id = f"{ORG_NAME}/{model_name}"
50
  local_dir = checkpoints_dir.joinpath(model_name)
 
72
  local_dir_use_symlinks=False,
73
  )
74
 
 
 
 
 
video2world_hf.py CHANGED
@@ -24,7 +24,7 @@ from .ar_utils_inference import load_vision_input, validate_args
24
  from .log import log
25
  from .io import read_prompts_from_file
26
 
27
- # from download_autoregressive import main as download_autoregressive
28
  from transformers import PreTrainedModel, PretrainedConfig
29
 
30
 
@@ -142,8 +142,7 @@ class ARVideo2World(PreTrainedModel):
142
  other_args = kwargs.copy()
143
  other_args.pop("config")
144
  config.update(other_args)
145
- # model_sizes = ["5B",] if "5B" in config.ar_model_dir else ["13B",]
146
- # model_types = ["Video2World",]
147
- # download_autoregressive(model_types, model_sizes, config.checkpoint_dir)
148
  model = cls(config)
149
  return model
 
24
  from .log import log
25
  from .io import read_prompts_from_file
26
 
27
+ from .download_autoregressive import main as download_autoregressive
28
  from transformers import PreTrainedModel, PretrainedConfig
29
 
30
 
 
142
  other_args = kwargs.copy()
143
  other_args.pop("config")
144
  config.update(other_args)
145
+ model_sizes = ["5B",] if "5B" in config.ar_model_dir else ["13B",]
146
+ download_autoregressive(model_sizes, config.checkpoint_dir)
 
147
  model = cls(config)
148
  return model