Safetensors
GGUF
Turkish
llama
Llama-3
instruct
finetune
chatml
gpt4
synthetic data
distillation
function calling
json mode
axolotl
roleplaying
chat
Instructions to use tda45/TdAI with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- llama-cpp-python
How to use tda45/TdAI with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="tda45/TdAI", filename="llama.cpp/models/ggml-vocab-aquila.gguf", )
output = llm( "Once upon a time,", max_tokens=512, echo=True ) print(output)
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use tda45/TdAI with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf tda45/TdAI # Run inference directly in the terminal: llama cli -hf tda45/TdAI
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf tda45/TdAI # Run inference directly in the terminal: llama cli -hf tda45/TdAI
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf tda45/TdAI # Run inference directly in the terminal: ./llama-cli -hf tda45/TdAI
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf tda45/TdAI # Run inference directly in the terminal: ./build/bin/llama-cli -hf tda45/TdAI
Use Docker
docker model run hf.co/tda45/TdAI
- LM Studio
- Jan
- Ollama
How to use tda45/TdAI with Ollama:
ollama run hf.co/tda45/TdAI
- Unsloth Studio
How to use tda45/TdAI with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for tda45/TdAI to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for tda45/TdAI to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for tda45/TdAI to start chatting
- Atomic Chat new
- Docker Model Runner
How to use tda45/TdAI with Docker Model Runner:
docker model run hf.co/tda45/TdAI
- Lemonade
How to use tda45/TdAI with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull tda45/TdAI
Run and chat with the model
lemonade run user.TdAI-{{QUANT_TAG}}List all available models
lemonade list
| int main(int argc, char ** argv){ | |
| std::setlocale(LC_NUMERIC, "C"); | |
| common_params params; | |
| common_init(); | |
| if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_LOOKUP)) { | |
| return 1; | |
| } | |
| // max. number of additional tokens to draft if match is found | |
| const int n_draft = params.speculative.draft.n_max; | |
| // init llama.cpp | |
| llama_backend_init(); | |
| llama_numa_init(params.numa); | |
| // load the model | |
| auto llama_init = common_init_from_params(params); | |
| auto * model = llama_init->model(); | |
| auto * ctx = llama_init->context(); | |
| const llama_vocab * vocab = llama_model_get_vocab(model); | |
| // tokenize the prompt | |
| std::vector<llama_token> inp; | |
| inp = common_tokenize(ctx, params.prompt, true, true); | |
| common_ngram_cache ngram_cache_context; | |
| common_ngram_cache ngram_cache_dynamic; | |
| common_ngram_cache ngram_cache_static; | |
| int64_t t_draft_flat_us = 0; | |
| int64_t t_draft_us = 0; | |
| { | |
| // Fill up context ngram cache with tokens from user input: | |
| const int64_t t_start_draft_us = ggml_time_us(); | |
| common_ngram_cache_update(ngram_cache_context, LLAMA_NGRAM_MIN, LLAMA_NGRAM_MAX, inp, inp.size(), false); | |
| if (!params.speculative.ngram_cache.lookup_cache_static.empty()) { | |
| try { | |
| ngram_cache_static = common_ngram_cache_load(params.speculative.ngram_cache.lookup_cache_static); | |
| } catch (std::ifstream::failure const &) { | |
| LOG_ERR("failed to open static lookup cache: %s", params.speculative.ngram_cache.lookup_cache_static.c_str()); | |
| exit(1); | |
| } | |
| } | |
| if (!params.speculative.ngram_cache.lookup_cache_dynamic.empty()) { | |
| try { | |
| ngram_cache_dynamic = common_ngram_cache_load(params.speculative.ngram_cache.lookup_cache_dynamic); | |
| } catch (std::ifstream::failure const &) {} // if the file does not exist it will simply be created at the end of the program | |
| } | |
| t_draft_flat_us += ggml_time_us() - t_start_draft_us; | |
| } | |
| const int max_context_size = llama_n_ctx(ctx); | |
| const int max_tokens_list_size = max_context_size - 4; | |
| if ((int) inp.size() > max_tokens_list_size) { | |
| LOG_ERR("%s: prompt too long (%d tokens, max %d)\n", __func__, (int) inp.size(), max_tokens_list_size); | |
| return 1; | |
| } | |
| LOG("\n\n"); | |
| for (auto id : inp) { | |
| LOG("%s", common_token_to_piece(ctx, id).c_str()); | |
| } | |
| fflush(stderr); | |
| const int n_input = inp.size(); | |
| const auto t_enc_start = ggml_time_us(); | |
| llama_decode(ctx, llama_batch_get_one( inp.data(), n_input - 1)); | |
| llama_decode(ctx, llama_batch_get_one(&inp.back(), 1)); | |
| const auto t_enc_end = ggml_time_us(); | |
| int n_predict = 0; | |
| int n_drafted = 0; | |
| int n_accept = 0; | |
| int n_past = inp.size(); | |
| bool has_eos = false; | |
| struct common_sampler * smpl = common_sampler_init(model, params.sampling); | |
| std::vector<llama_token> draft; | |
| llama_batch batch_tgt = llama_batch_init(llama_n_ctx(ctx), 0, 1); | |
| const auto t_dec_start = ggml_time_us(); | |
| while (true) { | |
| // print current draft sequence | |
| LOG_DBG("drafted %s\n", string_from(ctx, draft).c_str()); | |
| int i_dft = 0; | |
| while (true) { | |
| // sample from the target model | |
| llama_token id = common_sampler_sample(smpl, ctx, i_dft); | |
| common_sampler_accept(smpl, id, true); | |
| const std::string token_str = common_token_to_piece(ctx, id); | |
| if (!params.use_color) { | |
| LOG("%s", token_str.c_str()); | |
| } | |
| if (llama_vocab_is_eog(vocab, id)) { | |
| has_eos = true; | |
| } | |
| ++n_predict; | |
| // check if the target token matches the draft | |
| if (i_dft < (int) draft.size() && id == draft[i_dft]) { | |
| LOG_DBG("the sampled target token matches the %dth drafted token (%d, '%s') - accepted\n", i_dft, id, token_str.c_str()); | |
| ++n_accept; | |
| ++n_past; | |
| ++i_dft; | |
| inp.push_back(id); | |
| { | |
| // Update context ngram cache with the newly accepted token: | |
| const int64_t t_start_draft_us = ggml_time_us(); | |
| common_ngram_cache_update(ngram_cache_context, LLAMA_NGRAM_MIN, LLAMA_NGRAM_MAX, inp, 1, false); | |
| t_draft_us += ggml_time_us() - t_start_draft_us; | |
| } | |
| if (params.use_color) { | |
| // color accepted draft token | |
| LOG("\033[34m%s\033[0m", token_str.c_str()); | |
| fflush(stdout); | |
| } | |
| continue; | |
| } | |
| if (params.use_color) { | |
| LOG("%s", token_str.c_str()); | |
| } | |
| fflush(stdout); | |
| LOG_DBG("the sampled target token (%d, '%s') did not match, or we ran out of drafted tokens\n", id, token_str.c_str()); | |
| draft.clear(); | |
| draft.push_back(id); | |
| inp.push_back(id); | |
| { | |
| // Update context ngram cache with the newly accepted token: | |
| const int64_t t_start_draft_us = ggml_time_us(); | |
| common_ngram_cache_update(ngram_cache_context, LLAMA_NGRAM_MIN, LLAMA_NGRAM_MAX, inp, 1, false); | |
| t_draft_us += ggml_time_us() - t_start_draft_us; | |
| } | |
| break; | |
| } | |
| if ((params.n_predict > 0 && n_predict > params.n_predict) || has_eos) { | |
| break; | |
| } | |
| // KV cache management | |
| // clean the cache of draft tokens that weren't accepted | |
| llama_memory_seq_rm(llama_get_memory(ctx), 0, n_past, -1); | |
| common_batch_clear(batch_tgt); | |
| common_batch_add(batch_tgt, draft[0], n_past, { 0 }, true); | |
| // Draft already contains a single token sampled from the model: | |
| GGML_ASSERT(draft.size() == 1); | |
| GGML_ASSERT(draft[0] == inp.back()); | |
| const int64_t t_start_draft_us = ggml_time_us(); | |
| common_ngram_cache_draft(inp, draft, n_draft, LLAMA_NGRAM_MIN, LLAMA_NGRAM_MAX, ngram_cache_context, ngram_cache_dynamic, ngram_cache_static); | |
| for (size_t i = 1; i < draft.size(); ++i) { | |
| common_batch_add(batch_tgt, draft[i], n_past + i, { 0 }, true); | |
| } | |
| t_draft_us += ggml_time_us() - t_start_draft_us; | |
| n_drafted += draft.size() - 1; | |
| llama_decode(ctx, batch_tgt); | |
| ++n_past; | |
| draft.erase(draft.begin()); | |
| } | |
| auto t_dec_end = ggml_time_us(); | |
| // Update dynamic ngram cache with context ngram cache and save it to disk: | |
| common_ngram_cache_merge(ngram_cache_dynamic, ngram_cache_context); | |
| common_ngram_cache_save(ngram_cache_dynamic, params.speculative.ngram_cache.lookup_cache_dynamic); | |
| LOG("\n\n"); | |
| LOG_INF("encoded %4d tokens in %8.3f seconds, speed: %8.3f t/s\n", n_input, (t_enc_end - t_enc_start) / 1e6f, inp.size() / ((t_enc_end - t_enc_start) / 1e6f)); | |
| LOG_INF("decoded %4d tokens in %8.3f seconds, speed: %8.3f t/s\n", n_predict, (t_dec_end - t_dec_start) / 1e6f, n_predict / ((t_dec_end - t_dec_start) / 1e6f)); | |
| LOG_INF("\n"); | |
| LOG_INF("n_draft = %d\n", n_draft); | |
| LOG_INF("n_predict = %d\n", n_predict); | |
| LOG_INF("n_drafted = %d\n", n_drafted); | |
| LOG_INF("t_draft_flat = %.2f ms\n", t_draft_flat_us*1e-3); | |
| LOG_INF("t_draft = %.2f ms, %.2f us per token, %.2f tokens per second\n", | |
| t_draft_us*1e-3, 1.0f*t_draft_us/n_drafted, n_drafted/(1e-6*t_draft_us)); | |
| LOG_INF("n_accept = %d\n", n_accept); | |
| LOG_INF("accept = %.3f%%\n", 100.0f * n_accept / n_drafted); | |
| LOG_INF("\ntarget:\n\n"); | |
| common_perf_print(ctx, smpl); | |
| common_sampler_free(smpl); | |
| llama_batch_free(batch_tgt); | |
| llama_backend_free(); | |
| LOG("\n\n"); | |
| return 0; | |
| } | |