The Tensorium CLI (tools/tensorium_cli.py) is your command center for installers, miners, and health checks. In this final tutorial we’ll keep things approachable—plenty of friendly tips, caution blocks, verification commands, and even a few image placeholders so teammates ramp up fast.
- Learning goals
- Prerequisites
- 1. CLI installation
- 2. Command overview
- 3. Configuration via environment variables
- 4. Extending the CLI
- 5. Automation use cases
- 6. Logging best practices
- Example Output
- Summary
- Review questions
- Install and expose the CLI globally (
/usr/local/bin/tensorium). - Configure environment variables so every command knows which wallets/hotkeys to use.
- Extend the CLI with new subcommands safely (logging + error handling).
- Automate common operations (health checks, install pipelines, log collection).
- Tutorials 01–05 completed (env, wallets, miners).
- Python basics (argparse, subprocess, logging).
- Familiarity with
/opt/tensoriumlayout.
💡 Tip: Keep
docs/cli-cookbook.mdupdated with your favoritetensoriumone-liners so the whole team benefits.
cd /opt/tensorium/bittensor
source .venv/bin/activate
pip install -r tools/requirements.txt # optional extras for CLI extensions
chmod +x tools/tensorium_cli.py
sudo ln -sf /opt/tensorium/bittensor/tools/tensorium_cli.py /usr/local/bin/tensorium
⚠️ Warning: Make sure.venv/exists andbtcliworks before symlinking. Otherwise global commands will fail due to missing dependencies.
Now tensorium --help is available from any shell (assuming /usr/local/bin is on PATH).
tensorium list-subnets # btcli subnet list wrapper
tensorium wallet # wallet balance summary
tensorium start-miner # wrap scripts/run_miner_simple.sh
tensorium install # run scripts/install_bittensor.sh (sudo)
tensorium health # GPU, venv, port checks
tensorium logs # tail miner logs
Each subcommand emits structured JSON logs. Use --json when you want machine-friendly output.
Create /opt/tensorium/cli.env:
TENSORIUM_PROJECT_DIR=/opt/tensorium/bittensor
TENSORIUM_DEFAULT_NETUID=1
BT_WALLET_NAME=tensorium
BT_WALLET_HOTKEY=miner-main
BT_HOTKEY_PASSWORD=change_me
LOG_DIR=/opt/tensorium/logs
Load it:
set -a
source /opt/tensorium/cli.env
set +aNow commands shrink to: tensorium start-miner --netuid 1 --config configs/miner.yaml.
💬 Friendly reminder: Keep env files out of git (
.gitignore) and lock down permissions (chmod 600 /opt/tensorium/cli.env).
Steps:
- Open
tools/tensorium_cli.py. - Create a handler function.
- Register it with
sub.add_parser. - Add helpful logging + exit codes.
Example:
def health(args):
issues = []
if shutil.which("nvidia-smi") is None:
issues.append("No NVIDIA driver detected.")
if not (PROJECT_DIR / ".venv").exists():
issues.append("Virtual environment missing.")
# Add more validators here (ports, env files, logs)
if issues:
for item in issues:
logging.error(item)
return 1
logging.info("All health checks passed.")
return 0
⚠️ Warning: Always wrap subprocess calls with try/except orcheck=Falseso the CLI returns clean errors instead of stack traces.
- Installer pipelines:
tensorium install --target-dir /opt/tensorium. - Hourly health checks:
0 * * * * tensorium health >> /opt/tensorium/logs/health.log - CI verification: Run
tensorium list-subnets --jsoninside GitHub Actions to confirm upstream compatibility. - Incident response:
tensorium logs --netuid 1 --lines 100for quick triage.
Because tensorium ultimately wraps btcli, ensure BT_HOTKEY_PASSWORD or keyring integration is available on any host running these commands.
- Default log file:
/opt/tensorium/logs/tensorium-cli.log. - JSON lines example:
{"timestamp":"2025-11-17T10:05:12Z","level":"info","event":"start-miner","netuid":1} - Rotate with
logrotate:/opt/tensorium/logs/tensorium-cli.log { weekly rotate 4 compress missingok create 640 ubuntu ubuntu }
Verification commands:
tensorium --help | head -n 5
tensorium health
tail -n 20 /opt/tensorium/logs/tensorium-cli.log$ tensorium list-subnets --max-rows 3
[2025-11-17 10:02:11][INFO] Fetching subnet data via btcli ...
NETUID NAME TEMPO INCENTIVE DIVIDENDS
1 nakamoto 12 18.4% 11.0%
3 vision 12 21.1% 10.4%
7 language 18 17.6% 12.3%
$ tensorium health
[2025-11-17 10:04:55][INFO] Checking GPU availability ...
[2025-11-17 10:04:55][INFO] GPU: NVIDIA RTX 4090 • Driver 550.54 • CUDA 12.3
[2025-11-17 10:04:55][INFO] Verifying virtual environment ...
[2025-11-17 10:04:56][INFO] Axon ports 8091/8092 are free.
[2025-11-17 10:04:56][SUCCESS] All health checks passed.
$ tensorium start-miner --netuid 1 --config configs/miner-netuid-1.yaml
[2025-11-17 10:06:10][INFO] Launching miner profile netuid-1
[2025-11-17 10:06:10][INFO] Writing logs to /opt/tensorium/logs/miner-netuid-1.log
[2025-11-17 10:06:12][SUCCESS] Miner started (PID 3421). Use `tensorium logs --netuid 1` to tail output.
- Install the CLI inside the project venv, then symlink to
/usr/local/bin/tensoriumfor convenience. - Source
/opt/tensorium/cli.env(or use workflow env vars) so every subcommand knows which wallet/hotkey to operate on. - Extend the CLI with argparse subcommands + logging to provide guardrails for teammates.
- Capture logs via
/opt/tensorium/logs/tensorium-cli.logand rotate them regularly to prevent disk bloat.
- Why does Tensorium symlink the CLI into
/usr/local/bin, and what prerequisite must be met first? - How can environment variables reduce the number of command-line flags you need to pass to the CLI?
- Outline the steps required to add a new
healthsubcommand. - What are typical automation scenarios for the CLI, and how do they improve reliability?
- Where do CLI logs live, and how can you prevent them from consuming unlimited disk space?
Answers
- Symlinking makes
tensoriumavailable from any directory; ensure the virtual environment and file permissions are set before linking. - Variables like
BT_WALLET_NAMEorTENSORIUM_DEFAULT_NETUIDcan be sourced from an env file so commands inherit defaults. - Write a handler function, add it to the argparse subparsers, implement health logic, and register in the main dispatch.
- Installer scripts, hourly health checks, CI verifications, and log retrieval; automation standardizes operations and catches issues early.
/opt/tensorium/logs/tensorium-cli.log; manage it withlogrotateor another log rotation tool to rotate/compress files regularly.


