Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double free or corruption (fasttop) #450

Closed
AnBowell opened this issue Mar 22, 2024 · 1 comment
Closed

Double free or corruption (fasttop) #450

AnBowell opened this issue Mar 22, 2024 · 1 comment

Comments

@AnBowell
Copy link

AnBowell commented Mar 22, 2024

When attempting to create a multithreaded REST API using Rocket to serve a model, I've run into the following error.

double free or corruption (fasttop)

This is all the error I receive and I presume it's coming from the underlying libtorch library. I've seen other GitHub issues on both this crate and the tch-rs crate talking about how tensors are Send but not Sync, so I wrapped a SentenceEmbeddingsModel in a Mutex on the server start up and then passed it to each method in the API. I assumed this would keep the model safely wrapped, but it doesn't appear so as I get the same error.

I've noticed on the tch-rs crate there was a similar double-free error that was patched a while ago: LaurentMazare/tch-rs#475. I've also reported an issue there.

I understand this may be an issue for the tch-rs crate instead, but hoping there's a more sensible way I can wrap the model up for use across threads? I'm only using the encode method to


struct SbertModel(Arc<Mutex<SentenceEmbeddingsModel>>);
...
let sbert_model = SbertModel(Arc::new(Mutex::new(
    SentenceEmbeddingsBuilder::remote(SentenceEmbeddingsModelType::AllMiniLmL6V2)
        .create_model()
        .unwrap())));
...
let my_model = model.0.lock().await;
let encoding = my_model.encode(&[some_string])?;
drop(my_model); // Have tried both manually dropping and letting it go out of scope.
@AnBowell
Copy link
Author

After some deeper investigations, I've found this is actually originating in a different crate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant