2024-02-15 06:04:25 +08:00
|
|
|
// Copyright © 2023-2024 Apple Inc.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-03-05 13:06:11 +08:00
|
|
|
#include <optional>
|
|
|
|
|
2024-02-17 11:16:39 +08:00
|
|
|
#include "mlx/utils.h"
|
2024-02-15 06:04:25 +08:00
|
|
|
|
|
|
|
namespace mlx::core::fast {
|
|
|
|
|
2024-03-21 22:20:54 +08:00
|
|
|
array rms_norm(
|
|
|
|
const array& x,
|
|
|
|
const array& weight,
|
|
|
|
float eps,
|
|
|
|
StreamOrDevice s = {});
|
|
|
|
|
2024-03-22 04:55:51 +08:00
|
|
|
array layer_norm(
|
|
|
|
const array& x,
|
|
|
|
const std::optional<array>& weight,
|
|
|
|
const std::optional<array>& bias,
|
|
|
|
float eps,
|
|
|
|
StreamOrDevice s = {});
|
|
|
|
|
2024-02-15 06:04:25 +08:00
|
|
|
array rope(
|
|
|
|
const array& x,
|
|
|
|
int dims,
|
|
|
|
bool traditional,
|
|
|
|
float base,
|
|
|
|
float scale,
|
|
|
|
int offset,
|
2024-03-21 22:20:54 +08:00
|
|
|
StreamOrDevice s = {});
|
2024-02-15 06:04:25 +08:00
|
|
|
|
2024-03-05 13:06:11 +08:00
|
|
|
/** Computes: O = softmax(Q @ K.T) @ V **/
|
|
|
|
array scaled_dot_product_attention(
|
|
|
|
const array& queries,
|
|
|
|
const array& keys,
|
|
|
|
const array& values,
|
|
|
|
const float scale,
|
|
|
|
const std::optional<array>& mask = std::nullopt,
|
|
|
|
StreamOrDevice s = {});
|
|
|
|
|
2024-02-15 06:04:25 +08:00
|
|
|
} // namespace mlx::core::fast
|