### Load Toolformer Model and Tokenizer for Inference Source: https://github.com/conceptofmind/toolformer/blob/main/README.md Loads the Toolformer model and tokenizer from Hugging Face for text generation. Ensure you have the transformers library installed. This snippet is for setting up the inference pipeline. ```python import torch from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline tokenizer = AutoTokenizer.from_pretrained(r"dmayhem93/toolformer_v0_epoch2") model = AutoModelForCausalLM.from_pretrained( r"dmayhem93/toolformer_v0_epoch2", torch_dtype=torch.float16, low_cpu_mem_usage=True, ).cuda() generator = pipeline( "text-generation", model=model, tokenizer=tokenizer, device=0 ) ``` -------------------------------- ### Set up and Use Retriever for Data Retrieval Source: https://github.com/conceptofmind/toolformer/blob/main/README.md Initializes a Retriever tool and demonstrates its usage for retrieving relevant strings from a dataset based on a query. This snippet requires a 'retrieval_test_data.json' file. ```python from tools import Retriever import json if __name__ == '__main__': retriever = Retriever() ret_val = "location of New Orleans" with open('retrieval_test_data.json', encoding='utf-8') as f: ret_strings = json.load(f) print(', '.join(retriever.retrieval( ret_strings, ret_val, 3 ))) ``` -------------------------------- ### Run Data Generator with Multiple Devices Source: https://github.com/conceptofmind/toolformer/blob/main/README.md Launches the data generation script to run on multiple devices concurrently. Adjust 'x' to the total number of devices and 'y' to the specific device ID for this instance. ```bash python data_generator.py --num_devices=x, --device_id=y ``` -------------------------------- ### Toolformer Training Command Source: https://github.com/conceptofmind/toolformer/blob/main/README.md This command is used to fine-tune the GPT-J 6B model for Toolformer. It specifies batch size, epochs, output directory, dataset, tokenizer, and various training parameters including deepspeed configuration. ```bash deepspeed train_gptj_toolformer.py --model_name_or_path=EleutherAI/gpt-j-6B --per_device_train_batch_size=4 \ --num_train_epochs 10 --save_strategy=epoch --output_dir=finetune_toolformer_v0 --report_to "wandb" \ --dataset_name dmayhem93/toolformer-v0-postprocessed --tokenizer_name customToolformer \ --block_size 2048 --gradient_accumulation_steps 1 --do_train --do_eval --evaluation_strategy=epoch \ --logging_strategy=epoch --fp16 --overwrite_output_dir --adam_beta1=0.9 --adam_beta2=0.999 \ --weight_decay=2e-02 --learning_rate=1e-05 --warmup_steps=100 --per_device_eval_batch_size=1 \ --cache_dir="hf_cache" --gradient_checkpointing=True --deepspeed ds_config_gpt_j.json ``` -------------------------------- ### Run Data Generator on a Single Device Source: https://github.com/conceptofmind/toolformer/blob/main/README.md Executes the data generation script on a single device, typically used when only one GPU is available. Sets the number of devices to 1 and the device ID to 0. ```bash python data_generator.py --num_devices=1, --device_id=0 ``` -------------------------------- ### FlashAttention Paper Citation Source: https://github.com/conceptofmind/toolformer/blob/main/README.md BibTeX entry for the paper 'Flashattention: Fast and memory-efficient exact attention with io-awareness'. ```bibtex @Article{dao2022flashattention, title={Flashattention: Fast and memory-efficient exact attention with io-awareness}, author={Dao, Tri and Fu, Daniel Y and Ermon, Stefano and Rudra, Atri and R{'e}, Christopher}, journal={arXiv preprint arXiv:2205.14135}, year={2022} } ``` -------------------------------- ### Toolformer Paper Citation Source: https://github.com/conceptofmind/toolformer/blob/main/README.md BibTeX entry for the Toolformer paper, 'Toolformer: Language Models Can Teach Themselves to Use Tools'. ```bibtex @misc{https://doi.org/10.48550/arxiv.2302.04761, doi = {10.48550/ARXIV.2302.04761}, url = {https://arxiv.org/abs/2302.04761}, author = {Schick, Timo and Dwivedi-Yu, Jane and Dessì, Roberto and Raileanu, Roberta and Lomeli, Maria and Zettlemoyer, Luke and Cancedda, Nicola and Scialom, Thomas}, keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences}, title = {Toolformer: Language Models Can Teach Themselves to Use Tools}, publisher = {arXiv}, year = {2023}, copyright = {arXiv.org perpetual, non-exclusive license} } ``` -------------------------------- ### Set CUDA Visible Devices for Data Generation Source: https://github.com/conceptofmind/toolformer/blob/main/README.md Configures the CUDA_VISIBLE_DEVICES environment variable to specify which GPU(s) the data generation script should use. This is useful in multi-GPU environments. ```bash export CUDA_VISIBLE_DEVICES=5 python data_generator.py --num_devices=8, --device_id=5 ``` -------------------------------- ### Long Context Transformer Citation Source: https://github.com/conceptofmind/toolformer/blob/main/README.md BibTeX entry for the software 'Long Context Transformer v0.0.1'. ```bibtex @software{Liang_Long_Context_Transformer_2023, author = {Liang, Kaizhao}, doi = {10.5281/zenodo.7651809}, month = {2}, title = {{Long Context Transformer v0.0.1}}, url = {https://github.com/github/linguist}, version = {0.0.1}, year = {2023} } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.