Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

cli.py 5.9 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  1. import argparse
  2. import os
  3. import pprint
  4. import subprocess
  5. import sys
  6. import yaml
  7. arg_parser = argparse.ArgumentParser(
  8. description="T5 Summarisation Using Pytorch Lightning", prog="t5s"
  9. )
  10. # Command choice
  11. command_subparser = arg_parser.add_subparsers(
  12. dest="command", help="command (refer commands section in documentation)"
  13. )
  14. parser_req = command_subparser.add_parser(
  15. "requirements", help="Install Python Dependencies."
  16. )
  17. parser_start = command_subparser.add_parser("start", help="Define parameters")
  18. parser_start.add_argument(
  19. "-d",
  20. "--dataset",
  21. default="cnn_dailymail",
  22. help="Enter the name of the dataset to be used",
  23. type=str,
  24. )
  25. parser_start.add_argument(
  26. "-s", "--split", default=0.001, help="Enter the split required", type=float
  27. )
  28. parser_start.add_argument(
  29. "-n", "--name", default="summarsiation", help="Enter the name of the model"
  30. )
  31. parser_start.add_argument(
  32. "-mt", "--model_type", default="t5", help="Enter the model type", type=str
  33. )
  34. parser_start.add_argument(
  35. "-m",
  36. "--model_name",
  37. default="t5-base",
  38. help="Enter the model to be used eg t5-base",
  39. type=str,
  40. )
  41. parser_start.add_argument(
  42. "-e", "--epochs", default=5, help="Enter the number of epochs", type=int
  43. )
  44. parser_start.add_argument(
  45. "-lr",
  46. "--learning-rate",
  47. default=0.0001,
  48. help="Enter the number of epochs",
  49. type=float,
  50. )
  51. parser_start.add_argument(
  52. "-b", "--batch-size", default=2, help="Enter the number of batches", type=int
  53. )
  54. parser_dirs = command_subparser.add_parser(
  55. "dirs",
  56. help="Create directories that are ignored by git but required for the project",
  57. )
  58. parser_push = command_subparser.add_parser(
  59. "push", help="Upload Data to default DVC remote"
  60. )
  61. parser_pull = command_subparser.add_parser(
  62. "pull", help="Download Data from default DVC remote"
  63. )
  64. parser_run = command_subparser.add_parser(
  65. "run",
  66. help="run the DVC pipeline - recompute any modified outputs such as "
  67. "processed data or trained models",
  68. )
  69. parser_visualize = command_subparser.add_parser(
  70. "visualize", help="run the visualization using Streamlit"
  71. )
  72. parser_upload = command_subparser.add_parser(
  73. "upload", help="push the trained model to HF model hub"
  74. )
  75. parser_lint = command_subparser.add_parser("lint", help=" Lint using flake8")
  76. parser_clone = command_subparser.add_parser(
  77. "clone", help="Clone the T5 summarisation repo"
  78. )
  79. parser_clone.add_argument(
  80. "-u",
  81. "--username",
  82. help="Enter the your DAGsHub username that you have forked the main repo with",
  83. default="gagan3012",
  84. type=str,
  85. )
  86. class Run(object):
  87. def __init__(self, arguments: dict):
  88. self.arguments = arguments
  89. def execute(self):
  90. arguments = self.arguments
  91. print(f"arguments passed: {arguments['command']}")
  92. # os.chdir('../')
  93. cmd = [
  94. "requirements",
  95. "dirs",
  96. "push",
  97. "pull",
  98. "run",
  99. "visualize",
  100. "upload",
  101. "lint",
  102. ]
  103. if arguments["command"] == "clone":
  104. username = arguments["username"]
  105. list_files = subprocess.run(
  106. ["git", "clone", f"https://dagshub.com/{username}/summarization.git"]
  107. )
  108. os.chdir("./summarization/")
  109. retval = os.getcwd()
  110. print(retval)
  111. return list_files.returncode
  112. elif arguments["command"] == "start":
  113. os.chdir("./summarization/")
  114. print(
  115. """
  116. usage: t5s start [-h] [-d DATASET] [-s SPLIT] [-n NAME] [-mt MODEL_TYPE]
  117. [-m MODEL_NAME] [-e EPOCHS] [-lr LEARNING_RATE]
  118. [-b BATCH_SIZE]
  119. -h, --help show this help message and exit
  120. -d DATASET, --dataset DATASET
  121. Enter the name of the dataset to be used
  122. -s SPLIT, --split SPLIT
  123. Enter the split required
  124. -n NAME, --name NAME Enter the name of the model
  125. -mt MODEL_TYPE, --model_type MODEL_TYPE
  126. Enter the model type
  127. -m MODEL_NAME, --model_name MODEL_NAME
  128. Enter the model to be used eg t5-base
  129. -e EPOCHS, --epochs EPOCHS
  130. Enter the number of epochs
  131. -lr LEARNING_RATE, --learning-rate LEARNING_RATE
  132. Enter the number of epochs
  133. -b BATCH_SIZE, --batch-size BATCH_SIZE
  134. Enter the number of batches
  135. """
  136. )
  137. start(arguments=arguments)
  138. elif arguments["command"] in cmd:
  139. os.chdir("./summarization/")
  140. list_files = subprocess.run(["make", arguments["command"]])
  141. return list_files.returncode
  142. else:
  143. print("Command not supported")
  144. raise Exception
  145. def start(arguments):
  146. data_params = {"data": arguments["dataset"], "split": arguments["split"]}
  147. model_params = {
  148. "name": arguments["name"],
  149. "model_type": arguments["model_type"],
  150. "model_name": arguments["model_name"],
  151. "epochs": arguments["epochs"],
  152. "learning_rate": arguments["learning_rate"],
  153. "batch_size": arguments["batch_size"],
  154. }
  155. with open("data_params.yml", "w") as f:
  156. yaml.dump(data_params, f)
  157. with open("model_params.yml") as f:
  158. newdct = yaml.safe_load(f)
  159. newdct.update(model_params)
  160. with open("model_params.yml", "w") as f:
  161. yaml.dump(newdct, f)
  162. dicts = {}
  163. dicts.update(newdct)
  164. dicts.update(data_params)
  165. pprint.pprint("Final parameters for the run are: {}".format(dicts))
  166. def parse_args(args):
  167. arguments = vars(arg_parser.parse_args(args=args or ["--help"]))
  168. return arguments
  169. def main(args=None):
  170. if args is None:
  171. args = sys.argv[1:]
  172. parsed_args = parse_args(args=args)
  173. try:
  174. result = Run(arguments=parsed_args).execute()
  175. except Exception as e:
  176. print(str(e))
  177. result = 1
  178. sys.exit(result)
  179. if __name__ == "__main__":
  180. main()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...