mlx/python/src/load.h

50 lines
1.1 KiB
C
Raw Normal View History

// Copyright © 2023-2024 Apple Inc.
2023-12-01 03:12:53 +08:00
2023-11-30 02:52:08 +08:00
#pragma once
#include <nanobind/nanobind.h>
#include <nanobind/stl/optional.h>
#include <nanobind/stl/string.h>
#include <nanobind/stl/unordered_map.h>
#include <nanobind/stl/variant.h>
#include <optional>
#include <string>
2023-11-30 02:52:08 +08:00
#include <unordered_map>
#include <variant>
#include "mlx/io.h"
2023-11-30 02:52:08 +08:00
namespace nb = nanobind;
2023-11-30 02:52:08 +08:00
using namespace mlx::core;
using LoadOutputTypes = std::variant<
array,
std::unordered_map<std::string, array>,
SafetensorsLoad,
GGUFLoad>;
2023-11-30 02:52:08 +08:00
SafetensorsLoad mlx_load_safetensor_helper(nb::object file, StreamOrDevice s);
void mlx_save_safetensor_helper(
nb::object file,
nb::dict d,
std::optional<nb::dict> m);
GGUFLoad mlx_load_gguf_helper(nb::object file, StreamOrDevice s);
void mlx_save_gguf_helper(
nb::object file,
nb::dict d,
std::optional<nb::dict> m);
LoadOutputTypes mlx_load_helper(
nb::object file,
std::optional<std::string> format,
bool return_metadata,
StreamOrDevice s);
void mlx_save_helper(nb::object file, array a);
2023-11-30 02:52:08 +08:00
void mlx_savez_helper(
nb::object file,
nb::args args,
const nb::kwargs& kwargs,
bool compressed = false);