I tried  to modify my model function with a .clone() at the line you suggested, but with no change:
def kmodel(p,t,Cp,device=0):
    torch.autograd.set_detect_anomaly(True)
    Nv = p.shape[0]
    Nt = t.shape[1]
    
    ton = p[:,0].view(Nv,1).int()
    vp  = p[:,1].view(Nv,1).to(device)
    
    for i in range(Nv):
        Cp[i,ton[i]:] = Cp[i,:Nt-ton[i]].clone()  # <==========
        Cp[i,:ton[i]] = 0

    out = vp*Cp
    return out

But even if I run the code with device='cpu', I don’t get that warning/error …