Skip to content

Instantly share code, notes, and snippets.

View changx03's full-sized avatar
🏠
Working from home

Luke Chang changx03

🏠
Working from home
  • The University of Auckland
  • Auckland
  • 20:10 (UTC +12:00)
View GitHub Profile
@changx03
changx03 / kge_fb15k_237.py
Created August 21, 2023 01:17
PyTorch Geometric example for FB15K
import argparse
import os.path as osp
import torch
import torch.optim as optim
from torch_geometric.datasets import FB15k_237
from torch_geometric.nn import ComplEx, DistMult, RotatE, TransE
model_map = {
@changx03
changx03 / server_name.sh
Last active July 23, 2023 22:53
Access to CSML cluster
# Server 1:
ssh <UPI>@foscsmlprd01.its.auckland.ac.nz
# Server 2:
ssh <UPI>@foscsmlprd02.its.auckland.ac.nz
# Pssword: <UoA_PASSWORD>:<6_DIGITS_2FACTOR> eg, Pass1234:123456
# For Linux user, using GUI to tansfer files:
# Open `Files` browser, press ctrl+L
@changx03
changx03 / run_gpu_python.sh
Last active July 21, 2023 14:14
Instruction for executing Python code with a specific GPU and save console outputs and error to a log file
# Use `nvtop` or `nvidia-smi` to check avalible GPUs. Only allows the Python code to access a specific GPU:
# CUDA_VISIBLE_DEVICES=<GPU_INDEX>
# Redirect standard output to `main.log` and then redirect standard error to standard output:
# > main.log 2>&1
# Allows code to run in the bakcgounrd:
# &
CUDA_VISIBLE_DEVICES=0 python main.py > main.log 2>&1 &
@changx03
changx03 / torch_gpu_test.py
Created July 21, 2023 13:51
Testing for GPU availability
import torch
device = torch.device('cuda:0') if torch.cuda.is_available() else 'cpu'
print(f'Using: {device}')
print('GPU Memory Usage:')
print('Allocated:', round(torch.cuda.memory_allocated(0) / 1024**3, 1), 'GB')
print('Cached: ', round(torch.cuda.memory_reserved(0) / 1024**3, 1), 'GB')
# Run a trivial task
@changx03
changx03 / run_jupyer.sh
Last active July 23, 2023 22:59
Running Jupyter Lab on a remote server
# Instructions for connecting Jupyter Lab with the remove server
# SSH with port forward:
# Replace <PORT> with the port number you selected in the above step
# Replace <REMOTE_USER> with the remote server username
# Replace <REMOTE_HOST> with your remote server address
ssh -L 8080:localhost:<PORT> <REMOTE_USER>@<REMOTE_HOST>
####################################################################
# Replace <PORT> with your selected port number, e.g., 8080
@changx03
changx03 / change_cache_dir.sh
Last active September 26, 2023 00:24
Change Ubuntu cache directory on remove server
# These parameters are only apply in your current terminal.
# Run them again once you start a new terminal!
export XDG_CACHE_HOME=/data/<username>/.cache
export PIP_CACHE_DIR=/data/<username>/.cache
@changx03
changx03 / keychron_fn.sh
Created January 8, 2023 16:15
Set Keychron Linux Function Keys
#!/bin/bash
echo 0 | sudo tee /sys/module/hid_apple/parameters/fnmode
@changx03
changx03 / array_example.sh
Created July 14, 2022 02:24
Access an element from an array using index in bash
#!/bin/bash
# To access banana
DATA=("apple" "banana" "cherry")
IDX=1
echo ${DATA[$IDX]}
@changx03
changx03 / decompress.py
Last active October 21, 2021 04:46
Stack
# Predefined methods
class Stack:
def __init__(self):
self.__items = []
def is_empty(self):
return self.__items == []
def push(self, item):
self.__items.append(item)
@changx03
changx03 / Install_OpenCV4_CUDA10.md
Created January 25, 2021 04:30 — forked from raulqf/Install_OpenCV4_CUDA11_CUDNN8.md
How to install OpenCV 4.2 with CUDA 10.0 in Ubuntu 18.04

How to install OpenCV 4.2.0 with CUDA 10.0 in Ubuntu distro 18.04

First of all install update and upgrade your system:

    $ sudo apt update
    $ sudo apt upgrade

Then, install required libraries: