nvmlDeviceGetMigDeviceHandleByIndex return wrong MIG devices when some MIG devices deleted

My suggestion would be to file a bug. Be advised that if you do so, you will probably be asked for the complete code for your utility, as well as the full set/list of shell commands and nvidia-smi commands that you followed.