Loss function with targets of type list of list of tensors

Hello, everyone. I am new to fastAI, sorry for the silly question.
I am trying to use lr_find with my network model. My loss function receives, as targets, a list of list of tensor. Unfortunately I am geting this error message:

File “trainFastai.py”, line 38, in
File “trainFastai.py”, line 32, in main
fastai.train.lr_find(learner, start_lr=0.00001, end_lr=1.0, num_it=len(trainDataset)*10)
File “/usr/local/lib/python3.6/dist-packages/fastai/train.py”, line 41, in lr_find
learn.fit(epochs, start_lr, callbacks=[cb], wd=wd)
File “/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py”, line 200, in fit
fit(epochs, self, metrics=self.metrics, callbacks=self.callbacks+callbacks)
File “/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py”, line 101, in fit
loss = loss_batch(learn.model, xb, yb, learn.loss_func, learn.opt, cb_handler)
File “/usr/local/lib/python3.6/dist-packages/fastai/basic_train.py”, line 30, in loss_batch
loss = loss_func(out, *yb)
File “/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py”, line 493, in call
result = self.forward(*input, **kwargs)
TypeError: forward() takes 3 positional arguments but 12 were given

I think that Learner is unpacking the target lists. How should I work around this problem?

You should define your loss function to get that list unpacked. If it’s always the same size, you can name the arguments, if not, you can use a star:

def my_loss_func(out, *targets):

and targets will be a list.

Thanks for your reply @sgugger!
Using the star worked. Can you explain why I need this star?
Thanks again!

That’s just python syntax: *args means any number of arguments.