# Splade Encoder GPU Support

**URL:** <https://community.pinecone.io/t/splade-encoder-gpu-support/3197>\
**Category:** Support\
**Created:** [September 14, 2023, 9:59am UTC](https://community.pinecone.io/t/splade-encoder-gpu-support/3197 "2023-09-14T09:59:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashleychan](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@ashleychan](https://community.pinecone.io/u/ashleychan)\
**Post date:** [September 14, 2023, 9:59am UTC](https://community.pinecone.io/t/splade-encoder-gpu-support/3197/1 "2023-09-14T09:59:34Z")

</div>

I am using the pinecone-text library for generating sparse vectors [GitHub - pinecone-io/pinecone-text: Pinecone text client library](https://github.com/pinecone-io/pinecone-text/tree/main)

However generating the sparse vectors via Splade is taking a very long time and i think it is not utilizing the GPU. Has anyone tried to use a GPU for this?

---

<div class="post-metadata">

**Author:** ![Amnon](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/amnon/32/842_2.png) [@Amnon](https://community.pinecone.io/u/Amnon)\
**Post date:** [September 14, 2023, 1:02pm UTC](https://community.pinecone.io/t/splade-encoder-gpu-support/3197/2 "2023-09-14T13:02:50Z")

</div>

Hi @ashleychan,  
To leverage GPU you can simply init the SpladeEncoder as follow:

```auto
splade = SpladeEncoder(device="cuda")

```

or you can dynamically infer if cuda is available by:

```auto
import torch

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
splade = SpladeEncoder(device=device)

```

I’ll add it to the repo README so it will be clearer.

Thanks,  
Amnon

---

<div class="post-metadata">

**Author:** ![ashleychan](https://avatars.discourse-cdn.com/v4/letter/a/6a8cbe/32.png) [@ashleychan](https://community.pinecone.io/u/ashleychan)\
**Post date:** [September 19, 2023, 9:32am UTC](https://community.pinecone.io/t/splade-encoder-gpu-support/3197/3 "2023-09-19T09:32:30Z")

</div>

Thanks I also found out the solution prior to your reply and closed the issue on the repository.

Does this also apply to the BM25Encoder() ? Is there a way to initialize it with GPU or to make the bm25.fit() faster?

---

<div class="post-metadata">

**Author:** ![Amnon](https://sea2.discourse-cdn.com/flex020/user_avatar/community.pinecone.io/amnon/32/842_2.png) [@Amnon](https://community.pinecone.io/u/Amnon)\
**Post date:** [October 23, 2023, 12:22pm UTC](https://community.pinecone.io/t/splade-encoder-gpu-support/3197/4 "2023-10-23T12:22:43Z")

</div>

Unfortunately currently BM25 encoder have no optimizations. The result json is a simple DF count (a dictionary mapping between a token to the number of tokens it appears in) so theoretically you can parallelize multiple fit calls on distinct shards of your training data and then simply merge the outputs.
