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

gandlf_deploy 3.6 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
  1. #!usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import argparse
  4. import ast
  5. import os
  6. from GANDLF.cli import (
  7. deploy_targets,
  8. mlcube_types,
  9. run_deployment,
  10. recover_config,
  11. copyrightMessage,
  12. )
  13. if __name__ == "__main__":
  14. parser = argparse.ArgumentParser(
  15. prog="GANDLF_Deploy",
  16. formatter_class=argparse.RawTextHelpFormatter,
  17. description="Generate frozen/deployable versions of trained GaNDLF models.\n\n"
  18. + copyrightMessage,
  19. )
  20. parser.add_argument(
  21. "-m",
  22. "--model",
  23. metavar="",
  24. type=str,
  25. help="Path to the model directory you wish to deploy. Required for model MLCubes, ignored for metrics MLCubes.",
  26. default=None,
  27. )
  28. parser.add_argument(
  29. "-c",
  30. "--config",
  31. metavar="",
  32. type=str,
  33. default=None,
  34. help="Optional path to an alternative config file to be embedded with the model. If blank/default, we use the previous config from the model instead. Only relevant for model MLCubes. Ignored for metrics MLCubes",
  35. )
  36. parser.add_argument(
  37. "-t",
  38. "--target",
  39. metavar="",
  40. type=str,
  41. help="The target platform. Valid inputs are: "
  42. + ", ".join(deploy_targets)
  43. + " .",
  44. required=True,
  45. )
  46. parser.add_argument(
  47. "--mlcube-type",
  48. metavar="",
  49. type=str,
  50. help="The mlcube type. Valid inputs are: " + ", ".join(mlcube_types) + " .",
  51. required=True,
  52. )
  53. parser.add_argument(
  54. "-r",
  55. "--mlcube-root",
  56. metavar="",
  57. type=str,
  58. required=True,
  59. help="Path to an alternative MLCUBE_ROOT directory to use as a template (or a path to a specific mlcube YAML configuration file, in which case we will use the parent directory). The source repository contains an example (https://github.com/mlcommons/GaNDLF/tree/master/mlcube).",
  60. )
  61. parser.add_argument(
  62. "-o",
  63. "--outputdir",
  64. metavar="",
  65. type=str,
  66. help="Output directory path. For MLCube builds, generates an MLCube directory to be distributed with your MLCube.",
  67. required=True,
  68. )
  69. parser.add_argument(
  70. "-g",
  71. "--requires-gpu",
  72. metavar="",
  73. type=ast.literal_eval,
  74. help="True if the model requires a GPU by default, False otherwise. Only relevant for model MLCubes. Ignored for metrics MLCubes",
  75. default=True,
  76. )
  77. parser.add_argument(
  78. "-e",
  79. "--entrypoint",
  80. metavar="",
  81. type=str,
  82. help="An optional custom python entrypoint script to use instead of the default specified in mlcube.yaml. (Only for inference and metrics)",
  83. default=None,
  84. )
  85. args = parser.parse_args()
  86. if not os.path.exists(args.outputdir):
  87. os.makedirs(args.outputdir, exist_ok=True)
  88. config_to_use = args.config
  89. if not args.config and args.mlcube_type == "model":
  90. result = recover_config(args.model, args.outputdir + "/original_config.yml")
  91. assert (
  92. result
  93. ), "Error: No config was specified but automatic config extraction failed."
  94. config_to_use = args.outputdir + "/original_config.yml"
  95. if not args.model and args.mlcube_type == "model":
  96. raise AssertionError(
  97. "Error: a path to a model directory should be provided when deploying a model"
  98. )
  99. result = run_deployment(
  100. args.mlcube_root,
  101. args.outputdir,
  102. args.target,
  103. args.mlcube_type,
  104. args.entrypoint,
  105. config_to_use,
  106. args.model,
  107. args.requires_gpu,
  108. )
  109. assert result, "Deployment to the target platform failed."
Tip!

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

Comments

Loading...