Hello, I was trying to run GUI for a sentence-transformers model using streamlit, however streamlit does not seem to use my GPU locally as it gives me the following message: Use pytorch device: cpu. When not using streamlit I can use GPU properly can anyone help me with this?y
tagging @randyzwitch because I saw you replying to similar questions earlier
I tried to run pytorch gpu with streamlit locally. It works fine.
streamlit==1.20.0
torch==1.13.1+cu116
import torch
import streamlit as st
st.write(f'**cuda is available:** {torch.cuda.is_available()}')
st.subheader('tensor')
x = torch.randint(1, 100, (100, 100))
st.dataframe(x)
x = x.to(torch.device('cuda'))
res_gpu = x ** 2
st.subheader('gpu result operation')
st.write(res_gpu)
Hey @ferdy thanks for your response, so, this problem does not arise when I am using torch specifically, but does when I use sentence-transformers. Have changed the question accordingly
I tried it with sentence-transformer and it worked just fine.
from sentence_transformers import SentenceTransformer
import streamlit as st
model = SentenceTransformer('all-MiniLM-L6-v2', device='cuda')
#Our sentences we like to encode
sentences = ['The quick brown fox jumps over the lazy dog.']
if st.button('run'):
#Sentences are encoded by calling model.encode()
sentence_embeddings = model.encode(sentences)
#Print the embeddings
for sentence, embedding in zip(sentences, sentence_embeddings):
st.write("Sentence:", sentence)
st.dataframe(embedding.tolist(), use_container_width=True, height=300)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.