mirror of
https://github.com/nomic-ai/gpt4all
synced 2024-11-08 07:10:32 +00:00
Fix destruction and tear down of the embedding thread. (#2328)
* Fix destruction and tear down of the embedding thread. Signed-off-by: Adam Treat <treat.adam@gmail.com> * Fix order of deletion to prevent use after free. Signed-off-by: Adam Treat <treat.adam@gmail.com> --------- Signed-off-by: Adam Treat <treat.adam@gmail.com>
This commit is contained in:
parent
1427ef7195
commit
61cefcfd8a
@ -552,6 +552,7 @@ Database::~Database()
|
||||
{
|
||||
m_dbThread.quit();
|
||||
m_dbThread.wait();
|
||||
delete m_embLLM;
|
||||
}
|
||||
|
||||
void Database::scheduleNext(int folder_id, size_t countForFolder)
|
||||
|
@ -5,6 +5,7 @@ EmbeddingLLMWorker::EmbeddingLLMWorker()
|
||||
: QObject(nullptr)
|
||||
, m_networkManager(new QNetworkAccessManager(this))
|
||||
, m_model(nullptr)
|
||||
, m_stopGenerating(false)
|
||||
{
|
||||
moveToThread(&m_workerThread);
|
||||
connect(this, &EmbeddingLLMWorker::finished, &m_workerThread, &QThread::quit, Qt::DirectConnection);
|
||||
@ -14,6 +15,10 @@ EmbeddingLLMWorker::EmbeddingLLMWorker()
|
||||
|
||||
EmbeddingLLMWorker::~EmbeddingLLMWorker()
|
||||
{
|
||||
m_stopGenerating = true;
|
||||
m_workerThread.quit();
|
||||
m_workerThread.wait();
|
||||
|
||||
if (m_model) {
|
||||
delete m_model;
|
||||
m_model = nullptr;
|
||||
@ -148,6 +153,9 @@ void EmbeddingLLMWorker::requestSyncEmbedding(const QString &text)
|
||||
// this function is always called for storage into the database
|
||||
void EmbeddingLLMWorker::requestAsyncEmbedding(const QVector<EmbeddingChunk> &chunks)
|
||||
{
|
||||
if (m_stopGenerating)
|
||||
return;
|
||||
|
||||
if (!hasModel() && !loadModel()) {
|
||||
qWarning() << "WARNING: Could not load model for embeddings";
|
||||
return;
|
||||
|
@ -58,6 +58,7 @@ private:
|
||||
QNetworkAccessManager *m_networkManager;
|
||||
std::vector<float> m_lastResponse;
|
||||
LLModel *m_model = nullptr;
|
||||
std::atomic<bool> m_stopGenerating;
|
||||
QThread m_workerThread;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user