Using the reduce argument for nn.NLLLoss

I’m trying to use sample weights for the NLLLoss (similar to Keras’s weight argument). I thought I could do:

loss_function = nn.NLLLoss(reduce=False)

But I’m getting the error:

TypeError: init() got an unexpected keyword argument ‘reduce’

I was assuming this is because my pytorch version (torch 0.2.0.post4) didn’t have this option incorporated yet.
So I tried installing installing from master, but I’m getting the error:

CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  CMake 3.0 or higher is required.  You are running version 2.8.12.2


-- Configuring incomplete, errors occurred!

----------------------------------------
Rolling back uninstall of torch
Command "/home/nhartman/miniconda3/envs/rafaelEnv/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-xl7r5mzy-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-ewkrv8v7-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-xl7r5mzy-build/

My questions are:

(1) Do I actually need to reinstall pytorch from the source, or am I just not understanding how the NLLLoss() function works?
(2) If I need to install the new version for this functionality, can I do so without upgrading make (b/c I don’t have “sudo” privileges on this machine).

Thanks in advance!

1 Like
  1. Yes, the NLLLoss reduce keyword isn’t present in pytorch 0.2, so you’d have to install from source or wait for the next release.
  2. https://anaconda.org/anaconda/cmake <- If you have conda, you can try installing that via conda install cmake. I’m not 100% sure it’ll work.
2 Likes

conda install cmake

works for me, thanks a lot