Skip to content

Instantly share code, notes, and snippets.

View vwxyzjn's full-sized avatar
😃

Costa Huang vwxyzjn

😃
View GitHub Profile
import argparse
import pickle
from collections import namedtuple
import matplotlib.pyplot as plt
import gym
import torch
import torch.nn as nn
import torch.nn.functional as F

SSH + Screen This one is not about AI, but about something extremely useful I learned today. Have you ever been running an experiment in a server through SSH and all of asudden the connecton drops? damn! you lose the experiment... try this:

  1. ssh to your server
  2. screen
  3. launch your experiment
  4. "Ctrl-a" "d"

now you can quit your ssh and the experiment keeps running in the server. Whenever you want to check how is it going, go and:

import numpy as np
global_step = 0
milestone = [1000, 2000, 3000]
milestone_visited = np.zeros(len(milestone), dtype=np.int)
milestone_idx = 0
for _ in range(20000):
global_step+=1
if global_step >= milestone[milestone_idx]:
if not milestone_visited[milestone_idx]:
milestone_visited[milestone_idx] = 1
@vwxyzjn
vwxyzjn / JepTest.java
Last active December 3, 2024 09:17
Automatically load jep's C library
package tests;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import jep.Interpreter;
import jep.MainInterpreter;
import jep.SharedInterpreter;
public class JepTest {
public static void main(String args[]) throws Exception {
CREATE TABLE Positions
(
positionID CHAR(4) PRIMARY KEY,
positionTitle VARCHAR(50) NOT NULL,
salaryRate FLOAT NOT NULL
);
CREATE TABLE Employees
(
employeeID CHAR(6) PRIMARY KEY,
# Reference: https://arxiv.org/pdf/1509.02971.pdf
# https://github.com/seungeunrho/minimalRL/blob/master/ddpg.py
# https://github.com/openai/spinningup/blob/master/spinup/algos/pytorch/ddpg/ddpg.py
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
from torch.utils.tensorboard import SummaryWriter
from stable_baselines3.common.vec_env import DummyVecEnv
import gym
import numpy as np
from gym import error, spaces, utils
from gym.envs.registration import register
"""
First kind of termination: True Done
As an example, the true done of the Breakout game in Atari 2600
comes when you lose all of your lives.
@vwxyzjn
vwxyzjn / docker.sh
Created June 11, 2020 17:24
Reproduction of PPO
docker run -d --cpuset-cpus="0" -e WANDB=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx vwxyzjn/cleanrl:latest python ppo_atari_visual.py --gym-id BeamRiderNoFrameskip-v4 --total-timesteps 10000000 --wandb-project-name cleanrl.benchmark --wandb-entity cleanrl --prod-mode --capture-video --seed 1
docker run -d --cpuset-cpus="1" -e WANDB=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx vwxyzjn/cleanrl:latest python ppo_atari_visual.py --gym-id BeamRiderNoFrameskip-v4 --total-timesteps 10000000 --wandb-project-name cleanrl.benchmark --wandb-entity cleanrl --prod-mode --capture-video --seed 2
docker run -d --cpuset-cpus="2" -e WANDB=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx vwxyzjn/cleanrl:latest python ppo_atari_visual.py --gym-id QbertNoFrameskip-v4 --total-timesteps 10000000 --wandb-project-name cleanrl.benchmark --wandb-entity cleanrl --prod-mode --capture-video --seed 1
docker run -d --cpuset-cpus="3" -e WANDB=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx vwxyzjn/cleanrl:latest python ppo_atari_visual.py --gym-i
@vwxyzjn
vwxyzjn / done_notification.sh
Created October 28, 2020 17:44
Get a notification when my commands are done
### Linux:
# https://askubuntu.com/questions/656603/alert-when-terminal-program-finishes-running
# temporary
alias sd="notify-send 'DONE'"
# permanent
echo "alias sd=\"notify-send 'DONE'\"" >> ~/.bashrc
echo "alias sd=\"notify-send 'DONE'\"" >> ~/.zshrc
### Macos:
# https://apple.stackexchange.com/questions/9412/how-to-get-a-notification-when-my-commands-are-done#_=_
import kt_models
from datetime import datetime
import os
import time
import random
import argparse
from distutils.util import strtobool
import numpy as np
import joblib