Skip to content

Instantly share code, notes, and snippets.

View ahwillia's full-sized avatar

Alex Williams ahwillia

View GitHub Profile
@gngdb
gngdb / example_usage.py
Last active May 18, 2022 05:32
Wrap PyTorch functions for scipy's optimize.minimize: https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html (I also made a repo to do this https://github.com/gngdb/pytorch-minimize, although I had forgotten about this gist at the time)
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import numpy as np
from scipy import optimize
from obj import PyTorchObjective
@nirum
nirum / tf_sandbox.py
Last active June 23, 2017 03:51
monkeypatch for giving subclasses their own graph and session (tensorflow)
def tf_graph_wrapper(func):
"""Wraps a class method with a tf.Graph context manager"""
@wraps(func)
def wrapper(self, *args, **kwargs):
with self._graph.as_default():
return func(self, *args, **kwargs)
return wrapper
def tf_init(func):