Skip to content

Instantly share code, notes, and snippets.

View alexlimh's full-sized avatar

Minghan Li alexlimh

View GitHub Profile
import argparse
import collections
import functools
import gc
import os
import pathlib
import resource
import sys
import warnings
ATARI_DEFAULTS = dict(
# General
steps=2e8,
eval_every=1e5,
log_every=1e4,
prefill=5e4,
dataset_size=4e6,
pretrain=0,
# Environment
@alexlimh
alexlimh / dreamer.py
Created April 29, 2020 13:58
dreamer.py
import argparse
import collections
import functools
import gc
import os
import pathlib
import resource
import sys
import warnings
@alexlimh
alexlimh / dreamer.py
Last active April 29, 2020 14:02
dreamer.py: add config.reuse_actor; add EmpowStepActionBehavior models.py: add EmpowStepActionBehavior; change EmpowVIMBehavior; networks.py: change ActionHead class.
import argparse
import collections
import functools
import gc
import os
import pathlib
import resource
import sys
import warnings

Running Minecraft in Headless Linux System

Prerequisite

  1. xpra

    sudo apt-get install xpra

  2. jdk 1.8

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import collections
from dm_control import mujoco
from dm_control.rl import control
from dm_control.suite import base
from dm_control.suite import common
#!/bin/bash
#SBATCH --mem=50G
#SBATCH -c 8
#SBATCH --gres=gpu:1
#SBATCH -p gpu
CKPT=/checkpoint/minghan/${SLURM_JOB_ID}
touch $CKPT
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Mission xmlns="http://ProjectMalmo.microsoft.com">
<About>
<Summary>$(ENV_NAME)</Summary>
</About>
<ModSettings>
<MsPerTick>50</MsPerTick>
<!--<PrioritiseOffscreenRendering>true</PrioritiseOffscreenRendering>-->
</ModSettings>
@alexlimh
alexlimh / mutual information.py
Last active May 12, 2021 15:41
mutual information
# 1. retrieve top-k passages for each query
# 2. merge the top-k passages and get the union
# 3. calculate the dot-product on the union for each query
# 3.5. save the dot-products into .pkl or .npy file
# 4. put the score into this function and get mutual information
def get_mi(self, logits, tau=1.0): # logits are the dot-product scores, size: QxP, where Q is the number of queries, P is the number of retrieved passages
# tau is the temperature coef that controls the sharpness of the distribution
# numeric stability
max_logit = np.max(logits, axis=-1, keepdims=True)
probs = np.exp((logits - max_logit)/tau)/np.sum(np.exp((logits - max_logit)/tau), -1, keepdims=True)
#!/usr/bin/env python3
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
"""
Command line tool to get dense results and validate them
"""