bapi:

if local_rank in g0:


I am not sure if you acquired g0 and g1 from new_group API. If so, they are process group objects. So the above check would result in the following error:
TypeError: argument of type 'object' is not iterable