From 9773e5e0d978eb1f81d0694185d48a6da4326304 Mon Sep 17 00:00:00 2001 From: Bram Vanroy Date: Sat, 1 Feb 2020 16:38:14 +0100 Subject: [PATCH] CLI script to gather environment info (#2699) * add "info" command to CLI As a convenience, add the info directive to CLI. Running `python transformers-cli info` will return a string containing the transformers version, platform, python version, PT/TF version and GPU support * Swap f-strings for .format Still supporting 3.5 so can't use f-strings (sad face) * Add reference in issue to CLI * Add the expected fields to issue template This way, people can still add the information manually if they want. (Though I fear they'll just ignore it.) * Remove heading from output * black-ify * order of imports Should ensure isort test passes * use is_X_available over import..pass * style * fix copy-paste bug * Rename command info -> env Also adds the command to CONTRIBUTING.md in "Did you find a bug" section --- .github/ISSUE_TEMPLATE/bug-report.md | 20 +++++----- .github/ISSUE_TEMPLATE/migration.md | 21 ++++++---- CONTRIBUTING.md | 10 ++--- src/transformers/commands/env.py | 58 ++++++++++++++++++++++++++++ transformers-cli | 8 ++-- 5 files changed, 90 insertions(+), 27 deletions(-) create mode 100644 src/transformers/commands/env.py diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md index 13aa47b05e..cc03dd01fb 100644 --- a/.github/ISSUE_TEMPLATE/bug-report.md +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -39,12 +39,14 @@ Steps to reproduce the behavior: -## Environment - -* OS: -* Python version: -* PyTorch version: -* `transformers` version (or branch): -* Using GPU ? -* Distributed or parallel setup ? -* Any other relevant information: +## Environment info + + +- `transformers` version: +- Platform: +- Python version: +- PyTorch version (GPU?): +- Tensorflow version (GPU?): +- Using GPU in script?: +- Using distributed or parallel set-up in script?: diff --git a/.github/ISSUE_TEMPLATE/migration.md b/.github/ISSUE_TEMPLATE/migration.md index 9dfd9d1899..387d97d528 100644 --- a/.github/ISSUE_TEMPLATE/migration.md +++ b/.github/ISSUE_TEMPLATE/migration.md @@ -33,16 +33,21 @@ The tasks I am working on is: Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code. --> -## Environment +## Environment info + + +- `transformers` version: +- Platform: +- Python version: +- PyTorch version (GPU?): +- Tensorflow version (GPU?): +- Using GPU in script?: +- Using distributed or parallel set-up in script?: -* OS: -* Python version: -* PyTorch version: + * `pytorch-transformers` or `pytorch-pretrained-bert` version (or branch): -* `transformers` version (or branch): -* Using GPU? -* Distributed or parallel setup? -* Any other relevant information: + ## Checklist diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4887dc5764..4c313dad9f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,14 +41,10 @@ Did not find it? :( So we can act quickly on it, please follow these steps: less than 30s; * Provide the *full* traceback if an exception is raised. -To get the OS and software versions, execute the following code and copy-paste -the output: +To get the OS and software versions automatically, you can run the following command: -``` -import platform; print("Platform", platform.platform()) -import sys; print("Python", sys.version) -import torch; print("PyTorch", torch.__version__) -import tensorflow; print("Tensorflow", tensorflow.__version__) +```bash +python transformers-cli env ``` ### Do you want to implement a new model? diff --git a/src/transformers/commands/env.py b/src/transformers/commands/env.py new file mode 100644 index 0000000000..efc8fbb683 --- /dev/null +++ b/src/transformers/commands/env.py @@ -0,0 +1,58 @@ +import platform +from argparse import ArgumentParser + +from transformers import __version__ as version +from transformers import is_tf_available, is_torch_available +from transformers.commands import BaseTransformersCLICommand + + +def info_command_factory(_): + return EnvironmentCommand() + + +class EnvironmentCommand(BaseTransformersCLICommand): + @staticmethod + def register_subcommand(parser: ArgumentParser): + download_parser = parser.add_parser("env") + download_parser.set_defaults(func=info_command_factory) + + def run(self): + pt_version = "not installed" + pt_cuda_available = "NA" + if is_torch_available(): + import torch + + pt_version = torch.__version__ + pt_cuda_available = torch.cuda.is_available() + + tf_version = "not installed" + tf_cuda_available = "NA" + if is_tf_available(): + import tensorflow as tf + + tf_version = tf.__version__ + try: + # deprecated in v2.1 + tf_cuda_available = tf.test.is_gpu_available() + except AttributeError: + # returns list of devices, convert to bool + tf_cuda_available = bool(tf.config.list_physical_devices("GPU")) + + info = { + "`transformers` version": version, + "Platform": platform.platform(), + "Python version": platform.python_version(), + "PyTorch version (GPU?)": "{} ({})".format(pt_version, pt_cuda_available), + "Tensorflow version (GPU?)": "{} ({})".format(tf_version, tf_cuda_available), + "Using GPU in script?": "", + "Using distributed or parallel set-up in script?": "", + } + + print("\nCopy-and-paste the text below in your GitHub issue and FILL OUT the two last points.\n") + print(self.format_dict(info)) + + return info + + @staticmethod + def format_dict(d): + return "\n".join(["- {}: {}".format(prop, val) for prop, val in d.items()]) + "\n" diff --git a/transformers-cli b/transformers-cli index 0a980a3574..9813b83843 100755 --- a/transformers-cli +++ b/transformers-cli @@ -1,11 +1,12 @@ #!/usr/bin/env python from argparse import ArgumentParser -from transformers.commands.download import DownloadCommand -from transformers.commands.run import RunCommand -from transformers.commands.user import UserCommands from transformers.commands.convert import ConvertCommand +from transformers.commands.download import DownloadCommand +from transformers.commands.env import EnvironmentCommand +from transformers.commands.run import RunCommand from transformers.commands.serving import ServeCommand +from transformers.commands.user import UserCommands if __name__ == '__main__': parser = ArgumentParser('Transformers CLI tool', usage='transformers-cli []') @@ -14,6 +15,7 @@ if __name__ == '__main__': # Register commands ConvertCommand.register_subcommand(commands_parser) DownloadCommand.register_subcommand(commands_parser) + EnvironmentCommand.register_subcommand(commands_parser) RunCommand.register_subcommand(commands_parser) ServeCommand.register_subcommand(commands_parser) UserCommands.register_subcommand(commands_parser)