Skip to content

Instantly share code, notes, and snippets.

View universome's full-sized avatar
💭
༼∩☉ل͜☉༽⊃━☆゚. * ・ 。゚

Ivan Skorokhodov universome

💭
༼∩☉ل͜☉༽⊃━☆゚. * ・ 。゚
View GitHub Profile
@universome
universome / i3d_pytorch_jit.py
Created May 18, 2022 12:53
I3D network code suitable for conversion in pytorch JIT. Adapted from https://github.com/hassony2/kinetics_i3d_pytorch.
"""
I3D network code suitable for conversion in pytorch JIT.
Adapted from https://github.com/hassony2/kinetics_i3d_pytorch.
"""
import torch
import torch.nn.functional as F
# @torch.jit.script
@universome
universome / flax_hypernetwork.py
Created July 25, 2021 18:39
An example of a simple hypernetwork (i.e. a neural network, producing parameters for another network) in Flax
from typing import Sequence, Dict, Iterable, Any, Tuple
import jax
import jax.numpy as jnp
import flax
import flax.linen as nn
class MLP(nn.Module):
features: Sequence[int]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@universome
universome / jupyter-lab-shorcuts.json
Created September 3, 2019 07:10
Disable Cmd+F behaviour in Jupyter Lab
{
"shortcuts": [
{
"command": "documentsearch:start",
"keys": [
"Accel F"
],
"selector": ".jp-mod-searchable",
"disabled": true
}
from torch.distributions import MultivariateNormal
from torch.distributions import kl_divergence
mean = torch.rand(10, 100)
logstds = torch.rand(10, 100)
x = torch.rand(10, 100)
dist = MultivariateNormal(mean, scale_tril=torch.stack([torch.diag((ls).exp()) for ls in logstds]))
print('Testing LL')
print(dist.log_prob(x).mean())
@universome
universome / setup.sh
Last active February 21, 2018 17:58
Setting up pytorch on AWS DL AMI with pyvenv (cause preinstalled conda sucks again)
# Creating pyvenv
python3.6 -m venv --without-pip ~/pyvenvs/zoo
source ~/pyvenvs/zoo/bin/activate
# Getting pip inside
curl https://bootstrap.pypa.io/get-pip.py | python
# Reactivating to obtain pip from venv (without it we would use global pip)
deactivate && source ~/pyvenvs/zoo/bin/activate
# I dunno why, but we should specify 0.0.0.0 IP address for jupyter
# when we want to login remotely (for example, aws ec2 or docker)
jupyter-lab --ip=0.0.0.0 --no-browser --port=10000
# In case HTTP ports are not open in the server —
# use ssh forwarding on local machine
ssh -N -f -L localhost:8888:localhost:10000 user@host
@universome
universome / deploy.sh
Last active October 1, 2017 08:59
Deploy new ubuntu 14.04 instance with virtualenv and some useful packages
sudo apt-get update
sudo apt-get -y install python3-pip python-virtualenv python-dev
mkdir virtualenvs
virtualenv -p python3 virtualenvs/kek
git clone git@github.com:kek/kek-repo.git kek
cd kek
source ~/virtualenvs/kek/bin/activate
@universome
universome / virtualenv_install.sh
Created July 3, 2016 15:29
Installing virtualenv on ubuntu
sudo apt-get update
sudo apt-get install python3-pip python-virtualenv virtualenv
# and now you can use it via:
# virtualenv -p python3 kek
###
# Stop and remove all containers
docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)
###
###
# Run docker daemon (if you see stupid error "Cannot connect to the Docker daemon. Is the docker daemon running on this host?")
# Ubuntu 14.04:
sudo service docker start