xcx0902 commited on
Commit
0613d9c
·
verified ·
1 Parent(s): 80a1acf

Upload folder using huggingface_hub

Browse files
Files changed (6) hide show
  1. MultiplicationNet.py +1 -1
  2. device.py +2 -0
  3. model.pth +2 -2
  4. model.safetensors +2 -2
  5. test.py +20 -0
  6. train.py +3 -3
MultiplicationNet.py CHANGED
@@ -3,7 +3,7 @@ import torch.nn as nn
3
  class MultiplicationNet(nn.Module):
4
  def __init__(self):
5
  super(MultiplicationNet, self).__init__()
6
- layer_sizes = [2, 256, 512, 1024, 1]
7
  layers = []
8
  for i in range(len(layer_sizes) - 1):
9
  layers.append(nn.Linear(layer_sizes[i], layer_sizes[i + 1]))
 
3
  class MultiplicationNet(nn.Module):
4
  def __init__(self):
5
  super(MultiplicationNet, self).__init__()
6
+ layer_sizes = [2, 512, 1024, 2048, 1]
7
  layers = []
8
  for i in range(len(layer_sizes) - 1):
9
  layers.append(nn.Linear(layer_sizes[i], layer_sizes[i + 1]))
device.py CHANGED
@@ -5,3 +5,5 @@ device: str
5
  if torch.cuda.is_available(): device = 'cuda'
6
  elif torch.mps.is_available(): device = 'mps'
7
  else: device = 'cpu'
 
 
 
5
  if torch.cuda.is_available(): device = 'cuda'
6
  elif torch.mps.is_available(): device = 'mps'
7
  else: device = 'cpu'
8
+
9
+ print(f"Device set to {torch.Tensor().to(device).device}")
model.pth CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:cefcd52977cd055794c10dba186f321ad2b5aacee73975f99371d3843c0a524c
3
- size 2639793
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e68ce613b4003c2d7fee3ed8fafc38b6b53fb744e7a50f237710d63fad450bc
3
+ size 10517425
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ef5ab55b5daa68066891c2991cfe1628f76581bf0106deedb4b2fa907ae4dead
3
- size 2635388
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99a3bb67679f9a5ee8ea27df6fed196e33d35fb20bf73ca7192a03f0ff16017c
3
+ size 10513028
test.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from run import run
2
+ from tqdm import trange
3
+ import random
4
+
5
+ lacc = []
6
+
7
+ def test(round):
8
+ pbar = trange(round)
9
+ for r in pbar:
10
+ x = random.randint(1, 100)
11
+ y = random.randint(1, 100)
12
+ pans = run([x, y])
13
+ tans = x * y
14
+ acc = 1 - abs(tans - pans) / tans
15
+ lacc.append(acc)
16
+ pbar.set_description_str(f"Round {r}, Average Accuracy = {sum(lacc) / len(lacc) * 100}%")
17
+ print(f"Final Accuracy: {sum(lacc) / len(lacc) * 100}%")
18
+
19
+ if __name__ == '__main__':
20
+ test(100000)
train.py CHANGED
@@ -12,8 +12,8 @@ def generate_data(num_samples, min_val=0, max_val=100):
12
  return np.hstack([x1, x2]), y
13
 
14
  def train():
15
- num_samples = 20000
16
- num_epochs = 20000
17
  learning_rate = 0.01
18
 
19
  x, y = generate_data(num_samples)
@@ -23,7 +23,7 @@ def train():
23
  model = MultiplicationNet().to(device)
24
  criterion = nn.MSELoss().to(device)
25
  optimizer = optim.Adam(model.parameters(), lr=learning_rate)
26
- scheduler = optim.lr_scheduler.StepLR(optimizer, step_size=100, gamma=0.93)
27
 
28
  for epoch in range(num_epochs):
29
  outputs = model(x_train)
 
12
  return np.hstack([x1, x2]), y
13
 
14
  def train():
15
+ num_samples = 10000
16
+ num_epochs = 30000
17
  learning_rate = 0.01
18
 
19
  x, y = generate_data(num_samples)
 
23
  model = MultiplicationNet().to(device)
24
  criterion = nn.MSELoss().to(device)
25
  optimizer = optim.Adam(model.parameters(), lr=learning_rate)
26
+ scheduler = optim.lr_scheduler.StepLR(optimizer, step_size=100, gamma=0.95)
27
 
28
  for epoch in range(num_epochs):
29
  outputs = model(x_train)