Enable more warning flags, and fix more warnings (#3065)

Signed-off-by: Jared Van Bortel <jared@nomic.ai>
This commit is contained in:
Jared Van Bortel 2024-10-18 12:11:03 -04:00 committed by GitHub
parent eed92fd5b2
commit c3357b7625
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 27 additions and 69 deletions

View File

@ -11,7 +11,6 @@ function(gpt4all_add_warning_options target)
-Wextra-semi -Wextra-semi
-Wformat=2 -Wformat=2
-Wmissing-include-dirs -Wmissing-include-dirs
-Wnull-dereference
-Wstrict-overflow=2 -Wstrict-overflow=2
-Wvla -Wvla
# errors # errors
@ -22,8 +21,6 @@ function(gpt4all_add_warning_options target)
# disabled warnings # disabled warnings
-Wno-sign-compare -Wno-sign-compare
-Wno-unused-parameter -Wno-unused-parameter
-Wno-unused-function
-Wno-unused-variable
) )
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_compile_options("${target}" PRIVATE target_compile_options("${target}" PRIVATE

@ -1 +1 @@
Subproject commit b3b5c0571eda3065035a7f25f7b84640b159d821 Subproject commit 58a55efc4ae5dd3bc12887d47981faa7136027af

View File

@ -213,7 +213,7 @@ public:
protected: protected:
// These are pure virtual because subclasses need to implement as the default implementation of // These are pure virtual because subclasses need to implement as the default implementation of
// 'prompt' above calls these functions // 'prompt' above calls these functions
virtual std::vector<Token> tokenize(PromptContext &ctx, std::string_view str, bool special = false) = 0; virtual std::vector<Token> tokenize(std::string_view str, bool special = false) = 0;
virtual bool isSpecialToken(Token id) const = 0; virtual bool isSpecialToken(Token id) const = 0;
virtual std::string tokenToString(Token id) const = 0; virtual std::string tokenToString(Token id) const = 0;
virtual void initSampler(PromptContext &ctx) = 0; virtual void initSampler(PromptContext &ctx) = 0;

View File

@ -511,7 +511,7 @@ size_t LLamaModel::restoreState(std::span<const uint8_t> src)
return llama_state_set_data(d_ptr->ctx, src.data(), src.size()); return llama_state_set_data(d_ptr->ctx, src.data(), src.size());
} }
std::vector<LLModel::Token> LLamaModel::tokenize(PromptContext &ctx, std::string_view str, bool special) std::vector<LLModel::Token> LLamaModel::tokenize(std::string_view str, bool special)
{ {
bool atStart = m_tokenize_last_token == -1; bool atStart = m_tokenize_last_token == -1;
bool insertSpace = atStart || isSpecialToken(m_tokenize_last_token); bool insertSpace = atStart || isSpecialToken(m_tokenize_last_token);

View File

@ -54,7 +54,7 @@ private:
bool m_supportsCompletion = false; bool m_supportsCompletion = false;
protected: protected:
std::vector<Token> tokenize(PromptContext &ctx, std::string_view str, bool special) override; std::vector<Token> tokenize(std::string_view str, bool special) override;
bool isSpecialToken(Token id) const override; bool isSpecialToken(Token id) const override;
std::string tokenToString(Token id) const override; std::string tokenToString(Token id) const override;
void initSampler(PromptContext &ctx) override; void initSampler(PromptContext &ctx) override;

View File

@ -90,41 +90,33 @@ void LLModel::prompt(const std::string &prompt,
} }
} }
auto old_n_past = promptCtx.n_past; // prepare to fake n_past for tokenize
// tokenize the user prompt // tokenize the user prompt
std::vector<Token> embd_inp; std::vector<Token> embd_inp;
if (placeholders.empty()) { if (placeholders.empty()) {
// this is unusual, but well-defined // this is unusual, but well-defined
std::cerr << __func__ << ": prompt template has no placeholder\n"; std::cerr << __func__ << ": prompt template has no placeholder\n";
embd_inp = tokenize(promptCtx, promptTemplate, true); embd_inp = tokenize(promptTemplate, true);
} else { } else {
// template: beginning of user prompt // template: beginning of user prompt
const auto &phUser = placeholders[0]; const auto &phUser = placeholders[0];
std::string userPrefix(phUser.prefix()); std::string userPrefix(phUser.prefix());
if (!userPrefix.empty()) { if (!userPrefix.empty())
embd_inp = tokenize(promptCtx, userPrefix, true); embd_inp = tokenize(userPrefix, true);
promptCtx.n_past += embd_inp.size();
}
// user input (shouldn't have special token processing) // user input (shouldn't have special token processing)
auto tokens = tokenize(promptCtx, prompt, special); auto tokens = tokenize(prompt, special);
embd_inp.insert(embd_inp.end(), tokens.begin(), tokens.end()); embd_inp.insert(embd_inp.end(), tokens.begin(), tokens.end());
promptCtx.n_past += tokens.size();
// template: end of user prompt + start of assistant prompt // template: end of user prompt + start of assistant prompt
size_t start = phUser.position() + phUser.length(); size_t start = phUser.position() + phUser.length();
size_t end = placeholders.size() >= 2 ? placeholders[1].position() : promptTemplate.length(); size_t end = placeholders.size() >= 2 ? placeholders[1].position() : promptTemplate.length();
auto userToAsst = promptTemplate.substr(start, end - start); auto userToAsst = promptTemplate.substr(start, end - start);
if (!userToAsst.empty()) { if (!userToAsst.empty()) {
tokens = tokenize(promptCtx, userToAsst, true); tokens = tokenize(userToAsst, true);
embd_inp.insert(embd_inp.end(), tokens.begin(), tokens.end()); embd_inp.insert(embd_inp.end(), tokens.begin(), tokens.end());
promptCtx.n_past += tokens.size();
} }
} }
promptCtx.n_past = old_n_past; // restore n_past so decodePrompt can increment it
// decode the user prompt // decode the user prompt
if (!decodePrompt(promptCallback, responseCallback, allowContextShift, promptCtx, embd_inp)) if (!decodePrompt(promptCallback, responseCallback, allowContextShift, promptCtx, embd_inp))
return; // error return; // error
@ -133,7 +125,7 @@ void LLModel::prompt(const std::string &prompt,
if (!fakeReply) { if (!fakeReply) {
generateResponse(responseCallback, allowContextShift, promptCtx); generateResponse(responseCallback, allowContextShift, promptCtx);
} else { } else {
embd_inp = tokenize(promptCtx, *fakeReply, false); embd_inp = tokenize(*fakeReply, false);
if (!decodePrompt(promptCallback, responseCallback, allowContextShift, promptCtx, embd_inp, true)) if (!decodePrompt(promptCallback, responseCallback, allowContextShift, promptCtx, embd_inp, true))
return; // error return; // error
} }
@ -148,7 +140,7 @@ void LLModel::prompt(const std::string &prompt,
asstSuffix = "\n\n"; // default to a blank link, good for e.g. Alpaca asstSuffix = "\n\n"; // default to a blank link, good for e.g. Alpaca
} }
if (!asstSuffix.empty()) { if (!asstSuffix.empty()) {
embd_inp = tokenize(promptCtx, asstSuffix, true); embd_inp = tokenize(asstSuffix, true);
decodePrompt(promptCallback, responseCallback, allowContextShift, promptCtx, embd_inp); decodePrompt(promptCallback, responseCallback, allowContextShift, promptCtx, embd_inp);
} }
} }

