File size: 1,711 Bytes
48a990e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# llm_training_estimator.py

def get_gpu_teraflops(gpu_type: str, exo_flops: float = None) -> float:
    """

    Returns TFLOPs/s based on GPU type or Exo input.

    """
    gpu_lookup = {
        "A100": 312,   # FP16
        "H100": 700,
    }

    if gpu_type == "Exo":
        if exo_flops is None or exo_flops <= 0:
            raise ValueError("Exo TFLOPs must be provided.")
        return exo_flops

    return gpu_lookup.get(gpu_type, 0)


def get_gpu_cost_per_tflop_hour(gpu_type: str, manual_cost: float = None) -> float:
    """

    Returns ₹ cost per TFLOP-hour based on GPU type.

    """
    cost_lookup = {
        "A100": 17.64 * 83,   # $17.64 × ₹83 (approx.) = ₹1464 per TFLOP/hr
        "H100": 7.56 * 83     # ₹627 per TFLOP/hr
    }

    if gpu_type == "Exo" and manual_cost:
        return manual_cost
    return cost_lookup.get(gpu_type, 0)


def estimate_training_time_and_cost(params_billion: float, tokens_billion: float, teraflops: float,

                                    cost_per_tflop_hr: float = 0.0):
    """

    Estimate training time and cost.



    Returns:

    - FLOPs required

    - Time (hours/days)

    - Cost (₹)

    """
    total_flops_required = 6 * params_billion * 1e9 * tokens_billion * 1e9  # 6 × N × T
    time_seconds = total_flops_required / (teraflops * 1e12)
    time_hours = time_seconds / 3600
    time_days = time_hours / 24

    total_cost = (teraflops * time_hours) * cost_per_tflop_hr if cost_per_tflop_hr > 0 else 0

    return {
        "flops_required": total_flops_required,
        "time_hours": time_hours,
        "time_days": time_days,
        "total_cost": total_cost
    }