This commit is contained in:
KoDer 2026-10-02 19:30:49 +07:00
parent ecef2f41af
commit 87b45a1484
31 changed files with 65 additions and 87 deletions

View File

@ -28,12 +28,13 @@ set(SOURCES
xenith/converter.cpp xenith/converter.cpp
help.h help.h
xenith/ollama_api/handler.cpp xenith/ollama_api/handler.cpp
xenith/ollama_api/handler.h xenith/ollama_api/handler.hpp
xenith/ollama_api/server.h xenith/ollama_api/server.hpp
xenith/ollama_api/server.cpp xenith/ollama_api/server.cpp
xenith/ui/tui/tui.cpp xenith/ui/tui/tui.cpp
xenith/ui/tui.h xenith/ui/tui.hpp
xenith/ui/tui/mouse.cpp xenith/ui/tui/mouse.cpp
xenith/ui/tui/message.cpp
) )
# Заголовочные файлы (для удобства в IDE) # Заголовочные файлы (для удобства в IDE)

View File

@ -15,7 +15,7 @@
| файл | что делает | | файл | что делает |
|---|---| |---|---|
| `xenith/core/tensor.h` | матрицы, три формы GEMM, RMSNorm, RNG, пул потоков | | `xenith/core/tensor.hpp` | матрицы, три формы GEMM, RMSNorm, RNG, пул потоков |
| `xenith/core/model.cpp` | конфигурация, инициализация, прямой проход, RoPE, Adam | | `xenith/core/model.cpp` | конфигурация, инициализация, прямой проход, RoPE, Adam |
| `xenith/core/backward.cpp` | обратный проход (ручной, без автомиффов) | | `xenith/core/backward.cpp` | обратный проход (ручной, без автомиффов) |
| `xenith/core/trainer.cpp` | цикл обучения, расписание lr, чекпоинты, валидация | | `xenith/core/trainer.cpp` | цикл обучения, расписание lr, чекпоинты, валидация |

View File

