MLX
Loading...
Searching...
No Matches
fast.h
Go to the documentation of this file.
1// Copyright © 2023-2024 Apple Inc.
2
3#pragma once
4
5#include <optional>
6
7#include "mlx/utils.h"
8
9namespace mlx::core::fast {
10
12 const array& x,
13 const array& weight,
14 float eps,
15 StreamOrDevice s = {});
16
18 const array& x,
19 const std::optional<array>& weight,
20 const std::optional<array>& bias,
21 float eps,
22 StreamOrDevice s = {});
23
25 const array& x,
26 int dims,
27 bool traditional,
28 std::optional<float> base,
29 float scale,
30 int offset,
31 const std::optional<array>& freqs = std::nullopt,
32 StreamOrDevice s = {});
33
36 const array& queries,
37 const array& keys,
38 const array& values,
39 const float scale,
40 const std::optional<array>& mask = std::nullopt,
41 const std::optional<int> memory_efficient_threshold = std::nullopt,
42 StreamOrDevice s = {});
43
44std::tuple<array, array, array> affine_quantize(
45 const array& w,
46 int group_size = 64,
47 int bits = 4,
48 StreamOrDevice s = {});
49
51 const array& w,
52 const array& scales,
53 const array& biases,
54 int group_size = 64,
55 int bits = 4,
56 StreamOrDevice s = {});
57
59 const array& w,
60 const array& scales,
61 const array& biases,
62 int group_size = 64,
63 int bits = 4,
64 StreamOrDevice s = {});
65
66typedef std::variant<int, bool, Dtype> TemplateArg;
67
68typedef std::function<std::vector<array>(
69 const std::vector<array>&,
70 const std::vector<std::vector<int>>&,
71 const std::vector<Dtype>&,
72 std::tuple<int, int, int>,
73 std::tuple<int, int, int>,
74 std::vector<std::pair<std::string, TemplateArg>>,
75 std::optional<float>,
76 bool,
79
81 const std::string& name,
82 const std::vector<std::string>& input_names,
83 const std::vector<std::string>& output_names,
84 const std::string& source,
85 const std::string& header = "",
86 bool ensure_row_contiguous = true,
87 bool atomic_outputs = false);
88
89} // namespace mlx::core::fast
Definition array.h:20
Definition fast.h:9
array layer_norm(const array &x, const std::optional< array > &weight, const std::optional< array > &bias, float eps, StreamOrDevice s={})
std::function< std::vector< array >(const std::vector< array > &, const std::vector< std::vector< int > > &, const std::vector< Dtype > &, std::tuple< int, int, int >, std::tuple< int, int, int >, std::vector< std::pair< std::string, TemplateArg > >, std::optional< float >, bool, StreamOrDevice)> MetalKernelFunction
Definition fast.h:78
array affine_dequantize(const array &w, const array &scales, const array &biases, int group_size=64, int bits=4, StreamOrDevice s={})
array scaled_dot_product_attention(const array &queries, const array &keys, const array &values, const float scale, const std::optional< array > &mask=std::nullopt, const std::optional< int > memory_efficient_threshold=std::nullopt, StreamOrDevice s={})
Computes: O = softmax(Q @ K.T) @ V.
array rope(const array &x, int dims, bool traditional, std::optional< float > base, float scale, int offset, const std::optional< array > &freqs=std::nullopt, StreamOrDevice s={})
std::variant< int, bool, Dtype > TemplateArg
Definition fast.h:66
std::tuple< array, array, array > affine_quantize(const array &w, int group_size=64, int bits=4, StreamOrDevice s={})
MetalKernelFunction metal_kernel(const std::string &name, const std::vector< std::string > &input_names, const std::vector< std::string > &output_names, const std::string &source, const std::string &header="", bool ensure_row_contiguous=true, bool atomic_outputs=false)
array rms_norm(const array &x, const array &weight, float eps, StreamOrDevice s={})
std::variant< std::monostate, Stream, Device > StreamOrDevice
Definition utils.h:14