Source: https://github.com/Niko1221/Strata, commit 6f32ec070f23ced9f50e704d854d775da52591ab (engine 0.1.39, MIT). Every file is as upstream published it; later commits show exactly what this fork changes. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
54 lines
2.0 KiB
C++
54 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace strata::core {
|
|
class RemoteExperts;
|
|
class ExpertSource;
|
|
|
|
// Remote Expert Decode Optimization v1 on existing helper caches. One instance per serial engine.
|
|
class RemoteExpertOpt {
|
|
public:
|
|
RemoteExpertOpt() = default;
|
|
~RemoteExpertOpt();
|
|
RemoteExpertOpt(const RemoteExpertOpt&) = delete;
|
|
RemoteExpertOpt& operator=(const RemoteExpertOpt&) = delete;
|
|
|
|
void attach(RemoteExperts& remote); // before RemoteExperts::open
|
|
bool init(std::string& err); // after all helper caches are open
|
|
bool owns(int64_t layer, int32_t expert) const;
|
|
bool adapt(const std::vector<float>& usage, const std::vector<int32_t>& primary,
|
|
const std::vector<std::pair<int32_t, int32_t>>& pending, int max_swaps,
|
|
ExpertSource& source);
|
|
|
|
// Bracket the existing pool callback; its signature and dispatch remain unchanged.
|
|
void begin(const float* weights, int token_begin, int tokens);
|
|
void end() { weights_ = nullptr; }
|
|
void copy_rows(float* dst, const float* src, int token_begin, int tokens,
|
|
const int32_t* hit_rows, const int32_t* count, void* stream) const;
|
|
void combine(float* dst, float* scratch, int token_begin, int tokens,
|
|
const uint32_t* skip, uint32_t ring, void* stream) const;
|
|
|
|
private:
|
|
friend class RemoteExperts;
|
|
static size_t metadata_bytes();
|
|
bool active() const { return weights_ != nullptr; }
|
|
void prepare(const RemoteExperts& remote, void* metadata) const;
|
|
bool reduce(RemoteExperts& remote, const void* metadata, std::string& err);
|
|
void accumulate(const RemoteExperts& remote);
|
|
|
|
struct Peer { RemoteExperts* remote; float* sum = nullptr; };
|
|
std::vector<Peer> peers_;
|
|
float* h_sum_ = nullptr;
|
|
float* m_sum_ = nullptr;
|
|
int32_t* h_mask_ = nullptr;
|
|
int32_t* m_mask_ = nullptr;
|
|
const float* weights_ = nullptr;
|
|
int token_begin_ = 0, tokens_ = 0;
|
|
};
|
|
} // namespace strata::core
|