2021-03-30 03:22:42 +02:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2021 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_GPT_PIPE_MODEL_H
|
|
|
|
|
|
|
|
struct ircd::gpt::pipe::model
|
|
|
|
{
|
2021-04-17 20:53:50 +02:00
|
|
|
struct matrix;
|
2021-03-30 03:22:42 +02:00
|
|
|
struct tensor;
|
|
|
|
struct norm;
|
|
|
|
struct proj;
|
|
|
|
struct fcon;
|
|
|
|
struct attn;
|
|
|
|
struct ffnn;
|
|
|
|
struct block;
|
2022-06-20 03:59:29 +02:00
|
|
|
struct embed;
|
2021-03-30 03:22:42 +02:00
|
|
|
struct decoder;
|
|
|
|
|
2022-06-20 03:59:29 +02:00
|
|
|
const gpt::model::decoder *decode_const {nullptr};
|
|
|
|
gpt::model::decoder *decode_mutable {nullptr};
|
2021-03-30 03:22:42 +02:00
|
|
|
std::unique_ptr<model::decoder> decode;
|
|
|
|
|
2022-06-20 03:59:29 +02:00
|
|
|
model(const gpt::model::decoder &);
|
|
|
|
model(gpt::model::decoder &);
|
2021-03-30 03:22:42 +02:00
|
|
|
~model() noexcept;
|
|
|
|
};
|
|
|
|
|
2021-04-17 20:53:50 +02:00
|
|
|
struct ircd::gpt::pipe::model::matrix
|
|
|
|
{
|
|
|
|
cl::data
|
|
|
|
param, // Weights
|
|
|
|
moment[2]; // Adaptive moment estimations
|
|
|
|
|
|
|
|
matrix(cl::data *, const off_t, const const_buffer ¶m);
|
|
|
|
matrix(cl::data *, const off_t, const mutable_buffer ¶m);
|
|
|
|
};
|
|
|
|
|
2021-03-30 03:22:42 +02:00
|
|
|
struct ircd::gpt::pipe::model::tensor
|
|
|
|
{
|
2021-04-17 20:53:50 +02:00
|
|
|
matrix
|
|
|
|
bias,
|
|
|
|
weight;
|
2021-03-30 03:22:42 +02:00
|
|
|
|
2022-06-20 03:59:29 +02:00
|
|
|
tensor(cl::data *, const off_t, const const_buffer &bias, const off_t, const const_buffer &weight);
|
|
|
|
tensor(cl::data *, const off_t, const mutable_buffer &bias, const off_t, const mutable_buffer &weight);
|
2021-03-30 03:22:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ircd::gpt::pipe::model::attn
|
|
|
|
{
|
2021-04-17 20:53:50 +02:00
|
|
|
tensor
|
|
|
|
norm,
|
|
|
|
fcon,
|
|
|
|
proj;
|
|
|
|
|
2022-06-20 03:59:29 +02:00
|
|
|
attn(cl::data *, const off_t, const gpt::model::attn &);
|
|
|
|
attn(cl::data *, const off_t, gpt::model::attn &);
|
2021-03-30 03:22:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ircd::gpt::pipe::model::ffnn
|
|
|
|
{
|
2021-04-17 20:53:50 +02:00
|
|
|
tensor
|
|
|
|
norm,
|
|
|
|
fcon,
|
|
|
|
proj;
|
2021-03-30 03:22:42 +02:00
|
|
|
|
2022-06-20 03:59:29 +02:00
|
|
|
ffnn(cl::data *, const off_t, const gpt::model::ffnn &);
|
|
|
|
ffnn(cl::data *, const off_t, gpt::model::ffnn &);
|
2021-03-30 03:22:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ircd::gpt::pipe::model::block
|
|
|
|
{
|
2022-06-20 03:59:29 +02:00
|
|
|
model::attn
|
|
|
|
attn;
|
2021-04-17 20:53:50 +02:00
|
|
|
|
2022-06-20 03:59:29 +02:00
|
|
|
model::ffnn
|
|
|
|
ffnn;
|
2021-03-30 03:22:42 +02:00
|
|
|
|
2021-04-17 20:53:50 +02:00
|
|
|
block(cl::data *, const off_t, const gpt::model::block &, const size_t);
|
|
|
|
block(cl::data *, const off_t, gpt::model::block &, const size_t);
|
2021-03-30 03:22:42 +02:00
|
|
|
};
|
|
|
|
|
2022-06-20 03:59:29 +02:00
|
|
|
struct ircd::gpt::pipe::model::embed
|
2021-04-22 21:10:22 +02:00
|
|
|
{
|
2022-06-20 03:59:29 +02:00
|
|
|
tensor
|
|
|
|
norm;
|
2021-04-22 21:10:22 +02:00
|
|
|
|
|
|
|
matrix
|
|
|
|
pos,
|
|
|
|
token;
|
|
|
|
|
2022-06-20 03:59:29 +02:00
|
|
|
embed(cl::data *, const off_t, const gpt::model::embed &);
|
|
|
|
embed(cl::data *, const off_t, gpt::model::embed &);
|
2021-04-22 21:10:22 +02:00
|
|
|
};
|
|
|
|
|
2021-03-30 03:22:42 +02:00
|
|
|
struct ircd::gpt::pipe::model::decoder
|
|
|
|
{
|
2021-04-17 20:53:50 +02:00
|
|
|
// Combined-layer memory roots
|
|
|
|
cl::data
|
|
|
|
master[3];
|
|
|
|
|
|
|
|
// Layer blocks
|
|
|
|
model::block
|
2022-06-20 03:59:29 +02:00
|
|
|
layer[12];
|
2021-04-17 20:53:50 +02:00
|
|
|
|
2022-06-20 03:59:29 +02:00
|
|
|
// Language model head
|
|
|
|
model::embed
|
|
|
|
embed;
|
2021-03-30 03:22:42 +02:00
|
|
|
|
|
|
|
decoder(const gpt::model::decoder &);
|
2021-04-17 20:53:50 +02:00
|
|
|
decoder(gpt::model::decoder &);
|
2021-03-30 03:22:42 +02:00
|
|
|
~decoder() noexcept;
|
|
|
|
};
|