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

Random seed #321

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion kan/KAN.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class KAN(nn.Module):
'''

def __init__(self, width=None, grid=3, k=3, noise_scale=0.1, scale_base_mu=0.0, scale_base_sigma=1.0, base_fun=torch.nn.SiLU(), symbolic_enabled=True, bias_trainable=False, grid_eps=1.0, grid_range=[-1, 1], sp_trainable=True, sb_trainable=True,
device='cpu', seed=0):
device='cpu', seed=None):
'''
initalize a KAN model

Expand Down Expand Up @@ -123,6 +123,9 @@ def __init__(self, width=None, grid=3, k=3, noise_scale=0.1, scale_base_mu=0.0,
'''
super(KAN, self).__init__()

if seed is None:
seed = np.random.randint(0, 1e3)

torch.manual_seed(seed)
np.random.seed(seed)
random.seed(seed)
Expand Down
2 changes: 0 additions & 2 deletions kan/LBFGS.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,6 @@ def step(self, closure):
and returns the loss.
"""

torch.manual_seed(0)

assert len(self.param_groups) == 1

# Make sure the closure is always called with grad enabled
Expand Down
5 changes: 4 additions & 1 deletion kan/MultKAN.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
class MultKAN(nn.Module):

# include mult_ops = []
def __init__(self, width=None, grid=3, k=3, mult_arity = 2, noise_scale=1.0, scale_base_mu=0.0, scale_base_sigma=1.0, base_fun='silu', symbolic_enabled=True, affine_trainable=False, grid_eps=1.0, grid_range=[-1, 1], sp_trainable=True, sb_trainable=True, device='cpu', seed=0, save_plot_data=True, sparse_init=False, auto_save=True, first_init=True, ckpt_path='./model', state_id=0):
def __init__(self, width=None, grid=3, k=3, mult_arity = 2, noise_scale=1.0, scale_base_mu=0.0, scale_base_sigma=1.0, base_fun='silu', symbolic_enabled=True, affine_trainable=False, grid_eps=1.0, grid_range=[-1, 1], sp_trainable=True, sb_trainable=True, device='cpu', seed=None, save_plot_data=True, sparse_init=False, auto_save=True, first_init=True, ckpt_path='./model', state_id=0):

super(MultKAN, self).__init__()

if seed is None:
seed = np.random.randint(0, 1e3)

torch.manual_seed(seed)
np.random.seed(seed)
random.seed(seed)
Expand Down
5 changes: 4 additions & 1 deletion kan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def create_dataset(f,
normalize_input=False,
normalize_label=False,
device='cpu',
seed=0):
seed=None):
'''
create dataset

Expand Down Expand Up @@ -103,6 +103,9 @@ def create_dataset(f,
torch.Size([100, 2])
'''

if seed is None:
seed = np.random.randint(0, 1e3)

np.random.seed(seed)
torch.manual_seed(seed)

Expand Down