Large Language Models: Library Overview for Training, Fine-Tuning, Intererence and More
Tags: llm, machinelearning
Published: 2024-03-04 06:11:56

In essence, Large Language Models are neural networks with a transformer architecture. The evolution of LLMs is a history of scaling: input data sources and tokenization, training methods and pipeline, model architecture and number of parameters, and hardware required for training and interference with large language models. For all of these concerns, dedicated libraries emerged that provide the necessary support for this continued evolution.

This article provides a concise snapshot of libraries for LLM training, fine-tuning, interference, optimizations, vector databases, and utilities.

_This article was written in December 2023. The availability of the libraries may have changed until the publication date of this article_.

_This article originally appeared at my blog [admantium.com](https://admantium.com/blog/llm06_general_library_overview/)_.

### LLM Training

The training of LLMs needs high-level scheduling of input batches, gradient calculation and gradient updates for multiple nodes and GPUs.

- [Alpa](https://github.com/alpa-projects/alpa): Python project to train and run LLMs with on-premise GPU clusters.
- [Colossoal AI](https://github.com/hpcaitech/ColossalAI#OPT): Distributed training of LLMs that supports two specific forms of reinforcement learning: reward model creation and reinforcement learning with human intervention.
- [GPTNeoX](https://github.com/EleutherAI/gpt-neox): A library for efficiently scale training on several GPUs.
- [Fairscale](https://github.com/facebookresearch/fairscale): A PyTorch expansion for efficient data batching when training on a restricted amount of GPUs.
- [DeepSpeed](https://github.com/microsoft/DeepSpeed): Distributed training and interference.
- [JAX](https://github.com/google/jax): Combines two libraries into a coherent framework to execute machine learning pipelines parallelly on several nodes. It includes the [Tensorflow XLA](https://www.tensorflow.org/xla) library that provides just-in-time compilation for running on GPU, TPU or CPU, and the [Autograd](https://github.com/hips/autograd) function to compute function derivatives.
- [Megatron-LM](https://github.com/NVIDIA/Megatron-LM): A framework for multi-node and model-parallel training of transformer models.
- [T5X](https://github.com/google-research/t5x): An integrated framework for training, evaluation and interference.

### LLM Fine-Tuning

Pretrained LLMs, also called foundation models, need to be customized for specific domains and with specific training materials. This fine-tuning process produces models with desired capabilities and content.

- [llama_index](https://github.com/run-llama/llama_index): A framework for designing data ingestion pipelines to fine-tune LLMs with private data sources.
- [nanoGPT](https://github.com/karpathy/nanoGPT): Training and fine-tuning GPT2 models.
- [promptsource](https://github.com/bigscience-workshop/promptsource/): A tool for managing versioned NLP prompts, which can be used for example during fine-tuning.
- [trlx](https://github.com/CarperAI/trlx): Fine-tuning with using reinforcement learning by using a reward function or a reward-labeled dataset.
- [xturing](https://github.com/stochasticai/xturing): Complete and coherent fine-tuning of transformer models including data ingestion, multiple GPU training, and model optimizations like INT4 and LoRa.

### LLM Interference

Trained and potentially fine-tuned models needed to be loaded in memory and feed with appropriated tokenized input that matches the same structure that was used for training. The output of LLMs, which are neural networks, is a numerical representation that needs to be converted to text again. Interference libraries solve these task and allow users to work with texts.

- [Embedchain](https://github.com/embedchain/embedchain): A python library for designing retrieval-augment generation prompts using a simple API to reference external datasources and loading different LLMs as the application base.
- [ggml](https://github.com/ggerganov/ggml): LLM interference for Tensorflow models supporting CPU and GPU interaction. Subprojects for running LLMs exists, sich as [llama](https://github.com/ggerganov/llama.cpp) and [whisper](https://github.com/ggerganov/whisper.cpp).
- [lit-gpt](https://github.com/Lightning-AI/lit-gpt): A Python library for running several open source LLMs locally, such as LLaMA, Mistral, or StableLM.
- [lit-llama](https://github.com/lightning-AI/lit-llama): Running LLaMA models locally.
- [llama2.c](https://github.com/karpathy/llama2.c): Running fine-tuned LLaMA models.
- [LLMZoo]( https://github.com/FreedomIntelligence/LLMZoo): A framework for running open-source LLMs, and it also includes feature for training/fine-tuning and evaluating LLMs, as well as datasets.
- [Transformers](https://huggingface.co/transformers): Transformers is a versatile library for loading many pretrained models and incorporate them into a PyTorch or TensorFlow pipeline. This library exposes its models as objects with convenient methods that help to introspect and transform its properties.

### LLM Interference Optimizations

Interference is a compute-heavy process. Utilizing optimizations based on the trained model, such as reducing the floating-point precision, greatly reduces required resources with only minimal performance impact.

- [bitsandbytes](https://github.com/TimDettmers/bitsandbytes): Provides 8bit CUDA functions for training with PyTorch. It is used to parametrize the Transformer model definition.
- [peft](https://github.com/huggingface/peft): An acronym for parameter-efficient fine-tuning methods. This library enables the exposure and modification of trainable parameters from an LLM. It is used to define the custom quantization properties that create an abstracted model.
- [TensorRT-LLM](https://github.com/NVIDIA/TensorRT-LLM): A LLM interference optimizer that provides a high-level Python API for loading LLMs as well as creating standalone Python and C++ runtimes for executing LLMs. It also contains an integration to the Triton Interference Servers. Earlier known as [FasterTransformer](https://github.com/NVIDIA/FasterTransformer).

### LLM Interference Vector Databases

Vectors for single words or complete documents can be stored in a vector database. Providing embeddings in a simple-access store enables fast-retrieval during training, but are mostly used at interference time for providing textual context in prompts.

- [Chroma](https://www.trychroma.com/): Open-source project with Python bindings and API support for several large language models. The embeddings format can be tailored towards its use case: Default type is sentence transformer, but it can also work with OpenAI embeddings for GPT.
- [Milvus](https://milvus.io/): Provides a Kubernetes-ready database with convenient Python bindings. Internally, the key-value store [MinIO](https://min.io) is used.
- [PineCone](https://www.pinecone.io): An enterprise solution that offers managed GCP and AWS platforms for embeddings.
- [Postgres pgvector](https://github.com/pgvector/pgvector) An open-source extension to Postgres that allows the creation of custom schema to hold word vectors.
- [Redis Enterprise](https://redis.com/solutions/use-cases/vector-database/) An enterprise-only feature of Redis to store text, audio and video as vectors and even perform similarity comparisons with build-in commands.
- [Weaviate](https://weaviate.io/): Open-Source project that stores text documents and their vectors as JSON data and offers an easy-to-use API that processes GraphQL like requests for similarity searches.

## LLM Cloud Environment

All major cloud providers offer dedicated platforms to support at least training and interferences, if not all LLM lifecycle phases, as a paid service.

- [Enterprise-AI](https://www.nvidia.com/en-us/data-center/products/ai-enterprise/): Nvidias cloud platform for developing and hosting AI models, supporting tight integration with their [Triton SDK](https://www.nvidia.com/en-us/ai-data-science/products/triton-inference-server/) for developing interference server runners.
- [Fabric](https://www.microsoft.com/de-de/microsoft-fabric): Microsoft cloud platform covering the complete lifecycle of LLM development and interference.
- [Vertex AI](https://cloud.google.com/vertex-ai): Googles cloud platform for training and hosting LLMs and other generative AI models.

## LLM Utilities

This section includes other interesting projects or products I encountered during research.

- [evals](https://github.com/openai/evals): A framework for evaluating LLMs.
- [LLMOps](https://github.com/microsoft/lmops): Meta repository about Microsoft Research LLM projects, including prompts, acceleration, and alignment.
- [Meta Group](https://huggingface.co/facebook): All models published by Meta, including [Metaseq](https://github.com/facebookresearch/metaseq) for pretrained Transformer models.
- [Nebuly](https://www.nebuly.com/): Platform for getting user analytics from LLMs.
- [XManager](https://github.com/google-deepmind/xmanager): A platform for running and packaging machine learning projects that can be executed locally or via Google Cloud Platform.
- [Lambda Stack](https://lambdalabs.com/lambda-stack-deep-learning-software): A multi-repository that includes Tensorflow, Keras, PyTorch and Cuda support bundled into one package.

## Conclusion

The landscape of LLMs is huge. This article listed more than 30 libraries that can be used for LLM training, fine-tuning, interference, interference optimization and vector databases. It also listed cloud provider applications and other projects in the context of LLMs.