# Hugs

## Docs

- [Hugging Face Generative AI Services (HUGS)](https://huggingface.co/docs/hugs/index.md)
- [Help & Support](https://huggingface.co/docs/hugs/help.md)
- [Supported Models](https://huggingface.co/docs/hugs/models.md)
- [Frequently Asked Questions (FAQ)](https://huggingface.co/docs/hugs/faq.md)
- [Pricing](https://huggingface.co/docs/hugs/pricing.md)
- [Supported Hardware Providers](https://huggingface.co/docs/hugs/hardware.md)
- [Migrate from OpenAI to HUGS](https://huggingface.co/docs/hugs/guides/migrate.md)
- [Function Calling](https://huggingface.co/docs/hugs/guides/function-calling.md)
- [Run Inference on HUGS](https://huggingface.co/docs/hugs/guides/inference.md)
- [Docker](https://huggingface.co/docs/hugs/how-to/docker.md)
- [HUGS on Kubernetes](https://huggingface.co/docs/hugs/how-to/kubernetes.md)
- [HUGS on DigitalOcean](https://huggingface.co/docs/hugs/how-to/cloud/digital-ocean.md)
- [HUGS on Google Cloud](https://huggingface.co/docs/hugs/how-to/cloud/gcp.md)
- [HUGS on AWS with NVIDIA GPUs](https://huggingface.co/docs/hugs/how-to/cloud/aws.md)
- [HUGS on Azure](https://huggingface.co/docs/hugs/how-to/cloud/azure.md)
- [HUGS on AWS with Inferentia & Trainium](https://huggingface.co/docs/hugs/how-to/cloud/aws-neuron.md)

### Hugging Face Generative AI Services (HUGS)
https://huggingface.co/docs/hugs/index.md

# Hugging Face Generative AI Services (HUGS)

![HUGS Banner](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/hugs-banner.png)

> [!TIP]
> September 2025 Update: HUGS is currently deprecated.
>
> **We no longer offer HUGS deployments as this experiment is now discontinued.**

> Optimized, zero-configuration inference microservices for open AI models

Hugging Face Generative AI Services (HUGS) are optimized, zero-configuration inference microservices designed to simplify and accelerate the development of AI applications with open models. Built on open-source Hugging Face technologies such as Text Generation Inference or Transformers. HUGS provides the best solution for efficiently building Generative AI Applications with open models and are optimized for a variety of hardware accelerators, including NVIDIA GPUs, AMD GPUs, AWS Inferentia, and Google TPUs (soon).

## Key Features

- **Zero-configuration Deployment**: Automatically loads optimal settings based on your hardware environment.
- **Optimized Hardware Inference Engines**: Built on [Hugging Face's Text Generation Inference (TGI)](https://github.com/huggingface/text-generation-inference), optimized for a variety of hardware.
- **Hardware Flexibility**: Optimized for various accelerators, including NVIDIA GPUs, AMD GPUs, AWS Inferentia, and Google TPUs
- **Built for Open Models**: Compatible with a wide range of popular open AI models, including LLMs, Multimodal Models, and Embedding Models.
- **Industry Standardized APIs**: Easily deployable using Kubernetes and standardized on the OpenAI API.
- **Security and Control**: Deploy HUGS within your own infrastructure for enhanced security and data control.
- **Enterprise Compliance**: Minimizes compliance risks by including necessary licenses and terms of services.

## Why HUGS?

Enterprises often struggle with their model-serving infrastructure in terms of performance, engineering complexity, and compliance when using open models. Early-stage startups and large enterprises have built POCs using models not because they want to use closed models with black box APIs but because building their AI with open models takes more work.

HUGS are optimized, zero-configuration inference microservices designed to simplify and accelerate the development of AI models. With HUGS, we want to make switching from a closed-source API to a self-hosted open model easy.

HUGS deliver endpoints compatible with the OpenAI API, so you don't need to change your code when transitioning your POC to production with your model and infra. They automatically deliver maximum hardware efficiency.
HUGS make it easy to keep your applications at the cutting edge of Generative AI by offering updates when new battle-tested open models become available.

### Built for Open Models

Compatible with a wide range of popular open AI models, including:

- LLMs: Llama, Gemma, Mistral, Mixtral, Qwen, Deepseek (soon), T5 (soon), Yi (soon), Phi (soon), Command R (soon)
- (Soon) Multimodal Models: Idefics, Llava
- (Soon) Embedding Models: BGE, GTE, Mixbread, Arctic, Jina, Nomic

## Getting Started

To start using HUGS, you have several options. You can access HUGS as part of your Hugging Face Enterprise subscription, through Cloud Service Provider (CSP) marketplaces. Currently, you can find HUGS on Amazon Web Services (AWS) and Google Cloud Platform (GCP), and soon on Microsoft Azure. HUGS are also natively available inside DigitalOcean GPU Droplet.

For detailed instructions on deployment and usage:

- [Hugging Face Enterprise](https://huggingface.co/enterprise)
- Amazon Web Services (AWS)
    - [AWS with NVIDIA GPUs](./how-to/cloud/aws.mdx)
    - [AWS with Inferentia & Trainium](./how-to/cloud/aws-neuron.mdx)
- [DigitalOcean](./how-to/cloud/digital-ocean)
- [Google Cloud Platform (GCP)](./how-to/cloud/gcp)
- [Microsoft Azure](./how-to/cloud/azure) (coming soon)

## More Resources

- [Community Forum](https://discuss.huggingface.co/)
- [Enterprise Support](https://huggingface.co/contact/sales?from=hugs)

Experience the power of open models with the simplicity of HUGS. Start building your AI applications faster and more efficiently today!

### Help & Support
https://huggingface.co/docs/hugs/help.md

# Help & Support

Feel free to ask questions on the forum so the community can also benefit from the answers: https://discuss.huggingface.co/. If you have any other questions or issues, please contact us at api-enterprise@huggingface.co.

### Supported Models
https://huggingface.co/docs/hugs/models.md

# Supported Models

HUGS supports a wide range of open AI models, including LLMs, Multimodal Models, and Embedding Models. Below is a matrix of all the models supported by HUGS and the hardware they are supported on.

## 15 Models Supported

| Model | 1x NVIDIA A10G | 2x NVIDIA A10G | 4x NVIDIA A10G | 8x NVIDIA A10G | 1x NVIDIA L4 | 2x NVIDIA L4 | 4x NVIDIA L4 | 8x NVIDIA L4 | 1x NVIDIA L40S | 2x NVIDIA L40S | 4x NVIDIA L40S | 8x NVIDIA L40S | 1x NVIDIA A100 80GB | 2x NVIDIA A100 80GB | 4x NVIDIA A100 80GB | 8x NVIDIA A100 80GB | 1x NVIDIA H100 | 2x NVIDIA H100 | 4x NVIDIA H100 | 8x NVIDIA H100 | 8x AMD Instinct MI300X | 2x inf2 | 8x inf2 | 24x inf2 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| [meta-llama/Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| [meta-llama/Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct) | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ |
| [meta-llama/Meta-Llama-3.1-405B-Instruct-FP8](https://huggingface.co/meta-llama/Meta-Llama-3.1-405B-Instruct-FP8) | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
| [NousResearch/Hermes-3-Llama-3.1-8B](https://huggingface.co/NousResearch/Hermes-3-Llama-3.1-8B) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| [NousResearch/Hermes-3-Llama-3.1-70B](https://huggingface.co/NousResearch/Hermes-3-Llama-3.1-70B) | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ |
| [NousResearch/Hermes-3-Llama-3.1-405B-FP8](https://huggingface.co/NousResearch/Hermes-3-Llama-3.1-405B-FP8) | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ |
| [NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO](https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO) | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ |
| [mistralai/Mixtral-8x7B-Instruct-v0.1](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1) | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ |
| [mistralai/Mistral-7B-Instruct-v0.3](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| [mistralai/Mixtral-8x22B-Instruct-v0.1](https://huggingface.co/mistralai/Mixtral-8x22B-Instruct-v0.1) | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ |
| [google/gemma-2-27b-it](https://huggingface.co/google/gemma-2-27b-it) | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| [google/gemma-2-9b-it](https://huggingface.co/google/gemma-2-9b-it) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ |
| [Qwen/Qwen2.5-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct) | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| [meta-llama/Llama-3.2-11B-Vision-Instruct](https://huggingface.co/meta-llama/Llama-3.2-11B-Vision-Instruct) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| [meta-llama/Llama-3.2-90B-Vision-Instruct](https://huggingface.co/meta-llama/Llama-3.2-90B-Vision-Instruct) | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |

_**Last Updated**: 2024-11-28_

### Frequently Asked Questions (FAQ)
https://huggingface.co/docs/hugs/faq.md

# Frequently Asked Questions (FAQ)

## What is HUGS?

HUGS (Hugging Face Generative AI Services) are optimized, zero-configuration inference microservices designed to simplify and accelerate the development of AI applications with open models. For more details, see our [Introduction to HUGS](./index).

## Which models are supported by HUGS?

HUGS supports a wide range of open AI models, including LLMs, Multimodal Models, and Embedding Models. For a complete list of supported models, check our [Supported Models](./models) page.

## What hardware is compatible with HUGS?

HUGS is optimized for various hardware accelerators, including NVIDIA GPUs, AMD GPUs, AWS Inferentia, and Google TPUs. For more information, visit our [Supported Hardware](./hardware) page.

## How do I deploy HUGS?

You can deploy HUGS through various methods, including Docker and Kubernetes. For step-by-step deployment instructions, refer to our [Deployment Guide](./how-to/docker).

## Is HUGS available on cloud platforms?

Yes, HUGS is available on major cloud platforms. For specific instructions, check our guides for:

- [AWS with NVIDIA GPUs](./how-to/cloud/aws)
- [AWS with Inferentia & Trainium](./how-to/cloud/aws-neuron)
- [DigitalOcean](./how-to/cloud/digital-ocean)
- [Google Cloud](./how-to/cloud/gcp)
- [Microsoft Azure](./how-to/cloud/azure) (coming soon)

## How does HUGS pricing work?

HUGS offers a on-demand pricing based on the uptime of each container. For detailed pricing information, visit our [Pricing](./pricing) page.

## How do I run inference using HUGS?

To learn how to run inference with HUGS, check our [Inference Guide](./guides/inference).

## What are the key features of HUGS?

HUGS offers several key features, including optimized hardware inference engines, zero-configuration deployment, and industry-standardized APIs. For a complete list of features, see our [Introduction to HUGS](./index#key-features).

## How does HUGS ensure security and compliance?

HUGS allows deployment within your own infrastructure for enhanced security and data control. It also includes necessary licenses and terms of services to minimize compliance risks. For more information, refer to our [Security and Compliance](./index#key-features) section.

## Where can I get help or support for HUGS?

If you need assistance or have questions about HUGS, check our [Help & Support](./help) page for community forums and contact information.

## Can I use HUGS with my existing AI applications?

Yes, HUGS is designed to be easily integrated with existing AI applications. It provides industry-standardized APIs and is compatible with popular Open AI models.

## How does HUGS compare to other AI services?

HUGS offers unique advantages such as optimization for open models, hardware flexibility, and zero-configuration deployment. For a detailed comparison.

## Is HUGS suitable for both small startups and large enterprises?

Yes, HUGS is designed to meet the needs of both small startups and large enterprises. Its flexible deployment options and scalability make it suitable for a wide range of use cases.

### Pricing
https://huggingface.co/docs/hugs/pricing.md

# Pricing

HUGS (Hugging Face Generative AI Services) offers a on-demand pricing based on the uptime of each container, except for DigitalOcean.

## Cloud Marketplace Pricing

For deployments on major cloud platforms, HUGS is available through their respective marketplaces:

- **AWS Marketplace**: $1 per hour per container
- **Google Cloud Platform (GCP) Marketplace**: $1 per hour per container
- (Soon) **Microsoft Azure**

This pricing model is based on the uptime of each container, allowing you to scale your usage according to your needs.

## DigitalOcean

HUGS is available on DigitalOcean free of charge. You only pay for the compute resources used to run the containers.

## Hugging Face Enterprise Customers

For Hugging Face Enterprise customers, we offer custom billing options tailored to your specific requirements. Please contact our sales team for more information on enterprise pricing.

## Additional Costs

Please note that in addition to the HUGS pricing, you may incur costs for:

- Compute resources (e.g., GPU instances)
- Storage
- Data transfer
- Other cloud-specific services used in conjunction with HUGS

These costs are billed directly by your cloud provider and are not included in the HUGS pricing.

### Supported Hardware Providers
https://huggingface.co/docs/hugs/hardware.md

# Supported Hardware Providers

HUGS are optimized for a wide-variety of accelerators for ML inference, and support across different accelerator families and providers will continue to grow exponentially.

## NVIDIA GPUs

NVIDIA GPUs are widely used for machine learning and AI applications, offering high performance and specialized hardware for deep learning tasks. NVIDIA's CUDA platform provides a robust ecosystem for GPU-accelerated computing.

Supported device(s):

- **NVIDIA A10G**: 24GB GDDR6 memory, 9216 CUDA cores, 288 Tensor cores, 72 RT cores
- **NVIDIA L4**: 24GB GDDR6 memory, 7168 CUDA cores, 224 Tensor cores, 56 RT cores
- **NVIDIA L40S**: 48GB GDDR6 memory, 18176 CUDA cores, 568 Tensor cores, 142 RT cores
- **NVIDIA A100**: 40/80GB HBM2e memory, 6912 CUDA cores, 432 Tensor cores, 108 RT cores
- **NVIDIA H100**: 80GB HBM3 memory, 14592 CUDA cores, 456 Tensor cores, 144 RT cores

## AMD GPUs

AMD GPUs provide strong competition in the AI and machine learning space, offering high-performance computing capabilities with their CDNA architecture. AMD's ROCm (Radeon Open Compute) platform enables GPU-accelerated computing on Linux systems.

Supported device(s):

- **AMD Instinct MI300X**: 192GB HBM3 memory, 304 Compute Units, 4864 AI Accelerators

## AWS Accelerators (Inferentia/Trainium)

AWS Inferentia2 is a custom-built accelerator designed specifically for high-performance, cost-effective machine learning inference.

Supported device(s):

- **AWS Inferentia2**: Available in Amazon EC2 Inf2 instances, offering up to 12 Inferentia2 chips per instance. AWS Inferentia2 accelerators are optimized for deploying large language models and other compute-intensive ML workloads, providing high throughput and low latency for inference tasks. More information at [Amazon EC2 Inf2 Instances](https://aws.amazon.com/ec2/instance-types/inf2).
- **AWS Trainium**: _Coming soon!_

## Google TPUs

_Coming soon_

### Migrate from OpenAI to HUGS
https://huggingface.co/docs/hugs/guides/migrate.md

# Migrate from OpenAI to HUGS

Coming soon!

### Function Calling
https://huggingface.co/docs/hugs/guides/function-calling.md

# Function Calling

Function calling is a powerful capability that enables Large Language Models (LLMs) to interact with your code and external systems in a structured way. Instead of just generating text responses, LLMs can understand when to call specific functions and provide the necessary parameters to execute real-world actions.

## How Function Calling Works

The process follows these steps:

![Function Calling](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/function-callin.png)

This cycle can continue as needed, allowing for complex multi-step interactions between the application and the LLM.

## Example Use Cases

Function calling is useful for many practical applications, such as:

1. Data Retrieval: Converting natural language queries into API calls to fetch data (e.g., "Show me my recent orders" triggers a database query)
2. Action Execution: Transforming user requests into specific function calls (e.g., "Schedule a meeting" becomes a calendar API call)
3. Computation Tasks: Handling mathematical or logical operations through dedicated functions (e.g., calculating compound interest or statistical analysis)
4. Data Processing Pipelines: Chaining multiple function calls together (e.g., fetching data → parsing → transformation → storage)
5. UI/UX Integration: Triggering interface updates based on user interactions (e.g., updating map markers or displaying charts)

## Using Tools (Function Definitions)

Tools are the primary way to define callable functions for your LLM. Each tool requires:
- A unique name
- A clear description
- A JSON schema defining the expected parameters

Here's an example that defines weather-related functions:

```python
from huggingface_hub import InferenceClient

client = InferenceClient("http://localhost:8080") # Replace with your HUGS host
messages = [
    {
        "role": "system",
        "content": "Don't make assumptions about values. Ask for clarification if needed.",
    },
    {
        "role": "user",
        "content": "What's the weather like the next 3 days in San Francisco, CA?",
    },
]

tools = [
    {
        "type": "function",
        "function": {
            "name": "get_n_day_weather_forecast",
            "description": "Get an N-day weather forecast",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "The city and state, e.g. San Francisco, CA",
                    },
                    "format": {
                        "type": "string",
                        "enum": ["celsius", "fahrenheit"],
                        "description": "The temperature unit to use",
                    },
                    "num_days": {
                        "type": "integer",
                        "description": "The number of days to forecast",
                    },
                },
                "required": ["location", "format", "num_days"],
            },
        },
    }
]

response = client.chat_completion(
    messages=messages,
    tools=tools,
    tool_choice="auto",
    max_tokens=500,
)
print(response.choices[0].message.tool_calls[0].function)
# ChatCompletionOutputFunctionDefinition(arguments={'format': 'celsius', 'location': 'San Francisco, CA', 'num_days': 3}, name='get_n_day_weather_forecast', description=None)
```

The model will analyze the user's request and generate a structured call to the appropriate function with the correct parameters.

## Using Pydantic Models for structured outputs

For better type safety and validation, you can use Pydantic models to define your function schemas. This approach provides:
- Runtime type checking
- Automatic validation
- Better IDE support
- Clear documentation through Python types

Here's how to use Pydantic models for function calling:

```python
from pydantic import BaseModel, Field
from typing import List

class ParkObservation(BaseModel):
    location: str = Field(..., description="Where the observation took place")
    activity: str = Field(..., description="What activity was being done")
    animals_seen: int = Field(..., description="Number of animals spotted", ge=1, le=5)
    animals: List[str] = Field(..., description="List of animals observed")

client = InferenceClient("http://localhost:8080")  # Replace with your HUGS host
response_format = {"type": "json", "value": ParkObservation.model_json_schema()}

messages = [
    {
        "role": "user",
        "content": "I saw a puppy, a cat and a raccoon during my bike ride in the park.",
    },
]

response = client.chat_completion(
    messages=messages,
    response_format=response_format,
    max_tokens=500,
)
print(response.choices[0].message.content)
# {   "activity": "bike ride",
#     "animals": ["puppy", "cat", "raccoon"],
#     "animals_seen": 3,
#     "location": "the park"
# }
```

This will return a JSON object that matches your schema, making it easy to parse and use in your application.

## Advanced Usage Patterns

### Chaining Function Calls
LLMs can orchestrate multiple function calls to complete complex tasks:

```python
tools = [
    {
        "type": "function",
        "function": {
            "name": "search_products",
            "description": "Search product catalog",
            "parameters": {
                "type": "object",
                "properties": {
                    "query": {"type": "string"},
                    "category": {"type": "string", "enum": ["electronics", "clothing", "books"]}
                }
            }
        }
    },
    {
        "type": "function",
        "function": {
            "name": "create_order",
            "description": "Create a new order",
            "parameters": {
                "type": "object",
                "properties": {
                    "product_id": {"type": "string"},
                    "quantity": {"type": "integer", "minimum": 1}
                }
            }
        }
    }
]
```

### Error Handling and Execution

Always validate function calls before execution:

```python
import json

def get_n_day_weather_forecast(location, format, num_days):
    return '{"temperature": 70, "condition": "sunny"}'

def handle_tool_call(tool_call):
    try:
        args = tool_call.function.arguments
        # Validate required parameters
        if tool_call.function.name == "get_n_day_weather_forecast":
            if not all(k in args for k in ["location", "format", "num_days"]):
                raise ValueError("Missing required parameters")
            # Only pass arguments that match the function's parameters
            valid_args = {k: v for k, v in args.items() 
                         if k in get_n_day_weather_forecast.__code__.co_varnames}
            return get_n_day_weather_forecast(**valid_args)
    except json.JSONDecodeError:
        return {"error": "Invalid function arguments"}
    except Exception as e:
        return {"error": str(e)}

res = handle_tool_call(response.choices[0].message.tool_calls[0])
print(res)
# {"temperature": 70, "condition": "sunny"}
```

## Best Practices

1. **Function Design**
   - Keep function names clear and specific
   - Use detailed descriptions for functions and parameters
   - Include parameter constraints (min/max values, enums, etc.)

2. **Error Handling**
   - Validate all function inputs
   - Implement proper error handling for failed function calls
   - Consider retry logic for transient failures

3. **Security**
   - Validate and sanitize all inputs before execution
   - Implement rate limiting and access controls
   - Consider function call permissions based on user context

Never expose sensitive operations directly through function calls. Always implement proper validation and authorization checks.

For more information about basic inference capabilities, see our [Inference Guide](./inference).

### Run Inference on HUGS
https://huggingface.co/docs/hugs/guides/inference.md

# Run Inference on HUGS

HUGS, as already mentioned, is based on Text Generation Inference (TGI); meaning that running inference over a deployed HUGS container is exactly the same as for TGI. For more information, please refer to [Text Generation Inference Documentation on how to consume TGI](https://huggingface.co/docs/text-generation-inference/en/basic_tutorials/consuming_tgi).

In the inference examples show below, the host is assumed to be `localhost` which is the case when deploying HUGS via Kubernetes with port-forwarding or when deploying it with `docker run` on the current instance. If you have deployed HUGS on Kubernetes using an ingress under a specific IP, host, and/or with SSL (HTTPS), note that you should update the `localhost` references below with your host or IP.

## Messages API

The Messages API is an OpenAI-compatible endpoint under `/v1/chat/completions` following the [OpenAI OpenAPI Specification](https://github.com/openai/openai-openapi). Being OpenAI-compatible implies that the inference can be run not only with `cURL` but also with both the `huggingface_hub.InferenceClient` and the `openai.OpenAI` SDK in Python, as well as any other OpenAI-compatible SDK in any programming language.

### cURL

Using `cURL` is pretty straight forward to [install](https://curl.se/docs/install.html) and use.

```bash
curl http://localhost:8080/v1/chat/completions \
    -X POST \
    -d '{"model":"tgi","messages":[{"role":"user","content":"What is Deep Learning?"}],"temperature":0.7,"top_p":0.95,"max_tokens":128}}' \
    -H 'Content-Type: application/json'
```

### Python

As already mentioned, you can either use the `huggingface_hub.InferenceClient` from the `huggingface_hub` Python SDK (recommended), the `openai` Python SDK, or any SDK with an OpenAI-compatible interface that can consume the Messages API.

#### `huggingface_hub`

You can install it via pip as `pip install --upgrade --quiet huggingface_hub`, and then run the following snippet to mimic the `cURL` commands above i.e. sending requests to the Messages API:

```python
from huggingface_hub import InferenceClient

client = InferenceClient(base_url="http://localhost:8080", api_key="-")

chat_completion = client.chat.completions.create(
    messages=[
        {"role":"user","content":"What is Deep Learning?"},
    ],
    temperature=0.7,
    top_p=0.95,
    max_tokens=128,
)
```

Read more about the [`huggingface_hub.InferenceClient.chat_completion` method](https://huggingface.co/docs/huggingface_hub/en/package_reference/inference_client#huggingface_hub.AsyncInferenceClient.chat_completion).

#### `openai`

Alternatively, you can also use the Messages API via `openai`; you can install it via `pip as pip install --upgrade openai`, and then run:

```python
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8080/v1/", api_key="-")

chat_completion = client.chat.completions.create(
    model="tgi",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is Deep Learning?"},
    ],
    temperature=0.7,
    top_p=0.95,
    max_tokens=128,
)
```

## Other endpoints

Besides the endpoints mentioned above, TGI also comes with other endpoints as defined in the [TGI OpenAPI Specification](https://huggingface.github.io/text-generation-inference/) that can be used not also for inference but also for tokenization, metrics, or information about the deployed model.

### Docker
https://huggingface.co/docs/hugs/how-to/docker.md

# Docker

HUGS support deployment on Docker. You can run HUGS with default settings from a command line, or customize your configuration by creating your own docker-compose.yml file.

## Run HUGS with Docker

To run HUGS with Docker using default settings, run this command from from your shell:

```bash
export HUGS_CACHE=~/.cache/hugs
mkdir -p "$HUGS_CACHE"
docker run -it --rm \
    --gpus all \
    --shm-size=16GB \
    -v "$HUGS_CACHE:/tmp" \
    -p 8080:80 \
   'hfhugs/nvidia-google-gemma-2-9b-it:0.2.0'
```

The container URI might differ depending on the distribution and the model you are using.

The command sets the following default environment variables in the container:

- `HUGS_CACHE` defaults to `~/.cache/hugs`. This is the cache for the models, for faster loading next time.

## Run HUGS Container with AWS Inferentia2/Trainium

To run HUGS on AWS instances with Inferentia2 or Trainium accelerators, you'll need to use a compatible Docker image and configure access to the Neuron devices. There are two ways to provide container access to Neuron devices:

1. Using `--privileged` flag (grants access to all Neuron devices)
2. Using `--device` flags (grants access to specific Neuron devices)

You can run the container with the `--privileged` flag to grant access to all Neuron devices:

```bash
export HUGS_CACHE=~/.cache/hugs
mkdir -p "$HUGS_CACHE"
sudo docker run -it --rm \
    --shm-size=16GB \
    --privileged \
    -v "$HUGS_CACHE:/tmp" \
    -p 8080:80 \
    'hfhugs/neuron-meta-llama-meta-llama-3.1-8b-instruct:0.2.0'
```

Alternatively, you can specify individual Neuron devices using `--device` flags for more fine-grained control:

```bash
export HUGS_CACHE=~/.cache/hugs
mkdir -p "$HUGS_CACHE"
sudo docker run -it --rm \
    --shm-size=16GB \
    --device=/dev/neuron0 \
    --device=/dev/neuron1 \
    --device=/dev/neuron2 \
    --device=/dev/neuron3 \
    -v "$HUGS_CACHE:/tmp" \
    -p 8080:80 \
    'hfhugs/neuron-meta-llama-meta-llama-3.1-8b-instruct:0.2.0'
```

Using individual `--device` flags provides more fine-grained control over which Neuron devices are accessible to the container, which can be useful when running multiple containers on the same instance.

## Sample Docker Compose file

You can also use a `docker-compose.yml` file to customize your configuration.

```
version: '3.8'

services:
  hugs:
    image: hfhugs/nvidia-google-gemma-2-9b-it
    ports:
      - 8080:80
    volumes:
      - ${HUGS_CACHE:-~/.cache/hugs}:/tmp
    environment:
      - HUGS_CACHE=/tmp
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    shm_size: 16GB
    restart: on-failure:0

volumes:
  hugs_cache:

```

Edit the `docker-compose.yml` file to suit your needs. You can add or remove environment variables, change the port mappings. To start your HUGS instance, run this command from your shell:

```bash
docker compose up
```

### HUGS on Kubernetes
https://huggingface.co/docs/hugs/how-to/kubernetes.md

# HUGS on Kubernetes

HUGS (Hugging Face Generative AI Services) can be deployed on Kubernetes for scalable and manageable AI model inference. This guide will walk you through the process of deploying HUGS on a Kubernetes cluster.

## Requirements

- A Kubernetes Cluster (version 1.23 or later)
- Helm version v3 or higher

## HUGS Helm Chart

To install the HUGS chart on your Kubernetes cluster, follow these steps:

### Verify tool setup and cluster access

```bash
# Check if helm is installed
helm version
# Make sure `kubectl` is configured correctly and you can access the cluster
kubectl get pods
```

### Get the Helm Chart

Add the HUGS helm repo and update it:

```bash
helm repo add hugs https://raw.githubusercontent.com/huggingface/hugs-helm-chart/main/charts/hugs
helm repo update hugs
```

Get the default `values.yaml` configuration file:

```bash
helm show values hugs/hugs > values.yaml
```

### Modify values.yaml

Edit the `values.yaml` file to customize the Helm chart for your environment. Here are some key sections you might want to modify:

#### Model Selection

Choose the HUGS model you want to deploy. For example, to deploy the Gemma 2 9B Instruct model:

```yaml
image:
  repository: hfhugs
  name: nvidia-google-gemma-2-9b-it
  tag: latest
```

> [!NOTE]
> The container URI might differ depending on the distribution and the model you are using.

#### Resource Limits

Adjust the resource limits based on your cluster's capabilities and the model's requirements. For example:

```yaml
resources:
  limits:
    nvidia.com/gpu: 1
  requests:
    nvidia.com/gpu: 1
```

### Deploy (install the Helm chart)

Deploy the HUGS Helm chart:

```bash
# Create a HUGS namespace
kubectl create namespace hugs

# Deploy
helm upgrade --install \
  "hugs" \
  hugs/hugs \
  --namespace "hugs" \
  --values ./values.yaml
```

## Running Inference

Once HUGS is deployed, you can run inference using the provided API. For detailed instructions, refer to [the inference guide](../guides/inference).

## Troubleshooting

If you encounter issues with your HUGS deployment on Kubernetes, consider the following:

1. Check pod status: `kubectl get pods -n hugs`
2. View pod logs: `kubectl logs  -n hugs`
3. Ensure your cluster has sufficient resources for the chosen model
4. Verify that the correct NVIDIA drivers and CUDA versions are installed on your nodes if using GPU acceleration

For more specific troubleshooting steps, consult the HUGS documentation or community forums.

## Updating and Upgrading

To update your HUGS deployment after the initial setup, modify your `values.yaml` file and run the `helm upgrade` command again:

```bash
helm upgrade hugs hugs/hugs --namespace hugs --values ./values.yaml
```

Always check the release notes for any breaking changes or specific upgrade instructions when moving to a new version of HUGS.

By following this guide, you should be able to successfully deploy HUGS on your Kubernetes cluster and start running inference with your chosen AI models.

### HUGS on DigitalOcean
https://huggingface.co/docs/hugs/how-to/cloud/digital-ocean.md

# HUGS on DigitalOcean

The Hugging Face Generative AI Services, also known as HUGS, can be deployed in DigitalOcean (DO) via the GPU Droplets as 1-Click Models.

This collaboration brings Hugging Face's extensive library of pre-trained models and their Text Generation Inference (TGI) solution to DigitalOcean customers, enabling seamless integration of state-of-the-art Large Language Models (LLMs) within the GPU Droplets of Digitial Ocean.

HUGS provides access to a hand-picked and manually benchmarked collection of the most performant and latest open LLMs hosted in the Hugging Face Hub to TGI-optimized container applications, allowing users to deploy LLMs with a 1-Click deployment on DigitalOcean GPU Droplets.

With HUGS, developers can easily find, subscribe to, and deploy Hugging Face models using DigitalOcean's infrastructure, leveraging the power of NVIDIA GPUs on optimized, zero-configuration TGI containers.

**More How to:**

* [Deploying Hugging Face Generative AI Services on DigitalOcean GPU Droplet and Integrating with Open WebUI](https://www.digitalocean.com/community/tutorials/deploy-hugs-on-gpu-droplets-open-webui)

## 1-Click Deploy of HUGS in DO GPU Droplets

1. Create a DigitalOcean account with a valid payment method, if you don't have one already, and make sure that you have enough quota to spin up GPU Droplets.

2. Go to [DigitalOcean GPU Droplets](https://www.digitalocean.com/products/gpu-droplets) and create a new one.

![Create GPU Droplet on DigitalOcean](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/digital-ocean/create-gpu-droplet.png)

3. Choose a data-center region (New York i.e. NYC2, or Toronto i.e. TOR1, available at the time of writing this).

4. Choose the 1-Click Models when choosing an image, and select any of the available Hugging Face images that correspond to popular LLMs hosted on the Hugging Face Hub.

![Choose 1-Click Models on DigitalOcean](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/digital-ocean/one-click-models.png)

5. Configure the remaining options, and click on "Create GPU Droplet" when done.

### HUGS Inference on DO GPU Droplets

Once the HUGS LLM has been deployed in a DO GPU Droplet, you can either connect to it via the public IP exposed by the instance, or just connect to it via the Web Console.

![HUGS on DigitalOcean GPU Droplet](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/digital-ocean/hugs-gpu-droplet.png)

When connected to the HUGS Droplet, the initial SSH message will display a Bearer Token, which is required to send requests to the public IP of the deployed HUGS Droplet.

Then you can send requests to the Messages API via either `localhost` if connected within the HUGS Droplet, or via its public IP.

In the inference examples in the guide below, the host is assumed to be `localhost`, which is the case when deploying HUGS via GPU Droplet and connecting to the running instance via SSH. If you prefer to use the public IP instead, then you should update that in the examples provided below.

Refer to [Run Inference on HUGS](../../guides/inference) to see how to run inference on HUGS, but note that in this case you will need to use the Bearer Token provided, so find below the updated examples as in the guide, but using the Bearer Token to send the requests to the Messages API of the deployed HUGS Droplet (assuming that the Bearer Token is stored in the environment variable `export BEARER_TOKEN`).

#### cURL

Using `cURL` is pretty straight forward to [install](https://curl.se/docs/install.html) and use.

```bash
curl http://localhost:8080/v1/chat/completions \
    -X POST \
    -d '{"messages":[{"role":"user","content":"What is Deep Learning?"}],"temperature":0.7,"top_p":0.95,"max_tokens":128}}' \
    -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $BEARER_TOKEN"
```

#### Python

As already mentioned, you can either use the `huggingface_hub.InferenceClient` from the `huggingface_hub` Python SDK (recommended), the `openai` Python SDK, or any SDK with an OpenAI-compatible interface that can consume the Messages API.

##### `huggingface_hub`

You can install it via pip as `pip install --upgrade --quiet huggingface_hub`, and then run the following snippet to mimic the `cURL` commands above i.e. sending requests to the Messages API:

```python
import os
from huggingface_hub import InferenceClient

client = InferenceClient(base_url="http://localhost:8080", api_key=os.getenv("BEARER_TOKEN"))

chat_completion = client.chat.completions.create(
    messages=[
        {"role":"user","content":"What is Deep Learning?"},
    ],
    temperature=0.7,
    top_p=0.95,
    max_tokens=128,
)
```

Read more about the [`huggingface_hub.InferenceClient.chat_completion` method](https://huggingface.co/docs/huggingface_hub/en/package_reference/inference_client#huggingface_hub.AsyncInferenceClient.chat_completion).

##### `openai`

Alternatively, you can also use the Messages API via `openai`; you can install it via `pip as pip install --upgrade openai`, and then run:

```python
import os
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8080/v1/", api_key=os.getenv("BEARER_TOKEN"))

chat_completion = client.chat.completions.create(
    model="tgi",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is Deep Learning?"},
    ],
    temperature=0.7,
    top_p=0.95,
    max_tokens=128,
)
```

### Delete created DO GPU Droplet

Finally, once you are done using the deployed LLM via the GPU Droplet, you can safely delete it to avoid incurring in unnecessary costs via the "Actions" option within the deployed LLM, and then delete it.

### HUGS on Google Cloud
https://huggingface.co/docs/hugs/how-to/cloud/gcp.md

# HUGS on Google Cloud

The Hugging Face Generative AI Services, also known as HUGS, can be deployed in Google Cloud via the Google Cloud Marketplace offering.

This collaboration brings Hugging Face's extensive library of pre-trained models and their Text Generation Inference (TGI) solution to Google Cloud customers, enabling seamless integration of state-of-the-art Large Language Models (LLMs) within the Google Cloud infrastructure.

HUGS provides access to a hand-picked and manually benchmarked collection of the most performant and latest open LLMs hosted in the Hugging Face Hub to TGI-optimized container applications, allowing users to deploy third-party Kubernetes applications on GCP or on-premises environments.

With HUGS, developers can easily find, subscribe to, and deploy Hugging Face models using GCP infrastructure, leveraging the power of NVIDIA GPUs on optimized, zero-configuration TGI containers.

## Subscribe to HUGS on GCP Marketplace

1. Go to [HUGS Google Cloud Marketplace listing](https://console.cloud.google.com/marketplace/product/huggingface-public/hugs)

   ![HUGS on Google Cloud Marketplace](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/gcp/hugs-marketplace-listing.png)

2. Subscribe to the product in Google Cloud by following the instructions on the page. At the time of writing (October 2024), the steps are to:

   1. Click `Purchase`, then go to the next page.
   2. Configure the order by selecting the right plan, billing account, and confirming the terms. Then click `Subscribe`.

   ![HUGS Configuration on Google Cloud Marketplace](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/gcp/hugs-configuration.png)

3. You should see a "Your order request has been sent to Hugging Face" message. With a button "Go to Product Page". Click on it.

   ![HUGS Confirmation on Google Cloud Marketplace](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/gcp/hugs-confirmation.png)

To know whether you are subscribed or not, you can either see if the "Purchase" button or "Configure" button is enabled on the product page, meaning that either you or someone else from your organization has already requested access for your account. 

## Deploy HUGS on Google Cloud GKE

This example showcases how to deploy a HUGS container and model on Google Cloud GKE.

This example assumes that you have an Google Cloud Account, that you have [installed and setup the Google Cloud CLI](https://cloud.google.com/sdk/docs/install), and that you are logged in into your account with the necessary permissions to subscribe to offerings in the Google Cloud Marketplace, and create and manage IAM permissions and resources such as Google Kubernetes Engine (GKE). 

When deploying HUGS on Google Cloud through the UI you can either select an existing GKE cluster or create a new one. If you want to create a new one, you can follow the instructions [here](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-a-cluster). Additionally you need to define:

* Namespace: The namespace to deploy the HUGS container and model.
* App Instance Name: The name of the HUGS container.
* Hugs Model Id: Select the model you want to deploy from the Hugging Face Hub. You can find all supported model [here](../models)
* GPU Number: The number of GPUs you have available and want to use for the deployment, make sure to check the [supported model matrix](../../models) to know which model requires GPUs.
* GPU Type: The type of GPU you have available inside your GKE cluster.
* Reporting Service Account: The service account to use for reporting. 

   ![HUGS Deployment Configuration](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/gcp/hugs-deploy.png)

Next you click on `Deploy` and wait for the deployment to finish. This takes around 10-15 minutes.

If you want to better understand the different deployment options you have, e.g. 1x NVIDIA L4 GPU for Meta Llama 3.1 8B Instruct, you can checkout the [supported model matrix](../../models).

## Send request to the HUGS application

Every HUGS application includes instructions on how to retrieve the Ingress IP address and port to send requests to the application. A HUGS deployment is a deployment of a HELM chart that includes our model container, marketplace agent (sidecar), a volume and a ingress load balancer to make the application accessible from outside the cluster.

   ![HUGS Ingress](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/gcp/applicaiton-instructions.png)

Alternatively, you can also use the Messages API via `openai`. Learn more about inference [here](../guides/inference).

## Create a GPU GKE Cluster for HUGS

To deploy HUGS on Google Cloud, you'll need a GKE cluster with GPU support. Here's a step-by-step guide to create one:

1. Ensure you have the [Google Cloud CLI installed and configured](https://cloud.google.com/sdk/docs/install-sdk).

2. Set up environment variables for your cluster configuration:

```bash
export PROJECT_ID="your-project-id" # Your Google Cloud Project ID which is subscribed to HUGS
export CLUSTER_NAME="hugs-cluster" # The name of the GKE cluster
export LOCATION="us-central1" # The location of the GKE cluster
export MACHINE_TYPE="g2-standard-12" # The machine type of the GKE cluster
export GPU_TYPE="nvidia-l4" # The type of GPU to use
export GPU_COUNT=1 # The number of GPUs to use
```

3. Create the GKE cluster:

```bash
gcloud container clusters create $CLUSTER_NAME \
    --project=$PROJECT_ID \
    --zone=$LOCATION \
    --release-channel=stable \
    --cluster-version=1.29 \
    --machine-type=$MACHINE_TYPE \
    --num-nodes=1 \
    --no-enable-autoprovisioning
```

4. Add a GPU node pool to the cluster:

```bash
gcloud container node-pools create gpu-pool \
    --cluster=$CLUSTER_NAME \
    --zone=$LOCATION \
    --machine-type=$MACHINE_TYPE \
    --accelerator type=$GPU_TYPE,count=$GPU_COUNT,gpu-driver-version=default \
    --num-nodes=1 \
    --enable-autoscaling \
    --min-nodes=1 \
    --max-nodes=1 \
    --spot \
    --disk-type=pd-ssd \
    --disk-size=100GB 
```

5. Configure kubectl to use the new cluster:

```bash
gcloud container clusters get-credentials $CLUSTER_NAME --zone=$LOCATION
```

Your GKE cluster with GPU support is now ready for HUGS deployment. You can proceed to deploy HUGS using the Google Cloud Marketplace as described in the previous section.

For more detailed information on creating and managing GKE clusters, refer to the [official Google Kubernetes Engine documentation](https://cloud.google.com/kubernetes-engine/docs) or [run GPUs in GKE Standard node pools](https://cloud.google.com/kubernetes-engine/docs/how-to/gpus).

### HUGS on AWS with NVIDIA GPUs
https://huggingface.co/docs/hugs/how-to/cloud/aws.md

# HUGS on AWS with NVIDIA GPUs

The Hugging Face Generative AI Services, also known as HUGS, can be deployed in Amazon Web Services (AWS) via the AWS Marketplace offering.

This collaboration brings Hugging Face's extensive library of pre-trained models and their Text Generation Inference (TGI) solution to AWS customers, enabling seamless integration of state-of-the-art Large Language Models (LLMs) within the AWS infrastructure.

HUGS provides access to a hand-picked and manually benchmarked collection of the most performant and latest open LLMs hosted in the Hugging Face Hub to TGI-optimized container applications, allowing users to deploy third-party Kubernetes applications on AWS or on-premises environments.

With HUGS, developers can easily find, subscribe to, and deploy Hugging Face models using AWS infrastructure, leveraging the power of NVIDIA GPUs on optimized, zero-configuration TGI containers.

## Subscribe to HUGS on AWS Marketplace

1. Go to [HUGS AWS Marketplace listing](https://aws.amazon.com/marketplace/pp/prodview-bqy5zfvz3wox6)

   ![HUGS on AWS Marketplace](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/aws/hugs-marketplace-listing.png)

2. Subscribe to the product in AWS Marketplace by following the instructions on the page. At the time of writing (December 2024), the steps are to:

   1. Click `Continue to Subscribe`, then go to the next page.
   2. Click `Continue to Configuration`, then go to the next page.
   3. Select the fulfillment option e.g. `HUGS v2 for NVIDIA GPUs and AWS Inferentia2`, and the software version e.g. `0.2.0`.

   ![HUGS Configuration on AWS Marketplace](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/aws/hugs-configuration.png)

3. Then click `Continue to Launch`. You successfully subscribe to HUGS. You can now follow the steps below to deploy your preferred HUGS container and model using Amazon EKS, with the provided container URIs.

To know whether you are subscribed or not, you can either see if a blue modal appears on top of the product page with a text saying "You have access to this product", meaning that either you or someone else from your organization has already requested access for your account; otherwise, you can go to the AWS Marketplace service in the AWS Console and search for "HUGS (HUgging Face Generative AI Services)" is listed among your subscribed products.

## Deploy HUGS on Amazon EKS

This example showcases how to create a Kubernetes Cluster on Amazon EKS, how to create a node group with the necessary permissions and compute requirements, and how to deploy HUGS on Amazon EKS using a Helm template.

This example assumes that you have an AWS Account, that you have [installed and setup the AWS CLI](https://docs.aws.amazon.com/eks/latest/userguide/install-awscli.html), and that you are logged in into your account with the necessary permissions to subscribe to offerings in the AWS Marketplace, and create and manage IAM permissions and resources such as Elastic Kubernetes Service (EKS), Elastic Container Service (ECS), and EC2.

### Requirements

Before proceeding, you need to have installed both `kubectl`, `eksctl`, and `helm`, to interact with the Kubernetes Cluster, to create, configure and delete resources on Amazon EKS, and to interact with the Helm templates, respectively.

To install both `kubectl` and `eksctl` you can follow the instructions at [Amazon EKS Documentation - Set up kubectl and eksctl](https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html). Whilst for `helm` you can follow the instructions at [Helm Documentation - Installing Helm](https://helm.sh/docs/intro/install/).

Finally, for convenience the following environment variables will be set:

```bash
export REGION="us-east-1"
export NAMESPACE="default"
export CLUSTER_NAME="hugs-cluster"
export NODE_GROUP_NAME="hugs-node-group"
export SERVICE_ACCOUNT_NAME="hugs-service-account"
export DEPLOYMENT_NAME="hugs"
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
```

If your AWS Account has multiple profiles remember to set the `AWS_PROFILE` environment variable to your profile so that the EKS commands use the correct profile.

### Setup Amazon EKS

To create the EKS Cluster, Node Group, and add the necessary IAM permissions, you should run `eksctl` with the provided configuration file `eks-cluster.yaml` that looks like:

```yaml
# Specifies the API version and kind of the configuration
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

# Defines the basic cluster metadata
metadata:
  name: $CLUSTER_NAME # Cluster name, used in various AWS resource names
  region: $REGION # AWS region where the cluster will be created
  version: "1.30" # Kubernetes version to use for the cluster

# IAM configuration for the cluster
iam:
  withOIDC: true # Enables IAM roles for service accounts (IRSA) using OIDC
  serviceAccounts:
    # Configures a service account for marketplace metering
    - metadata:
        name: $SERVICE_ACCOUNT_NAME
        namespace: $NAMESPACE
      attachPolicyARNs:
        - arn:aws:iam::aws:policy/AWSMarketplaceMeteringRegisterUsage
    # Configures a service account for the AWS Load Balancer Controller (just required
    # if ingress is enabled within the HUGS Helm Template)
    - metadata:
        name: aws-load-balancer-controller
        namespace: $NAMESPACE
      attachPolicyARNs:
        - arn:aws:iam::$AWS_ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy
      roleName: AmazonEKSLoadBalancerControllerRole

# Defines the managed node group for the cluster
managedNodeGroups:
  - name: $NODE_GROUP_NAME
    instanceType: g5.xlarge # GPU-enabled instance type, required by HUGS
    minSize: 1
    maxSize: 2 # Set to a greater number if you want to enable auto-scaling
    desiredCapacity: 1 # Fixed size node group, can be adjusted for scaling

# Specifies the EKS add-ons to be installed (default ones)
# All the addons below will be installed within the `kube-system` namespace
addons:
  - name: vpc-cni # Amazon VPC CNI plugin for Kubernetes
  - name: coredns # CoreDNS for Kubernetes DNS services
  - name: kube-proxy # kube-proxy for Kubernetes network proxy

# Configures CloudWatch logging for the cluster
cloudWatch:
  clusterLogging:
    enableTypes: ["*"] # Enables all types of control plane logging
```

Alternatively, you can download the file from the [`huggingface/hugs-helm-chart`](https://github.com/huggingface/hugs-helm-chart) GitHub repository as follows:

```bash
curl -O https://raw.githubusercontent.com/huggingface/hugs-helm-chart/main/aws/eks-cluster.yaml
```

Optionally, before creating the cluster you may need to create the IAM Policy required to enable the AWS LoadBalancer Controller i.e. `AWSLoadBalancerControllerIAMPolicy`, so as to deploy the ingress which requires the AWS LoadBalancer Controller to be enabled, as per [Install AWS Load Balancer Controller with Helm - Step 1: Create IAM Role using eksctl](https://docs.aws.amazon.com/eks/latest/userguide/lbc-helm.html#lbc-helm-iam).

```bash
curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.7.2/docs/install/iam_policy.json
aws iam create-policy \
    --policy-name AWSLoadBalancerControllerIAMPolicy \
    --policy-document file://iam_policy.json
```

Note that the policy just needs to be created once per account, meaning that if it's already created then you can reuse the existing one. Otherwise, you can alternatively create the policy under a different name, but along this example the policy is assumed to be named `AWSLoadBalancerControllerIAMPolicy`.

Alternatively, if you decided to skip the AWS LoadBalancer creation above, then you should remove the `iam.serviceAccounts` for the `aws-load-balancer-controller` before moving on to the next step.

Then you need to run the following command, that will replace the values set in the environment variables above within the [`eks-cluster.yaml`](https://github.com/huggingface/hugs-helm-chart/blob/main/aws/eks-cluster.yaml) file provided in [`huggingface/hugs-helm-chart`](https://github.com/huggingface/hugs-helm-chart). To replace the environment variable values within the `eks-cluster.yaml` file above, [`envsubst`](https://linux.die.net/man/1/envsubst) will be used, which may not be available for Windows users.

```bash
envsubst  eks-cluster.yaml
```

Once the `eks-cluster.yaml` file has been updated, then you can just run the following command:

```bash
eksctl create cluster --config-file eks-cluster.yaml
```

If you want to enable or use the AWS LoadBalancer, you will need to deploy that separately before deploying HUGS, in order to enable the ingress.

```bash
helm repo add eks https://aws.github.io/eks-charts
helm repo update eks
helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
    --namespace $NAMESPACE \
    --set clusterName=$CLUSTER_NAME \
    --set serviceAccount.create=false \
    --set serviceAccount.name=aws-load-balancer-controller
```

If you decide to deploy the AWS LoadBalancer Controller and enable the ingress within the HUGS deployment, then you will need to wait until the ALB controller is running before deploying HUGS, to do so you can use the following `kubectl` command:

```bash
kubectl wait --namespace $NAMESPACE \
    --for=condition=ready pod \
    --selector=app.kubernetes.io/name=aws-load-balancer-controller \
    --timeout=90s
```

### Deploy HUGS with Helm on Amazon EKS

Finally, you can install the Helm template to deploy the HUGS container with the selected model, e.g. `meta-llama/Llama-3.1-8B-Instruct`; and you need to set the container URI provided by the AWS Marketplace for your account, either via the `--set` option when running `helm install` (as shown below), or modifying its value within the [`eks-values.yaml`](https://github.com/huggingface/hugs-helm-chart/blob/main/aws/eks-values.yaml) file provided in [`huggingface/hugs-helm-chart`](https://github.com/huggingface/hugs-helm-chart).

```bash
curl -O https://raw.githubusercontent.com/huggingface/hugs-helm-chart/main/aws/eks-values.yaml

helm repo add hugs https://raw.githubusercontent.com/huggingface/hugs-helm-chart/main/charts/hugs
helm repo update hugs

helm install $DEPLOYMENT_NAME hugs/hugs \
    -f eks-values.yaml \
    --set image.registry="XXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com" \
    --set image.repository="hugging-face" \
    --set image.name="nvidia-meta-llama-meta-llama-3.1-8b-instruct" \
    --set image.tag="0.1.0" \
    --set serviceAccountName=$SERVICE_ACCOUNT_NAME \
    --set nodeSelector."eks\.amazonaws\.com/nodegroup"=$NODE_GROUP_NAME
```

The command above assumes that you followed the steps within this example, if you changed the node group name, the service account name, the container, or the number of accelerators; you should manually modify or create a new `values.yaml` file out of [`eks-values.yaml`](https://github.com/huggingface/hugs-helm-chart/blob/main/aws/eks-values.yaml) with your custom settings.

### Inference on HUGS

To run the inference over the deployed HUGS service, you can either:

- Forward the port via port-forwarding to a local port as e.g. 8080 (so that you can send requests to the service via `localhost`) with the command:

  ```bash
  kubectl port-forward service/$DEPLOYMENT_NAME 8080:80
  ```

- Use the external IP or hostname of the ingress, if `ingress.enabled: true`, that can be retrieved with the following command:

  ```bash
  kubectl get ingress $DEPLOYMENT_NAME -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
  ```

Then you can send requests to the Messages API via either `localhost`, the ingress IP or the ingress hostname, from outside the running pod.

In the inference examples in the guide below, the host is assumed to be `localhost` which is the case when deploying HUGS via Kubernetes with port-forwarding. If you have deployed HUGS on Kubernetes using an ingress under a specific IP, host, and/or with SSL (HTTPS), note that you should update the `localhost` references below with your host or IP.

Refer to [Run Inference on HUGS](../../guides/inference) to see how to run inference on HUGS.

### Uninstall HUGS

Since HUGS was installed via `helm install` you can simply uninstall it as:

```bash
helm uninstall $DEPLOYMENT_NAME
```

And `helm uninstall` will remove all the workloads created, in this case being the Deployment, the Service, the Ingress, and the Horizontal Pod Autoscaler (HPA); alternatively, if you also installed the AWS LoadBalancer Controller, you can also uninstall it as follows:

```bash
helm uninstall aws-load-balancer-controller
```

Alternatively, once you are done using Amazon EKS Cluster, you can safely delete it to avoid incurring in unnecessary costs as:

```bash
eksctl delete cluster --name=$CLUSTER_NAME --region=$REGION
```

### HUGS on Azure
https://huggingface.co/docs/hugs/how-to/cloud/azure.md

# HUGS on Azure

Coming soon!

### HUGS on AWS with Inferentia & Trainium
https://huggingface.co/docs/hugs/how-to/cloud/aws-neuron.md

# HUGS on AWS with Inferentia & Trainium

The Hugging Face Generative AI Services, also known as HUGS, can be deployed in Amazon Web Services (AWS) via the AWS Marketplace offering.

This collaboration brings Hugging Face's extensive library of pre-trained models and their Text Generation Inference (TGI) solution to AWS customers, enabling seamless integration of state-of-the-art Large Language Models (LLMs) within the AWS infrastructure.

HUGS provides access to a hand-picked and manually benchmarked collection of the most performant and latest open LLMs hosted in the Hugging Face Hub to TGI-optimized container applications, allowing users to deploy third-party Kubernetes applications on AWS or on-premises environments.

With HUGS, developers can easily find, subscribe to, and deploy Hugging Face models using AWS infrastructure, leveraging the power of AWS Neuron Inferentia2 on optimized, zero-configuration TGI containers.

HUGS provides the following AWS Neuron-compatible models within the HUGS 0.2.0 release (find below the Hugging Face Model ID and their HUGS `IMAGE_NAME`):

- [meta-llama/Meta-Llama-3.1-8B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-8B-Instruct): `neuron-meta-llama-meta-llama-3.1-8b-instruct`
- [meta-llama/Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct): `neuron-meta-llama-meta-llama-3.1-70b-instruct`
- [NousResearch/Hermes-3-Llama-3.1-8B](https://huggingface.co/NousResearch/Hermes-3-Llama-3.1-8B): `neuron-nousresearch-hermes-3-llama-3.1-8b`
- [NousResearch/Hermes-3-Llama-3.1-70B](https://huggingface.co/NousResearch/Hermes-3-Llama-3.1-70B): `neuron-nousresearch-hermes-3-llama-3.1-70b`
- [NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO](https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO): `neuron-nousresearch-nous-hermes-2-mixtral-8x7b-dpo`
- [mistralai/Mixtral-8x7B-Instruct-v0.1](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1): `neuron-mistralai-mixtral-8x7b-instruct-v0.1`
- [mistralai/Mistral-7B-Instruct-v0.3](https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.3): `neuron-mistralai-mistral-7b-instruct-v0.3`
- [mistralai/Mixtral-8x22B-Instruct-v0.1](https://huggingface.co/mistralai/Mixtral-8x22B-Instruct-v0.1): `neuron-mistralai-mixtral-8x22b-instruct-v0.1`

You can find all the models supported on HUGS in [Supported Models](../../models.mdx).

## Subscribe to HUGS on AWS Marketplace

1. Go to [HUGS AWS Marketplace listing](https://aws.amazon.com/marketplace/pp/prodview-bqy5zfvz3wox6)

   ![HUGS on AWS Marketplace](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/aws/hugs-marketplace-listing.png)

2. Subscribe to the product in AWS Marketplace by following the instructions on the page. At the time of writing (December 2024), the steps are to:

   1. Click `Continue to Subscribe`, then go to the next page.
   2. Click `Continue to Configuration`, then go to the next page.
   3. Select the fulfillment option e.g. `HUGS v2 for NVIDIA GPUs and AWS Inferentia2`, and the software version e.g. `0.2.0`. Note that AWS Neuron Inferentia2 support has been included from 0.2.0 onwards.

   ![HUGS Configuration on AWS Marketplace](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hugs/aws/hugs-configuration.png)

3. Then click `Continue to Launch`. You successfully subscribe to HUGS. You can now follow the steps below to deploy your preferred HUGS container and model using Amazon EKS, with the provided container URIs.

To know whether you are subscribed or not, you can either see if a blue modal appears on top of the product page with a text saying "You have access to this product", meaning that either you or someone else from your organization has already requested access for your account; otherwise, you can go to the AWS Marketplace service in the AWS Console and search for "HUGS (HUgging Face Generative AI Services)" is listed among your subscribed products.

## Deploy HUGS on Amazon EKS

This example showcases how to create a Kubernetes Cluster on Amazon EKS, how to create an Inferentia2 node group with the necessary permissions and compute requirements, and how to deploy HUGS on Amazon EKS running on Inferentia2 using a Helm template.

This example assumes that you have an AWS Account, that you have [installed and setup the AWS CLI](https://docs.aws.amazon.com/eks/latest/userguide/install-awscli.html), and that you are logged in into your account with the necessary permissions to subscribe to offerings in the AWS Marketplace, and create and manage IAM permissions and resources such as Elastic Kubernetes Service (EKS), Elastic Container Service (ECS), and EC2.

### Requirements

Before proceeding, you need to have installed both `kubectl`, `eksctl`, and `helm`, to interact with the Kubernetes Cluster, to create, configure and delete resources on Amazon EKS, and to interact with the Helm templates, respectively.

To install both `kubectl` and `eksctl` you can follow the instructions at [Amazon EKS Documentation - Set up kubectl and eksctl](https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html). Whilst for `helm` you can follow the instructions at [Helm Documentation - Installing Helm](https://helm.sh/docs/intro/install/).

Finally, for convenience the following environment variables will be set:

```bash
export REGION="us-east-1"
export NAMESPACE="default"
export CLUSTER_NAME="hugs-cluster"
export CLUSTER_VERSION="1.30"
export NODE_GROUP_NAME="hugs-node-group"
export SERVICE_ACCOUNT_NAME="hugs-service-account"
export DEPLOYMENT_NAME="hugs"
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
export AMI_ID=$(aws ssm get-parameter --name /aws/service/eks/optimized-ami/$CLUSTER_VERSION/amazon-linux-2-gpu/recommended/image_id --region $REGION --query "Parameter.Value" --output text)
```

If your AWS Account has multiple profiles remember to set the `AWS_PROFILE` environment variable to your profile so that the EKS commands use the correct profile.

Optionally, before creating the cluster you may need to create the IAM Policy required to enable the AWS LoadBalancer Controller i.e. `AWSLoadBalancerControllerIAMPolicy`, so as to deploy the ingress which requires the AWS LoadBalancer Controller to be enabled, as per [Install AWS Load Balancer Controller with Helm - Step 1: Create IAM Role using eksctl](https://docs.aws.amazon.com/eks/latest/userguide/lbc-helm.html#lbc-helm-iam).

```bash
curl -O https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.7.2/docs/install/iam_policy.json
aws iam create-policy \
    --policy-name AWSLoadBalancerControllerIAMPolicy \
    --policy-document file://iam_policy.json
```

Note that the policy just needs to be created once per account, meaning that if it's already created then you can reuse the existing one. Otherwise, you can alternatively create the policy under a different name, but along this example the policy is assumed to be named `AWSLoadBalancerControllerIAMPolicy`.

Finally, note that by default this guide will show you how to create the EKS Cluster with a Nodegroup with an `inf2.xlarge` instance, so please make sure that you have the required EC2 quota to be able to spin up AWS Inferentia2 instances, find more information in [AWS re:Post - Inferentia and Trainium Service Quotas](https://repost.aws/articles/ARgmEMvbR6Re200FQs8rTduA/inferentia-and-trainium-service-quotas).

### Setup Amazon EKS

To create the EKS Cluster, Node Group, and add the necessary IAM permissions, you should run `eksctl` with the provided configuration file `eks-cluster.yaml` that looks like:

```yaml
# Specifies the API version and kind of the configuration
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

# Defines the basic cluster metadata
metadata:
  name: $CLUSTER_NAME # Cluster name, used in various AWS resource names
  region: $REGION # AWS region where the cluster will be created
  version: $CLUSTER_VERSION # Kubernetes version to use for the cluster

# IAM configuration for the cluster
iam:
  withOIDC: true # Enables IAM roles for service accounts (IRSA) using OIDC
  serviceAccounts:
    # Configures a service account for marketplace metering
    - metadata:
        name: $SERVICE_ACCOUNT_NAME
        namespace: $NAMESPACE
      attachPolicyARNs:
        - arn:aws:iam::aws:policy/AWSMarketplaceMeteringRegisterUsage
    # Configures a service account for the AWS Load Balancer Controller (just required
    # if ingress is enabled within the HUGS Helm Template)
    - metadata:
        name: aws-load-balancer-controller
        namespace: $NAMESPACE
      attachPolicyARNs:
        - arn:aws:iam::$AWS_ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy
      roleName: AmazonEKSLoadBalancerControllerRole

# Defines the managed node group for the cluster
managedNodeGroups:
  - name: $NODE_GROUP_NAME
    instanceType: inf2.48xlarge # Inf2-enabled instance type, required by HUGS
    minSize: 1
    maxSize: 2 # Set to a greater number if you want to enable auto-scaling
    desiredCapacity: 1 # Fixed size node group, can be adjusted for scaling
    volumeSize: 500
    ami: $AMI_ID
    amiFamily: AmazonLinux2
    iam:
      attachPolicyARNs:
      - arn:aws:iam::aws:policy/AmazonEKSWorkerNodePolicy
      - arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
      - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
      - arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess
    overrideBootstrapCommand: |
      #!/bin/bash

      /etc/eks/bootstrap.sh $CLUSTER_NAME

# Specifies the EKS add-ons to be installed (default ones)
# All the addons below will be installed within the `kube-system` namespace
addons:
  - name: vpc-cni # Amazon VPC CNI plugin for Kubernetes
  - name: coredns # CoreDNS for Kubernetes DNS services
  - name: kube-proxy # kube-proxy for Kubernetes network proxy

# Configures CloudWatch logging for the cluster
cloudWatch:
  clusterLogging:
    enableTypes: ["*"] # Enables all types of control plane logging
```

Since the AWS LoadBalancer Controller is optional and required by the Ingress, if you decide not to deploy the Ingress later on, then you should remove the `iam.serviceAccounts` for the `aws-load-balancer-controller` before moving on to the next step i.e. the following content from the file above should be removed:

```yaml
    # Configures a service account for the AWS Load Balancer Controller (just required
    # if ingress is enabled within the HUGS Helm Template)
    - metadata:
        name: aws-load-balancer-controller
        namespace: $NAMESPACE
      attachPolicyARNs:
        - arn:aws:iam::$AWS_ACCOUNT_ID:policy/AWSLoadBalancerControllerIAMPolicy
      roleName: AmazonEKSLoadBalancerControllerRole
```

Then you need to run the following command, that will replace the values set in the environment variables above within the [`eks-cluster.yaml`](https://github.com/huggingface/hugs-helm-chart/blob/main/aws/eks-cluster.yaml) file provided in [`huggingface/hugs-helm-chart`](https://github.com/huggingface/hugs-helm-chart). To replace the environment variable values within the `eks-cluster.yaml` file above, [`envsubst`](https://linux.die.net/man/1/envsubst) will be used, which may not be available for Windows users.

```bash
envsubst  cluster.yaml
```

Once the `cluster.yaml` file has been updated, then you can just run the following command:

```bash
eksctl create cluster --config-file cluster.yaml
```

Optionally, if you want to enable or use the AWS LoadBalancer Controller, you will need to deploy that separately before deploying HUGS, in order to enable the Ingress; otherwise, feel free to jump into the HUGS deployment section below.

```bash
helm repo add eks https://aws.github.io/eks-charts
helm repo update eks
helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
    --namespace $NAMESPACE \
    --set clusterName=$CLUSTER_NAME \
    --set serviceAccount.create=false \
    --set serviceAccount.name=aws-load-balancer-controller
```

If you decided to deploy the AWS LoadBalancer Controller and enable the Ingress within the HUGS deployment, then you will need to wait until the ALB controller is running before deploying HUGS, to do so you can use the following `kubectl` command:

```bash
kubectl wait --namespace $NAMESPACE \
    --for=condition=ready pod \
    --selector=app.kubernetes.io/name=aws-load-balancer-controller \
    --timeout=90s
```

### Deploy HUGS with Helm on Amazon EKS

Finally, you can install the Helm template to deploy HUGS from [`huggingface/hugs-helm-chart`](https://github.com/huggingface/hugs-helm-chart) as it follows:

```bash
helm repo add hugs https://raw.githubusercontent.com/huggingface/hugs-helm-chart/0.0.4/charts/hugs
helm repo update hugs
```

Once installed, to deploy the HUGS container for a given model, e.g. `neuron-meta-llama-meta-llama-3.1-8b-instruct`, you need visit the AWS Marketplace Offering for HUGS in the "Launch this Software" tab after Subscribing to it and Configuring it, there you will see all the available `CONTAINER_URI`s. In this case, since we want to showcase how to deploy an LLM on AWS Inferentia2, you will need to select any container URI starting with `neuron-...`, as those are the ones compatible with AWS Neuron Devices e.g. `XXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com/hugging-face/neuron-meta-llama-meta-llama-3.1-8b-instruct`, and then just export the following environment variables:

```bash
export IMAGE_REGISTRY="XXXXXXXXXXXX.dkr.ecr.us-east-1.amazonaws.com"
export IMAGE_REPOSITORY="hugging-face"
export IMAGE_NAME="neuron-meta-llama-meta-llama-3.1-8b-instruct"
```

In this case, we used the `neuron-meta-llama-meta-llama-3.1-8b-instruct` model, but you could select / use any of the available models listed in the introduction of this guide, or you can just explore all the AWS Neuron-compatible models in [Supported Models](../../models).

Then you can install the Helm template with any of the following approaches:

- (Recommended) Via a custom `values.yaml` file:

    You should first create the `values.yaml` file that's compliant with the [`huggingface/hugs-helm-chart`](https://github.com/huggingface/hugs-helm-chart) values, and then update the ones related to AWS Inferentia2:

    ```yaml
    image:
      registry: $IMAGE_REGISTRY # Add your custom HUGS Registry here
      repository: $IMAGE_REPOSITORY # For AWS should always be "hugging-face"
      name: $IMAGE_NAME
      tag: latest

    serviceAccountName: $SERVICE_ACCOUNT_NAME

    securityContext:
      privileged: true

    ingress:
      enabled: true
      className: alb
      annotations:
        alb.ingress.kubernetes.io/scheme: internet-facing
      hosts:
        - host: ""
          paths:
            - path: /
              pathType: Prefix

    resources:
      requests:
        aws.amazon.com/neuron: 1
      limits:
        aws.amazon.com/neuron: 1

    nodeSelector:
      eks.amazonaws.com/nodegroup: $NODE_GROUP_NAME
    ```

    The `values.yaml` file created above just contains the required values related to our specific configuration and to AWS Inferentia2 and AWS EKS restrictions specifically. Then we need to replace the variables defined above with `envsubst` as we did before, pulling the values from the environment values defined in the beginning of the tutorial:

    ```bash
    envsubst  values-replaced.yaml
    ```

    Finally, just install the file with the replacements `values-replaced.yaml` with `helm install` as:

    ```bash
    helm install -f values-replaced.yaml $DEPLOYMENT_NAME hugs/hugs
    ```

    

    For testing that the replacements are correct and checking what the Helm Template will create, you can always call the exact same command but instead of `helm install` use `helm template` and check the produced / generated Kubernetes Manifest files to be applied in the EKS Cluster.

    ```bash
    helm template -f values-replaced.yaml $DEPLOYMENT_NAME hugs/hugs
    ```

    

- Via the `--set` option when running `helm install`:

    ```bash
    helm install $DEPLOYMENT_NAME hugs/hugs \
        --set image.registry=$IMAGE_REGISTRY \
        --set image.repository=$IMAGE_REPOSITORY \
        --set image.name=$IMAGE_NAME \
        --set image.tag="0.2.0" \
        --set resources.requests."aws\.amazon\.com/neuron"=1 \
        --set resources.limits."aws\.amazon\.com/neuron"=1 \
        --set serviceAccountName=$SERVICE_ACCOUNT_NAME \
        --set nodeSelector."eks\.amazonaws\.com/nodegroup"=$NODE_GROUP_NAME
    ```

    Note that for nested values or complex ones, using the CLI arguments may get a bit tricky, specially with character escaping.

### Inference on HUGS

To run the inference over the deployed HUGS service, you can either:

- Forward the port via port-forwarding to a local port as e.g. 8080 (so that you can send requests to the service via `localhost`) with the command:

  ```bash
  kubectl port-forward service/$DEPLOYMENT_NAME 8080:80
  ```

- Use the external IP or hostname of the ingress, only if the AWS LoadBalancer Controller was deployed into the EKS Cluster and `ingress.enabled: true` was set in the `values.yaml` file in the Helm Template with the correct `alb` configuration, that can be retrieved with the following command:

  ```bash
  kubectl get ingress $DEPLOYMENT_NAME -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
  ```

Then you can send requests to the Messages API via either `localhost`, the ingress IP or the ingress hostname, from outside the running pod.

In the inference examples in the guide below, the host is assumed to be `localhost` which is the case when deploying HUGS via Kubernetes with port-forwarding. If you have deployed HUGS on Kubernetes using an ingress under a specific IP, host, and/or with SSL (HTTPS), note that you should update the `localhost` references below with your host or IP.

To run inference on HUGS once deployed, you can start with a simple `cURL` command to send a request to the OpenAI API-compatible endpoint exposed by HUGS as follows:

```bash
curl http://localhost:8080/v1/chat/completions \
    -X POST \
    -d '{"model":"tgi","messages":[{"role":"user","content":"What is Deep Learning?"}],"temperature":0.7,"top_p":0.95,"max_tokens":128}}' \
    -H 'Content-Type: application/json'
```

For more information and different alternatives on running inference on HUGS, you should refer to the guide [Run Inference on HUGS](../../guides/inference).

### Uninstall HUGS

Since HUGS was installed via `helm install` you can simply uninstall it as:

```bash
helm uninstall $DEPLOYMENT_NAME
```

And `helm uninstall` will remove all the workloads created, in this case being the Deployment, the Service, the Ingress, and the Horizontal Pod Autoscaler (HPA); alternatively, if you also installed the AWS LoadBalancer Controller, you can also uninstall it as follows:

```bash
helm uninstall aws-load-balancer-controller
```

Alternatively, once you are done using Amazon EKS Cluster, you can safely delete it to avoid incurring in unnecessary costs as:

```bash
eksctl delete cluster --name=$CLUSTER_NAME --region=$REGION
```
