It seems that you cannot do that on a cuda tensor; should move it to cpu before apply_:
val_if_not_shown = 0  # 0 can be any other number within dtype range
y.cpu().apply_(lambda val: d.get(val, val_if_not_shown)).to(y.device)
# in case that some of the values in `y` don't exist in `d.keys()`

Beware that it is an inplace operation.