podstack 1.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,126 @@
1
+ """
2
+ Podstack GPU SDK - Run code on cloud GPUs.
3
+
4
+ Example usage:
5
+ import podstack
6
+
7
+ # Define an image with dependencies
8
+ image = (
9
+ podstack.Image.debian_slim()
10
+ .pip_install("torch", "transformers")
11
+ )
12
+
13
+ # Or use a preset environment
14
+ image = podstack.Image.ml()
15
+
16
+ # Or install from requirements.txt
17
+ image = podstack.Image.debian_slim().pip_install_from_requirements("requirements.txt")
18
+
19
+ # Create an app
20
+ app = podstack.App("my-app")
21
+
22
+ # Define a GPU function with full GPU
23
+ @app.function(gpu="H100", image=image)
24
+ def train(epochs: int):
25
+ import torch
26
+ # Print GPU info at start
27
+ podstack.print_gpu_status()
28
+ print(f"Training for {epochs} epochs on {torch.cuda.get_device_name()}")
29
+ return {"status": "done"}
30
+
31
+ # Use fractional GPU for cost savings (25%, 50%, 75%, or 100%)
32
+ @app.function(gpu="L40S", fraction=25, image=image)
33
+ def inference(data):
34
+ # Uses 25% of an L40S GPU - great for inference workloads
35
+ return model.predict(data)
36
+
37
+ # Run remotely with real-time status tracking
38
+ call = train.spawn(epochs=10)
39
+ for update in call.stream_status():
40
+ print(f"Status: {update.status}")
41
+ if update.queue_position:
42
+ print(f" Queue position: {update.queue_position}")
43
+ result = call.get()
44
+
45
+ # Or use the low-level runner
46
+ # Supports psk_xxx tokens (from cloud.podstack.ai portal) or pjt_xxx tokens (project tokens)
47
+ gpu = podstack.GPURunner(token="psk_xxx", project_id="xxx")
48
+ result = gpu.run("print('hello')", gpu="L40S", fraction=50) # 50% GPU
49
+
50
+ # Custom API URL (optional - defaults to PODSTACK_API_URL env var or production URL)
51
+ gpu = podstack.GPURunner(token="psk_xxx", project_id="xxx", api_url="https://your-api.example.com")
52
+
53
+ GPU Utilities (use inside your GPU functions):
54
+ podstack.nvidia_smi() # Get nvidia-smi output
55
+ podstack.gpu_info() # Get GPU info as dict
56
+ podstack.cuda_available() # Check if CUDA is available
57
+ podstack.cuda_device_count() # Get number of GPUs
58
+ podstack.print_gpu_status() # Print formatted GPU status
59
+
60
+ GPU Types:
61
+ - A10: Entry-level, good for inference
62
+ - L40, L40S: Mid-range, balanced performance
63
+ - A100-40G, A100-80G: High-end training
64
+ - H100: Top-tier performance
65
+
66
+ Fractional GPU:
67
+ - fraction=25: 25% of GPU (lowest cost, good for small inference)
68
+ - fraction=50: 50% of GPU (balanced)
69
+ - fraction=75: 75% of GPU
70
+ - fraction=100: Full GPU (default, best for training)
71
+ """
72
+
73
+ from .runner import GPURunner, ExecutionResult, StatusUpdate
74
+ from .image import Image, ImageDefinition
75
+ from .app import App, Function, FunctionCall, method
76
+ from .volume import Volume, CloudBucketMount
77
+ from .secret import Secret, SecretDict
78
+ from .utils import (
79
+ nvidia_smi,
80
+ gpu_info,
81
+ cuda_available,
82
+ cuda_device_count,
83
+ print_gpu_status,
84
+ )
85
+ from .exceptions import (
86
+ PodstackError,
87
+ ExecutionError,
88
+ AuthenticationError,
89
+ ValidationError,
90
+ TimeoutError,
91
+ InsufficientBalanceError,
92
+ )
93
+
94
+ __version__ = "0.3.3"
95
+
96
+ __all__ = [
97
+ # Core classes
98
+ "App",
99
+ "Function",
100
+ "FunctionCall",
101
+ "Image",
102
+ "ImageDefinition",
103
+ "Volume",
104
+ "CloudBucketMount",
105
+ "Secret",
106
+ "SecretDict",
107
+ # Low-level runner
108
+ "GPURunner",
109
+ "ExecutionResult",
110
+ "StatusUpdate",
111
+ # GPU utilities
112
+ "nvidia_smi",
113
+ "gpu_info",
114
+ "cuda_available",
115
+ "cuda_device_count",
116
+ "print_gpu_status",
117
+ # Decorators
118
+ "method",
119
+ # Exceptions
120
+ "PodstackError",
121
+ "ExecutionError",
122
+ "AuthenticationError",
123
+ "ValidationError",
124
+ "TimeoutError",
125
+ "InsufficientBalanceError",
126
+ ]