mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-12 11:56:36 +00:00
feat: stream model conversion (#1581)
This commit is contained in:
1 parent
e9dee542c4
commit
da6db07c5c
12 files changed
+676
-82
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "streaming_writer.h"
|
||||
#include "tensor_storage.h"
|
||||
|
||||
bool is_safetensors_file(const std::string& file_path);
|
||||
@@ -14,4 +15,26 @@ bool write_safetensors_file(const std::string& file_path,
|
||||
const std::vector<TensorWriteInfo>& tensors,
|
||||
std::string* error = nullptr);
|
||||
|
||||
class SafetensorsStreamingWriter : public StreamingModelWriter {
|
||||
public:
|
||||
SafetensorsStreamingWriter() = default;
|
||||
|
||||
bool write_metadata(const std::string& file_path,
|
||||
const std::vector<TensorWritePlan>& tensors,
|
||||
std::string* error = nullptr) override;
|
||||
bool write_tensor(std::ostream& output,
|
||||
size_t tensor_index,
|
||||
const uint8_t* data,
|
||||
size_t size,
|
||||
std::string* error = nullptr) const override;
|
||||
uint64_t file_size() const override;
|
||||
|
||||
private:
|
||||
std::string file_path_;
|
||||
std::vector<TensorWritePlan> tensors_;
|
||||
std::vector<uint64_t> tensor_offsets_;
|
||||
uint64_t data_start_ = 0;
|
||||
uint64_t file_size_ = 0;
|
||||
};
|
||||
|
||||
#endif // __SD_MODEL_IO_SAFETENSORS_IO_H__
|
||||
Reference in new issue
Block a user