@ -1 +1 @@
Subproject commit 1f0618a86f9dbb7386237241cee96cc425dd7b55 Subproject commit 9e59f1036657303b29eaf709945f339e403e5f2f

View File

@ -31,7 +31,7 @@ Chat::Chat(QObject *parent)
connectLLM(); connectLLM();
} }
Chat::Chat(bool isServer, QObject *parent) Chat::Chat(server_tag_t, QObject *parent)
: QObject(parent) : QObject(parent)
, m_id(Network::globalInstance()->generateUniqueId()) , m_id(Network::globalInstance()->generateUniqueId())
, m_name(tr("Server Chat")) , m_name(tr("Server Chat"))

View File

@ -45,6 +45,10 @@ class Chat : public QObject
QML_UNCREATABLE("Only creatable from c++!") QML_UNCREATABLE("Only creatable from c++!")
public: public:
// tag for constructing a server chat
struct server_tag_t { explicit server_tag_t() = default; };
static inline constexpr server_tag_t server_tag = server_tag_t();
enum ResponseState { enum ResponseState {
ResponseStopped, ResponseStopped,
LocalDocsRetrieval, LocalDocsRetrieval,
@ -56,7 +60,7 @@ public:
Q_ENUM(ResponseState) Q_ENUM(ResponseState)
explicit Chat(QObject *parent = nullptr); explicit Chat(QObject *parent = nullptr);
explicit Chat(bool isServer, QObject *parent = nullptr); explicit Chat(server_tag_t, QObject *parent = nullptr);
virtual ~Chat(); virtual ~Chat();
void destroy() { m_llmodel->destroy(); } void destroy() { m_llmodel->destroy(); }
void connectLLM(); void connectLLM();

View File

@ -98,9 +98,8 @@ protected:
// them as they are only called from the default implementation of 'prompt' which we override and // them as they are only called from the default implementation of 'prompt' which we override and
// completely replace // completely replace
std::vector<Token> tokenize(PromptContext &ctx, std::string_view str, bool special) override std::vector<Token> tokenize(std::string_view str, bool special) override
{ {
(void)ctx;
(void)str; (void)str;
(void)special; (void)special;
throw std::logic_error("not implemented"); throw std::logic_error("not implemented");

View File

@ -147,7 +147,7 @@ public:
if (m_serverChat) if (m_serverChat)
return; return;
m_serverChat = new Chat(true /*isServer*/, this); m_serverChat = new Chat(Chat::server_tag, this);
beginInsertRows(QModelIndex(), m_chats.size(), m_chats.size()); beginInsertRows(QModelIndex(), m_chats.size(), m_chats.size());
m_chats.append(m_serverChat); m_chats.append(m_serverChat);
endInsertRows(); endInsertRows();

View File

@ -179,6 +179,8 @@ void ChatLLM::handleForceMetalChanged(bool forceMetal)
reloadModel(); reloadModel();
m_reloadingToChangeVariant = false; m_reloadingToChangeVariant = false;
} }
#else
Q_UNUSED(forceMetal);
#endif #endif
} }

