I'm writing code for a Deep Q Network in python. My computer has 32GB of memory but I run into significant issues as the training goes on because the replay buffer maxes out the RAM.
I'm looking through the replay buffer code to see where I can reduce the RAM requirements. The replay buffer stores two Numpy arrays of 1 million elements with a dtype of numpy.int8.
However, only values 0, 1, 2, 3 are possible in one of the arrays, and only -1, 0, 1 in the other. Either way, it should only need 2 bits to represent each array element.
How can I create an array, where each entry takes up only 2 bits of memory as opposed to 8? I don't mind doing some degree of hardcoding, for example something like:
if bitarray[i][0] == 0 and bitarray[i][1] == 0:
numberAtPositionI = -1
Since your actions take only 2 bits you can encode 4 actions in 8 bits.
This will save memory at the expense of more computation effort to encode/decode the actions.
Eg:
Now you can map this 4 values to any arbitrary 4 values you need using a dictionary
So you can retrieve the mapping by doing: