Make select_device() robust to batch_size=-1
#5940
Merged
select_device() robust to batch_size=-1
#5940