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
35 const array& x,
36 int dims,
37 bool traditional,
38 std::optional<float> base,
39 float scale,
40 const array& offset,
41 const std::optional<array>& freqs = std::nullopt,
42 StreamOrDevice s = {});
43
46 const array& queries,
47 const array& keys,
48 const array& values,
49 const float scale,
50 const std::optional<array>& mask = std::nullopt,
51 const std::optional<int> memory_efficient_threshold = std::nullopt,
52 StreamOrDevice s = {});
53
54std::tuple<array, array, array> affine_quantize(
55 const array& w,
56 int group_size = 64,
57 int bits = 4,
58 StreamOrDevice s = {});
59
61 const array& w,
62 const array& scales,
63 const array& biases,
64 int group_size = 64,
65 int bits = 4,
66 StreamOrDevice s = {});
67
68typedef std::variant<int, bool, Dtype> TemplateArg;
69
70typedef std::function<std::vector<array>(
71 const std::vector<array>&,
72 const std::vector<Shape>&,
73 const std::vector<Dtype>&,
74 std::tuple<int, int, int>,
75 std::tuple<int, int, int>,
76 std::vector<std::pair<std::string, TemplateArg>>,
77 std::optional<float>,
78 bool,
81
83 const std::string& name,
84 const std::vector<std::string>& input_names,
85 const std::vector<std::string>& output_names,
86 const std::string& source,
87 const std::string& header = "",
88 bool ensure_row_contiguous = true,
89 bool atomic_outputs = false);
90
91} // namespace mlx::core::fast
Definition array.h:24
Definition fast.h:9
array layer_norm(const array &x, const std::optional< array > &weight, const std::optional< array > &bias, float eps, StreamOrDevice s={})
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:68
std::function< std::vector< array >(const std::vector< array > &, const std::vector< Shape > &, 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:80
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:15