Commit
·
de70c0a
1
Parent(s):
42bb292
Update script.py
Browse files
script.py
CHANGED
@@ -4,7 +4,17 @@ from safetensors.torch import load_file
|
|
4 |
from diffusers import AutoPipelineForText2Image
|
5 |
import torch
|
6 |
import re
|
|
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
def do_train(script_args):
|
9 |
# Pass all arguments to trainer.py
|
10 |
subprocess.run(['python', 'trainer.py'] + script_args)
|
@@ -51,30 +61,31 @@ def do_inference(dataset_name, output_dir, num_tokens):
|
|
51 |
repo_id=f"{username}/{output_dir}",
|
52 |
repo_type="model",
|
53 |
)
|
|
|
|
|
|
|
|
|
54 |
def main():
|
55 |
# Capture all arguments except the script name
|
56 |
-
print(sys.argv)
|
57 |
script_args = sys.argv[1:]
|
58 |
-
print(script_args)
|
59 |
-
# Extract dataset_name argument
|
60 |
-
dataset_name = None
|
61 |
-
output_dir = None
|
62 |
-
for arg in script_args:
|
63 |
-
if arg.startswith('--dataset_name='):
|
64 |
-
dataset_name = arg.split('=')[1]
|
65 |
-
continue
|
66 |
-
if arg.startswith('--output_dir='):
|
67 |
-
output_dir = arg.split('=')[1]
|
68 |
-
continue
|
69 |
-
if arg.startswith('--train_text_encoder_ti'):
|
70 |
-
num_tokens = 0
|
71 |
-
elif arg.startswith('--num_new_tokens_per_abstraction='):
|
72 |
-
num_tokens = arg.split('=')[1]
|
73 |
-
if dataset_name is None or output_dir is None:
|
74 |
-
raise ValueError("Dataset name not provided.")
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
do_train(script_args)
|
77 |
-
do_inference(dataset_name, output_dir,
|
78 |
|
79 |
if __name__ == "__main__":
|
80 |
main()
|
|
|
4 |
from diffusers import AutoPipelineForText2Image
|
5 |
import torch
|
6 |
import re
|
7 |
+
import argparse
|
8 |
|
9 |
+
def parse_arguments():
|
10 |
+
parser = argparse.ArgumentParser(description="Process script arguments.")
|
11 |
+
parser.add_argument('--dataset_name', required=True, help='Name of the dataset.')
|
12 |
+
parser.add_argument('--output_dir', required=True, help='Output directory.')
|
13 |
+
parser.add_argument('--num_new_tokens_per_abstraction', type=int, default=0, help='Number of new tokens per abstraction.')
|
14 |
+
parser.add_argument('--train_text_encoder_ti', action='store_true', help='Flag to train text encoder TI.')
|
15 |
+
|
16 |
+
return parser.parse_args()
|
17 |
+
|
18 |
def do_train(script_args):
|
19 |
# Pass all arguments to trainer.py
|
20 |
subprocess.run(['python', 'trainer.py'] + script_args)
|
|
|
61 |
repo_id=f"{username}/{output_dir}",
|
62 |
repo_type="model",
|
63 |
)
|
64 |
+
|
65 |
+
import sys
|
66 |
+
import argparse
|
67 |
+
|
68 |
def main():
|
69 |
# Capture all arguments except the script name
|
|
|
70 |
script_args = sys.argv[1:]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
+
# Create the argument parser
|
73 |
+
parser = argparse.ArgumentParser()
|
74 |
+
parser.add_argument('--dataset_name', required=True)
|
75 |
+
parser.add_argument('--output_dir', required=True)
|
76 |
+
parser.add_argument('--num_new_tokens_per_abstraction', type=int, default=0)
|
77 |
+
parser.add_argument('--train_text_encoder_ti', action='store_true')
|
78 |
+
|
79 |
+
# Parse known arguments
|
80 |
+
args, _ = parser.parse_known_args(script_args)
|
81 |
+
|
82 |
+
# Set num_tokens to 0 if '--train_text_encoder_ti' is not present
|
83 |
+
if not args.train_text_encoder_ti:
|
84 |
+
args.num_new_tokens_per_abstraction = 0
|
85 |
+
|
86 |
+
# Proceed with training and inference
|
87 |
do_train(script_args)
|
88 |
+
do_inference(args.dataset_name, args.output_dir, args.num_new_tokens_per_abstraction)
|
89 |
|
90 |
if __name__ == "__main__":
|
91 |
main()
|