accelerate_cli.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. # Copyright 2021 The HuggingFace Team. 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. from accelerate.commands.config import get_config_parser
  16. from accelerate.commands.env import env_command_parser
  17. from accelerate.commands.estimate import estimate_command_parser
  18. from accelerate.commands.launch import launch_command_parser
  19. from accelerate.commands.merge import merge_command_parser
  20. from accelerate.commands.test import test_command_parser
  21. from accelerate.commands.to_fsdp2 import to_fsdp2_command_parser
  22. from accelerate.commands.tpu import tpu_command_parser
  23. from accelerate.commands.utils import CustomArgumentParser
  24. def main():
  25. parser = CustomArgumentParser("Accelerate CLI tool", usage="accelerate <command> [<args>]", allow_abbrev=False)
  26. subparsers = parser.add_subparsers(help="accelerate command helpers")
  27. # Register commands
  28. get_config_parser(subparsers=subparsers)
  29. estimate_command_parser(subparsers=subparsers)
  30. env_command_parser(subparsers=subparsers)
  31. launch_command_parser(subparsers=subparsers)
  32. merge_command_parser(subparsers=subparsers)
  33. tpu_command_parser(subparsers=subparsers)
  34. test_command_parser(subparsers=subparsers)
  35. to_fsdp2_command_parser(subparsers=subparsers)
  36. # Let's go
  37. args = parser.parse_args()
  38. if not hasattr(args, "func"):
  39. parser.print_help()
  40. exit(1)
  41. # Run
  42. args.func(args)
  43. if __name__ == "__main__":
  44. main()