To display the running time of the Linux system in a human-readable format, you can use the following command.
uptime -p
To kill a process by its PID, first use htop
to obtain the PID. (ref)
kill -9 PID
To obtain an IPv4 address, if the IPv4 address is unavailable, run the following code :
dhclient -v
To use conda
to create new environment with a specific name and Python version, run the following code:
conda create -n py3.10 python==3.10
To import a file from another directory in python, using the following approach: Suppose you have two folders at the same level:
/project/some_folder/some_file.py
/project/another_floder/another.py
You can make one module visible to the other using the following code:
import sys
sys.path.append('../')
To resolve the issue where the Visual Studio Code terminal shows multiple Conda environments on the server, follows these steps:
(py3.10)(base)future@lif323:~/work$
- Delete the
~/.vscode-server
directory on the server. - Connect to the server again.
To run .notebook
on a remote server throught vs code, you need to following these steps:
- Install
jupyter
extension on vs code on the remote server side. - Open
.notebook
file and SelectKernel
- Install
jupyter
python package throughpip install jupyter
on the python environment associate with theKernel
.
To add a new user in ubuntu, use the following command:
sudo adduser username
To grant the user with administrative privileges, use:
sudo usermod -aG sudo username
Running Hugging Face Models Offline ref1
Model
- load the pre-trained model and save to locally:
model_saved = "./model-distilbert-base-uncased-finetuned-sst-2-english/"
model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
model.save_pretrained(model_saved)
- Transfer the
model_saved
directory to offline server (e.g. to./model_path
). Then, load the model from the offline path:
model = AutoModelForSequenceClassification.from_pretrained('./model_path')
Dataset
- Load the dataset and save it locally:
from datasets import load_dataset, load_from_disk
dataset = load_dataset('glue', 'sst2')
dataset.save_to_disk('./dataset_saved')
- Transfer the
./dataset_saved
directory to the offline server (e.g../dataset_path/
). Then, load the dataset from the offline path:
dataset = load_from_disk('./dataset_path')
Problem When multiple Conda environments are activated simultaneously (e.g., (pytorch) (base) shown in the prompt), it may cause confusion or unexpected behavior. ref
(pytorch) (base) db@server
Resolution To resolve this issue:
- Disable the auto-activation of the base environment:
conda config --set auto_activate_base False
- Restart your shell (close and reopen the terminal).
- If needed, re-enable base activation later with:
conda config --set auto_activate_base True