Skip to content

Instantly share code, notes, and snippets.

View seba-1511's full-sized avatar

Séb Arnold seba-1511

View GitHub Profile
import torch
import torch.utils.dlpack
import jax
import jax.dlpack
# A generic mechanism for turning a JAX function into a PyTorch function.
def j2t(x_jax):
x_torch = torch.utils.dlpack.from_dlpack(jax.dlpack.to_dlpack(x_jax))
return x_torch
inner_model = nnModuleModel(input_size=input_size, output_size=num_classes)
metamodel = nnModuleModel(input_size=input_size, output_size=1)
step = 0
metaopt = Optim(metamodel.parameters(), with_no_grad=True) # conventional optimizer with "with no_grad"
for epoch in num_epochs:
# Normal training loop
@seba-1511
seba-1511 / learn2learn-reptile-fix#132.py
Created May 15, 2020 19:28
Working implementation of Reptile
#!/usr/bin/env python3
"""
TODO:
* Remove dependency on ppt and randopt.
* Replace get_problems with mini-imagenet dataset.
"""
import os
import random
@seba-1511
seba-1511 / hello_world.md
Created April 4, 2020 19:31 — forked from lava/hello_world.md
Hello, world: Deep analysis of a shallow program.

Hello, world!

Please explain in detail what will happen if the following program is executed:

#include <iostream>

int main() {
    std::cout << "Hello, world!" << std::endl;
}
@seba-1511
seba-1511 / cython_tricks.md
Created February 24, 2020 02:59 — forked from ctokheim/cython_tricks.md
cython tricks

Cython

Cython has two major benefits:

  1. Making python code faster, particularly things that can't be done in scipy/numpy
  2. Wrapping/interfacing with C/C++ code

Cython gains most of it's benefit from statically typing arguments. However, statically typing is not required, in fact, regular python code is valid cython (but don't expect much of a speed up). By incrementally adding more type information, the code can speed up by several factors. This gist just provides a very basic usage of cython.

@seba-1511
seba-1511 / config_dict.py
Created February 21, 2019 18:40 — forked from JACKHAHA363/config_dict.py
A principled way to have config dictionary that can be saved/restored, support pre-defined type and default values, and support cmd parsing
import yaml
import argparse
class _ConfigDict(dict):
""" A subclass of dict that supports required args
"""
# Change this to customize it
fields = []
@classmethod
@seba-1511
seba-1511 / ram_image_example.py
Created November 19, 2018 04:52 — forked from alexlee-gk/ram_image_example.py
Get color and depth image as numpy array using Panda3d 1.10.0 and python 3.5
import numpy as np
import time
import cv2
from direct.showbase.ShowBase import ShowBase
from panda3d.core import FrameBufferProperties, WindowProperties
from panda3d.core import GraphicsPipe, GraphicsOutput
from panda3d.core import Texture
from panda3d.core import loadPrcFileData
loadPrcFileData('', 'show-frame-rate-meter true')
@seba-1511
seba-1511 / example
Created September 15, 2017 19:02 — forked from takluyver/example
Debug on interrupt
$ python3 interrupt-debug.py
0
1
2
3
^C--Return--
> /home/takluyver/scratch/interrupt-debug.py(6)handle_sigint()->None
-> pdb.set_trace()
(Pdb) p a
4
This file will contain the explanations to run dtrpo sequentially, and how to reproduce the results of algorithm "dtrpo-bench".