While this is an ugly hack, and isn’t guaranteed to work, it might be quite efficient.
try:
    a in c
    do stuff assuming a is in c
except RuntimeError:
    do stuff assuming a is not in c

Besides isn’t it a bug that pytorch throws an error only when a is not in c?