Implementation:Huggingface Optimum EnvironmentCommand
| Knowledge Sources | |
|---|---|
| Domains | CLI, Diagnostics |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
Concrete tool for displaying Optimum runtime environment information (package versions, platform, GPU availability) provided by the Huggingface Optimum CLI.
Description
EnvironmentCommand is a leaf CLI command registered under `optimum-cli env`. When run, it collects version information for `optimum`, `transformers`, `huggingface_hub`, and `torch`, along with platform and Python version details. The output is formatted for copy-pasting into GitHub issue reports.
Usage
Run `optimum-cli env` from the terminal to display the current environment configuration. This is primarily used for debugging and issue reporting.
Code Reference
Source Location
- Repository: Huggingface_Optimum
- File: optimum/commands/env.py
- Lines: 1-56
Signature
class EnvironmentCommand(BaseOptimumCLICommand):
COMMAND = CommandInfo(name="env", help="Get information about the environment used.")
@staticmethod
def format_dict(d):
"""Format a dictionary as a bullet-point list string."""
def run(self):
"""Collect and print environment information.
Returns:
dict: Dictionary containing version and platform information.
"""
Import
from optimum.commands.env import EnvironmentCommand
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | — | — | No additional inputs; environment is introspected at runtime |
Outputs
| Name | Type | Description |
|---|---|---|
| run() returns | dict | Dictionary with keys: optimum version, transformers version, Platform, Python version, huggingface_hub version, PyTorch version |
| stdout | str | Formatted environment info printed to console |
Usage Examples
Command Line
optimum-cli env
Programmatic Usage
from optimum.commands.env import EnvironmentCommand
# EnvironmentCommand is typically invoked via the CLI, but can be used programmatically
cmd = EnvironmentCommand.__new__(EnvironmentCommand)
info = cmd.run()
print(info)
# {'`optimum` version': '1.x.x', '`transformers` version': '4.x.x', ...}