Pytorch Not implement Error when running Training

Hey all,

I am doing some stuff for uni, I have to build a basic neural net based of the dataset provided to us which is a series of opcodes and the net has to determine which is malware and which is clean based on a predefined tag.

There I am getting is when I run the code to start the train net I get a not implmeneted error. from googling most people reckon that it is an indenting issue but I have typed and retpyed it to check for this and I am still getting the error.

model.train() 
for data in dataset_train:
    optimizer.zero_grad()
    output = model(data)
    loss = criterion(output)
    loss.backward()
    optimizer.step()
    train_loss += loss.item() * data.size(0)

model.eval() 
for data in dataset_test:
    output = model(data)
    loss = criterion(output, data)
    valid_loss += loss.item() * data.size(0)

train_loss = train_loss / len(train_loader.sampler)
valid_loss = valid_loss / len(valid_loader.sampler)

print('Epoch: {} \tTraining Loss: {:.6f} \tValidation Loss: {:.6f}'.format(
    epoch + 1,
    train_loss,
))

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-32-302975be982c> in <module>
      2 for data in sampleset:
      3     optimizer.zero_grad()
----> 4     output = model(data)
      5     loss = criterion(output)
      6     loss.backward()

D:\Anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)
    725             result = self._slow_forward(*input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),

D:\Anaconda3\lib\site-packages\torch\nn\modules\module.py in _forward_unimplemented(self, *input)
    173         registered hooks while the latter silently ignores them.
    174     """
--> 175     raise NotImplementedError
    176 
    177 

NotImplementedError: 

As I said I have a feeling that maybe I have not imported the data correctly, the code to pull in the opcodes into a list is done for us already we just have to prep it for the neural net. I done that use the code below.

sampleset = []
sampleset.extend(malware)
sampleset.extend(clean)

sampleset = torch.LongTensor(sampleset)

dataset_train = torch.utils.data.DataLoader(sampleset, batch_size=1000, shuffle=True)
dataset_test = torch.utils.data.DataLoader(sampleset, batch_size=500, shuffle=True)

Any advice or pointers would be appreciated

If the indentation is correct, make sure the spelling is also right as others were also running into it by typing e.g. forwrad instead of forward.

I have went through and I cant see anything that is misspelt though I could be being blind
here is the forward function in case there is something wrong in there

Could you post the code by wrapping it into three backticks ```, please?
In your current cell it seems that def forward doesn’t have any indentation level and is thus a global method.

AH yeah I was being stupid. going to chalk it down to not being used to Jupyter notebook… I had the net defined in the box above so when I put the forward function in the next box it wasn’t indented and I just started reading them as two separate functions!

error 406 replace user

Cheers for the help :slight_smile: