-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmix.exs
More file actions
171 lines (152 loc) · 4.78 KB
/
Copy pathmix.exs
File metadata and controls
171 lines (152 loc) · 4.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
defmodule LlamaCppEx.Precompiler do
@moduledoc false
@all_targets ["aarch64-apple-darwin", "x86_64-linux-gnu"]
def all_supported_targets(:fetch), do: @all_targets
def all_supported_targets(:compile) do
case current_target() do
{:ok, target} -> [target]
_ -> []
end
end
def current_target do
system_arch = to_string(:erlang.system_info(:system_architecture))
cond do
system_arch =~ ~r/aarch64.*apple.*darwin/ -> {:ok, "aarch64-apple-darwin"}
system_arch =~ ~r/x86_64.*linux.*gnu/ -> {:ok, "x86_64-linux-gnu"}
true -> {:error, "unsupported target: #{system_arch}"}
end
end
def build_native(args), do: ElixirMake.Precompiler.mix_compile(args)
def precompile(args, _target) do
case ElixirMake.Precompiler.mix_compile(args) do
{:ok, _} -> :ok
error -> error
end
end
def unavailable_target(_target), do: :compile
end
defmodule LlamaCppEx.MixProject do
use Mix.Project
@version "0.8.37"
@source_url "https://github.com/nyo16/llama_cpp_ex"
def project do
[
app: :llama_cpp_ex,
version: @version,
elixir: "~> 1.18",
start_permanent: Mix.env() == :prod,
deps: deps(),
compilers: Mix.compilers() ++ [:elixir_make],
make_env: &make_env/0,
make_clean: ["clean"],
make_precompiler: {:nif, LlamaCppEx.Precompiler},
make_precompiler_url:
"https://github.com/nyo16/llama_cpp_ex/releases/download/v#{@version}/@{artefact_filename}",
make_precompiler_filename: "llama_cpp_ex_nif",
make_precompiler_priv_paths: ["llama_cpp_ex_nif.so"],
make_precompiler_nif_versions: [versions: ["2.17", "2.18"]],
make_force_build: System.get_env("LLAMA_BACKEND") != nil,
description: description(),
package: package(),
name: "LlamaCppEx",
source_url: @source_url,
homepage_url: @source_url,
docs: docs()
]
end
def application do
[extra_applications: [:logger]]
end
defp deps do
[
{:elixir_make, "~> 0.8", runtime: false},
{:fine, "~> 0.1", runtime: false},
{:telemetry, "~> 1.0"},
{:ecto, "~> 3.0", optional: true},
{:req, "~> 0.5", optional: true},
{:ex_doc, "~> 0.34", only: :dev, runtime: false},
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false},
{:benchee, "~> 1.0", only: :bench, runtime: false},
{:benchee_html, "~> 1.0", only: :bench, runtime: false}
]
end
defp description do
"Elixir bindings for llama.cpp — run LLMs locally with Metal, CUDA, Vulkan, or CPU acceleration."
end
defp package do
[
name: "llama_cpp_ex",
licenses: ["Apache-2.0"],
links: %{
"GitHub" => @source_url,
"Changelog" => "https://hexdocs.pm/llama_cpp_ex/changelog.html",
"llama.cpp" => "https://github.com/ggml-org/llama.cpp"
},
files: ~w(
lib c_src Makefile mix.exs README.md CHANGELOG.md LICENSE .formatter.exs
checksum.exs
)
]
end
defp docs do
[
main: "readme",
extras: [
"README.md",
"CHANGELOG.md",
"LICENSE",
"docs/architecture.md",
"docs/cross-platform-builds.md",
"docs/adr/001-cpp-nif-over-rustler.md",
"docs/adr/002-fine-for-nif-ergonomics.md",
"docs/adr/003-static-linking.md",
"docs/adr/004-streaming-via-enif-send.md",
"docs/adr/005-batching-architecture.md",
"docs/adr/006-continuous-batching.md",
"docs/adr/007-prefix-caching.md",
"docs/adr/008-batching-strategies.md",
"docs/examples.md",
"docs/performance.md",
"docs/release-guide.md"
],
groups_for_extras: [
"Architecture Decision Records": ~r/docs\/adr\/.*/
],
groups_for_modules: [
"High-Level API": [LlamaCppEx],
"Core Modules": [
LlamaCppEx.Model,
LlamaCppEx.Context,
LlamaCppEx.Sampler,
LlamaCppEx.Tokenizer,
LlamaCppEx.Chat,
LlamaCppEx.Embedding,
LlamaCppEx.Grammar,
LlamaCppEx.Schema,
LlamaCppEx.Server,
LlamaCppEx.Hub
],
"Batching Strategies": [
LlamaCppEx.Server.BatchStrategy,
LlamaCppEx.Server.Strategy.DecodeMaximal,
LlamaCppEx.Server.Strategy.PrefillPriority,
LlamaCppEx.Server.Strategy.Balanced
],
Internal: [LlamaCppEx.NIF]
]
]
end
defp make_env do
env = %{"FINE_INCLUDE_DIR" => Fine.include_dir()}
env =
case System.get_env("LLAMA_BACKEND") do
nil -> env
backend -> Map.put(env, "LLAMA_BACKEND", backend)
end
case System.get_env("LLAMA_CMAKE_ARGS") do
nil -> env
args -> Map.put(env, "LLAMA_CMAKE_ARGS", args)
end
end
end