codalab / worksheets-examples

Examples and tutorials for CodaLab Worksheets.
38 stars 19 forks source link

errors running 01-nli tutorial #3

Closed heeryoncho closed 5 years ago

heeryoncho commented 5 years ago

When I ran the NLI tutorial (01-nli), I experienced the following two errors:

  1. ValueError: some of the strides of a given numpy array are negative.
  2. TypeError: can’t convert CUDA tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

[Solution 1] I modified the models.py code.

    # Sort by length (keep idx)
    sent_len_sorted, idx_sort = np.sort(sent_len)[::-1], np.argsort(-sent_len)
    sent_len_sorted = sent_len_sorted.copy()   ### Inserted this line.
    idx_unsort = np.argsort(idx_sort)

[Solution 2] I modified the train_nli.py

    ### initially it was total_norm = np.sqrt(total_norm)
    total_norm = np.sqrt(total_norm.cpu())   ### Inserted .cpu()

If anyone is experiencing the same error when trying out the NLI tutorial, the above fix might just work.

percyliang commented 5 years ago

Thanks for pointing out the fixes. Updated the repo with these fixes and it seems to work now.