Customise a model from the portal: a file, a model, a button
A page for anyone in a project, built for the one who knows least: an Excel, CSV or JSONL file of questions and answers, previewed; a model; a name; who may use it; and a button. The weights to train on are found from where the model's came (a GGUF repository's base model), the card's memory from their size, the node as the one with the most free. When it is done the adapter is published by itself (a llama.cpp model's replicas replaced to load it) and is a model of its own in the chat and the API. The project's by default; its members share it wider (confirmed, and never wider than the knowledge bases its pairs came from) or delete it. One trains at a time per project. ctl train start needs only --model and --data now, and --publish publishes when done. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fcda4d3f85
commit
a53b2f4be9
33 files changed
+2199
-134
No files matched your search
@@ -0,0 +1,5 @@
|
||||
-- Training from the portal: the project a job was started in, which sees
|
||||
-- it, manages it and pays for it; and whether what it makes is published
|
||||
-- by itself when it is done, rather than by an administrator.
|
||||
ALTER TABLE train_jobs ADD COLUMN project_id TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE train_jobs ADD COLUMN publish INTEGER NOT NULL DEFAULT 0;
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Training from the portal: the project a job was started in, which sees
|
||||
-- it, manages it and pays for it; and whether what it makes is published
|
||||
-- by itself when it is done, rather than by an administrator.
|
||||
ALTER TABLE train_jobs ADD COLUMN project_id TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE train_jobs ADD COLUMN publish INTEGER NOT NULL DEFAULT 0;
|
||||
+51
-13
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -34,6 +35,11 @@ type TrainJob struct {
|
||||
StartedAt time.Time
|
||||
FinishedAt time.Time
|
||||
CreatedBy string
|
||||
// Project is the project a job was started in from the portal: its
|
||||
// members see and manage it, and it pays. Empty for an administrator's.
|
||||
Project string
|
||||
// Publish has what the job makes published when it is done.
|
||||
Publish bool
|
||||
}
|
||||
|
||||
// The states of a training job.
|
||||
@@ -55,27 +61,25 @@ func (s *DB) CreateTrainJob(ctx context.Context, j TrainJob) error {
|
||||
if j.CreatedAt.IsZero() {
|
||||
j.CreatedAt = time.Now()
|
||||
}
|
||||
gguf := 0
|
||||
if j.GGUF {
|
||||
gguf = 1
|
||||
}
|
||||
_, err := s.db.ExecContext(ctx, `INSERT INTO train_jobs (id, name, model, base_repo, base_revision, node, owner, gpu_memory_mib,
|
||||
params, gguf, data, pairs, state, created_at, created_by) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
j.ID, j.Name, j.Model, j.BaseRepo, j.BaseRevision, j.Node, j.Owner, j.GPUMemoryMiB, j.Params, gguf, j.Data, j.Pairs,
|
||||
TrainQueued, millis(j.CreatedAt), j.CreatedBy)
|
||||
params, gguf, data, pairs, state, created_at, created_by, project_id, publish)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
j.ID, j.Name, j.Model, j.BaseRepo, j.BaseRevision, j.Node, j.Owner, j.GPUMemoryMiB, j.Params, boolInt(j.GGUF), j.Data, j.Pairs,
|
||||
TrainQueued, millis(j.CreatedAt), j.CreatedBy, j.Project, boolInt(j.Publish))
|
||||
return err
|
||||
}
|
||||
|
||||
const trainCols = `id, name, model, base_repo, base_revision, node, owner, gpu_memory_mib, params, gguf, pairs, state, step, steps,
|
||||
loss, message, peak_mib, created_at, started_at, finished_at, created_by`
|
||||
loss, message, peak_mib, created_at, started_at, finished_at, created_by, project_id, publish`
|
||||
|
||||
func scanTrainJob(sc scanner) (TrainJob, error) {
|
||||
var j TrainJob
|
||||
var gguf int
|
||||
var gguf, publish int
|
||||
var created, started, finished int64
|
||||
err := sc.Scan(&j.ID, &j.Name, &j.Model, &j.BaseRepo, &j.BaseRevision, &j.Node, &j.Owner, &j.GPUMemoryMiB, &j.Params, &gguf,
|
||||
&j.Pairs, &j.State, &j.Step, &j.Steps, &j.Loss, &j.Message, &j.PeakMiB, &created, &started, &finished, &j.CreatedBy)
|
||||
j.GGUF = gguf != 0
|
||||
&j.Pairs, &j.State, &j.Step, &j.Steps, &j.Loss, &j.Message, &j.PeakMiB, &created, &started, &finished, &j.CreatedBy,
|
||||
&j.Project, &publish)
|
||||
j.GGUF, j.Publish = gguf != 0, publish != 0
|
||||
j.CreatedAt = fromMillis(created)
|
||||
if started > 0 {
|
||||
j.StartedAt = fromMillis(started)
|
||||
@@ -128,13 +132,47 @@ func (s *DB) UpdateTrainJob(ctx context.Context, j TrainJob) error {
|
||||
if !j.FinishedAt.IsZero() {
|
||||
finished = millis(j.FinishedAt)
|
||||
}
|
||||
_, err := s.db.ExecContext(ctx, `UPDATE train_jobs SET state = ?, step = ?, steps = ?, loss = ?, message = ?,
|
||||
_, err := s.db.ExecContext(ctx, `UPDATE train_jobs SET node = ?, state = ?, step = ?, steps = ?, loss = ?, message = ?,
|
||||
peak_mib = ?, started_at = ?, finished_at = ? WHERE id = ? AND state NOT IN (?, ?, ?)`,
|
||||
j.State, j.Step, j.Steps, j.Loss, j.Message, j.PeakMiB, started, finished, j.ID,
|
||||
j.Node, j.State, j.Step, j.Steps, j.Loss, j.Message, j.PeakMiB, started, finished, j.ID,
|
||||
TrainDone, TrainFailed, TrainCancelled)
|
||||
return err
|
||||
}
|
||||
|
||||
// TrainJobsFor lists the jobs started in projects, or by a person outside
|
||||
// any project, newest first.
|
||||
func (s *DB) TrainJobsFor(ctx context.Context, projects []string, createdBy string, limit int) ([]TrainJob, error) {
|
||||
q := `SELECT ` + trainCols + ` FROM train_jobs WHERE (project_id = '' AND publish = 1 AND created_by = ?)`
|
||||
args := []any{createdBy}
|
||||
if len(projects) > 0 {
|
||||
q += ` OR project_id IN (?` + strings.Repeat(", ?", len(projects)-1) + `)`
|
||||
for _, p := range projects {
|
||||
args = append(args, p)
|
||||
}
|
||||
}
|
||||
return queryAll(ctx, s.db, q+` ORDER BY created_at DESC LIMIT ?`, append(args, limit),
|
||||
func(r *sql.Rows) (TrainJob, error) { return scanTrainJob(r) })
|
||||
}
|
||||
|
||||
// SetTrainNote changes what a job says of itself, ended or not: what
|
||||
// happened when what it made was published.
|
||||
func (s *DB) SetTrainNote(ctx context.Context, id, message string) error {
|
||||
_, err := s.db.ExecContext(ctx, `UPDATE train_jobs SET message = ? WHERE id = ?`, message, id)
|
||||
return err
|
||||
}
|
||||
|
||||
// SetTrainOwner changes who a job's adapter belongs to.
|
||||
func (s *DB) SetTrainOwner(ctx context.Context, id, owner string) error {
|
||||
res, err := s.db.ExecContext(ctx, `UPDATE train_jobs SET owner = ? WHERE id = ?`, owner, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n, _ := res.RowsAffected(); n == 0 {
|
||||
return ErrNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PutTrainArtifact keeps what a job made.
|
||||
func (s *DB) PutTrainArtifact(ctx context.Context, job, kind string, data []byte) error {
|
||||
_, err := s.db.ExecContext(ctx, `INSERT INTO train_artifacts (job_id, kind, data) VALUES (?, ?, ?)
|
||||
|
||||
Reference in new issue
Block a user