|
| 1 | +# The MIT License (MIT) |
| 2 | +# |
| 3 | +# Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 6 | +# this software and associated documentation files (the "Software"), to deal in |
| 7 | +# the Software without restriction, including without limitation the rights to |
| 8 | +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 9 | +# the Software, and to permit persons to whom the Software is furnished to do so, |
| 10 | +# subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
| 17 | +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
| 18 | +# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 19 | +# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 20 | +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | + |
| 22 | +import tritonclient.grpc as t_client |
| 23 | +import argparse |
| 24 | +import sys |
| 25 | + |
| 26 | +def get_args(): |
| 27 | + parser = argparse.ArgumentParser(description='Load or unload a model in Triton server.') |
| 28 | + parser.add_argument('action', action='store', choices=['load', 'unload', 'reload']) |
| 29 | + parser.add_argument('-u', '--url', required=False, action='store', default='localhost:8001', help='Server url.') |
| 30 | + parser.add_argument('-m', '--model', required=True, action='store', help='Model name.') |
| 31 | + return parser.parse_args() |
| 32 | + |
| 33 | + |
| 34 | +def main(args): |
| 35 | + client = t_client.InferenceServerClient(url=args.url) |
| 36 | + if args.action in ['reload', 'unload']: |
| 37 | + try: |
| 38 | + client.unload_model(args.model) |
| 39 | + print('Successfully unloaded model', args.model) |
| 40 | + except: |
| 41 | + print('Could not unload model', args.model) |
| 42 | + sys.exit(1) |
| 43 | + |
| 44 | + if args.action in ['reload', 'load']: |
| 45 | + try: |
| 46 | + client.load_model(args.model) |
| 47 | + print('Successfully loaded model', args.model) |
| 48 | + except: |
| 49 | + print('Could not load model', args.model) |
| 50 | + sys.exit(1) |
| 51 | + |
| 52 | + |
| 53 | +if __name__ == '__main__': |
| 54 | + args = get_args() |
| 55 | + main(args) |
0 commit comments