


"""simple docstring"""







import argparse
import os
import platform

import numpy as np
import psutil
import torch

from accelerate import __version__ as version
from accelerate.commands.config import default_config_file, load_config_from_file

from ..utils import is_npu_available, is_xpu_available




def        UpperCAmelCase__	(lowerCAmelCase_=None       ):




					'''simple docstring'''


					if subparsers is not None:
										__SCREAMING_SNAKE_CASE						       =    subparsers.add_parser("env"       )
					else:
										__SCREAMING_SNAKE_CASE						       =    argparse.ArgumentParser("Accelerate env command"       )

					parser.add_argument(
					    "--config_file"  ,						default=lowerCAmelCase_  ,						help="The config file to use for the default values in the launching script."       )

					if subparsers is not None:
										parser.set_defaults(func=lowerCAmelCase_       )
					return parser




def        UpperCAmelCase__	(lowerCAmelCase_       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    torch.__version__
					__SCREAMING_SNAKE_CASE						       =    torch.cuda.is_available()
					__SCREAMING_SNAKE_CASE						       =    is_xpu_available()
					__SCREAMING_SNAKE_CASE						       =    is_npu_available()

					__SCREAMING_SNAKE_CASE						       =    "Not found"
					# Get the default from the config file.
					if args.config_file is not None or os.path.isfile(lowerCAmelCase_       ):
										__SCREAMING_SNAKE_CASE						       =    load_config_from_file(args.config_file       ).to_dict()

					__SCREAMING_SNAKE_CASE						       =    {
					    "`Accelerate` version": version,
					    "Platform": platform.platform(),
					    "Python version": platform.python_version(),
					    "Numpy version": np.__version__,
					    "PyTorch version (GPU?)": f"""{pt_version} ({pt_cuda_available})""",
					    "PyTorch XPU available": str(lowerCAmelCase_       ),
					    "PyTorch NPU available": str(lowerCAmelCase_       ),
					    "System RAM": f"""{psutil.virtual_memory().total / 1024 ** 3:.2f} GB""",
					}
					if pt_cuda_available:
										__SCREAMING_SNAKE_CASE						       =    torch.cuda.get_device_name()

					print("\nCopy-and-paste the text below in your GitHub issue\n"       )
					print("\n".join([f"""- {prop}: {val}""" for prop, val in info.items()]       )       )

					print("- `Accelerate` default config:" if args.config_file is None else "- `Accelerate` config passed:"       )
					__SCREAMING_SNAKE_CASE						       =    (
					    "\n".join([f"""\t- {prop}: {val}""" for prop, val in accelerate_config.items()]       )
					    if isinstance(lowerCAmelCase_  ,						lowerCAmelCase_       )
					    else f"""\t{accelerate_config}"""
					)
					print(lowerCAmelCase_       )

					__SCREAMING_SNAKE_CASE						       =    accelerate_config

					return info




def        UpperCAmelCase__	():




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    env_command_parser()
					__SCREAMING_SNAKE_CASE						       =    parser.parse_args()
					env_command(lowerCAmelCase_       )
					return 0


if __name__ == "__main__":
		raise SystemExit(main())









"""simple docstring"""







from __future__ import annotations

import requests




def        UpperCAmelCase__	(lowerCAmelCase_       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    f"""https://hacker-news.firebaseio.com/v0/item/{story_id}.json?print=pretty"""
					return requests.get(lowerCAmelCase_       ).json()




def        UpperCAmelCase__	(lowerCAmelCase_ = 10       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    "https://hacker-news.firebaseio.com/v0/topstories.json?print=pretty"
					__SCREAMING_SNAKE_CASE						       =    requests.get(lowerCAmelCase_       ).json()[:max_stories]
					return [get_hackernews_story(lowerCAmelCase_       ) for story_id in story_ids]




def        UpperCAmelCase__	(lowerCAmelCase_ = 10       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    hackernews_top_stories(lowerCAmelCase_       )
					return "\n".join("* [{title}]({url})".format(**lowerCAmelCase_       ) for story in stories       )


if __name__ == "__main__":
		print(hackernews_top_stories_as_markdown())
