Skip to content

Commit 1fa67a5

Browse files
committed
Report the actual device we're using.
1 parent cf4eb53 commit 1fa67a5

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

gpt4all-chat/chat.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ void Chat::connectLLM()
5656
connect(m_llmodel, &ChatLLM::recalcChanged, this, &Chat::handleRecalculating, Qt::QueuedConnection);
5757
connect(m_llmodel, &ChatLLM::generatedNameChanged, this, &Chat::generatedNameChanged, Qt::QueuedConnection);
5858
connect(m_llmodel, &ChatLLM::reportSpeed, this, &Chat::handleTokenSpeedChanged, Qt::QueuedConnection);
59+
connect(m_llmodel, &ChatLLM::reportDevice, this, &Chat::handleDeviceChanged, Qt::QueuedConnection);
5960
connect(m_llmodel, &ChatLLM::databaseResultsChanged, this, &Chat::handleDatabaseResultsChanged, Qt::QueuedConnection);
6061
connect(m_llmodel, &ChatLLM::modelInfoChanged, this, &Chat::handleModelInfoChanged, Qt::QueuedConnection);
6162

@@ -345,6 +346,12 @@ void Chat::handleTokenSpeedChanged(const QString &tokenSpeed)
345346
emit tokenSpeedChanged();
346347
}
347348

349+
void Chat::handleDeviceChanged(const QString &device)
350+
{
351+
m_device = device;
352+
emit deviceChanged();
353+
}
354+
348355
void Chat::handleDatabaseResultsChanged(const QList<ResultInfo> &results)
349356
{
350357
m_databaseResults = results;

gpt4all-chat/chat.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Chat : public QObject
2525
Q_PROPERTY(QList<QString> collectionList READ collectionList NOTIFY collectionListChanged)
2626
Q_PROPERTY(QString modelLoadingError READ modelLoadingError NOTIFY modelLoadingErrorChanged)
2727
Q_PROPERTY(QString tokenSpeed READ tokenSpeed NOTIFY tokenSpeedChanged);
28+
Q_PROPERTY(QString device READ device NOTIFY deviceChanged);
2829
QML_ELEMENT
2930
QML_UNCREATABLE("Only creatable from c++!")
3031

@@ -88,6 +89,7 @@ class Chat : public QObject
8889
QString modelLoadingError() const { return m_modelLoadingError; }
8990

9091
QString tokenSpeed() const { return m_tokenSpeed; }
92+
QString device() const { return m_device; }
9193

9294
public Q_SLOTS:
9395
void serverNewPromptResponsePair(const QString &prompt);
@@ -115,6 +117,7 @@ public Q_SLOTS:
115117
void isServerChanged();
116118
void collectionListChanged(const QList<QString> &collectionList);
117119
void tokenSpeedChanged();
120+
void deviceChanged();
118121

119122
private Q_SLOTS:
120123
void handleResponseChanged(const QString &response);
@@ -125,6 +128,7 @@ private Q_SLOTS:
125128
void handleRecalculating();
126129
void handleModelLoadingError(const QString &error);
127130
void handleTokenSpeedChanged(const QString &tokenSpeed);
131+
void handleDeviceChanged(const QString &device);
128132
void handleDatabaseResultsChanged(const QList<ResultInfo> &results);
129133
void handleModelInfoChanged(const ModelInfo &modelInfo);
130134
void handleModelInstalled();
@@ -137,6 +141,7 @@ private Q_SLOTS:
137141
ModelInfo m_modelInfo;
138142
QString m_modelLoadingError;
139143
QString m_tokenSpeed;
144+
QString m_device;
140145
QString m_response;
141146
QList<QString> m_collections;
142147
ChatModel *m_chatModel;

gpt4all-chat/chatllm.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,22 +271,28 @@ bool ChatLLM::loadModel(const ModelInfo &modelInfo)
271271
MySettings::globalInstance()->setDeviceList(deviceList);
272272

273273
// Pick the best match for the device
274+
QString actualDevice = m_llModelInfo.model->implementation().buildVariant() == "metal" ? "Metal" : "CPU";
274275
const QString requestedDevice = MySettings::globalInstance()->device();
275276
if (requestedDevice != "CPU") {
276277
const size_t requiredMemory = m_llModelInfo.model->requiredMem(filePath.toStdString());
277278
std::vector<LLModel::GPUDevice> availableDevices = m_llModelInfo.model->availableGPUDevices(requiredMemory);
278279
if (!availableDevices.empty() && requestedDevice == "Auto" && availableDevices.front().type == 2 /*a discrete gpu*/) {
279280
m_llModelInfo.model->initializeGPUDevice(availableDevices.front());
281+
actualDevice = QString::fromStdString(availableDevices.front().name);
280282
} else {
281283
for (LLModel::GPUDevice &d : availableDevices) {
282284
if (QString::fromStdString(d.name) == requestedDevice) {
283285
m_llModelInfo.model->initializeGPUDevice(d);
286+
actualDevice = QString::fromStdString(d.name);
284287
break;
285288
}
286289
}
287290
}
288291
}
289292

293+
// Report which device we're actually using
294+
emit reportDevice(actualDevice);
295+
290296
bool success = m_llModelInfo.model->loadModel(filePath.toStdString());
291297
MySettings::globalInstance()->setAttemptModelLoad(QString());
292298
if (!success) {

gpt4all-chat/chatllm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public Q_SLOTS:
129129
void shouldBeLoadedChanged();
130130
void requestRetrieveFromDB(const QList<QString> &collections, const QString &text, int retrievalSize, QList<ResultInfo> *results);
131131
void reportSpeed(const QString &speed);
132+
void reportDevice(const QString &device);
132133
void databaseResultsChanged(const QList<ResultInfo>&);
133134
void modelInfoChanged(const ModelInfo &modelInfo);
134135

gpt4all-chat/main.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ Window {
10131013
anchors.rightMargin: 30
10141014
color: theme.mutedTextColor
10151015
visible: currentChat.tokenSpeed !== ""
1016-
text: qsTr("Speed: ") + currentChat.tokenSpeed + "<br>" + qsTr("Device: ") + MySettings.device
1016+
text: qsTr("Speed: ") + currentChat.tokenSpeed + "<br>" + qsTr("Device: ") + currentChat.device
10171017
font.pixelSize: theme.fontSizeLarge
10181018
}
10191019

0 commit comments

Comments
 (0)