Fastai not running on the GPU

Hi! I am relatively new to fastai and working on creating a language model on genomic data. I am adapting the code from 12_nlp for my project and noticed that it isn’t running on the GPU (nvidia-smi > no running processes found). If I run the code from 10_nlp, PID on the GPU and GPU Mem Usage @ 12Gb).

Torch:1.7
Cuda: 10.2

I thought it might be related to large bs, however reducing from bs=400 to bs=16 did not help.

Appreciate any thoughts/suggestions! :slight_smile:

stoi = defaultdict(int, {v:k for k,v in enumerate(vocab)})
nums = L(stoi[i] for i in tokens)

def group_chunks(ds, bs):
    m = len(ds) // bs
    new_ds = L()
    for i in range(m): new_ds += L(ds[i + m*j] for j in range(bs))

    return new_ds

bs = 256
sl = 50

seq = L((tensor(nums[i:i+sl]), tensor(nums[i+1:i+sl+1])) for i in range(0, len(nums)-sl-1, sl))
seq[2]

cut = int(len(seq) * 0.8)
dls = DataLoaders.from_dsets(group_chunks(seq[:cut], bs),
                             group_chunks(seq[cut:], bs),
                             bs=bs, drop_last=True, shuffle=False)

def get_lm_model(data,stoi):
    vocab_sz = len(stoi)
    
    encoder = AWD_LSTM(vocab_sz, 300, 400, 3, hidden_p=0.2, pad_token=0,
                             input_p=0.5, embed_p=0.1, weight_p=0.4)
    enc = encoder.encoder
    decoder = LinearDecoder(vocab_sz, 300, output_p=0.1, tie_encoder=enc, bias=True)
    model = SequentialRNN(encoder, decoder)
    
    learn = LMLearner(data, model, metrics=accuracy, loss_func=CrossEntropyLossFlat()) #.to_fp16()
    
    return learn

learn = get_lm_model(dls, stoi)
learn.lr_find()

noob :frowning: added

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print('Using device:', device)


cut = int(len(seq) * 0.8)
dls = DataLoaders.from_dsets(group_chunks(seq[:cut], bs),
                             group_chunks(seq[cut:], bs),
                             bs=bs, device=device, drop_last=True, shuffle=False)

Runs on the GPU :smiley: