Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parameter server strategy #8

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
31 changes: 31 additions & 0 deletions distml/operator/jax_operator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import numpy as np
import cupy as cp

import jax
from jax import value_and_grad
import jax.numpy as jnp
Expand Down Expand Up @@ -349,6 +350,36 @@ def reset_optimizer_for_params(self, params):
self.tree = tree_structure(params)
self.opt_state = self.opt_init(params)

def ones(self, shape, cpu=True):
if cpu:
return np.ones(shape)
else:
return jnp.ones(shape)

def zeros(self, shape, cpu=True):
if cpu:
return np.zeros(shape)
else:
return jnp.zeros(shape)

def ones_like(self, x, cpu=True):
if cpu:
return np.ones_like(x)
else:
return jnp.ones_like(x)

def zeros_like(self, x, cpu=True):
if cpu:
return np.zeros_like(x)
else:
return jnp.zeros_like(x)

def numel(self, v):
return np.size(v)

def asarray(self, v):
return jnp.asarray(v)

def clean_redundancy(self):
del self._train_loader
del self._validation_loader
Expand Down