MLX
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1// Copyright © 2023-2024 Apple Inc.
2
3#pragma once
4
5#include <variant>
6
7#include "mlx/array.h"
8#include "mlx/io/load.h"
9#include "mlx/stream.h"
10#include "mlx/utils.h"
11
12namespace mlx::core {
14 std::variant<std::monostate, array, std::string, std::vector<std::string>>;
15using GGUFLoad = std::pair<
16 std::unordered_map<std::string, array>,
17 std::unordered_map<std::string, GGUFMetaData>>;
18using SafetensorsLoad = std::pair<
19 std::unordered_map<std::string, array>,
20 std::unordered_map<std::string, std::string>>;
21
23void save(std::shared_ptr<io::Writer> out_stream, array a);
24
26void save(std::string file, array a);
27
29array load(std::shared_ptr<io::Reader> in_stream, StreamOrDevice s = {});
30
32array load(std::string file, StreamOrDevice s = {});
33
36 std::shared_ptr<io::Reader> in_stream,
37 StreamOrDevice s = {});
39 const std::string& file,
40 StreamOrDevice s = {});
41
43 std::shared_ptr<io::Writer> in_stream,
44 std::unordered_map<std::string, array>,
45 std::unordered_map<std::string, std::string> metadata = {});
47 std::string file,
48 std::unordered_map<std::string, array>,
49 std::unordered_map<std::string, std::string> metadata = {});
50
53GGUFLoad load_gguf(const std::string& file, StreamOrDevice s = {});
54
56 std::string file,
57 std::unordered_map<std::string, array> array_map,
58 std::unordered_map<std::string, GGUFMetaData> meta_data = {});
59
60} // namespace mlx::core
Definition array.h:20
Definition allocator.h:7
GGUFLoad load_gguf(const std::string &file, StreamOrDevice s={})
Load array map and metadata from .gguf file format.
std::pair< std::unordered_map< std::string, array >, std::unordered_map< std::string, std::string > > SafetensorsLoad
Definition io.h:18
void save_gguf(std::string file, std::unordered_map< std::string, array > array_map, std::unordered_map< std::string, GGUFMetaData > meta_data={})
std::variant< std::monostate, array, std::string, std::vector< std::string > > GGUFMetaData
Definition io.h:13
std::variant< std::monostate, Stream, Device > StreamOrDevice
Definition utils.h:14
SafetensorsLoad load_safetensors(std::shared_ptr< io::Reader > in_stream, StreamOrDevice s={})
Load array map from .safetensors file format.
void save_safetensors(std::shared_ptr< io::Writer > in_stream, std::unordered_map< std::string, array >, std::unordered_map< std::string, std::string > metadata={})
std::pair< std::unordered_map< std::string, array >, std::unordered_map< std::string, GGUFMetaData > > GGUFLoad
Definition io.h:15
array load(std::shared_ptr< io::Reader > in_stream, StreamOrDevice s={})
Load array from reader in .npy format.
void save(std::shared_ptr< io::Writer > out_stream, array a)
Save array to out stream in .npy format.