o
    ;iq                     @   s   d dl mZ d dlmZ ddlmZ ddlmZ G dd dZG dd	 d	eZ	G d
d deZ
G dd deZG dd deZG dd deZG dd deZG dd deZdZedeef ZdedejfddZdS )    )Union)api_pb2   )deprecation_warning)InvalidErrorc                   @   s@   e Zd ZU eed< eed< dedefddZdejfddZ	dS )	
_GPUConfiggpu_typecountc                 C   sJ   | j j}|}|dkr|d| 7 }tdd| d| d || _|| _d S )Nr   :)i        z`gpu=z (...)` is deprecated. Use `gpu="z"` instead.)	__class____name__r   r   r	   )selfr   r	   name	str_value r   =/home/ubuntu/.local/lib/python3.10/site-packages/modal/gpu.py__init__   s   
z_GPUConfig.__init__returnc                 C   s   t j| j| jdS )z?Convert this GPU config to an internal protobuf representation.r   r	   )r   	GPUConfigr   r	   r   r   r   r   	_to_proto   s   z_GPUConfig._to_protoN)
r   
__module____qualname__str__annotations__intr   r   r   r   r   r   r   r   r   
   s
   
 	r   c                       2   e Zd ZdZ	ddef fddZdd Z  ZS )	T4z
    [NVIDIA T4 Tensor Core](https://www.nvidia.com/en-us/data-center/tesla-t4/) GPU class.

    A low-cost data center GPU based on the Turing architecture, providing 16GB of GPU memory.
    r   r	   c                       t  d| d S )Nr    superr   r   r	   r   r   r   r   &      zT4.__init__c                 C      d| j  dS )NzGPU(T4, count=)r	   r   r   r   r   __repr__,      zT4.__repr__r   r   r   r   __doc__r   r   r*   __classcell__r   r   r%   r   r       s    r    c                       r   )	L4z
    [NVIDIA L4 Tensor Core](https://www.nvidia.com/en-us/data-center/l4/) GPU class.

    A mid-tier data center GPU based on the Ada Lovelace architecture, providing 24GB of GPU memory.
    Includes RTX (ray tracing) support.
    r   r	   c                    r!   )Nr0   r"   r$   r%   r   r   r   8   r&   zL4.__init__c                 C   r'   )NzGPU(L4, count=r(   r)   r   r   r   r   r*   >   r+   zL4.__repr__r,   r-   r   r   r%   r   r0   0   s    	r0   c                       sB   e Zd ZdZddddedeedf f fddZd	d
 Z  Z	S )A100z
    [NVIDIA A100 Tensor Core](https://www.nvidia.com/en-us/data-center/a100/) GPU class.

    The flagship data center GPU of the Ampere architecture. Available in 40GB and 80GB GPU memory configurations.
    r   N)r	   sizer	   r2   c                   sH   |dks|st  d| d S |dkrt  d| d S td| d)N40GBz	A100-40GB80GBz	A100-80GBzsize='z@' is invalid. A100s can only have memory values of 40GB or 80GB.)r#   r   
ValueError)r   r	   r2   r%   r   r   r   I   s
   zA100.__init__c                 C   s   d| j  d| j dS )NzGPU(z, count=r(   r   r   r   r   r   r*   V   s   zA100.__repr__)
r   r   r   r.   r   r   r   r   r*   r/   r   r   r%   r   r1   B   s    	
r1   c                       4   e Zd ZdZdddef fddZdd Z  ZS )	A10Gau  
    [NVIDIA A10G Tensor Core](https://www.nvidia.com/en-us/data-center/products/a10-gpu/) GPU class.

    A mid-tier data center GPU based on the Ampere architecture, providing 24 GB of memory.
    A10G GPUs deliver up to 3.3x better ML training performance, 3x better ML inference performance,
    and 3x better graphics performance, in comparison to NVIDIA T4 GPUs.
    r   r)   r	   c                   r!   )Nr7   r"   r$   r%   r   r   r   c      zA10G.__init__c                 C   r'   )NzGPU(A10G, count=r(   r)   r   r   r   r   r*   l   r+   zA10G.__repr__r-   r   r   r%   r   r7   Z       	r7   c                       r6   )	H100a:  
    [NVIDIA H100 Tensor Core](https://www.nvidia.com/en-us/data-center/h100/) GPU class.

    The flagship data center GPU of the Hopper architecture.
    Enhanced support for FP8 precision and a Transformer Engine that provides up to 4X faster training
    over the prior generation for GPT-3 (175B) models.
    r   r)   r	   c                   r!   )Nr:   r"   r$   r%   r   r   r   y   r8   zH100.__init__c                 C   r'   )NzGPU(H100, count=r(   r)   r   r   r   r   r*      r+   zH100.__repr__r-   r   r   r%   r   r:   p   r9   r:   c                       r6   )	L40Sz
    [NVIDIA L40S](https://www.nvidia.com/en-us/data-center/l40s/) GPU class.

    The L40S is a data center GPU for the Ada Lovelace architecture. It has 48 GB of on-chip
    GDDR6 RAM and enhanced support for FP8 precision.
    r   r)   r	   c                   r!   )Nr;   r"   r$   r%   r   r   r      r8   zL40S.__init__c                 C   r'   )NzGPU(L40S, count=r(   r)   r   r   r   r   r*      r+   zL40S.__repr__r-   r   r   r%   r   r;      s    	r;   c                       r6   )	AnyzUSelects any one of the GPU classes available within Modal, according to availability.r   r)   r	   c                   r!   )NANYr"   r$   r%   r   r   r      s   zAny.__init__c                 C   r'   )NzGPU(Any, count=r(   r)   r   r   r   r   r*      r+   zAny.__repr__r-   r   r   r%   r   r<      s    r<   a
  
**GPU configuration shortcodes**

You can pass a wide range of `str` values for the `gpu` parameter of
[`@app.function`](https://modal.com/docs/reference/modal.App#function).

For instance:
- `gpu="H100"` will attach 1 H100 GPU to each container
- `gpu="L40S"` will attach 1 L40S GPU to each container
- `gpu="T4:4"` will attach 4 T4 GPUs to each container

You can see a list of Modal GPU options in the
[GPU docs](https://modal.com/docs/guide/gpu).

**Example**

```python
@app.function(gpu="A100-80GB:4")
def my_gpu_function():
    ... # This will have 4 A100-80GB with each container
```

**Deprecation notes**

An older deprecated way to configure GPU is also still supported,
but will be removed in future versions of Modal. Examples:

- `gpu=modal.gpu.H100()` will attach 1 H100 GPU to each container
- `gpu=modal.gpu.T4(count=4)` will attach 4 T4 GPUs to each container
- `gpu=modal.gpu.A100()` will attach 1 A100-40GB GPUs to each container
- `gpu=modal.gpu.A100(size="80GB")` will attach 1 A100-80GB GPUs to each container
Nvaluer   c                 C   s   t | tr	|  S t | tr=d}d| v r2| dd\} }zt|}W n ty1   td| dw |  }t	j
||dS | d u rEt	
 S td|  d)Nr   r
   zInvalid GPU count: z. Value must be an integer.r   zInvalid GPU config: zG. Value must be a string or `None` (or a deprecated `modal.gpu` object))
isinstancer   r   r   splitr   r5   r   upperr   r   )r>   r	   	count_strr   r   r   r   parse_gpu_config   s*   


rC   )typingr   modal_protor   _utils.deprecationr   	exceptionr   r   r    r0   r1   r7   r:   r;   r<   r.   r   GPU_Tr   rC   r   r   r   r   <module>   s   
!