Batch Processing in NengoDL with Different Inputs

Hello folks,

I was trying to do GPU computation on Nengo and read this article on simulating Nengo models using NengoDL: https://www.nengo.ai/nengo-dl/examples/from-nengo.html#Batch-processing

I had a doubt regarding Batch Processing - if my model takes different input for different simulations, how do I apply batch processing on it?

Here is a snippet of my code:

def simulate (n):
    x_in = nengo.Node(x_input[n])
    x = nengo.Ensemble(...)
    .......
    with nengo_dl.Simulator(model) as sim:
        sim.run(0.5)

In this code, x_input is a collection of vectors, and I am calling the simulate function with n as a parameter, in order to pass different value of x_input[n] at each call. How can I do this in batches instead?

TIA !

Hi @RohanAj!

For batch inputs, you can specify different inputs for each batch run using the data function parameter for the sim.run() function, as shown in this section of the batch processing example.

In the case of your code, you’ll want to do something like this:

with nengo_dl.Simulator(model, minibatch_size=reps) as sim:
    sim.run(
        0.5, 
        data={
            x_in=[DATA]
        }
    )

Hey @xchoo!

Thanks for the response.

I ran the code, but I got the following error:

ValidationError: node data: should have rank 3 (batch_size, n_steps, dimensions), found rank 2

For reference, my Data (x_input) is a collection of vectors of shape (256)

Hi @RohanAj,

Apologies for the confusion, the code above was meant to be pseudo-ish code because I didn’t know how your data was being formatted ([DATA] was meant to be a placeholder for your data).

Since your data is a vector of 256D, you’ll need to amalgamate the data for all of your batch runs into one matrix that is batch_size x n_steps x dimensions in size, where:

  • batch_size is the number of different batches you want to run the code with
  • n_steps is the number of steps the simulation is running for. This is computed as sim_runtime / sim.dt. For your example, you are running it for 0.5s and the sim dt is 0.001s by default, so n_steps = 500.
  • dimensions is the dimensionality of your data, which is in this case is 256.

Hi @xchoo,

Thanks a lot for the help! My computational speed increased tenfold :slight_smile:

That’s great to hear! :smiley: