This guide provides a complete walkthrough for configuring a new GPU-powered virtual machine for machine learning and development tasks.
1. Install Miniconda
Minconda is a minimal installer for conda, a powerful package and environment manager. It’s recommended for managing Python environments and dependencies.
Steps:
-
Download the Installer:
Fetch the latest Miniconda installer for Linux.
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -
Run the Installation Script:
Execute the script you just downloaded. Follow the on-screen prompts. It’s recommended to accept the defaults and allow the installer to initialize Miniconda3 by running conda init.
bash Miniconda3-latest-Linux-x86_64.sh -
Activate the Changes:
For the installation to take effect, you need to either close and reopen your terminal or source your .bashrc file.
source ~/.bashrc -
Verify Installation:
Check that conda is installed correctly by checking its version.
conda --version
2. Install Node.js, npm, and Claude Code
Node.js is a JavaScript runtime, and npm is its package manager. These are often required for various development tools. We will install the official Claude Code CLI tool.
Steps:
-
Install Node.js and npm (Recommended Method):
The best way to install Node.js is by using
nvm(Node Version Manager). This tool installs Node and npm in your user directory, which completely avoids the permission errors mentioned in Step 3 and allows you to easily switch between different Node.js versions.a. Install nvm:
This command downloads and runs the nvm installation script.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashb. Activate nvm:
For the nvm command to work, you must either close and reopen your terminal or run the following command to update your current session:
source ~/.bashrcNote: If you use a different shell, you may need to source
~/.zshrcor~/.profile.c. Install the latest Long-Term Support (LTS) version of Node.js:
This is the recommended version for most users. It will also install the corresponding version of npm.
nvm install --ltsd. Set the LTS version as your default:
This command ensures that any new terminal you open will automatically use the Node.js version you just installed.
nvm alias default ltse. Verify the installation:
Check that Node.js and npm are installed correctly before proceeding.
node -v npm -vYou should see version numbers output for both commands (e.g.,
v20.18.0and10.7.0). -
Install Claude Code (Global Method):
This is the standard method for making the
claudecommand available system-wide for your user.npm install -g @anthropic-ai/claude-codeImportant: Do NOT use
sudofor this command. If you usednvmas described above, you will not have permission errors. -
(If Needed) Fix npm Permission Errors:
If the previous command failed, it’s likely because you did not use
nvmand installed Node.js through another method likeapt-get. The best practice is to remove that system version of Node.js and follow Step 1.If you must fix a non-nvm installation, you can change npm’s default directory to a location inside your home folder.
- Create a directory for global packages:
mkdir ~/.npm-global - Configure npm to use the new directory path:
npm config set prefix '~/.npm-global' - Add the new directory to your
PATH: Open~/.bashrcwith an editor likenanoand add the following line to the end of the file:export PATH=~/.npm-global/bin:$PATH - Apply the changes to your current terminal session:
source ~/.bashrc - Now, re-run the installation command without
sudo:npm install -g @anthropic-ai/claude-code
- Create a directory for global packages:
3. Configure GitHub and GitHub CLI
Setting up Git and the GitHub CLI (gh) is essential for version control and interacting with GitHub repositories.
Steps:
-
Configure Git:
Set your global username and email. These will be associated with your commits.
git config --global user.name "Your Name" git config --global user.email "your.email@example.com" -
Install the GitHub CLI:
Follow the official instructions for your Linux distribution. For Debian/Ubuntu:
sudo apt install gh -y -
Authenticate with GitHub:
Log in to your GitHub account. This will guide you through an authentication process in your browser.
gh auth login
4. Install Google Cloud CLI
The Google Cloud CLI (gcloud) is necessary for interacting with your Google Cloud Platform projects and resources from the command line.
Steps:
-
Run the Interactive Installer:
This command downloads and runs the installer, which will guide you through the process.
curl https://sdk.cloud.google.com | bash -
Restart Your Shell:
Close and reopen your terminal or source your shell’s configuration file to add the CLI to your path.
source ~/.bashrc -
Initialize the gcloud CLI:
This command walks you through setting up your initial configuration, including logging in and selecting a default project.
gcloud init
5. Install Hugging Face CLI
The huggingface-cli allows you to interact with the Hugging Face Hub, download models, and manage your account.
Steps:
-
Install the Library:
The CLI is part of the huggingface_hub Python library. Install it using pip.
pip install huggingface_hub -
Log In:
Log in to your Hugging Face account. You will need an access token, which you can generate from your account settings on the Hugging Face website.
hf auth loginPaste your token when prompted.
Now you are ready to go!
6. Docker Workflow for Background Training Jobs
This section explains how to set up a clean directory structure and run a Docker container in the background for long-running training jobs.
Directory Structure Setup
First, create a set of folders in your home directory to organize your project. This structure cleanly separates your configurations, data, base models, and results.
# Create the project folders in your home directory
mkdir ~/dataset
mkdir ~/models
mkdir ~/simple_posttraining
mkdir ~/simple_posttraining/llama_factory_sft
mkdir ~/trained_output
~/dataset/: Store your training datasets here.~/models/: Store your pre-trained base models (e.g., Llama-3-8B-Instruct) here.~/simple_posttraining/llama_factory_sft/: Your training configuration.yamlfiles live here.~/trained_output/: The newly trained models and checkpoints will be saved here.
Configuring Your Training YAML
Your .yaml file tells LLaMA Factory where to find everything. The paths you specify must match the paths inside the Docker container.
Create a file like ~/simple_posttraining/llama_factory_sft/my_lora_tune.yaml with the following content:
# model_name_or_path points to where the base model is INSIDE the container
model_name_or_path: /app/models/Meta-Llama-3-8B-Instruct
# dataset_dir points to the data folder INSIDE the container
dataset_dir: /app/data
dataset: your_dataset_name # Make sure this is defined in dataset_info.json
# output_dir points to where the results will be saved INSIDE the container
output_dir: /app/output
# Other training parameters
finetuning_type: lora
template: llama3
overwrite_output_dir: true
per_device_train_batch_size: 2
gradient_accumulation_steps: 8
learning_rate: 1.0e-4
num_train_epochs: 3.0
fp16: true
Running the Docker Container
This command will start the container in detached (-d) mode and connect your local folders to the paths inside the container.
docker run \
-d \
--name llama-trainer \
--gpus=all \
--ipc=host \
-v ~/simple_posttraining/llama_factory_sft:/app/configs \
-v ~/dataset:/app/data \
-v ~/models:/app/models \
-v ~/trained_output:/app/output \
hiyouga/llamafactory:latest \
tail -f /dev/null
Breakdown of the -v (volume mounts):
-v ~/simple_posttraining/llama_factory_sft:/app/configs: Maps your local config folder to/app/configsin the container.-v ~/dataset:/app/data: Maps your local dataset folder to/app/data.-v ~/models:/app/models: Maps your local base models folder to/app/models.-v ~/trained_output:/app/output: Maps your local output folder to/app/output.
Starting the Training Job
Use docker exec to run the training command inside the container, pointing to your configuration file.
docker exec -it llama-trainer llamafactory-cli train /app/configs/my_lora_tune.yaml
The training will now begin. Because of the volume mounts, the final trained model will appear in your ~/trained_output folder on your VM.
Managing the Container
-
View Logs:
See the real-time training output.
docker logs -f llama-trainer -
Stop the Container:
When your experiment is finished, you can stop the container.
docker stop llama-trainer -
Remove the Container:
After stopping, you can remove it. Your files will remain safe in your local directories.
docker rm llama-trainer