@ -1,8 +1,8 @@
#include "xenith/core/checkpoint.h" #include "xenith/core/checkpoint.hpp"
#include "xenith/core/generate.h" #include "xenith/core/generate.hpp"
#include "xenith/core/train.h" #include "xenith/core/train.hpp"
#include "xenith/core/gradcheck.h" #include "xenith/core/gradcheck.h"
#include "xenith/ui/tui.h" #include "xenith/ui/tui.hpp"
#include <cstdio> #include <cstdio>
#include "help.h" #include "help.h"
#include <cstdlib> #include <cstdlib>
@ -358,10 +358,9 @@ static int cmd_update(const Args& a) {
static int cmd_tui(const Args& a) static int cmd_tui(const Args& a)
{ {
ui::Tui tui = ui::Tui(); while (ui::app.is_running())
while (tui.is_running())
{ {
tui.update(); ui::app.update();
} }
std::cout << "\033[2J\033[H" << std::flush; std::cout << "\033[2J\033[H" << std::flush;
return 0; return 0;

View File

@ -1,15 +0,0 @@
#ifndef XENITH_SETTINGS_H
#define XENITH_SETTINGS_H
#pragma once
#include "xenith/preprocessing/tokenizer.h"
struct llm_prm
{
bool use_mmap = true;
bool use_mlock = false;
int num_thread = 1;
unsigned int num_gpu = 256;
};
#endif

View File

@ -1,4 +1,4 @@
#include "converter.h" #include "converter.hpp"
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>

View File

@ -1,4 +1,4 @@
#include "train.h" #include "train.hpp"
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>

View File

@ -1,4 +1,4 @@
#include "checkpoint.h" #include "checkpoint.hpp"
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include "model.h" #include "model.hpp"
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>

View File

@ -1,4 +1,4 @@
#include "generate.h" #include "generate.hpp"
#include <cstdio> #include <cstdio>
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>

View File

@ -1,6 +1,6 @@
// generate.h — генерация текста с KV-кэшем // generate.h — генерация текста с KV-кэшем
#pragma once #pragma once
#include "checkpoint.h" #include "checkpoint.hpp"
#include <string> #include <string>
#include <vector> #include <vector>

View File

@ -1,8 +1,8 @@
// gradcheck.cpp — проверяем, что обратный проход совпадает с численным // gradcheck.cpp — проверяем, что обратный проход совпадает с численным
// и заодно меряем скорость. // и заодно меряем скорость.
#include "gradcheck.h" #include "gradcheck.h"
#include "generate.h" #include "generate.hpp"
#include "train.h" #include "train.hpp"
#include <cstdio> #include <cstdio>
#include <cmath> #include <cmath>
#include <chrono> #include <chrono>

View File

@ -1,6 +1,6 @@
// gradcheck.h — численная проверка градиентов и бенчмарк // gradcheck.h — численная проверка градиентов и бенчмарк
#pragma once #pragma once
#include "checkpoint.h" #include "checkpoint.hpp"
namespace xt { namespace xt {
int run_gradcheck(bool verbose); int run_gradcheck(bool verbose);

View File

@ -1,4 +1,4 @@
#include "model.h" #include "model.hpp"
#include <cstdio> #include <cstdio>
#include <cmath> #include <cmath>
#include <algorithm> #include <algorithm>

View File

@ -1,5 +1,5 @@
#pragma once #pragma once
#include "tensor.h" #include "tensor.hpp"
#include <string> #include <string>
#include <vector> #include <vector>

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "model.h" #include "model.hpp"
#include "checkpoint.h" #include "checkpoint.hpp"
#include <vector> #include <vector>
namespace xt { namespace xt {

View File

@ -1,5 +1,5 @@
#include "train.h" #include "train.hpp"
#include "checkpoint.h" #include "checkpoint.hpp"
#include <cstdio> #include <cstdio>
#include <cmath> #include <cmath>
#include <fstream> #include <fstream>

View File

@ -1,2 +1,2 @@
#include "handler.h" #include "handler.hpp"

View File

@ -1,5 +1,5 @@
#ifndef XENITH_HANDLER_H #pragma once
#define XENITH_HANDLER_H
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
@ -63,7 +63,4 @@ namespace api
std::string digest; std::string digest;
models_details details; models_details details;
}; };
} }
#endif

View File

@ -1,4 +1,4 @@
#include "server.h" #include "server.hpp"
namespace api namespace api
{ {

View File

@ -1,14 +0,0 @@
#ifndef XENITH_SERVER_H
#define XENITH_SERVER_H
#include "handler.h"
namespace api
{
class server
{
server();
~server();
};
}
#endif //XENITH_SERVER_H

View File

@ -0,0 +1,13 @@
#pragma once
#include "handler.hpp"
namespace api
{
class server
{
server();
~server();
};
}

View File

@ -3,7 +3,7 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
#include <string> #include <string>
#include "./xenith/libs/cpp-httplib-0.57.1/httplib.h" #include "./xenith/libs/cpp-httplib-0.57.1/httplib.hpp"
#include "./xenith/libs/json-3.12.0/nlohmann/json.hpp" #include "./xenith/libs/json-3.12.0/nlohmann/json.hpp"

View File

@ -1,4 +1,4 @@
#include "tokenizer.h" #include "tokenizer.hpp"
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>

View File

@ -4,7 +4,7 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <unordered_map> #include <unordered_map>
#include "./../converter.h" #include "./../converter.hpp"
#include "models/test_model.h" #include "models/test_model.h"
void proccesing_promt(const std::string& text, Model& mdl, uint32_t layer_idx = 0); void proccesing_promt(const std::string& text, Model& mdl, uint32_t layer_idx = 0);

View File

@ -1,12 +1,7 @@
#ifndef XENITH_TUI_H #pragma once
#define XENITH_TUI_H
#include <cstdint> #include <cstdint>
#include <iostream>
#include <memory> #include <memory>
#include <sys/ioctl.h>
#include <unistd.h>
#include <sys/select.h>
#include <termios.h> #include <termios.h>
#include <vector> #include <vector>
#include <string> #include <string>
@ -52,7 +47,6 @@ namespace ui
inline static bool running = true; inline static bool running = true;
inline static int width = 80; inline static int width = 80;
inline static int height = 24; inline static int height = 24;
struct SplitDesc { struct SplitDesc {
enum Type { VERTICAL, HORIZONTAL }; enum Type { VERTICAL, HORIZONTAL };
Type type; Type type;
@ -60,22 +54,17 @@ namespace ui
std::vector<std::unique_ptr<SplitDesc>> children; std::vector<std::unique_ptr<SplitDesc>> children;
SplitDesc(Type t, int pos) : type(t), position(pos) {} SplitDesc(Type t, int pos) : type(t), position(pos) {}
}; };
struct border_charset { struct border_charset {
std::string_view top_left, top_right, bottom_left, bottom_right; std::string_view top_left, top_right, bottom_left, bottom_right;
std::string_view bottom, top, horizontal, vertical, bg; std::string_view bottom, top, horizontal, vertical, bg;
std::string_view cross, tee_up, tee_down, tee_left, tee_right; std::string_view cross, tee_up, tee_down, tee_left, tee_right;
}; };
// Ваша структура, которая теперь будет использоваться по назначению
struct TuiCell { struct TuiCell {
std::string ch; // UTF-8 последовательность (например, "│" или "┌") std::string ch;
int width; // Ширина на экране (обычно 1) int width;
TuiCell() : ch(" "), width(1) {} TuiCell() : ch(" "), width(1) {}
TuiCell(const std::string& c, int w) : ch(c), width(w) {} TuiCell(const std::string& c, int w) : ch(c), width(w) {}
}; };
inline static struct termios orig_termios; inline static struct termios orig_termios;
inline static const border_charset border_clip { inline static const border_charset border_clip {
.top_left="╭", .top_right="╮", .bottom_left="╰", .bottom_right="╯", .top_left="╭", .top_right="╮", .bottom_left="╰", .bottom_right="╯",
@ -99,7 +88,6 @@ namespace ui
.top_left="▟", .top_right="▙", .bottom_left="▜", .bottom_right="▛", .top_left="▟", .top_right="▙", .bottom_left="▜", .bottom_right="▛",
.bottom="█", .top="█", .vertical="█", .bg="█" .bottom="█", .top="█", .vertical="█", .bg="█"
}; };
static void get_console_size(); static void get_console_size();
static bool wait_for_input_or_timeout(int timeout_ms); static bool wait_for_input_or_timeout(int timeout_ms);
void apply_color() const; void apply_color() const;
@ -118,13 +106,11 @@ namespace ui
static void invert_color(); static void invert_color();
static void draw_button(int x, int y, int w, int h, std::string_view label, border_charset charset = border_solid); static void draw_button(int x, int y, int w, int h, std::string_view label, border_charset charset = border_solid);
static void invert_color_off(); static void invert_color_off();
// --- ОБНОВЛЕННЫЕ СИГНАТУРЫ ---
void draw_split_border(int w, int h, border_charset charset, int x, int y, const SplitDesc* root); void draw_split_border(int w, int h, border_charset charset, int x, int y, const SplitDesc* root);
static void apply_splits_recursive(std::vector<std::vector<TuiCell>>& grid, int offset_x, int offset_y, int w, int h, border_charset charset, const SplitDesc* split); static void apply_splits_recursive(std::vector<std::vector<TuiCell>>& grid, int offset_x, int offset_y, int w, int h, border_charset charset, const SplitDesc* split);
static void apply_single_split(std::vector<std::vector<TuiCell>>& grid, int offset_x, int offset_y, int w, int h, border_charset charset, const SplitDesc* split); static void apply_single_split(std::vector<std::vector<TuiCell>>& grid, int offset_x, int offset_y, int w, int h, border_charset charset, const SplitDesc* split);
static void draw_border_to_buffer(std::vector<std::vector<TuiCell>>& grid, int w, int h, border_charset charset); static void draw_border_to_buffer(std::vector<std::vector<TuiCell>>& grid, int w, int h, border_charset charset);
}; };
}
#endif Tui app = Tui();
}

View File

@ -0,0 +1,7 @@
#include "message.h"
#include "./../tui.hpp"
namespace ui
{
}

View File

@ -1,4 +1,4 @@
#include "../tui.h" #include "../tui.hpp"
namespace ui namespace ui
{ {

View File

@ -1,8 +1,12 @@
#include "../tui.h" #include "../tui.hpp"
#include <chrono> #include <chrono>
#include <csignal> #include <csignal>
#include <cstring> #include <cstring>
#include <sys/ioctl.h>
#include <unistd.h>
#include <sys/select.h>
#include <iostream>
namespace ui namespace ui