checkpoint.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #
  2. # Copyright 2021 The FATE Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the 'License');
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an 'AS IS' BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import sys
  17. import click
  18. from flow_client.flow_cli.utils import cli_args
  19. from flow_client.flow_cli.utils.cli_utils import preprocess, access_server
  20. @click.group(short_help='Checkpoint Operations')
  21. @click.pass_context
  22. def checkpoint(ctx, **kwargs):
  23. pass
  24. @checkpoint.command('list', short_help='List checkpoints')
  25. @cli_args.ROLE_REQUIRED
  26. @cli_args.PARTYID_REQUIRED
  27. @cli_args.MODEL_ID_REQUIRED
  28. @cli_args.MODEL_VERSION_REQUIRED
  29. @cli_args.COMPONENT_NAME_REQUIRED
  30. @click.pass_context
  31. def list_checkpoints(ctx, **kwargs):
  32. config_data, dsl_data = preprocess(**kwargs)
  33. access_server('post', ctx, 'checkpoint/list', config_data)
  34. @checkpoint.command('get', short_help='Get a checkpoint by step_index or step_name')
  35. @cli_args.ROLE_REQUIRED
  36. @cli_args.PARTYID_REQUIRED
  37. @cli_args.MODEL_ID_REQUIRED
  38. @cli_args.MODEL_VERSION_REQUIRED
  39. @cli_args.COMPONENT_NAME_REQUIRED
  40. @click.option('--step-index', help='Step index', type=click.INT)
  41. @click.option('--step-name', help='Step name', type=click.STRING)
  42. @click.pass_context
  43. def get_checkpoint(ctx, **kwargs):
  44. config_data, dsl_data = preprocess(**kwargs)
  45. if len(config_data.keys() & {'step_index', 'step_name'}) != 1:
  46. click.echo("Error: Missing option '--step-index' or '--step-name'.", err=True)
  47. sys.exit(2)
  48. access_server('post', ctx, 'checkpoint/get', config_data)