Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notes added on next steps as well as bug fix (layer norm applied in w…
…rong order)
- Loading branch information
1 parent
223263b
commit 0be63b0
Showing
8 changed files
with
238 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
from transformerDqn import * | ||
import gym | ||
import torch | ||
from dqn import DQN, ReplayBuffer | ||
from torch.optim import Adam | ||
from torch.nn.functional import mse_loss | ||
|
||
#creating DQN | ||
embedding_size = 24 | ||
dropout = 0.1 | ||
B = 32 | ||
input_size = 3 | ||
dim_feedforward = 16 | ||
nhead = 1 | ||
num_actions = 4 | ||
num_encoder_layers = 1 | ||
embedder = CartPoleEmbedder | ||
embedding_params = {'dropout': dropout, 'B': B, 'input_size': input_size, 'embedding_size': embedding_size} | ||
encoder_layer_params = {'d_model':embedding_size, 'nhead':nhead, 'dim_feedforward':dim_feedforward, 'dropout':dropout} | ||
dqn = TransformerDqn(embedder=embedder,embedder_params=embedding_params, | ||
encoder_layer_params=encoder_layer_params,output_size=num_actions, | ||
num_encoder_layers=1) | ||
|
||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
|
||
Here are notes on the training procedure used in TXL. | ||
|
||
1. How does adaptive embedding work? The complicated version div_val==2 doesn't seem to actually be used (must have been experimental) | ||
This seems to just me a normal learned embedding layer. | ||
|
||
|
||
How does choosing what goes in a batch happen (do we use consecutive segments so that cache doesn't get too large?) | ||
How does masking work? | ||
|
||
What are tgt_len, mem_len and ext_len? | ||
|
||
|
||
LMOrderedIterator: | ||
They've just implemented batches coming sequentially which may be unoptimal (semi correlated updates) | ||
This allows them at each step to just store memory from previous step. (can make a better iterator than this***) |
This file contains 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 contains 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 contains 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 contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import torch | ||
import numpy as np | ||
|
||
|
||
|
||
class ReplayBuffer: | ||
def __init__(self, max_size=2000): | ||
self.max_size = max_size | ||
|
||
self.cur_states = [] | ||
self.actions = [] | ||
self.next_states = [] | ||
self.rewards = [] | ||
self.dones = [] | ||
|
||
def __len__(self): | ||
return len(self.cur_states) | ||
|
||
def add(self, cur_state, action, next_state, reward, done): | ||
self.cur_states.append(cur_state) | ||
self.actions.append(action) | ||
self.next_states.append(next_state) | ||
self.rewards.append(reward) | ||
self.dones.append(done) | ||
|
||
def sample(self, sample_size=32): | ||
sample_transitions = {} | ||
if self.__len__() >= sample_size: | ||
# pick up only random 32 events from the memory | ||
# TODO : Replace np with torch functionality and remove import numpy from above | ||
indices = np.random.choice(self.__len__(), size=sample_size) | ||
sample_transitions['cur_states'] = torch.stack(self.cur_states)[indices] | ||
sample_transitions['actions'] = torch.stack(self.actions)[indices] | ||
sample_transitions['next_states'] = torch.stack(self.next_states)[indices] | ||
sample_transitions['rewards'] = torch.Tensor(self.rewards)[indices] | ||
sample_transitions['dones'] = torch.Tensor(self.dones)[indices] | ||
else: | ||
# if the current buffer size is not greater than 32 then pick up the entire memory | ||
sample_transitions['cur_states'] = torch.stack(self.cur_states) | ||
sample_transitions['actions'] = torch.stack(self.actions) | ||
sample_transitions['next_states'] = torch.stack(self.next_states) | ||
sample_transitions['rewards'] = torch.Tensor(self.rewards) | ||
sample_transitions['dones'] = torch.Tensor(self.dones) | ||
|
||
return sample_transitions |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
|
||
import torch.nn as nn | ||
import torch | ||
|
||
class Tester(nn.Module): | ||
def __init__(self): | ||
super(Tester, self).__init__() | ||
|
||
self.linear = nn.Linear(5,5) | ||
self.dropout = nn.Dropout(p=0.5) | ||
|
||
def forward(self,input): | ||
|
||
output = self.linear(input) | ||
print(self.dropout(output)) | ||
return output | ||
|
||
test = Tester() | ||
input = torch.rand(1,5) | ||
|
||
|
||
test.forward(input) |
Oops, something went wrong.