Simulated Device vs Real OPU memory consumption

Hello,

I have a small question regarding SimulatedDevice.

I’m trying to replicate your transfer learning notebook but on a language model using bert. However, when running the code on my laptop the memory consumption is huge causing the script to crash ( 16GB RAM + 32GB swap)

Specifically

opu_mapping = OPUMap(n_components=n_components, simulated=True, max_n_features=25088)

will eventually lead to this being executed in simulated_device.py line 69-70 & then crashing.

real_comp = rng.normal(loc=0.0, scale=std, size=matrix_shape).astype(np.float32)
imag_comp = rng.normal(loc=0.0, scale=std, size=matrix_shape).astype(np.float32)

I tried running the same thing on the actual OPU but it didn’t consume much memory.

I was wondering how you try to simulate the OPU & why does it require that much memory, I would be more than happy if you can give me keywords or papers to do some research on if the answer is too complex to explain here.

Thank you

1 Like

Hi Wassim,

The simulation generates two float32 matrices of size (n_features, n_components), that represent the random matrix behaving like an OPU. Memory errors come from a too large number of components. You can overcome this by reducing it.

Our computes have 128 GB of memory, so even if number of components is the same on your laptop, you might have fragmentation issues. However memory occupation shouldn’t be different, can you post details on this in order to troubleshoot?

1 Like

Hello,

I remember that the consumption on the actual OPU was around 2 - 3 GB. However on my machine theoretically it went up to 40GB then it crashed. I will double-check this when i book the OPU again but I’m quite certain that was the situation. I will also need to double check what was the max_n_features on the OPU since I didn’t hardcode it there

To reproduce this I just ran the transfer learning notebook you provided.

1 Like

Hi Wassim,

Actually the simulated OPU takes a lot more memory than the real OPU, because the latter already has the matrix in analog (which is the core advantage of being an optical computing technology :sunglasses: ). Anytime you use a simulated OPU, you need to lower n_components in order not to run out of memory.

2 Likes