[
  {
    "path": "Aptfile",
    "content": "rocm-dev\nrocm-libs\nrocm-cmake\nmiopen-hip\nrocblas"
  },
  {
    "path": "Dockerfile",
    "content": "# Start from the latest ROCm base image\nFROM rocm/dev-ubuntu-22.04:6.0-complete\n\n# Set environment variables\nENV DEBIAN_FRONTEND=noninteractive\nRUN apt-get update && apt-get install -y \\\n    git \\\n    && rm -rf /var/lib/apt/lists/*\n\n\n# Install rocm-smi\nRUN apt-get update && apt-get install -y rocm-smi\n\n\n# Set up a new user\nRUN useradd -m -s /bin/bash user\nUSER user\nWORKDIR /home/user/app\n\n# Set up Python environment\nENV PATH=\"/home/user/.local/bin:${PATH}\"\nRUN python3 -m pip install --user --upgrade pip\n\nCOPY --chown=user:user requirements.txt .\n\n\nRUN pip install --user --no-cache-dir -r requirements.txt\n\n# Copy the application code\nCOPY --chown=user:user . /home/user/app/\n\n# Set an argument for the model path\nARG MODEL_PATH\nENV MODEL_PATH=${MODEL_PATH}\n\n# Set the entry point to run the inference script\nENTRYPOINT [\"python3\", \"src/run_inference.py\"]"
  },
  {
    "path": "LICENSE",
    "content": "Apache License\nVersion 2.0, January 2004\nhttp://www.apache.org/licenses/\n\nTERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n1. Definitions.\n\n\"License\" shall mean the terms and conditions for use, reproduction,\nand distribution as defined by Sections 1 through 9 of this document.\n\n\"Licensor\" shall mean the copyright owner or entity authorized by\nthe copyright owner that is granting the License.\n\n\"Legal Entity\" shall mean the union of the acting entity and all\nother entities that control, are controlled by, or are under common\ncontrol with that entity. For the purposes of this definition,\n\"control\" means (i) the power, direct or indirect, to cause the\ndirection or management of such entity, whether by contract or\notherwise, or (ii) ownership of fifty percent (50%) or more of the\noutstanding shares, or (iii) beneficial ownership of such entity.\n\n\"You\" (or \"Your\") shall mean an individual or Legal Entity\nexercising permissions granted by this License.\n\n\"Source\" form shall mean the preferred form for making modifications,\nincluding but not limited to software source code, documentation\nsource, and configuration files.\n\n\"Object\" form shall mean any form resulting from mechanical\ntransformation or translation of a Source form, including but\nnot limited to compiled object code, generated documentation,\nand conversions to other media types.\n\n\"Work\" shall mean the work of authorship, whether in Source or\nObject form, made available under the License, as indicated by a\ncopyright notice that is included in or attached to the work\n(an example is provided in the Appendix below).\n\n\"Derivative Works\" shall mean any work, whether in Source or Object\nform, that is based on (or derived from) the Work and for which the\neditorial revisions, annotations, elaborations, or other modifications\nrepresent, as a whole, an original work of authorship. For the purposes\nof this License, Derivative Works shall not include works that remain\nseparable from, or merely link (or bind by name) to the interfaces of,\nthe Work and Derivative Works thereof.\n\n\"Contribution\" shall mean any work of authorship, including\nthe original version of the Work and any modifications or additions\nto that Work or Derivative Works thereof, that is intentionally\nsubmitted to Licensor for inclusion in the Work by the copyright owner\nor by an individual or Legal Entity authorized to submit on behalf of\nthe copyright owner. For the purposes of this definition, \"submitted\"\nmeans any form of electronic, verbal, or written communication sent\nto the Licensor or its representatives, including but not limited to\ncommunication on electronic mailing lists, source code control systems,\nand issue tracking systems that are managed by, or on behalf of, the\nLicensor for the purpose of discussing and improving the Work, but\nexcluding communication that is conspicuously marked or otherwise\ndesignated in writing by the copyright owner as \"Not a Contribution.\"\n\n\"Contributor\" shall mean Licensor and any individual or Legal Entity\non behalf of whom a Contribution has been received by Licensor and\nsubsequently incorporated within the Work.\n\n2. Grant of Copyright License. Subject to the terms and conditions of\nthis License, each Contributor hereby grants to You a perpetual,\nworldwide, non-exclusive, no-charge, royalty-free, irrevocable\ncopyright license to reproduce, prepare Derivative Works of,\npublicly display, publicly perform, sublicense, and distribute the\nWork and such Derivative Works in Source or Object form.\n\n3. Grant of Patent License. Subject to the terms and conditions of\nthis License, each Contributor hereby grants to You a perpetual,\nworldwide, non-exclusive, no-charge, royalty-free, irrevocable\n(except as stated in this section) patent license to make, have made,\nuse, offer to sell, sell, import, and otherwise transfer the Work,\nwhere such license applies only to those patent claims licensable\nby such Contributor that are necessarily infringed by their\nContribution(s) alone or by combination of their Contribution(s)\nwith the Work to which such Contribution(s) was submitted. If You\ninstitute patent litigation against any entity (including a\ncross-claim or counterclaim in a lawsuit) alleging that the Work\nor a Contribution incorporated within the Work constitutes direct\nor contributory patent infringement, then any patent licenses\ngranted to You under this License for that Work shall terminate\nas of the date such litigation is filed.\n\n4. Redistribution. You may reproduce and distribute copies of the\nWork or Derivative Works thereof in any medium, with or without\nmodifications, and in Source or Object form, provided that You\nmeet the following conditions:\n\n(a) You must give any other recipients of the Work or\nDerivative Works a copy of this License; and\n\n(b) You must cause any modified files to carry prominent notices\nstating that You changed the files; and\n\n(c) You must retain, in the Source form of any Derivative Works\nthat You distribute, all copyright, patent, trademark, and\nattribution notices from the Source form of the Work,\nexcluding those notices that do not pertain to any part of\nthe Derivative Works; and\n\n(d) If the Work includes a \"NOTICE\" text file as part of its\ndistribution, then any Derivative Works that You distribute must\ninclude a readable copy of the attribution notices contained\nwithin such NOTICE file, excluding those notices that do not\npertain to any part of the Derivative Works, in at least one\nof the following places: within a NOTICE text file distributed\nas part of the Derivative Works; within the Source form or\ndocumentation, if provided along with the Derivative Works; or,\nwithin a display generated by the Derivative Works, if and\nwherever such third-party notices normally appear. The contents\nof the NOTICE file are for informational purposes only and\ndo not modify the License. You may add Your own attribution\nnotices within Derivative Works that You distribute, alongside\nor as an addendum to the NOTICE text from the Work, provided\nthat such additional attribution notices cannot be construed\nas modifying the License.\n\nYou may add Your own copyright statement to Your modifications and\nmay provide additional or different license terms and conditions\nfor use, reproduction, or distribution of Your modifications, or\nfor any such Derivative Works as a whole, provided Your use,\nreproduction, and distribution of the Work otherwise complies with\nthe conditions stated in this License.\n\n5. Submission of Contributions. Unless You explicitly state otherwise,\nany Contribution intentionally submitted for inclusion in the Work\nby You to the Licensor shall be under the terms and conditions of\nthis License, without any additional terms or conditions.\nNotwithstanding the above, nothing herein shall supersede or modify\nthe terms of any separate license agreement you may have executed\nwith Licensor regarding such Contributions.\n\n6. Trademarks. This License does not grant permission to use the trade\nnames, trademarks, service marks, or product names of the Licensor,\nexcept as required for reasonable and customary use in describing the\norigin of the Work and reproducing the content of the NOTICE file.\n\n7. Disclaimer of Warranty. Unless required by applicable law or\nagreed to in writing, Licensor provides the Work (and each\nContributor provides its Contributions) on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\nimplied, including, without limitation, any warranties or conditions\nof TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\nPARTICULAR PURPOSE. You are solely responsible for determining the\nappropriateness of using or redistributing the Work and assume any\nrisks associated with Your exercise of permissions under this License.\n\n8. Limitation of Liability. In no event and under no legal theory,\nwhether in tort (including negligence), contract, or otherwise,\nunless required by applicable law (such as deliberate and grossly\nnegligent acts) or agreed to in writing, shall any Contributor be\nliable to You for damages, including any direct, indirect, special,\nincidental, or consequential damages of any character arising as a\nresult of this License or out of the use or inability to use the\nWork (including but not limited to damages for loss of goodwill,\nwork stoppage, computer failure or malfunction, or any and all\nother commercial damages or losses), even if such Contributor\nhas been advised of the possibility of such damages.\n\n9. Accepting Warranty or Additional Liability. While redistributing\nthe Work or Derivative Works thereof, You may choose to offer,\nand charge a fee for, acceptance of support, warranty, indemnity,\nor other liability obligations and/or rights consistent with this\nLicense. However, in accepting such obligations, You may act only\non Your own behalf and on Your sole responsibility, not on behalf\nof any other Contributor, and only if You agree to indemnify,\ndefend, and hold each Contributor harmless for any liability\nincurred by, or claims asserted against, such Contributor by reason\nof your accepting any such warranty or additional liability.\n\nEND OF TERMS AND CONDITIONS\n\nAPPENDIX: How to apply the Apache License to your work.\n\nTo apply the Apache License to your work, attach the following\nboilerplate notice, with the fields enclosed by brackets \"[]\"\nreplaced with your own identifying information. (Don't include\nthe brackets!)  The text should be enclosed in the appropriate\ncomment syntax for the file format. We also recommend that a\nfile or class name and description of purpose be included on the\nsame \"printed page\" as the copyright notice for easier\nidentification within third-party archives.\n\nCopyright [yyyy] [name of copyright owner]\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n\n# ROCm Dependency Notice\n\nThis project uses ROCm, which is licensed under the MIT License.\nSee https://rocm.docs.amd.com/en/latest/about/license.html for details."
  },
  {
    "path": "README.md",
    "content": "# ⚙️ AMD GPU Inference\n\n[![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202-green.svg)](https://github.com/bentoml/OpenLLM/blob/main/LICENSE)\n[![X](https://badgen.net/badge/icon/@slash_ml/000000?icon=twitter&label=Follow)](https://twitter.com/slash_ml)\n[![Community](https://img.shields.io/discord/123456789012345678?logo=discord&label=Join%20Discord)](https://discord.com/invite/EXJkWygF)\n\n\nThis project provides a Docker-based inference engine for running Large Language Models (LLMs) on AMD GPUs. It's designed to work with models from Hugging Face, with a focus on the LLaMA model family.\n\n## Prerequisites\n\n- AMD GPU with ROCm support\n- Docker installed on your system\n- ROCm drivers installed on your host system (version 5.4.2 or compatible)\n\n## Project Structure\n\n```\namd-gpu-inference/\n├── src/\n│   ├── __init__.py\n│   ├── engine.py\n│   ├── model.py\n│   ├── utils.py\n│   └── amd_setup.py\n├── Dockerfile\n├── requirements.txt\n├── run_inference.py\n├── run-docker-amd.sh\n└── README.md\n```\n\n## Quick Start\n\n1. Clone this repository:\n   ```\n   git clone https://github.com/slashml/amd-gpu-inference.git\n   cd amd-gpu-inference\n   ```\n\n2. Make the run script executable:\n   ```\n   chmod +x run-docker-amd.sh\n   ```\n\n3. Run the inference engine with a specified model and prompt:\n   ```\n   ./run-docker-amd.sh \"meta-llama/Llama-2-7b-chat-hf\" \"Translate the following English text to French: 'Hello, how are you?'\"\n   ```\n   Replace `\"meta-llama/Llama-2-7b-chat-hf\"` with the Hugging Face model you want to use, and provide your own prompt.\n\n## Detailed Usage\n\n### Aptfile\n\nThe project includes an `Aptfile` that lists the necessary ROCm packages to be installed in the Docker container. This ensures that all required ROCm drivers and libraries are available for the inference engine to utilize the AMD GPU effectively.\n\n### Building the Docker Image\n\nThe `run-docker-amd.sh` script builds the Docker image automatically. If you want to build it manually, use:\n\n```\ndocker build -t amd-gpu-inference .\n```\n\n### Running the Container\n\nThe `run-docker-amd.sh` script handles running the container with the necessary AMD GPU flags. If you want to run it manually:\n\n```\ndocker run --rm -it \\\n    --device=/dev/kfd \\\n    --device=/dev/dri \\\n    --group-add=video \\\n    --cap-add=SYS_PTRACE \\\n    --security-opt seccomp=unconfined \\\n    amd-gpu-inference \"model_name\" \"your prompt here\"\n```\n\nReplace `\"model_name\"` with the Hugging Face model you want to use, and `\"your prompt here\"` with your input text.\n\n## Customization\n\n### Changing the Model\n\nYou can use any model available on Hugging Face by specifying its repository name when running the container. For example:\n\n```\n./run-docker-amd.sh \"facebook/opt-1.3b\" \"Your prompt here\"\n```\n\n### Modifying the Inference Logic\n\nIf you need to change how the inference is performed, modify the `run_inference.py` file. Remember to rebuild the Docker image after making changes.\n\n## Troubleshooting\n\n- Ensure that your AMD GPU drivers and ROCm are correctly installed and configured on your host system.\n- If you encounter \"out of memory\" errors, try using a smaller model or reducing the input/output length.\n- For model-specific issues, refer to the model's documentation on Hugging Face.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## Acknowledgements\n\n- This project uses the Hugging Face Transformers library.\n- ROCm is developed by AMD. Licensed under MIT License\n  See https://rocm.docs.amd.com/en/latest/about/license.html for details.\n\nFor any questions or issues, please open an issue in the GitHub repository."
  },
  {
    "path": "examples/question_answering.py",
    "content": "from src.engine import InferenceEngine\n\ndef question_answering_example():\n    model_path = \"models/llama-2-1b\"\n    engine = InferenceEngine(model_path)\n\n    context = \"The Great Wall of China is an ancient wall in China. The wall is 6,259 km long and was built to protect the Chinese states and empires against nomadic invasions from the north. It was built from the 3rd century BC to the 17th century AD.\"\n    question = \"How long is the Great Wall of China?\"\n\n    prompt = f\"Context: {context}\\n\\nQuestion: {question}\\n\\nAnswer:\"\n    result = engine.run_inference(prompt, max_length=50)\n\n    print(\"Question Answering Example:\")\n    print(f\"Context: {context}\")\n    print(f\"Question: {question}\")\n    print(f\"Answer: {result['output']}\")\n    print(f\"Inference Time: {result['inference_time']}\")\n\nif __name__ == \"__main__\":\n    question_answering_example()"
  },
  {
    "path": "examples/text_generation.py",
    "content": "from src.engine import InferenceEngine\n\ndef text_generation_example():\n    # You can change this to any supported LLaMA model on Hugging Face\n    model_name = \"meta-llama/Llama-3-8b\"\n    engine = InferenceEngine(model_name)\n\n    prompt = \"Write a short story about a robot learning to paint:\"\n    result = engine.run_inference(prompt, max_length=200)\n\n    print(\"Text Generation Example:\")\n    print(f\"Model: {model_name}\")\n    print(f\"Prompt: {prompt}\")\n    print(f\"Generated Story: {result['output']}\")\n    print(f\"Inference Time: {result['inference_time']}\")\n\nif __name__ == \"__main__\":\n    text_generation_example()"
  },
  {
    "path": "requirements.txt",
    "content": "--extra-index-url https://download.pytorch.org/whl/rocm6.1\ntorch==2.4.0+rocm6.1\ntorchvision==0.19.0+rocm6.1\ntorchaudio==2.4.0+rocm6.1\ntransformers==4.37.2\nnumpy==1.26.3\npandas==2.1.4\nscipy==1.11.4\nscikit-learn==1.3.2\ntqdm==4.66.1\nmatplotlib==3.8.2\njupyter==1.0.0\nipython==8.20.0\nfastapi==0.109.0\nuvicorn==0.25.0\npytest==7.4.4\nloguru==0.7.2\npython-dotenv==1.0.0"
  },
  {
    "path": "run-docker-amd.sh",
    "content": "#!/bin/bash\n\nset -e\n\n# Check if model name and prompt are provided\nif [ \"$#\" -ne 2 ]; then\n    echo \"Usage: $0 <model_name> <prompt>\"\n    echo \"Example: $0 meta-llama/Llama-2-7b-chat-hf \\\"Translate the following English text to French: 'Hello, how are you?'\\\"\"\n    exit 1\nfi\n\nMODEL_NAME=\"$1\"\nPROMPT=\"$2\"\n\n# Build the Docker image\necho \"Building Docker image...\"\ndocker build -t amd-gpu-inference .\n\n# Run the container\necho \"Running container with AMD GPU support...\"\ndocker run --rm -it \\\n    --device=/dev/kfd \\\n    --device=/dev/dri \\\n    --group-add=video \\\n    --cap-add=SYS_PTRACE \\\n    --security-opt seccomp=unconfined \\\n    amd-gpu-inference \"$MODEL_NAME\" \"$PROMPT\"\n\necho \"Container execution completed.\""
  },
  {
    "path": "run_inference.py",
    "content": "import os\nimport sys\nfrom src.engine import InferenceEngine\nfrom src.utils import print_gpu_utilization, get_gpu_info\n\ndef run_inference(model_name, prompt):\n    print(f\"GPU Info: {get_gpu_info()}\")\n    print_gpu_utilization()\n\n\n    print(f\"Initializing inference engine...\")\n    print(f\"GPU Info: {get_gpu_info()}\")\n    print_gpu_utilization()\n\n    engine = InferenceEngine(model_name)\n\n    result = engine.run_inference(prompt, max_length=200)\n\n    print(f\"Input: {result['input']}\")\n    print(f\"Output: {result['output']}\")\n    print(f\"Inference Time: {result['inference_time']}\")\n\n    print_gpu_utilization()\n\nif __name__ == \"__main__\":\n    if len(sys.argv) > 1:\n        prompt = \" \".join(sys.argv[1:])\n    else:\n        prompt = \"Explain the concept of machine learning in simple terms.\"\n    \n    run_inference(prompt)"
  },
  {
    "path": "src/__init__.py",
    "content": ""
  },
  {
    "path": "src/amd_setup.py",
    "content": "import os\nimport torch\n\ndef setup_amd_environment():\n    if torch.version.hip is None:\n        print(\"This is not an AMD GPU environment. No setup needed.\")\n        return\n\n    # Set environment variables for ROCm\n    os.environ['HIP_VISIBLE_DEVICES'] = '0'  # Use the first GPU\n    os.environ['HSA_OVERRIDE_GFX_VERSION'] = '11.0.0'  # Updated for newer AMD GPUs\n\n    # Check if ROCm is properly set up\n    try:\n        assert torch.cuda.is_available()\n        print(f\"ROCm is properly set up. Using GPU: {torch.cuda.get_device_name(0)}\")\n    except AssertionError:\n        print(\"Error: ROCm is not properly set up or no AMD GPU is available.\")\n        print(\"Please ensure that ROCm 6.2 is installed and configured correctly.\")\n\ndef optimize_for_amd():\n    if torch.version.hip is None:\n        return\n\n    # Set benchmark mode\n    torch.backends.cudnn.benchmark = True\n\n    # Enable TF32 for improved performance (if supported by the GPU)\n    torch.backends.cuda.matmul.allow_tf32 = True\n    torch.backends.cudnn.allow_tf32 = True\n\n    print(\"Applied optimizations for AMD GPU with ROCm 6.2.\")\n\n# Call these functions when importing this module\nsetup_amd_environment()\noptimize_for_amd()"
  },
  {
    "path": "src/engine.py",
    "content": "import torch\nfrom .model import LlamaModel\nfrom .utils import set_seed, format_time\n\nclass InferenceEngine:\n    def __init__(self, model_path, seed=42):\n        set_seed(seed)\n        self.model = LlamaModel(model_path)\n        self.is_amd_gpu = torch.version.hip is not None\n\n    def run_inference(self, prompt, max_length=100, temperature=0.7):\n        if self.is_amd_gpu:\n            start_event = torch.cuda.Event(enable_timing=True)\n            end_event = torch.cuda.Event(enable_timing=True)\n            start_event.record()\n        else:\n            start_time = torch.cuda.Event(enable_timing=True)\n            end_time = torch.cuda.Event(enable_timing=True)\n            start_time.record()\n\n        output = self.model(prompt, max_length=max_length, temperature=temperature)\n\n        if self.is_amd_gpu:\n            end_event.record()\n            torch.cuda.synchronize()\n            inference_time = start_event.elapsed_time(end_event)\n        else:\n            end_time.record()\n            torch.cuda.synchronize()\n            inference_time = start_time.elapsed_time(end_time)\n\n        return {\n            \"input\": prompt,\n            \"output\": output,\n            \"inference_time\": format_time(inference_time)\n        }\n\n    def batch_inference(self, prompts, **kwargs):\n        results = []\n        for prompt in prompts:\n            results.append(self.run_inference(prompt, **kwargs))\n        return results"
  },
  {
    "path": "src/model.py",
    "content": "import torch\nfrom transformers import AutoTokenizer, AutoModelForCausalLM\n\nclass LlamaModel:\n    def __init__(self, model_name):\n        self.device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n        if self.device.type == \"cuda\" and torch.version.hip is not None:\n            print(\"Using AMD GPU with ROCm\")\n        elif self.device.type == \"cuda\":\n            print(\"Using NVIDIA GPU\")\n        else:\n            print(\"Using CPU\")\n\n        print(f\"Loading model {model_name} from Hugging Face...\")\n        self.tokenizer = AutoTokenizer.from_pretrained(model_name)\n        self.model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16).to(self.device)\n        print(\"Model loaded successfully.\")\n\n    def generate(self, prompt, max_length=100, temperature=0.7):\n        input_ids = self.tokenizer.encode(prompt, return_tensors=\"pt\").to(self.device)\n        \n        with torch.no_grad():\n            output = self.model.generate(\n                input_ids,\n                max_length=max_length,\n                temperature=temperature,\n                num_return_sequences=1,\n                do_sample=True,\n                top_p=0.95,\n            )\n        \n        generated_text = self.tokenizer.decode(output[0], skip_special_tokens=True)\n        return generated_text\n\n    def __call__(self, prompt, **kwargs):\n        return self.generate(prompt, **kwargs)"
  },
  {
    "path": "src/utils.py",
    "content": "import random\nimport torch\nimport numpy as np\n\ndef set_seed(seed):\n    random.seed(seed)\n    np.random.seed(seed)\n    torch.manual_seed(seed)\n    if torch.cuda.is_available():\n        torch.cuda.manual_seed_all(seed)\n\ndef format_time(time_ms):\n    \"\"\"Convert time from milliseconds to a human-readable format.\"\"\"\n    if time_ms < 1000:\n        return f\"{time_ms:.2f}ms\"\n    elif time_ms < 60000:\n        return f\"{time_ms/1000:.2f}s\"\n    else:\n        minutes = int(time_ms / 60000)\n        seconds = (time_ms % 60000) / 1000\n        return f\"{minutes}m {seconds:.2f}s\"\n\ndef get_gpu_memory_usage():\n    \"\"\"Get the current GPU memory usage.\"\"\"\n    if torch.cuda.is_available():\n        return torch.cuda.memory_allocated() / 1024**2  # Convert to MB\n    else:\n        return 0\n\ndef print_gpu_utilization():\n    \"\"\"Print current GPU utilization.\"\"\"\n    if torch.cuda.is_available():\n        if torch.version.hip is not None:\n            print(f\"AMD GPU Memory Usage: {get_gpu_memory_usage():.2f} MB\")\n        else:\n            print(f\"NVIDIA GPU Memory Usage: {get_gpu_memory_usage():.2f} MB\")\n    else:\n        print(\"CUDA is not available. Running on CPU.\")\n\ndef is_amd_gpu():\n    \"\"\"Check if the current GPU is an AMD GPU.\"\"\"\n    return torch.cuda.is_available() and torch.version.hip is not None\n\ndef get_gpu_info():\n    \"\"\"Get information about the current GPU.\"\"\"\n    if not torch.cuda.is_available():\n        return \"No GPU available\"\n    \n    if is_amd_gpu():\n        return f\"AMD GPU: {torch.cuda.get_device_name(0)}\"\n    else:\n        return f\"NVIDIA GPU: {torch.cuda.get_device_name(0)}\""
  }
]