The upstream release tree, every tracked file byte for byte, from https://github.com/VecSzn/PolyStrata at tag v0.1.45-poly.1, commit d0cd84dc6bd009d1d9e2191e4e28cc76b80f1ee3. Nothing added, removed or edited; git diff against this commit is the whole story of the fork. Verified: the commit's tree hash equals the upstream commit's tree hash.
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
|