Can't compile the student's code. RuntimeError

When I submit the assignment, I get the following error and I can’t pass the assignment although I solved all the questions correctly.

Cell #7. Can’t compile the student’s code. Error: RuntimeError(“Expected object of scalar type Long but got scalar type Float for sequence element 1 in sequence argument at position #1 ‘tensors’”).

5 Likes

Hi Abdullah!
Hope you are doing well. Can you be more specific about the assignment number? (4A or 4B -Conditional GAN or Controllable GAN) and if possible send me your notebook through a Private message so that I can point out specifically where the issue is.
Regards,
Nithin

1 Like

Hi Nithin,
I already solved the problem yesterday.
Thanks for your interest :heart::handshake:t4:

1 Like

May I ask how you solve the problem? I also got the same error in the assignment.

1 Like

I just replaced the test-check code cell #7 with another one (I searched for another solved assignment online), although it was look like it, I found the problem was solved and I can’t know how !!!

try this one below:

combined = combine_vectors(torch.tensor([[1, 2], [3, 4]]), torch.tensor([[5, 6], [7, 8]]));
assert torch.all(combined == torch.tensor([[1, 2, 5, 6], [3, 4, 7, 8]]))
assert (type(combined[0][0].item()) == float)
combined = combine_vectors(torch.randn(1, 4, 5), torch.randn(1, 8, 5));
assert tuple(combined.shape) == (1, 12, 5)
assert tuple(combine_vectors(torch.randn(1, 10, 12).long(), torch.randn(1, 20, 12).long()).shape) == (1, 30, 12)
print(“Success!”)

2 Likes

I still have the same issue, and this is the code I used to convert data type to float, is this the way you used to convert the data type?

image

Comparing to the code you sent with the unit test in the assignment, only the gpu code is deleted.

1 Like

I think this is another case in which the torch version that the grader is using is less permissive than the one in the notebook. It looks like the grader’s version of torch.cat can’t handle different types. I wrote that code like this and it passes the grader:

combined = torch.cat((x.float(), y.float()), dim = 1)

The point is that I do the conversion to float before the cat, of course.

17 Likes

I see, thanks Paul!!

1 Like

This regarding 4A assignment

1 Like

I still have the same issue, I have tried all the above mentioned solutions.

1 Like

Do all the tests pass in the notebook? Please show us the actual output you get from the grader, as was done in the initial post on this thread.

1 Like


Cell #UNQ_C4. Can’t compile the student’s code. Error: RuntimeError(“Expected object of scalar type Float but got scalar type Long for sequence element 1 in sequence argument at position #1 ‘tensors’”,)

1 Like

I’ll need to look at your source code. Please see your DMs for a message from me about how to proceed.

1 Like

The problem is that your combine_vectors code is correct and agrees with the solution above, but that doesn’t help if you don’t actually call it. You are directly doing torch.cat instead of calling combine_vectors.

3 Likes

i used this code but not complie error shows
ell #UNQ_C4. Can’t compile the student’s code. Error: RuntimeError(“Expected object of scalar type Float but got scalar type Long for sequence element 1 in sequence argument at position #1 ‘tensors’”,)

1 Like

Are you sure you used that code everywhere? There should be only one call to torch.cat in the whole notebook and that is within the scope of the combine_vectors function. If you directly call torch.cat elsewhere, that is a mistake. Well, you can make it work by fixing the same issue everywhere, but you’re working harder than you need to.

2 Likes

Worked for me! Thanks!

1 Like

I run to the same issue. The problem is that the cell output is kind of misleading. I have got the “Congratulations …” message, network trained and worked. But the grader shows the error because of my wrong approach to torch.cat usage. The key to solution was here in the discussion, there should be only one usage of torch.cat in the notebook.

1 Like

Can you help me too, please?
I have the same error, I’ve already tried everything that’s posted here

1 Like

Are you sure that you are calling combine_vectors everywhere, instead of manually re-implementing it in some places? You have fix the logic in combine_vectors and then make sure you are actually calling it everywhere it is needed. There should be no other occurrences of torch.cat in your notebook.

1 Like