`FaissIndex` to support multiple GPU and `custom_index`
MEMBER
Hi @rentruewang, thansk for reporting and for your PR!!! We should definitely support this. 
2022-02-15T09:21:50Z
https://github.com/huggingface/datasets/issues/3716#issuecomment-1040041071
https://api.github.com/repos/huggingface/datasets/issues/3716
IC_kwDODunzps49_cRv
https://api.github.com/repos/huggingface/datasets/issues/comments/1040041071/reactions
2022-02-15T09:21:50Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1040041071
https://avatars.githubusercontent.com/u/8515462?v=4
https://api.github.com/users/albertvillanova/events{/privacy}
https://api.github.com/users/albertvillanova/followers
https://api.github.com/users/albertvillanova/following{/other_user}
https://api.github.com/users/albertvillanova/gists{/gist_id}
https://github.com/albertvillanova
albertvillanova
MDQ6VXNlcjg1MTU0NjI=
https://api.github.com/users/albertvillanova/orgs
https://api.github.com/users/albertvillanova/received_events
https://api.github.com/users/albertvillanova/repos
https://api.github.com/users/albertvillanova/starred{/owner}{/repo}
https://api.github.com/users/albertvillanova/subscriptions
User
https://api.github.com/users/albertvillanova
public
CONTRIBUTOR
@albertvillanova Great! :)
2022-02-15T10:32:01Z
https://github.com/huggingface/datasets/issues/3716#issuecomment-1040109627
https://api.github.com/repos/huggingface/datasets/issues/3716
IC_kwDODunzps49_tA7
https://api.github.com/repos/huggingface/datasets/issues/comments/1040109627/reactions
2022-02-15T10:32:01Z
https://api.github.com/repos/huggingface/datasets/issues/comments/1040109627
https://avatars.githubusercontent.com/u/32859905?v=4
https://api.github.com/users/rentruewang/events{/privacy}
https://api.github.com/users/rentruewang/followers
https://api.github.com/users/rentruewang/following{/other_user}
https://api.github.com/users/rentruewang/gists{/gist_id}
https://github.com/rentruewang
rentruewang
MDQ6VXNlcjMyODU5OTA1
https://api.github.com/users/rentruewang/orgs
https://api.github.com/users/rentruewang/received_events
https://api.github.com/users/rentruewang/repos
https://api.github.com/users/rentruewang/starred{/owner}{/repo}
https://api.github.com/users/rentruewang/subscriptions
User
https://api.github.com/users/rentruewang
public
**Is your feature request related to a problem? Please describe.**
Currently, because `device` is of the type `int | None`, to leverage `faiss-gpu`'s multi-gpu support, you need to create a `custom_index`. However, if using a `custom_index` created by e.g. `faiss.index_cpu_to_all_gpus`, then `FaissIndex.save` does not work properly because it checks the device id (which is an int, so no multiple GPUs).

**Describe the solution you'd like**
I would like `FaissIndex` to support multiple GPUs, by passing in a list to `add_faiss_index`.

**Describe alternatives you've considered**
Alternatively, I would like it to at least provide a warning cause it wasn't the behavior that I expected.

**Additional context**
Relavent source code here:
 https://github.com/huggingface/datasets/blob/6ed6ac9448311930557810383d2cfd4fe6aae269/src/datasets/search.py#L340-L349

Device management needs changing to support multiple GPUs, probably by `isinstance` calls.

I can provide a PR if you like :)

Thanks for reading!