View File

@ -51,7 +51,7 @@ enum class LLModelTypeV1 { // since chat version 6 (v2.5.0)
NONE = -1, // no state NONE = -1, // no state
}; };
static LLModelTypeV1 parseLLModelTypeV1(int type) inline LLModelTypeV1 parseLLModelTypeV1(int type)
{ {
switch (LLModelTypeV1(type)) { switch (LLModelTypeV1(type)) {
case LLModelTypeV1::GPTJ: case LLModelTypeV1::GPTJ:
@ -68,7 +68,7 @@ static LLModelTypeV1 parseLLModelTypeV1(int type)
} }
} }
static LLModelTypeV1 parseLLModelTypeV0(int v0) inline LLModelTypeV1 parseLLModelTypeV0(int v0)
{ {
switch (LLModelTypeV0(v0)) { switch (LLModelTypeV0(v0)) {
case LLModelTypeV0::MPT: return LLModelTypeV1::MPT; case LLModelTypeV0::MPT: return LLModelTypeV1::MPT;

View File

@ -967,8 +967,6 @@ void ChatViewTextProcessor::handleCodeBlocks()
cursor.setPosition(matchesCode[index].capturedEnd(), QTextCursor::KeepAnchor); cursor.setPosition(matchesCode[index].capturedEnd(), QTextCursor::KeepAnchor);
cursor.removeSelectedText(); cursor.removeSelectedText();
int startPos = cursor.position();
QTextFrameFormat frameFormat = frameFormatBase; QTextFrameFormat frameFormat = frameFormatBase;
QString capturedText = matchesCode[index].captured(1); QString capturedText = matchesCode[index].captured(1);
QString codeLanguage; QString codeLanguage;
@ -1004,7 +1002,7 @@ void ChatViewTextProcessor::handleCodeBlocks()
QTextFrame *mainFrame = cursor.currentFrame(); QTextFrame *mainFrame = cursor.currentFrame();
cursor.setCharFormat(textFormat); cursor.setCharFormat(textFormat);
QTextFrame *frame = cursor.insertFrame(frameFormat); cursor.insertFrame(frameFormat);
QTextTable *table = cursor.insertTable(codeLanguage.isEmpty() ? 1 : 2, 1, tableFormat); QTextTable *table = cursor.insertTable(codeLanguage.isEmpty() ? 1 : 2, 1, tableFormat);
if (!codeLanguage.isEmpty()) { if (!codeLanguage.isEmpty()) {
@ -1016,7 +1014,6 @@ void ChatViewTextProcessor::handleCodeBlocks()
headerCursor.insertText(codeLanguage); headerCursor.insertText(codeLanguage);
QTextTableCell copy = headerTable->cellAt(0, 1); QTextTableCell copy = headerTable->cellAt(0, 1);
QTextCursor copyCursor = copy.firstCursorPosition(); QTextCursor copyCursor = copy.firstCursorPosition();
int startPos = copyCursor.position();
CodeCopy newCopy; CodeCopy newCopy;
newCopy.text = lines.join("\n"); newCopy.text = lines.join("\n");
newCopy.startPos = copyCursor.position(); newCopy.startPos = copyCursor.position();

View File

@ -290,7 +290,7 @@ static bool selectCountChunks(QSqlQuery &q, int folder_id, int &count)
return true; return true;
} }
static bool selectChunk(QSqlQuery &q, const QList<int> &chunk_ids, int retrievalSize) static bool selectChunk(QSqlQuery &q, const QList<int> &chunk_ids)
{ {
QString chunk_ids_str = QString::number(chunk_ids[0]); QString chunk_ids_str = QString::number(chunk_ids[0]);
for (size_t i = 1; i < chunk_ids.size(); ++i) for (size_t i = 1; i < chunk_ids.size(); ++i)
@ -307,10 +307,6 @@ static const QString INSERT_COLLECTION_SQL = uR"(
returning id; returning id;
)"_s; )"_s;
static const QString DELETE_COLLECTION_SQL = uR"(
delete from collections where name = ? and folder_id = ?;
)"_s;
static const QString SELECT_FOLDERS_FROM_COLLECTIONS_SQL = uR"( static const QString SELECT_FOLDERS_FROM_COLLECTIONS_SQL = uR"(
select f.id, f.path select f.id, f.path
from collections c from collections c
@ -379,15 +375,6 @@ static bool addCollection(QSqlQuery &q, const QString &collection_name, const QD
return true; return true;
} }
static bool removeCollection(QSqlQuery &q, const QString &collection_name, int folder_id)
{
if (!q.prepare(DELETE_COLLECTION_SQL))
return false;
q.addBindValue(collection_name);
q.addBindValue(folder_id);
return q.exec();
}
static bool selectFoldersFromCollection(QSqlQuery &q, const QString &collection_name, QList<QPair<int, QString>> *folders) static bool selectFoldersFromCollection(QSqlQuery &q, const QString &collection_name, QList<QPair<int, QString>> *folders)
{ {
if (!q.prepare(SELECT_FOLDERS_FROM_COLLECTIONS_SQL)) if (!q.prepare(SELECT_FOLDERS_FROM_COLLECTIONS_SQL))
@ -520,10 +507,6 @@ static const QString GET_FOLDER_EMBEDDING_MODEL_SQL = uR"(
where ci.folder_id = ?; where ci.folder_id = ?;
)"_s; )"_s;
static const QString SELECT_ALL_FOLDERPATHS_SQL = uR"(
select path from folders;
)"_s;
static const QString FOLDER_REMOVE_ALL_DOCS_SQL[] = { static const QString FOLDER_REMOVE_ALL_DOCS_SQL[] = {
uR"( uR"(
delete from embeddings delete from embeddings
@ -598,17 +581,6 @@ static bool sqlGetFolderEmbeddingModel(QSqlQuery &q, int id, QString &embedding_
return true; return true;
} }
static bool selectAllFolderPaths(QSqlQuery &q, QList<QString> *folder_paths)
{
if (!q.prepare(SELECT_ALL_FOLDERPATHS_SQL))
return false;
if (!q.exec())
return false;
while (q.next())
folder_paths->append(q.value(0).toString());
return true;
}
static const QString INSERT_COLLECTION_ITEM_SQL = uR"( static const QString INSERT_COLLECTION_ITEM_SQL = uR"(
insert into collection_items(collection_id, folder_id) insert into collection_items(collection_id, folder_id)
values(?, ?) values(?, ?)
@ -2499,7 +2471,7 @@ void Database::retrieveFromDB(const QList<QString> &collections, const QString &
return; return;
QSqlQuery q(m_db); QSqlQuery q(m_db);
if (!selectChunk(q, searchResults, retrievalSize)) { if (!selectChunk(q, searchResults)) {
qDebug() << "ERROR: selecting chunks:" << q.lastError(); qDebug() << "ERROR: selecting chunks:" << q.lastError();
return; return;
} }

View File

@ -58,11 +58,6 @@ Download::Download()
m_startTime = QDateTime::currentDateTime(); m_startTime = QDateTime::currentDateTime();
} }
static bool operator==(const ReleaseInfo& lhs, const ReleaseInfo& rhs)
{
return lhs.version == rhs.version;
}
std::strong_ordering Download::compareAppVersions(const QString &a, const QString &b) std::strong_ordering Download::compareAppVersions(const QString &a, const QString &b)
{ {
static QRegularExpression versionRegex(R"(^(\d+(?:\.\d+){0,2})(-.+)?$)"); static QRegularExpression versionRegex(R"(^(\d+(?:\.\d+){0,2})(-.+)?$)");