This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ | |
| TODO: | |
| * Remove dependency on ppt and randopt. | |
| * Replace get_problems with mini-imagenet dataset. | |
| """ | |
| import os | |
| import random |
Cython has two major benefits:
- Making python code faster, particularly things that can't be done in scipy/numpy
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import yaml | |
| import argparse | |
| class _ConfigDict(dict): | |
| """ A subclass of dict that supports required args | |
| """ | |
| # Change this to customize it | |
| fields = [] | |
| @classmethod |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ 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 contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| This file will contain the explanations to run dtrpo sequentially, and how to reproduce the results of algorithm "dtrpo-bench". |