mirror of
https://github.com/nomic-ai/gpt4all.git
synced 2025-08-04 17:42:25 +00:00
Add fixme's and clean up a bit.
This commit is contained in:
parent
a3d08cdcd5
commit
1eca524171
@ -1,5 +1,4 @@
|
|||||||
#include "llmodel.h"
|
#include "llmodel.h"
|
||||||
#include "dlhandle.h"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -7,10 +6,7 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
|
static bool requires_avxonly() {
|
||||||
|
|
||||||
static
|
|
||||||
bool requires_avxonly() {
|
|
||||||
#ifdef __x86_64__
|
#ifdef __x86_64__
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
return !__builtin_cpu_supports("avx2");
|
return !__builtin_cpu_supports("avx2");
|
||||||
@ -24,7 +20,6 @@ bool requires_avxonly() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LLModel::Implementation::Implementation(Dlhandle &&dlhandle_) : dlhandle(std::move(dlhandle_)) {
|
LLModel::Implementation::Implementation(Dlhandle &&dlhandle_) : dlhandle(std::move(dlhandle_)) {
|
||||||
auto get_model_type = dlhandle.get<const char *()>("get_model_type");
|
auto get_model_type = dlhandle.get<const char *()>("get_model_type");
|
||||||
assert(get_model_type);
|
assert(get_model_type);
|
||||||
@ -42,8 +37,9 @@ bool LLModel::Implementation::isImplementation(const Dlhandle &dl) {
|
|||||||
return dl.get<bool(uint32_t)>("is_g4a_backend_model_implementation");
|
return dl.get<bool(uint32_t)>("is_g4a_backend_model_implementation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::vector<LLModel::Implementation> &LLModel::getImplementationList() {
|
const std::vector<LLModel::Implementation> &LLModel::getImplementationList() {
|
||||||
|
// NOTE: allocated on heap so we leak intentionally on exit so we have a chance to clean up the
|
||||||
|
// individual models without the cleanup of the static list interfering
|
||||||
static auto* libs = new std::vector<LLModel::Implementation>([] () {
|
static auto* libs = new std::vector<LLModel::Implementation>([] () {
|
||||||
std::vector<LLModel::Implementation> fres;
|
std::vector<LLModel::Implementation> fres;
|
||||||
|
|
||||||
@ -51,6 +47,9 @@ const std::vector<LLModel::Implementation> &LLModel::getImplementationList() {
|
|||||||
// Iterate over all libraries
|
// Iterate over all libraries
|
||||||
for (const auto& f : std::filesystem::directory_iterator(path)) {
|
for (const auto& f : std::filesystem::directory_iterator(path)) {
|
||||||
// Get path
|
// Get path
|
||||||
|
// FIXME: Remove useless comment and avoid usage of 'auto' where having the type is
|
||||||
|
// helpful for code readability so someone doesn't have to look up the docs for what
|
||||||
|
// type is returned by 'path' as it is not std::string
|
||||||
const auto& p = f.path();
|
const auto& p = f.path();
|
||||||
// Check extension
|
// Check extension
|
||||||
if (p.extension() != LIB_FILE_EXT) continue;
|
if (p.extension() != LIB_FILE_EXT) continue;
|
||||||
@ -76,6 +75,8 @@ const std::vector<LLModel::Implementation> &LLModel::getImplementationList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const LLModel::Implementation* LLModel::getImplementation(std::ifstream& f, const std::string& buildVariant) {
|
const LLModel::Implementation* LLModel::getImplementation(std::ifstream& f, const std::string& buildVariant) {
|
||||||
|
// FIXME: Please remove all these useless comments as the code itself is more than enough in these
|
||||||
|
// instances to tell what is going on
|
||||||
// Iterate over all libraries
|
// Iterate over all libraries
|
||||||
for (const auto& i : getImplementationList()) {
|
for (const auto& i : getImplementationList()) {
|
||||||
f.seekg(0);
|
f.seekg(0);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#ifndef LLMODEL_H
|
#ifndef LLMODEL_H
|
||||||
#define LLMODEL_H
|
#define LLMODEL_H
|
||||||
#include "dlhandle.h"
|
|
||||||
|
#include "dlhandle.h" // FIXME: would be nice to move this into implementation file
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@ -9,13 +10,13 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
|
||||||
class LLModel {
|
class LLModel {
|
||||||
public:
|
public:
|
||||||
class Implementation {
|
class Implementation {
|
||||||
LLModel *(*construct_)();
|
LLModel *(*construct_)();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
// FIXME: Move the whole implementation details to cpp file
|
||||||
Implementation(Dlhandle&&);
|
Implementation(Dlhandle&&);
|
||||||
|
|
||||||
static bool isImplementation(const Dlhandle&);
|
static bool isImplementation(const Dlhandle&);
|
||||||
@ -30,6 +31,7 @@ public:
|
|||||||
return fres;
|
return fres;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PromptContext {
|
struct PromptContext {
|
||||||
std::vector<float> logits; // logits of current context
|
std::vector<float> logits; // logits of current context
|
||||||
std::vector<int32_t> tokens; // current tokens in the context window
|
std::vector<int32_t> tokens; // current tokens in the context window
|
||||||
@ -62,16 +64,20 @@ public:
|
|||||||
virtual void setThreadCount(int32_t /*n_threads*/) {}
|
virtual void setThreadCount(int32_t /*n_threads*/) {}
|
||||||
virtual int32_t threadCount() const { return 1; }
|
virtual int32_t threadCount() const { return 1; }
|
||||||
|
|
||||||
|
// FIXME: This is unused??
|
||||||
const Implementation& getImplementation() const {
|
const Implementation& getImplementation() const {
|
||||||
return *implementation;
|
return *implementation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Maybe have an 'ImplementationInfo' class for the GUI here, but the DLHandle stuff should
|
||||||
|
// be hidden in cpp file
|
||||||
|
// FIXME: Avoid usage of 'get' for getters
|
||||||
static const std::vector<Implementation>& getImplementationList();
|
static const std::vector<Implementation>& getImplementationList();
|
||||||
static const Implementation *getImplementation(std::ifstream& f, const std::string& buildVariant);
|
static const Implementation *getImplementation(std::ifstream& f, const std::string& buildVariant);
|
||||||
static LLModel *construct(const std::string &modelPath, std::string buildVariant = "default");
|
static LLModel *construct(const std::string &modelPath, std::string buildVariant = "default");
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const Implementation *implementation;
|
const Implementation *implementation; // FIXME: This is dangling! You don't initialize it in ctor either
|
||||||
|
|
||||||
virtual void recalculateContext(PromptContext &promptCtx,
|
virtual void recalculateContext(PromptContext &promptCtx,
|
||||||
std::function<bool(bool)> recalculate) = 0;
|
std::function<bool(bool)> recalculate) = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user