Skip to content

Commit 0511fa9

Browse files
authored
Add script for interacting with user vault (#117)
* add script for interacting with user vault
1 parent 56fd0f4 commit 0511fa9

9 files changed

Lines changed: 279 additions & 21 deletions

File tree

centml/cli/cluster.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from centml.sdk import DeploymentType, DeploymentStatus, ServiceStatus, ApiException, HardwareInstanceResponse
77
from centml.sdk.api import get_centml_client
88

9-
109
# convert deployment type enum to a user friendly name
1110
depl_type_to_name_map = {
1211
DeploymentType.INFERENCE: "inference",

centml/cli/login.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from centml.sdk import auth
1515
from centml.sdk.config import settings
1616

17-
1817
CLIENT_ID = settings.CENTML_WORKOS_CLIENT_ID
1918
SERVER_HOST = "127.0.0.1"
2019
SERVER_PORT = 57983
@@ -51,18 +50,14 @@ def do_GET(self):
5150
self.send_response(200)
5251
self.send_header("Content-type", "text/html")
5352
self.end_headers()
54-
self.wfile.write(
55-
"""
53+
self.wfile.write("""
5654
<html>
5755
<body>
5856
<h1>Succesfully logged into CentML CLI</h1>
5957
<p>You can now close this tab and continue in the CLI.</p>
6058
</body>
6159
</html>
62-
""".encode(
63-
"utf-8"
64-
)
65-
)
60+
""".encode("utf-8"))
6661

6762
def log_message(self, format, *args):
6863
# Override this to suppress logging

examples/sdk/create_cserve.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ def get_default_cserve_config(cclient, name, model):
3636
def main():
3737
with get_centml_client() as cclient:
3838
### Get the configurations for the Qwen model
39-
qwen_config = get_fastest_cserve_config(
40-
cclient, name="qwen-fastest", model="Qwen/Qwen2-VL-7B-Instruct"
41-
)
39+
qwen_config = get_fastest_cserve_config(cclient, name="qwen-fastest", model="Qwen/Qwen2-VL-7B-Instruct")
4240
# qwen_config = get_default_cserve_config(cclient, name="qwen-default", model="Qwen/Qwen2-VL-7B-Instruct")
4341

4442
### Modify the recipe if necessary

examples/sdk/create_inference.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ def main():
3838
cclient.delete(deployment.id)
3939
'''
4040

41+
4142
if __name__ == "__main__":
4243
main()

examples/sdk/get_deployment_usage.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from centml.sdk.api import get_centml_client
44
from centml.sdk import Metric
55

6-
76
HOUR_IN_SECONDS = 60 * 60
87
DAY_IN_SECONDS = 24 * HOUR_IN_SECONDS
98
MAX_DATA_POINTS = 10_000
@@ -17,22 +16,23 @@ def get_step_size(start_time_in_seconds: int, end_time_in_seconds: int) -> int:
1716
# 2 days to 7 days: 5m
1817
elif time_delta_in_seconds <= 7 * DAY_IN_SECONDS:
1918
return 5 * 60
20-
# 7 days to 14 days: 10m
19+
# 7 days to 14 days: 10m
2120
elif time_delta_in_seconds <= 14 * DAY_IN_SECONDS:
2221
return 10 * 60
23-
# 14 days to 30 days: 30m
22+
# 14 days to 30 days: 30m
2423
elif time_delta_in_seconds <= 30 * DAY_IN_SECONDS:
2524
return 30 * 60
26-
# 30 days to 60 days: 1 hour
25+
# 30 days to 60 days: 1 hour
2726
elif time_delta_in_seconds <= 60 * DAY_IN_SECONDS:
2827
return HOUR_IN_SECONDS
29-
# 60 days to 90 days: 2 hours
28+
# 60 days to 90 days: 2 hours
3029
elif time_delta_in_seconds <= 90 * DAY_IN_SECONDS:
3130
return 2 * HOUR_IN_SECONDS
32-
# 90+ days: 3 hours (This catches all ranges greater than 90 days)
31+
# 90+ days: 3 hours (This catches all ranges greater than 90 days)
3332
else:
3433
return 3 * HOUR_IN_SECONDS
3534

35+
3636
def main():
3737
with get_centml_client() as cclient:
3838
start_time = 1752084581

scripts/data_collection.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
AutoModelForCausalLM,
88
AutoTokenizer,
99
AutoModelForImageClassification,
10-
AutoModelForObjectDetection
10+
AutoModelForObjectDetection,
1111
)
1212

1313

14-
1514
from centml.compiler.prediction.kdtree import KDTreeWithValues
1615
from centml.compiler.prediction.profiler import Profiler
1716
from scripts.timer import timed
@@ -26,8 +25,8 @@
2625
# Different HuggingFace Models + Different Input Sizes
2726
llm_tests = [
2827
("google/gemma-7b", (1, 128)),
29-
("microsoft/phi-2", (1,512)),
30-
("microsoft/phi-2", (2,512)),
28+
("microsoft/phi-2", (1, 512)),
29+
("microsoft/phi-2", (2, 512)),
3130
("facebook/bart-large", (1, 1024)),
3231
("facebook/bart-large", (2, 512)),
3332
("gpt2-xl", (1, 1024)),
@@ -212,6 +211,7 @@ def image_classification_test(model_name, batch_size, custom_backend):
212211
gc.collect()
213212
torch.cuda.empty_cache()
214213

214+
215215
def object_detection_test(model_name, batch_size, custom_backend):
216216
global cuda_kernel_time
217217
global actual_time
@@ -240,6 +240,7 @@ def object_detection_test(model_name, batch_size, custom_backend):
240240
gc.collect()
241241
torch.cuda.empty_cache()
242242

243+
243244
# for model_name, input_size in large_llm_tests:
244245
# llm_test(model_name, input_size, custom_backend)
245246

scripts/timer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import torch
22

3+
34
def timed(fn):
45
start = torch.cuda.Event(enable_timing=True)
56
end = torch.cuda.Event(enable_timing=True)

scripts/user_vault/README.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# User Vault Scripts
2+
3+
Scripts for managing user vault (secrets) in CentML Platform.
4+
5+
## Overview
6+
7+
The CentML User Vault is a secure storage system for sensitive information that can be used across your deployments. This includes environment variables, API tokens, SSH keys, and certificates. These scripts allow you to view and manage your vault items from the command line.
8+
9+
## Prerequisites
10+
11+
### 1. Install the centml package
12+
13+
From the repository root directory:
14+
15+
```bash
16+
pip install -e ./
17+
```
18+
19+
Or install directly from GitHub:
20+
21+
```bash
22+
pip install git+https://github.com/CentML/centml-python-client.git@main
23+
```
24+
25+
### 2. Authenticate with CentML
26+
27+
Login to your CentML account:
28+
29+
```bash
30+
centml login
31+
```
32+
33+
This will open a browser window for authentication. Once completed, your credentials will be stored locally.
34+
35+
## Available Scripts
36+
37+
### get_vault_items.py
38+
39+
Retrieves and displays all items stored in your CentML vault.
40+
41+
#### Supported Vault Types
42+
43+
| Type | Description | Example Use Case |
44+
|------|-------------|------------------|
45+
| `env_vars` | Environment variables | Database URLs, API endpoints |
46+
| `ssh_keys` | SSH keys | Git repository access |
47+
| `bearer_tokens` | Bearer tokens | Service authentication |
48+
| `access_tokens` | Access tokens | HuggingFace tokens, Weights & Biases API keys |
49+
| `certificates` | Certificates | TLS/SSL certificates |
50+
51+
#### Usage
52+
53+
Run the script from the `scripts/user_vault` directory:
54+
55+
```bash
56+
cd scripts/user_vault
57+
python get_vault_items.py [OPTIONS]
58+
```
59+
60+
#### Command Line Options
61+
62+
| Option | Description | Default |
63+
|--------|-------------|---------|
64+
| `--type TYPE` | Filter results by vault type (see supported types above) | Show all types |
65+
| `--search QUERY` | Filter items by key name (case-sensitive substring match) | No filter |
66+
| `--show-values` | Display the actual secret values | Keys only |
67+
| `--help` | Show help message and exit | - |
68+
69+
#### Examples
70+
71+
**List all vault items (keys only):**
72+
73+
```bash
74+
python get_vault_items.py
75+
```
76+
77+
**List only environment variables:**
78+
79+
```bash
80+
python get_vault_items.py --type env_vars
81+
```
82+
83+
**List only access tokens (e.g., HuggingFace tokens):**
84+
85+
```bash
86+
python get_vault_items.py --type access_tokens
87+
```
88+
89+
**Search for items containing "HF" in the key name:**
90+
91+
```bash
92+
python get_vault_items.py --search HF
93+
```
94+
95+
**Show all items with their values:**
96+
97+
```bash
98+
python get_vault_items.py --show-values
99+
```
100+
101+
**Combine multiple options:**
102+
103+
```bash
104+
python get_vault_items.py --type env_vars --show-values --search DATABASE
105+
```
106+
107+
#### Example Output
108+
109+
Without `--show-values`:
110+
111+
```
112+
Found 5 vault item(s)
113+
114+
==================================================
115+
Type: access_tokens (2 item(s))
116+
==================================================
117+
HF_TOKEN
118+
WANDB_API_KEY
119+
120+
==================================================
121+
Type: env_vars (3 item(s))
122+
==================================================
123+
API_KEY
124+
DATABASE_URL
125+
MY_SECRET
126+
```
127+
128+
With `--show-values`:
129+
130+
```
131+
Found 5 vault item(s)
132+
133+
==================================================
134+
Type: access_tokens (2 item(s))
135+
==================================================
136+
HF_TOKEN: hf_xxxxxxxxxxxxxxxxxxxx
137+
WANDB_API_KEY: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
138+
139+
==================================================
140+
Type: env_vars (3 item(s))
141+
==================================================
142+
API_KEY: sk-xxxxxxxxxxxxxxxx
143+
DATABASE_URL: postgresql://user:pass@host:5432/db
144+
MY_SECRET: my-secret-value
145+
```
146+
147+
## Troubleshooting
148+
149+
### Authentication Error
150+
151+
If you see an authentication error, try logging in again:
152+
153+
```bash
154+
centml login
155+
```
156+
157+
### Module Not Found
158+
159+
If you see `ModuleNotFoundError`, ensure you have installed the centml package:
160+
161+
```bash
162+
pip install -e ./
163+
```
164+
165+
### No Items Found
166+
167+
If the script returns "No vault items found", verify that:
168+
1. You are logged into the correct CentML account
169+
2. You have created vault items in the CentML web UI or via API

0 commit comments

Comments
 (0)