CoolFace
Modelpublic

Felipe97/llama-cpp-compiled

sourceHugging Faceupdated 2d agoView on Hugging Face
0likes1.1kdownloads
llama.cpp149 linesDownload Raw Back to app
1#include "build-info.h"2 3#include "llama.h"4 5#include <cstdio>6#include <cstdlib>7#include <string>8#include <vector>9 10// embedded data generated by cmake11extern const char * LICENSES[];12 13// visible14int llama_server(int argc, char ** argv);15int llama_cli(int argc, char ** argv);16 17// hidden18int llama_completion(int argc, char ** argv);19int llama_bench(int argc, char ** argv);20int llama_batched_bench(int argc, char ** argv);21int llama_fit_params(int argc, char ** argv);22int llama_quantize(int argc, char ** argv);23int llama_perplexity(int argc, char ** argv);24int llama_download(int argc, char ** argv);25 26// Self-update is only supported for binaries built with llama-install.sh27static int llama_update(int argc, char ** argv) {28    (void) argc;29    (void) argv;30 31#ifdef LLAMA_INSTALL_BUILD32#if defined(_WIN32)33    return system("powershell -NoProfile -ExecutionPolicy Bypass -Command \"irm https://llama.app/install.ps1 | iex\"");34#else35    return system("curl -fsSL https://llama.app/install.sh | sh");36#endif37#else38    printf("Updates are available only when installed from https://llama.app\n");39    return 1;40#endif41}42 43static const char * progname;44 45static int help(int argc, char ** argv);46static int version(int argc, char ** argv);47static int licenses(int argc, char ** argv);48 49struct command {50    const char * name;51    const char * desc;52    std::vector<std::string> aliases;53    bool hidden;54    int (*func)(int, char **);55    bool flags = false; // allow --name56};57 58#ifdef LLAMA_INSTALL_BUILD59#define UPDATE_HIDDEN false60#else61#define UPDATE_HIDDEN true62#endif63 64static const command cmds[] = {65    {"serve",         "HTTP API server",                                    {"server"},   false,         llama_server       },66    {"cli",           "Command-line interactive interface",                 {"client"},   false,         llama_cli          },67    {"update",        "Update llama to the latest release",                 {},           UPDATE_HIDDEN, llama_update       },68    {"download",      "Download a model",                                   {"get"},      false,         llama_download     },69    {"completion",    "Text completion",                                    {"complete"}, true,          llama_completion   },70    {"bench",         "Benchmark prompt processing and text generation",    {},           true,          llama_bench        },71    {"batched-bench", "Benchmark batched decoding performance",             {},           true,          llama_batched_bench},72    {"fit-params",    "Compute parameters to fit a model in device memory", {},           true,          llama_fit_params   },73    {"quantize",      "Quantize a model",                                   {},           true,          llama_quantize     },74    {"perplexity",    "Compute model perplexity and KL divergence",         {},           true,          llama_perplexity   },75    {"version",       "Show version",                                       {},           false,         version,           true },76    {"licenses",      "Show third-party licenses",                          {"credits"},  false,         licenses,          true },77    {"help",          "Show available commands",                            {},           false,         help,              true },78};79 80#undef UPDATE_HIDDEN81 82static int version(int /*argc*/, char ** /*argv*/) {83    llama_print_build_info(llama_version(), stdout);84    return 0;85}86 87static int licenses(int /*argc*/, char ** /*argv*/) {88    for (int i = 0; LICENSES[i]; ++i) {89        printf("%s\n", LICENSES[i]);90    }91    return 0;92}93 94static int help(int argc, char ** argv) {95    const bool show_all = argc >= 2 && std::string(argv[1]) == "all";96 97    printf("Usage: %s <command> [options]\n\nAvailable commands:\n", progname);98 99    for (const auto & cmd : cmds) {100        if (show_all || !cmd.hidden) {101            printf("  %-15s %s\n", cmd.name, cmd.desc);102        }103    }104    printf("\n");105 106    if (!show_all) {107        printf("Run '%s help all' to show additional commands.\n", progname);108    }109    printf("Run '%s <command> --help' for command-specific usage.\n", progname);110 111    return 0;112}113 114static bool matches(std::string arg, const command & cmd) {115    if (cmd.flags && arg.size() > 2 && arg[0] == '-' && arg[1] == '-') {116        arg.erase(0, 2);117    }118    if (arg == cmd.name) {119        return true;120    }121    for (const auto & alias : cmd.aliases) {122        if (arg == alias) {123            return true;124        }125    }126    return false;127}128 129int main(int argc, char ** argv) {130    progname = argv[0];131 132    const std::string arg = argc >= 2 ? argv[1] : "help";133 134    for (const auto & cmd : cmds) {135        if (matches(arg, cmd)) {136            // keep cmd.name so the router's child processes re-invoke correctly137#ifdef _WIN32138            _putenv_s("LLAMA_APP_CMD", cmd.name);139#else140            setenv("LLAMA_APP_CMD", cmd.name, 1);141#endif142            return cmd.func(argc - 1, argv + 1);143        }144    }145 146    fprintf(stderr, "error: unknown command '%s'\n", arg.c_str());147    return 1;148}149