-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathvalidator.config.js
More file actions
231 lines (200 loc) · 6.7 KB
/
Copy pathvalidator.config.js
File metadata and controls
231 lines (200 loc) · 6.7 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
const path = require('path');
const os = require('os');
// Helper functions
function getPythonInterpreter() {
const projectRoot = __dirname;
const venvPython = path.join(projectRoot, '.venv', 'bin', 'python');
const fs = require('fs');
return fs.existsSync(venvPython) ? venvPython : 'python3';
}
function getNetworkSettings(chainEndpoint) {
if (chainEndpoint.includes('test')) return 379;
if (chainEndpoint.includes('finney')) return 34;
return null;
}
function getLogParam(loglevel) {
switch (loglevel) {
case 'trace': return '--logging.trace';
case 'debug': return '--logging.debug';
default: return '--logging.info';
}
}
function getAutoUpdateParam(autoUpdate) {
return autoUpdate === 'true' ? '' : '--autoupdate-off';
}
function getHeartbeatParam(heartbeat) {
return heartbeat === 'true' ? '--heartbeat' : '';
}
// Load environment variables
require('dotenv').config({ path: path.resolve(__dirname, '.env.validator') });
// Get configuration from environment with defaults
const config = {
// Wallet
walletName: process.env.WALLET_NAME || 'default',
walletHotkey: process.env.WALLET_HOTKEY || 'default',
// Network
chainEndpoint: process.env.CHAIN_ENDPOINT || '',
callbackPort: process.env.CALLBACK_PORT || '10525',
externalCallbackPort: process.env.EXTERNAL_CALLBACK_PORT || null,
externalIp: process.env.EXTERNAL_IP || null,
// Cache
cacheDir: process.env.SN34_CACHE_DIR || path.join(os.homedir(), '.cache', 'sn34'),
// Device
device: process.env.DEVICE || 'cuda',
// Logging
loglevel: process.env.LOGLEVEL || 'info',
// Features
autoUpdate: process.env.AUTO_UPDATE || 'false',
heartbeat: process.env.HEARTBEAT || 'false',
storeFailedMedia: process.env.STORE_FAILED_MEDIA === 'true',
// Service intervals
datasetInterval: process.env.DATASET_INTERVAL || '1800',
// API configuration
benchmarkApiUrl: process.env.BENCHMARK_API_URL || 'https://gas.bitmind.ai',
// Service selection
startValidator: process.env.START_VALIDATOR !== 'false',
startGenerator: process.env.START_GENERATOR !== 'false',
startData: process.env.START_DATA !== 'false',
};
// Determine netuid. NETUID wins so testnet 169 is not forced to 379.
const netuid = process.env.NETUID
? parseInt(process.env.NETUID, 10)
: getNetworkSettings(config.chainEndpoint);
if (!netuid) {
throw new Error('NETUID is required (set NETUID or a known CHAIN_ENDPOINT)');
}
// Build command parameters
const logParam = getLogParam(config.loglevel);
const autoUpdateParam = getAutoUpdateParam(config.autoUpdate);
const heartbeatParam = getHeartbeatParam(config.heartbeat);
const pythonInterpreter = getPythonInterpreter();
// Project paths
const projectRoot = __dirname;
const validatorScript = path.join(projectRoot, 'neurons', 'validator', 'validator.py');
const generatorScript = path.join(projectRoot, 'neurons', 'validator', 'services', 'generator_service.py');
const dataScript = path.join(projectRoot, 'neurons', 'validator', 'services', 'data_service.py');
// Build apps array
const apps = [];
// Allow optional override of HF cache dir via env. Must be resolved before any Python starts.
const HF_HOME_RESOLVED = process.env.HF_HOME
|| process.env.HUGGINGFACE_HOME
|| process.env.HUGGINGFACE_CACHE_DIR
|| path.join(os.homedir(), '.cache', 'huggingface');
// Common HF env
const HF_ENV = {
TRANSFORMERS_VERBOSITY: 'error',
DIFFUSERS_VERBOSITY: 'error',
TOKENIZERS_PARALLELISM: 'false',
HF_HUB_VERBOSITY: 'error',
ACCELERATE_LOG_LEVEL: 'error',
HUGGINGFACE_HUB_TOKEN: process.env.HUGGINGFACE_HUB_TOKEN,
HF_HOME: HF_HOME_RESOLVED,
HF_HUB_DISABLE_TELEMETRY: '1',
};
// Torch env. expandable_segments collapses fragmented allocator
// segments so reserved-but-unallocated VRAM (often several GiB at
// equilibrium) becomes reusable. Critical at the ~70GB VLM+LLM working
// set on an 80GB card where headroom for activations is tight; without
// this we OOM on long-context prompt-gen calls.
const TORCH_ENV = {
PYTORCH_CUDA_ALLOC_CONF: process.env.PYTORCH_CUDA_ALLOC_CONF
|| 'expandable_segments:True',
};
// Validator service
if (config.startValidator) {
const validatorArgs = [
'--wallet.name', config.walletName,
'--wallet.hotkey', config.walletHotkey,
'--netuid', netuid.toString(),
'--subtensor.chain_endpoint', config.chainEndpoint,
'--neuron.callback_port', config.callbackPort,
'--cache.base-dir', config.cacheDir,
'--benchmark.api-url', config.benchmarkApiUrl,
logParam,
autoUpdateParam,
];
if (process.env.EPOCH_LENGTH) {
validatorArgs.push('--epoch-length', process.env.EPOCH_LENGTH);
}
// Add external callback port if provided
if (config.externalCallbackPort) {
validatorArgs.push('--neuron.external-callback-port', config.externalCallbackPort);
}
// Add external IP if provided (needed when auto-detected outbound IP
// differs from the inbound-reachable public IP, e.g. some cloud GPU hosts)
if (config.externalIp) {
validatorArgs.push('--neuron.external-ip', config.externalIp);
}
if (heartbeatParam) {
validatorArgs.push(heartbeatParam);
}
if (config.storeFailedMedia) {
validatorArgs.push('--store-failed-media');
}
apps.push({
name: 'sn34-validator',
script: validatorScript,
interpreter: pythonInterpreter,
args: validatorArgs.join(' '),
env: {
WANDB_API_KEY: process.env.WANDB_API_KEY,
...HF_ENV,
...TORCH_ENV,
},
watch: false,
instances: 1,
autorestart: true,
});
}
// Generator service
if (config.startGenerator) {
apps.push({
name: 'sn34-generator',
script: generatorScript,
interpreter: pythonInterpreter,
args: [
'--wallet.name', config.walletName,
'--wallet.hotkey', config.walletHotkey,
'--cache.base-dir', config.cacheDir,
'--device', config.device,
'--log-level', config.loglevel,
].join(' '),
env: {
...HF_ENV,
...TORCH_ENV,
},
watch: false,
instances: 1,
autorestart: true,
});
}
// Data service
if (config.startData) {
apps.push({
name: 'sn34-data',
script: dataScript,
interpreter: pythonInterpreter,
args: [
'--wallet.name', config.walletName,
'--wallet.hotkey', config.walletHotkey,
'--netuid', netuid.toString(),
'--subtensor.chain_endpoint', config.chainEndpoint,
'--cache.base-dir', config.cacheDir,
'--benchmark-api-url', config.benchmarkApiUrl,
'--dataset-interval', config.datasetInterval,
logParam,
].join(' '),
env: {
...HF_ENV,
TMPDIR: path.join(config.cacheDir, 'tmp'),
TEMP: path.join(config.cacheDir, 'tmp'),
TMP: path.join(config.cacheDir, 'tmp'),
},
watch: false,
instances: 1,
autorestart: true,
});
}
module.exports = {
apps,
};