Repository: OptimalScale/LMFlow Branch: main Commit: 63a001770e82 Files: 281 Total size: 2.7 MB Directory structure: gitextract_35w5f4e3/ ├── .gitattributes ├── .github/ │ ├── ISSUE_TEMPLATE/ │ │ ├── api-feedback.md │ │ ├── blank-template.md │ │ ├── bug-report.md │ │ └── feature-request.md │ └── workflows/ │ └── documentation.yaml ├── .gitignore ├── .pre-commit-config.yaml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── configs/ │ ├── accelerate_dsz0_config.yaml │ ├── accelerate_dsz2_config.yaml │ ├── accelerate_dsz3_config.yaml │ ├── accelerate_fsdp_config.yaml │ ├── accelerate_singlegpu_config.yaml │ ├── archive/ │ │ ├── accelerate_multigpu_config.yaml │ │ ├── accelerate_singlegpu_config.yaml │ │ ├── ds_config_chatbot.json │ │ ├── ds_config_eval.json │ │ ├── ds_config_multimodal.json │ │ └── ds_config_vis_chatbot.json │ ├── deepspeed/ │ │ ├── zero0_no_offload.json │ │ ├── zero2.json │ │ ├── zero2_no_offload.json │ │ ├── zero3.json │ │ ├── zero3_for_eval.json │ │ └── zero3_no_offload.json │ └── iterative_dpo.yaml ├── contrib/ │ ├── README.md │ ├── langchain/ │ │ ├── README.md │ │ └── retrieval_chatbot.py │ ├── long-context/ │ │ ├── hf_sft_full_finetune.sh │ │ ├── hf_sft_lora_flashattn.sh │ │ └── sft_summarizer.py │ ├── rlhflow/ │ │ ├── reward_modeling.py │ │ └── run_reward_modeling.sh │ ├── text2image/ │ │ ├── README.md │ │ ├── accelerate_t2i_config.yaml │ │ ├── diffuser_args.py │ │ ├── diffuser_finetuner.py │ │ ├── finetune_t2i.py │ │ ├── finetune_t2i.sh │ │ ├── requirements.txt │ │ └── t2i_dataset.py │ └── tool-finetune/ │ ├── README.md │ ├── function_call_finetune.py │ └── run_function_call_finetune.sh ├── docs/ │ ├── dev_notes/ │ │ └── finetuning.mmd │ ├── readme/ │ │ ├── Position_Interpolation.md │ │ ├── README_es.md │ │ ├── README_hindi.md │ │ ├── README_jp.md │ │ ├── README_ko.md │ │ ├── README_zh-hans.md │ │ ├── flash_attn2.md │ │ └── multi_node.md │ ├── requirements.txt │ └── source/ │ ├── _static/ │ │ └── check_before_after_lora_tuning.jsonl │ ├── about/ │ │ ├── authors.md │ │ ├── changelog.md │ │ └── index.md │ ├── blogs/ │ │ ├── benchmark.md │ │ └── index.md │ ├── conf.py │ ├── examples/ │ │ ├── DATASETS.md │ │ ├── TASK_GUIDE.md │ │ ├── checkpoints.md │ │ ├── customize_conversation_template.md │ │ ├── finetuning.md │ │ ├── index.md │ │ ├── medical_finetune.md │ │ ├── raft.md │ │ ├── reward_modeling.md │ │ └── supported_conversation_template.md │ └── index.md ├── examples/ │ ├── benchmarking.py │ ├── chatbot.py │ ├── chatbot_gradio.py │ ├── detail_memory.py │ ├── dpo_train.py │ ├── dpov2_train.py │ ├── evaluation.py │ ├── finetune.py │ ├── finetune_multi_modal.py │ ├── inference.py │ ├── iterative_dpo_train.py │ ├── merge_lora.py │ ├── multistage_finetune.py │ ├── raft_align.py │ ├── reward_modeling.py │ ├── rm_inference.py │ ├── sglang_inference.py │ ├── speculative_inference.py │ ├── tool_inference.py │ ├── vis_chatbot.py │ ├── vis_chatbot_gradio.py │ └── vllm_inference.py ├── experimental/ │ ├── Hymba/ │ │ ├── README.md │ │ └── run_finetune_hymba.sh │ ├── LISA-diffusion/ │ │ ├── README.md │ │ ├── diffusion_dpo/ │ │ │ ├── train_diffusion_dpo.py │ │ │ └── train_diffusion_dpo_lisa.py │ │ ├── instruct_pix2pix/ │ │ │ ├── test_instruct_pix2pix.py │ │ │ └── train_instruct_pix2pix_lisa.py │ │ ├── latent_consistency_model/ │ │ │ ├── train_lcm_distill_sd_wds_lisa.py │ │ │ └── train_lcm_distill_sd_wds_lora.py │ │ ├── requirement.txt │ │ └── single_lisa.py │ └── RAFT-diffusion/ │ ├── README.md │ ├── SD256-RAFT.ipynb │ ├── requirements.txt │ └── train_text_to_image_lora.py ├── pyproject.toml ├── requirements.txt ├── scripts/ │ ├── archive/ │ │ ├── bash.sh │ │ ├── convert_llama_weights_to_hf.py │ │ ├── download_model.sh │ │ ├── export_llama_state_dict_checkpoint.py │ │ ├── run_all_benchmark.sh │ │ ├── run_app.sh │ │ ├── run_benchmark.sh │ │ ├── run_chatbot.sh │ │ ├── run_chatbot_chatglm.sh │ │ ├── run_chatbot_cpu.sh │ │ ├── run_detail_gpu_memory.sh │ │ ├── run_dpo_align.sh │ │ ├── run_dpov2_align.sh │ │ ├── run_evaluation.sh │ │ ├── run_evaluation_accelerator.sh │ │ ├── run_evaluation_with_lora.sh │ │ ├── run_finetune.sh │ │ ├── run_finetune_with_custom_optim.sh │ │ ├── run_finetune_with_lisa.sh │ │ ├── run_finetune_with_lora.sh │ │ ├── run_finetune_with_qlora.sh │ │ ├── run_inference.sh │ │ ├── run_inference_multimodal_model.sh │ │ ├── run_iterative_dpo.sh │ │ ├── run_multistage_finetune.sh │ │ ├── run_raft_align.sh │ │ ├── run_reward_modeling.sh │ │ ├── run_reward_modeling_with_lisa.sh │ │ ├── run_reward_modeling_with_lora.sh │ │ ├── run_rm_inference.sh │ │ ├── run_tool.sh │ │ └── run_vllm_inference.sh │ ├── multimodal/ │ │ ├── README.md │ │ ├── run_finetune_multi_modal_stage1.sh │ │ ├── run_finetune_multi_modal_stage2.sh │ │ ├── run_vis_chatbot_blip2.sh │ │ ├── run_vis_chatbot_gradio_minigpt4.sh │ │ ├── run_vis_chatbot_llava.sh │ │ └── run_vis_chatbot_minigpt4.sh │ ├── run_finetune.sh │ ├── run_finetune_with_custom_optim.sh │ ├── run_finetune_with_lisa.sh │ ├── run_finetune_with_lora.sh │ ├── run_finetune_with_qlora.sh │ ├── run_merge_lora.sh │ ├── run_sglang_inference.sh │ └── run_unittest.sh ├── setup.py ├── src/ │ └── lmflow/ │ ├── __init__.py │ ├── args.py │ ├── datasets/ │ │ ├── __init__.py │ │ ├── dataset.py │ │ └── multi_modal_dataset.py │ ├── models/ │ │ ├── __init__.py │ │ ├── auto_model.py │ │ ├── base_model.py │ │ ├── decoder_model.py │ │ ├── encoder_decoder_model.py │ │ ├── hf_decoder_model.py │ │ ├── hf_model_mixin.py │ │ ├── hf_text_regression_model.py │ │ ├── interfaces/ │ │ │ ├── __init__.py │ │ │ └── tunable.py │ │ ├── regression_model.py │ │ ├── text_regression_model.py │ │ ├── vision2seq_model.py │ │ └── vision_encoder/ │ │ ├── __init__.py │ │ └── clip_encoder.py │ ├── optim/ │ │ ├── __init__.py │ │ ├── adabelief.py │ │ ├── adabound.py │ │ ├── adadelta.py │ │ ├── adagrad.py │ │ ├── adam.py │ │ ├── adamax.py │ │ ├── adamp.py │ │ ├── adamw_schedule_free.py │ │ ├── adan.py │ │ ├── dummy.py │ │ ├── lamb.py │ │ ├── lars.py │ │ ├── muon.py │ │ ├── nadam.py │ │ ├── novograd.py │ │ ├── optimizers.py │ │ ├── radam.py │ │ ├── sgd_schedule_free.py │ │ ├── sgdp.py │ │ ├── sophia.py │ │ ├── utils.py │ │ └── yogi.py │ ├── pipeline/ │ │ ├── __init__.py │ │ ├── auto_pipeline.py │ │ ├── base_aligner.py │ │ ├── base_pipeline.py │ │ ├── base_tuner.py │ │ ├── dpo_aligner.py │ │ ├── dpov2_aligner.py │ │ ├── evaluator.py │ │ ├── finetuner.py │ │ ├── inferencer.py │ │ ├── iterative_dpo_aligner.py │ │ ├── raft_aligner.py │ │ ├── rm_inferencer.py │ │ ├── rm_tuner.py │ │ ├── sglang_inferencer.py │ │ ├── utils/ │ │ │ ├── __init__.py │ │ │ ├── dpov2_dataprocessor.py │ │ │ ├── dpov2_trainer.py │ │ │ ├── lisa_trainer.py │ │ │ ├── memory_safe_dpov2_align.py │ │ │ ├── memory_safe_vllm_inference.py │ │ │ ├── raft_trainer.py │ │ │ ├── rm_dataprocessor.py │ │ │ └── rm_trainer.py │ │ └── vllm_inferencer.py │ ├── tokenization/ │ │ ├── __init__.py │ │ ├── hf_decoder_model.py │ │ └── hf_text_regression_model.py │ ├── utils/ │ │ ├── __init__.py │ │ ├── common.py │ │ ├── constants.py │ │ ├── conversation_template/ │ │ │ ├── __init__.py │ │ │ ├── base.py │ │ │ ├── chatglm.py │ │ │ ├── chatml.py │ │ │ ├── deepseek.py │ │ │ ├── gemma.py │ │ │ ├── hymba.py │ │ │ ├── internlm.py │ │ │ ├── llama.py │ │ │ ├── phi.py │ │ │ ├── qwen.py │ │ │ ├── yi.py │ │ │ └── zephyr.py │ │ ├── data_utils.py │ │ ├── debug/ │ │ │ └── profiler.py │ │ ├── deprecated.py │ │ ├── envs.py │ │ ├── llava_conversation_lib.py │ │ ├── model.py │ │ ├── multimodal.py │ │ ├── position_interpolation/ │ │ │ ├── __init__.py │ │ │ └── llama_rope_scaled_monkey_patch.py │ │ ├── protocol.py │ │ ├── test_utils.py │ │ └── versioning.py │ └── version.py └── tests/ ├── __init__.py ├── conftest.py ├── datasets/ │ ├── __init__.py │ ├── conftest.py │ └── test_dataset.py ├── models/ │ ├── __init__.py │ ├── test_auto_model.py │ ├── test_hf_decoder_model.py │ └── test_tool_inferencer.py ├── pipeline/ │ ├── test_auto_pipeline.py │ ├── test_finetuner_distributed_loss.py │ ├── test_memory_safe_vllm_inferencer.py │ └── test_sglang_infernecer.py └── utils/ ├── __init__.py ├── test_conversation_formatter.py ├── test_conversation_template.py └── test_data_utils.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ *.html linguist-detectable=false *.js linguist-detectable=false *.ipynb linguist-detectable=false *RAFT.pdf filter=lfs diff=lfs merge=lfs -text *.gif filter=lfs diff=lfs merge=lfs -text docs/figs/*.gif filter=lfs diff=lfs merge=lfs -text ================================================ FILE: .github/ISSUE_TEMPLATE/api-feedback.md ================================================ --- name: API Feedback about: Provide feedback regarding the current design of the API. title: "[API Design]" labels: '' assignees: '' --- ================================================ FILE: .github/ISSUE_TEMPLATE/blank-template.md ================================================ --- name: Blank Template about: Other issues title: '' labels: '' assignees: '' --- ================================================ FILE: .github/ISSUE_TEMPLATE/bug-report.md ================================================ --- name: Bug Report about: Create a report to help us improve title: "[BUG]" labels: bug assignees: '' --- **Describe the bug** A clear and concise description of what the bug is. **To Reproduce** Steps to reproduce the behavior: 1. Go to '...' 2. Click on '....' 3. Scroll down to '....' 4. See error **Expected behavior** A clear and concise description of what you expected to happen. **Screenshots** If applicable, add screenshots to help explain your problem. **Desktop (please complete the following information):** - OS: [e.g. iOS] - Browser [e.g. chrome, safari] - Version [e.g. 22] **Smartphone (please complete the following information):** - Device: [e.g. iPhone6] - OS: [e.g. iOS8.1] - Browser [e.g. stock browser, safari] - Version [e.g. 22] **Additional context** Add any other context about the problem here. ================================================ FILE: .github/ISSUE_TEMPLATE/feature-request.md ================================================ --- name: Feature Request about: Suggest an idea for this project title: "[New Feature]" labels: '' assignees: '' --- **Is your feature request related to a problem? Please describe.** A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] **Describe the solution you'd like** A clear and concise description of what you want to happen. **Describe alternatives you've considered** A clear and concise description of any alternative solutions or features you've considered. **Additional context** Add any other context or screenshots about the feature request here. ================================================ FILE: .github/workflows/documentation.yaml ================================================ name: Docs on: [push, pull_request, workflow_dispatch] jobs: docs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: python environment setup uses: actions/setup-python@v5.1.0 with: python-version: "3.11" - name: Install dependencies run: | pip install -r ./docs/requirements.txt - name: Sphinx build run: | sphinx-build docs/source _build - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: publish_branch: gh-pages github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: _build/ force_orphan: true ================================================ FILE: .gitignore ================================================ # Initially taken from Github's Python gitignore file # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class _build # C extensions *.so # tests and logs tests/fixtures/cached_*_text.txt logs/ lightning_logs/ lang_code_data/ log/ regression_test/*/new_output_models regression_test/*/new_log output_dir/ tests_out # data files data/ # output models output_models adapter_model/ # output data output_data/ # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover .hypothesis/ .pytest_cache/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_default/ ipython_config.py # pyenv .python-version # celery beat schedule file celerybeat-schedule # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/ # vscode .vs .vscode # Pycharm .idea # TF code tensorflow_code # Models proc_data # examples runs /runs_old /wandb /examples/runs /examples/**/*.args /examples/rag/sweep # data # /data serialization_dir # emacs *.*~ debug.env # vim .*.swp #ctags tags # .lock *.lock # DS_Store (MacOS) .DS_Store # ruff .ruff_cache # lm_evaluation cache lm_cache/ ================================================ FILE: .pre-commit-config.yaml ================================================ repos: - repo: https://github.com/astral-sh/ruff-pre-commit rev: "v0.11.4" hooks: - id: ruff args: ["--fix", "--show-fixes", "--output-format=full"] exclude: ^.*\.(ipynb)$ - id: ruff-format ================================================ FILE: CODE_OF_CONDUCT.md ================================================ # Contributor Covenant Code of Conduct ## Our Pledge We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. ## Our Standards Examples of behavior that contributes to a positive environment for our community include: * Demonstrating empathy and kindness toward other people * Being respectful of differing opinions, viewpoints, and experiences * Giving and gracefully accepting constructive feedback * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience * Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: * The use of sexualized language or imagery, and sexual attention or advances of any kind * Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or email address, without their explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. ## Scope This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at LMFLow. All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the reporter of any incident. ## Enforcement Guidelines Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: ### 1. Correction **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. ### 2. Warning **Community Impact**: A violation through a single incident or series of actions. **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. ### 3. Temporary Ban **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. ### 4. Permanent Ban **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. **Consequence**: A permanent ban from any sort of public interaction within the community. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see the FAQ at https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. ================================================ FILE: CONTRIBUTING.md ================================================ # LMFlow We welcome contributions from the open-source community with open arms! We value and appreciate all types of participation, not just code. Whether you're answering questions, offering help, improving the documentation, or simply reaching out, your contributions are immensely valuable to us. So, if you're interested, don't hesitate to get involved! To start, we encourage everyone to say hello in our public Discord channel. Here, we discuss the latest trends in Large Foundation models, showcase personal projects, help each other with contributions, or just hang out over a cup of coffee. Join us on Discord! No matter how you choose to contribute, we strive to maintain an open, welcoming, and kind community. We ask that you read our code of conduct and be respectful during your interactions. It's also essential that you become familiar with the ethical guidelines that guide our project and adhere to the same principles of transparency and responsibility. We highly value feedback from the community, so please don't hesitate to speak up if you have any valuable feedback that can help improve the library. We read and consider every message, comment, issue, and pull request (PR). ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================

LMFlow

# LMFlow

English | 简体中文 | Español | 日本語 | 한국어 | हिंदी

[![Website](https://img.shields.io/badge/Website-Demo-20B2AA.svg)](https://lmflow.com) [![Code License](https://img.shields.io/badge/Code%20License-Apache_2.0-green.svg)](https://github.com/OptimalScale/LMFlow/blob/main/LICENSE) [![Python 3.9+](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/downloads/release/python-390/) [![Doc](https://img.shields.io/badge/Website-Doc-ff69b4.svg)](https://optimalscale.github.io/LMFlow/) [![Embark](https://img.shields.io/badge/Discord-LMFlow-%237289da.svg?logo=discord)](https://discord.gg/u9VJNpzhvA) [![slack badge](https://img.shields.io/badge/Slack-Join-blueviolet?logo=slack&)](https://join.slack.com/t/lmflow/shared_invite/zt-1wju9nicy-woXbNtS~5MavHSAtiMxmxQ) [![WeChat badge](https://img.shields.io/badge/WeChat-Join-brightgreen?logo=wechat&)](https://ibb.co/ZhM4hhn) An extensible, convenient, and efficient toolbox for finetuning large machine learning models, designed to be user-friendly, speedy and reliable, and accessible to the entire community.

LMFlow-features

## Latest News > [!IMPORTANT] > * :exclamation: [2025-07-09] We have a major update to LMFlow with full Accelerate support and extensive streamlining. If you're looking for the previous version, please use `git checkout v0.0.10`, or check out the [v0.0.10 branch](https://github.com/OptimalScale/LMFlow/tree/v0.0.10). View all releases [here](https://github.com/OptimalScale/LMFlow/tags). * [2024-12-02] Support [Hymba](https://github.com/NVlabs/hymba), a new family of small language models featuring a hybrid-head parallel architecture. Check out [Post-training Hymba](https://github.com/OptimalScale/LMFlow/tree/main/experimental/Hymba) for more details. * [2024-07-01] 🏆 LMFlow receives the [**Best Demo Paper Award**](https://docs.google.com/presentation/d/1TVDooAZqkNObz5ysVhDFtqnnVHR-u8wqYvgix-gzPMs/edit#slide=id.g2e55907bbcc_0_70) at **NAACL 2024**! 🎉 * [2024-06-30] Expanding Optimization Options! We now support custom optimizer training with a variety of optimizers. Dive into the details and try out the new features with our updated script at [custom_optimizers](https://github.com/OptimalScale/LMFlow/blob/main/scripts/run_finetune_with_custom_optim.sh). * [2024-04-25] :rocket: Support conversation template! We've preset the latest [Llama-3](https://huggingface.co/meta-llama/Meta-Llama-3-70B) and [Phi-3](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct) conversation templates as well as some frequently used templates such as `chatml` (see all templates [here](https://optimalscale.github.io/LMFlow/examples/DATASETS.html#conversation-template)), and we are working on adding more preset templates. Adding corresponding `--conversation_template` in the shell script and you are all set! :rocket:
More news... * [2024-03-27] Support [LISA](https://arxiv.org/abs/2403.17919), enabling 7B training in 24G memory without offloading! * [2023-09-11] Support [speculative decoding](https://arxiv.org/abs/2211.17192). Check out [speculative_decoding](https://github.com/OptimalScale/LMFlow/blob/main/scripts/speculative_decoding/README.md) for the usage and acceleration details. * [2023-08-14] Support long context inference with position interpolation (Linear & NTK scaling ) for LLaMA models. Check out [postion_interpolation](https://github.com/OptimalScale/LMFlow/blob/main/readme/Position_Interpolation.md) for more details. * [2023-08-07] Support [Flash Attention-2](https://crfm.stanford.edu/2023/07/17/flash2.html). Check out [flash_attention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md) for more details. * [2023-08-02] Support [Llama2](https://ai.meta.com/llama/), [ChatGLM2](https://huggingface.co/THUDM/chatglm2-6b), and [Baichuan](https://huggingface.co/baichuan-inc/Baichuan-7B) models. * [2023-07-23] [LMFlow multimodal chatbot](https://github.com/OptimalScale/LMFlow/blob/main/scripts/run_vis_chatbot_gradio_minigpt4.sh) is now available! Support multimodal inputs of images and texts. [Online Demo](http://multimodal.lmflow.online) is also provided (We hold the service on a single GPU, hence one may experience "queuing" or "application busy" sometimes when multiple users are accessing at the same time, please wait and attempt again later when such event happens)![image](https://github.com/OptimalScale/LMFlow/blob/rpan-vision-encoder/docs/assets/multimodal-chatbot-demo.gif) * [2023-06-22] [LMFlow paper](https://arxiv.org/abs/2306.12420) is out! Check out our implementation details at https://arxiv.org/abs/2306.12420 * [2023-06-16] Our finetuned Robin-33B-V2 scored an impressive 64.1 on the Huggingface LLM leaderboard in our offline evaluation, outperforming major open-source LLMs! All checkpoints (7B, 13B, 33B, and 65B) are [released](https://huggingface.co/OptimalScale)! Checkout the performance [here](https://medium.com/@hkust.ml/robin-v2-launches-achieves-unparalleled-performance-on-openllm-4f6886e822c1). * [2023-06-07] LMFlow is now officially available on PyPI! Install it with `pip install lmflow-finetune`! * [2023-05-30] Release [Robin-13B-v2](https://huggingface.co/OptimalScale/robin-13b-v2-delta) and [Robin-33B-v2](https://huggingface.co/OptimalScale/robin-33b-v2-delta)! * [2023-05-15] Release [LMFlow-data](http://lmflow.org:5000/lmflow_data.tar.gz), the training dataset of Robin-7B-v2. A new [test data](http://lmflow.org:5000/lmflow_chat_en_dialog_multiturn_single_nll_text2text.tar.gz) is also released. * [2023-05-09] Release [Robin-7B-v2](http://lmflow.org:5000/robin-7b-v2-delta.tar.gz), achieving competitive performance on chitchat, commonsense reasoning and instruction-following tasks. Refer to our [comprehensive study](https://medium.com/@hkust.ml/lmflow-benchmark-an-automatic-evaluation-framework-for-open-source-llms-ef5c6f142418). * [2023-05-08] Release [LMFlow Benchmark](https://medium.com/@hkust.ml/lmflow-benchmark-an-automatic-evaluation-framework-for-open-source-llms-ef5c6f142418), an automatic evaluation framework for open-source chat-style LLMs. [Benchmark results](https://docs.google.com/spreadsheets/d/1JYh4_pxNzmNA9I0YM2epgRA7VXBIeIGS64gPJBg5NHA/edit#gid=0) on 31 popular models are reported. [Participate in LMFlow Benchmark](https://github.com/OptimalScale/LMFlow#33-lmflow-benchmark). * [2023-04-21] Release [Robin-7B](http://lmflow.org:5000/robin-7b.tar.gz) (based on LLaMA-7B), and two models for commercial use: Parakeets-2.7B (based on GPT-NEO-2.7B) and Cokatoo-7B (based on StableLM-7B) [Download here](https://github.com/OptimalScale/LMFlow/tree/main#model-zoo) * [2023-04-15] Inference: Support streaming output and ChatGLM. * [2023-04-10] We propose a new alignment algorithm: [Reward rAnked FineTuning (RAFT)](https://optimalscale.github.io/LMFlow/examples/raft.html), which is more efficient than conventional (PPO-based) RLHF. [[Paper](https://arxiv.org/abs/2304.06767)] * [2023-04-02] [Web service](https://lmflow.com/) is online! * [2023-04-01] Release three instruction-tuned checkpoints and three medical checkpoints in [model zoo](https://github.com/OptimalScale/LMFlow#model-zoo): LLaMA-7B-tuned, LLaMA-13B-tuned, LLaMA-33B-tuned, LLaMA-7B-medical, LLaMA-13B-medical, and LLaMA-33B-medical. * [2023-03-27] Support full tuning and lora tuning for all decoder models. * [2023-03-27] [Tasked tuned model beats ChatGPT on medical domain](https://github.com/OptimalScale/LMFlow#model-performance). * [2023-03-27] Release code and checkpoints - [version 0.0.1](https://optimalscale.github.io/LMFlow/)! [Our tasked-tuned model beats ChatGPT on medical domain](https://github.com/OptimalScale/LMFlow#model-performance).
## Table of Contents - [LMFlow](#lmflow) - [Latest News](#latest-news) - [Table of Contents](#table-of-contents) - [Quick Start](#quick-start) - [Setup](#setup) - [Prepare Dataset](#prepare-dataset) - [Finetuning](#finetuning) - [Estimated Hardware Requirement](#estimated-hardware-requirement) - [Full Finetuning](#full-finetuning) - [LISA](#lisa) - [LoRA](#lora) - [Inference](#inference) - [Deployment](#deployment) - [Evaluation](#evaluation) - [Supported Features](#supported-features) - [Support](#support) - [License](#license) - [Citation](#citation) ## Quick Start ### Setup Our package has been tested on Linux OS (Ubuntu 20.04). Other OS platforms (MacOS, Windows) are not fully tested, where you may encounter unexpected errors. If you are using LMFlow for the first time, we recommend you to try on a Linux machine or Google Colab. ```bash git clone -b v1.0.0 https://github.com/OptimalScale/LMFlow.git cd LMFlow conda create -n lmflow python=3.9 -y conda activate lmflow conda install mpi4py pip install -e . ```
Looking for a previous version? ```bash git clone -b v0.0.10 https://github.com/OptimalScale/LMFlow.git cd LMFlow conda create -n lmflow python=3.9 -y conda activate lmflow conda install mpi4py pip install -e . ```
For CUDA versions 10.3-11.7 ```bash git clone -b v0.0.5 https://github.com/OptimalScale/LMFlow.git cd LMFlow conda create -n lmflow python=3.9 -y conda activate lmflow conda install mpi4py pip install -e . ```
> [!TIP] > We use WandB to track and visualize the training process by default. Before running the training scripts, users may need to log in to WandB using the command: > >```bash >wandb login >``` > > For detailed instructions, refer to the [WandB Quickstart Guide](https://docs.wandb.ai/quickstart/). Step 1 (registration) and Step 2 (login using your WandB API key) should be sufficient to set up your environment. > >
Disabling wandb > > One can disable wandb by either: > > 1. Adding environment variable before running the training command. > >```bash >export WANDB_MODE=disabled >``` > > 2. OR, specifying the integrations to report the results and logs to. In the training script, add: > >```bash >--report_to none \ >``` > >
### Prepare Dataset Please refer to our [doc](https://optimalscale.github.io/LMFlow/examples/DATASETS.html). ### Finetuning #### Estimated Hardware Requirement | Method | 0.5B | 3B | 7B | 14B | 30B | 70B | `x`B | | ---------------------- | ---- | ---- | ---- | ----- | ----- | ----- | ------- | | Full `bf16`/`fp16` | 9GB | 55GB |120GB | 240GB | 600GB | 1200GB| `18x`GB | | LoRA | 1GB | 6GB | 16GB | 32GB | 64GB | 160GB | `2x`GB | | QLoRA `quant_bit=8` | 0.7GB| 3GB | 10GB | 20GB | 40GB | 80GB| `x`GB | | QLoRA `quant_bit=4` | 0.4GB| 1.5GB| 6GB | 12GB | 24GB | 48GB| `x/2`GB | #### Full Finetuning Full training updates all the parameters to finetune a language model. Here is an example to finetune a GPT-2 base model. ```sh cd data && ./download.sh alpaca && cd - bash ./scripts/run_finetune.sh \ --model_name_or_path gpt2 \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_gpt2 ``` > [!TIP] > For conversation dataset, specify a conversation template for better performance by adding `--conversation_template` to the command. > >
Llama-3-8B conversation dataset example > >```bash >cd data && ./download.sh alpaca && cd - > >bash ./scripts/run_finetune.sh \ > --model_name_or_path meta-llama/Meta-Llama-3-8B \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama3 \ > --output_model_path output_models/finetuned_llama3_8b >``` > >
#### LISA [LISA](https://arxiv.org/abs/2403.17919) is a memory-efficient finetuning algorithm that allows tradeoff between memory and the number of randomly unfreezed layers. This script currently is only tested in single gpus. Please stay tuned for our latest updates :smile: ```sh cd data && ./download.sh alpaca && cd - bash ./scripts/run_finetune_with_lisa.sh \ --model_name_or_path meta-llama/Llama-2-7b-hf \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_llama2_7b \ --lisa_activated_layers 1 \ --lisa_interval_steps 20 ``` > [!TIP] >
Llama-2-7B conversation dataset example > >```bash >cd data && ./download.sh alpaca && cd - > >bash ./scripts/run_finetune_with_lisa.sh \ > --model_name_or_path meta-llama/Llama-2-7b-hf \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama2 \ > --output_model_path output_models/finetuned_llama2_7b_lisa \ > --lisa_activated_layers 1 \ > --lisa_interval_steps 20 >``` > >
#### LoRA LoRA is a parameter-efficient finetuning algorithm and is more efficient than full finetuning. ```sh cd data && ./download.sh alpaca && cd - bash ./scripts/run_finetune_with_lora.sh \ --model_name_or_path facebook/galactica-1.3b \ --dataset_path data/alpaca/train_conversation \ --output_lora_path output_models/finetuned_galactica_lora ``` > [!TIP] >
Llama-2-7B conversation dataset example > >```bash >cd data && ./download.sh alpaca && cd - > >bash ./scripts/run_finetune_with_lora.sh \ > --model_name_or_path meta-llama/Llama-2-7b-hf \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama2 \ > --output_model_path output_models/finetuned_llama2_7b_lora \ >``` > >
> >
Merge LoRA Weight > >Merge LoRA weight and the base model into one using: > >```sh >bash ./scripts/run_merge_lora.sh \ > --model_name_or_path Qwen/Qwen1.5-1.8B \ > --lora_model_path output_models/lora \ > --output_model_path output_models/lora_merged \ >``` > >
### Inference After finetuning, you can run the following command to chat with the model. ```sh bash ./scripts/run_chatbot.sh output_models/finetuned_gpt2 ``` > [!TIP] > We recommend using SGLang for faster batch inference. > >
Faster inference using SGLang > >```bash >bash ./scripts/run_sglang_inference.sh >``` > Note: If you encounter error ModuleNotFoundError: No module named 'common_ops' when using SGLang, please try `apt-get update` and then `apt install numactl`. >
### Deployment If you want to deploy your own model locally, we provide a gradio-based UI for building chatbots. Running the following command will launch the demo for robin-7b: ```sh pip install gradio python ./examples/chatbot_gradio.py --deepspeed configs/ds_config_chatbot.json --model_name_or_path YOUR-LLAMA --lora_model_path ./robin-7b --prompt_structure "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.###Human: {input_text}###Assistant:" --end_string "#" --max_new_tokens 200 ``` ### Evaluation We recommend using [LM Evaluation Harness](https://github.com/EleutherAI/lm-evaluation-harness) for most evaluation purposes. ## Supported Features
Finetune Acceleration & Memory Optimization * LISA: Layerwise Importance Sampling for Memory-Efficient Large Language Model Fine-Tuning LISA is a novel and memory-efficient training strategy for large language models that outperforms existing methods like LoRA by selectively freezing layers during optimization. Check out [LISA](https://arxiv.org/abs/2403.17919) for more details. In LMFLow, activate LISA using `--use_lisa 1` in your training command. Control the number of activation layers with `--lisa_activated_layers 2`, and adjust the freezing layers interval using `--lisa_step_interval 20`. * LoRA LoRA is a parameter-efficient finetuning algorithm and is more efficient than full finetuning. Check out [finetuning-lora](#finetuning-lora) for more details. * FlashAttention LMFlow supports both FlashAttention-1 and the latest FlashAttention-2. Check out [flash_attention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md) for more details. * Gradient Checkpointing [Gradient checkpointing](https://github.com/cybertronai/gradient-checkpointing) is a memory optimization technique that trades compute for memory. It is useful when the model is too large to fit into GPU memory. Use it by just adding `--gradient_checkpointing` to your training command. * Deepspeed Zero3 LMFlow supports [Deepspeed Zero-3 Offload](https://www.deepspeed.ai/2021/03/07/zero3-offload.html). We provide an example [deepspeed config](https://github.com/OptimalScale/LMFlow/blob/main/configs/ds_config_zero3.json), and you can directly use it.
Inference Acceleration * LLaMA Inference on CPU Thanks to the great efforts of [llama.cpp](https://github.com/ggerganov/llama.cpp). It is possible for everyone to run their LLaMA models on CPU by 4-bit quantization. We provide a script to convert LLaMA LoRA weights to `.pt` files. You only need to use `convert-pth-to-ggml.py` in llama.cpp to perform quantization. * FlashAttention LMFlow supports both FlashAttention-1 and the latest FlashAttention-2. Check out [flash_attention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md) for more details. * vLLM Try vLLM for fast and easy-to-use LLM inference and serving. Thanks for the [great work](https://github.com/vllm-project/vllm)!
Long Context * Position Interpolation for LLaMA Models Now LMFlow supports the latest Linear & NTK (Neural Kernel theory) scaling techniques for LLaMA models. Check out [postion_interpolation](https://github.com/OptimalScale/LMFlow/blob/main/readme/Position_Interpolation.md) for more details.
Model Customization * Vocabulary Extension Now you can train your own sentencepiece tokenizer and merge it with model's origin hf tokenizer. Check out [vocab_extension](https://github.com/OptimalScale/LMFlow/blob/main/scripts/vocab_extension) for more details.
Multimodal * Multimodal Chatbot LMFlow supports multimodal inputs of images and texts. Check out our [LMFlow multimodal chatbot](https://github.com/OptimalScale/LMFlow/blob/main/scripts/run_vis_chatbot_gradio_minigpt4.sh).
Custom Optimization * Custom Optimization LMFlow now supports custom optimizer training with a variety of optimizers. Elevate your model's performance with tailored optimization strategies. Dive into the details and try out the new features with our updated script at [custom_optimizers](https://github.com/OptimalScale/LMFlow/blob/main/scripts/run_finetune_with_custom_optim.sh). The following table evaluates the performance of custom optimizers in the fine-tuning process of GPT-2 on the Alpaca dataset, emphasizing their individual impacts on the training loss. The specific hyperparameter settings utilize default configurations, which can be customized and adjusted at [custom_optimizers](https://github.com/OptimalScale/LMFlow/blob/main/scripts/run_finetune_with_custom_optim.sh). It is important to note that the evaluations were conducted over a duration of 0.1 epochs to provide a preliminary insight into the optimizers' effectiveness. | Optimizer Name | Train Loss | |----------------|------------| | RMSprop | 2.4016 | | LION-32bit | 2.4041 | | Adam | 2.4292 | | AdamP | 2.4295 | | AdamW | 2.4469 | | AdaFactor | 2.4543 | | AdaBound | 2.4547 | | AdamWScheduleFree | 2.4677 | | Adan | 2.5063 | | NAdam | 2.5569 | | AdaBelief | 2.5857 | | AdaMax | 2.5924 | | RAdam | 2.6104 | | AdaDelta | 2.6298 | | AdaGrad | 2.8657 | | Yogi | 2.9314 | | NovoGrad | 3.1071 | | Sophia | 3.1517 | | LAMB | 3.2350 | | LARS | 3.3329 | | SGDScheduleFree | 3.3541 | | SGDP | 3.3567 | | SGD | 3.3734 |
## Support If you need any help, please submit a Github issue. ## License The code included in this project is licensed under the [Apache 2.0 license](https://github.com/OptimalScale/LMFlow/blob/main/LICENSE). If you wish to use the codes and models included in this project for commercial purposes, please sign this [document](https://docs.google.com/forms/d/e/1FAIpQLSfJYcci6cbgpIvx_Fh1xDL6pNkzsjGDH1QIcm4cYk88K2tqkw/viewform?usp=pp_url) to obtain authorization. ## Citation If you find this repository useful, please consider giving ⭐ and citing our [paper](https://arxiv.org/abs/2306.12420): ```citation @article{diao2023lmflow, title={Lmflow: An extensible toolkit for finetuning and inference of large foundation models}, author={Diao, Shizhe and Pan, Rui and Dong, Hanze and Shum, Ka Shun and Zhang, Jipeng and Xiong, Wei and Zhang, Tong}, journal={arXiv preprint arXiv:2306.12420}, year={2023} } ``` ```citation @article{dong2023raft, title={Raft: Reward ranked finetuning for generative foundation model alignment}, author={Dong, Hanze and Xiong, Wei and Goyal, Deepanshu and Pan, Rui and Diao, Shizhe and Zhang, Jipeng and Shum, Kashun and Zhang, Tong}, journal={arXiv preprint arXiv:2304.06767}, year={2023} } ``` ```citation @article{pan2024lisa, title={LISA: Layerwise Importance Sampling for Memory-Efficient Large Language Model Fine-Tuning}, author={Pan, Rui and Liu, Xiang and Diao, Shizhe and Pi, Renjie and Zhang, Jipeng and Han, Chi and Zhang, Tong}, journal={arXiv preprint arXiv:2403.17919}, year={2024} } ``` ================================================ FILE: configs/accelerate_dsz0_config.yaml ================================================ compute_environment: LOCAL_MACHINE debug: false deepspeed_config: gradient_accumulation_steps: 16 zero3_init_flag: false zero_stage: 0 distributed_type: DEEPSPEED downcast_bf16: 'no' machine_rank: 0 main_training_function: main mixed_precision: bf16 num_machines: 1 num_processes: 8 gpu_ids: rdzv_backend: static same_network: true tpu_env: [] tpu_use_cluster: false tpu_use_sudo: false use_cpu: false main_process_port: 12580 ================================================ FILE: configs/accelerate_dsz2_config.yaml ================================================ compute_environment: LOCAL_MACHINE debug: false deepspeed_config: offload_optimizer_device: none offload_param_device: none zero3_init_flag: false zero_stage: 2 distributed_type: DEEPSPEED downcast_bf16: 'no' machine_rank: 0 main_training_function: main mixed_precision: bf16 num_machines: 1 num_processes: 8 gpu_ids: rdzv_backend: static same_network: true tpu_env: [] tpu_use_cluster: false tpu_use_sudo: false use_cpu: false main_process_port: 12580 ================================================ FILE: configs/accelerate_dsz3_config.yaml ================================================ compute_environment: LOCAL_MACHINE debug: false deepspeed_config: deepspeed_multinode_launcher: standard offload_optimizer_device: none offload_param_device: none zero3_init_flag: true zero3_save_16bit_model: true zero_stage: 3 distributed_type: DEEPSPEED downcast_bf16: 'no' machine_rank: 0 main_training_function: main mixed_precision: bf16 num_machines: 1 num_processes: 8 gpu_ids: rdzv_backend: static same_network: true tpu_env: [] tpu_use_cluster: false tpu_use_sudo: false use_cpu: false main_process_port: 12580 ================================================ FILE: configs/accelerate_fsdp_config.yaml ================================================ compute_environment: LOCAL_MACHINE debug: false distributed_type: FSDP fsdp_config: fsdp_auto_wrap_policy: TRANSFORMER_BASED_WRAP fsdp_min_num_params: 1000000 fsdp_backward_prefetch: BACKWARD_PRE fsdp_forward_prefetch: false fsdp_cpu_ram_efficient_loading: true fsdp_offload_params: false fsdp_sharding_strategy: FULL_SHARD fsdp_state_dict_type: FULL_STATE_DICT fsdp_sync_module_states: true fsdp_use_orig_params: true downcast_bf16: true machine_rank: 0 main_training_function: main mixed_precision: bf16 num_machines: 1 num_processes: 8 # NOTE: distributed_type should be `NO` if you're training on a single GPU rdzv_backend: static same_network: true tpu_env: [] tpu_use_cluster: false tpu_use_sudo: false use_cpu: false main_process_port: 1204 ================================================ FILE: configs/accelerate_singlegpu_config.yaml ================================================ compute_environment: LOCAL_MACHINE debug: false distributed_type: 'NO' fsdp_config: fsdp_auto_wrap_policy: SIZE_BASED_WRAP fsdp_min_num_params: 1000000 fsdp_backward_prefetch: BACKWARD_PRE fsdp_forward_prefetch: false fsdp_cpu_ram_efficient_loading: true fsdp_offload_params: false fsdp_sharding_strategy: 'NO_SHARD' fsdp_state_dict_type: FULL_STATE_DICT fsdp_sync_module_states: true fsdp_use_orig_params: true downcast_bf16: true machine_rank: 0 main_training_function: main mixed_precision: bf16 num_machines: 1 num_processes: 1 rdzv_backend: static same_network: true tpu_env: [] tpu_use_cluster: false tpu_use_sudo: false use_cpu: false main_process_port: 1204 ================================================ FILE: configs/archive/accelerate_multigpu_config.yaml ================================================ compute_environment: LOCAL_MACHINE distributed_type: MULTI_GPU downcast_bf16: 'no' dynamo_config: dynamo_backend: INDUCTOR gpu_ids: machine_rank: 0 main_training_function: main mixed_precision: bf16 num_machines: 1 num_processes: 1 rdzv_backend: static same_network: true tpu_env: [] tpu_use_cluster: false tpu_use_sudo: false use_cpu: false main_process_port: 11002 ================================================ FILE: configs/archive/accelerate_singlegpu_config.yaml ================================================ compute_environment: LOCAL_MACHINE distributed_type: 'NO' downcast_bf16: 'no' dynamo_config: dynamo_backend: INDUCTOR gpu_ids: machine_rank: 0 main_training_function: main mixed_precision: bf16 num_machines: 1 num_processes: 1 rdzv_backend: static same_network: true tpu_env: [] tpu_use_cluster: false tpu_use_sudo: false use_cpu: false ================================================ FILE: configs/archive/ds_config_chatbot.json ================================================ { "fp16": { "enabled": false }, "bf16": { "enabled": true }, "comms_logger": { "enabled": false, "verbose": false, "prof_all": false, "debug": false }, "steps_per_print": 20000000000000000, "train_micro_batch_size_per_gpu": 1, "wall_clock_breakdown": false } ================================================ FILE: configs/archive/ds_config_eval.json ================================================ { "fp16": { "enabled": false }, "bf16": { "enabled": false }, "steps_per_print": 2000, "train_micro_batch_size_per_gpu": 1, "wall_clock_breakdown": false } ================================================ FILE: configs/archive/ds_config_multimodal.json ================================================ { "fp16": { "enabled": "auto", "loss_scale": 0, "loss_scale_window": 1000, "initial_scale_power": 16, "hysteresis": 2, "min_loss_scale": 1 }, "bf16": { "enabled": "auto" }, "train_micro_batch_size_per_gpu": "auto", "train_batch_size": "auto", "gradient_accumulation_steps": "auto", "zero_optimization": { "stage": 2, "overlap_comm": true, "contiguous_gradients": true, "sub_group_size": 1e9, "reduce_bucket_size": "auto" } } ================================================ FILE: configs/archive/ds_config_vis_chatbot.json ================================================ { "fp16": { "enabled": false }, "bf16": { "enabled": false }, "comms_logger": { "enabled": false, "verbose": false, "prof_all": false, "debug": false }, "steps_per_print": 20000000000000000, "train_micro_batch_size_per_gpu": 1, "wall_clock_breakdown": false } ================================================ FILE: configs/deepspeed/zero0_no_offload.json ================================================ { "fp16": { "enabled": "auto", "loss_scale": 0, "loss_scale_window": 1000, "initial_scale_power": 16, "hysteresis": 2, "min_loss_scale": 1 }, "bf16": { "enabled": "auto" }, "zero_optimization": { "stage": 0, "allgather_partitions": true, "allgather_bucket_size": 2e8, "overlap_comm": true, "reduce_scatter": true, "reduce_bucket_size": 2e8, "contiguous_gradients": true }, "gradient_accumulation_steps": "auto", "gradient_clipping": "auto", "steps_per_print": 2000, "train_batch_size": "auto", "train_micro_batch_size_per_gpu": "auto", "wall_clock_breakdown": false } ================================================ FILE: configs/deepspeed/zero2.json ================================================ { "fp16": { "enabled": "auto", "loss_scale": 0, "loss_scale_window": 1000, "initial_scale_power": 16, "hysteresis": 2, "min_loss_scale": 1 }, "bf16": { "enabled": "auto" }, "zero_optimization": { "stage": 2, "offload_optimizer": { "device": "cpu", "pin_memory": true }, "allgather_partitions": true, "allgather_bucket_size": 2e8, "overlap_comm": true, "reduce_scatter": true, "reduce_bucket_size": 2e8, "contiguous_gradients": true }, "gradient_accumulation_steps": "auto", "gradient_clipping": "auto", "steps_per_print": 2000, "train_batch_size": "auto", "train_micro_batch_size_per_gpu": "auto", "wall_clock_breakdown": false } ================================================ FILE: configs/deepspeed/zero2_no_offload.json ================================================ { "fp16": { "enabled": "auto", "loss_scale": 0, "loss_scale_window": 1000, "initial_scale_power": 16, "hysteresis": 2, "min_loss_scale": 1 }, "bf16": { "enabled": "auto" }, "zero_optimization": { "stage": 2, "allgather_partitions": true, "allgather_bucket_size": 2e8, "overlap_comm": true, "reduce_scatter": true, "reduce_bucket_size": 2e8, "contiguous_gradients": true }, "gradient_accumulation_steps": "auto", "gradient_clipping": "auto", "steps_per_print": 2000, "train_batch_size": "auto", "train_micro_batch_size_per_gpu": "auto", "wall_clock_breakdown": false } ================================================ FILE: configs/deepspeed/zero3.json ================================================ { "fp16": { "enabled": "auto", "loss_scale": 0, "loss_scale_window": 1000, "initial_scale_power": 16, "hysteresis": 2, "min_loss_scale": 1 }, "bf16": { "enabled": "auto" }, "zero_optimization": { "stage": 3, "offload_optimizer": { "device": "cpu" }, "overlap_comm": true, "contiguous_gradients": true, "sub_group_size": 1e9, "reduce_bucket_size": "auto", "stage3_prefetch_bucket_size": "auto", "stage3_param_persistence_threshold": "auto", "stage3_max_live_parameters": 2e10, "stage3_max_reuse_distance": 2e10, "stage3_gather_16bit_weights_on_model_save": true }, "gradient_accumulation_steps": "auto", "gradient_clipping": "auto", "steps_per_print": 2000, "train_batch_size": "auto", "train_micro_batch_size_per_gpu": "auto", "wall_clock_breakdown": false } ================================================ FILE: configs/deepspeed/zero3_for_eval.json ================================================ { "bf16": { "enabled": true }, "zero_optimization": { "stage": 3, "offload_optimizer": { "device": "cpu", "pin_memory": true }, "offload_param": { "device": "cpu", "pin_memory": true }, "overlap_comm": true, "contiguous_gradients": true, "sub_group_size": 1e9, "reduce_bucket_size": "auto", "stage3_prefetch_bucket_size": "auto", "stage3_param_persistence_threshold": "auto", "stage3_max_live_parameters": 1e9, "stage3_max_reuse_distance": 1e9, "stage3_gather_16bit_weights_on_model_save": true }, "steps_per_print": 2000, "train_micro_batch_size_per_gpu": 1, "wall_clock_breakdown": false } ================================================ FILE: configs/deepspeed/zero3_no_offload.json ================================================ { "fp16": { "enabled": "auto", "loss_scale": 0, "loss_scale_window": 1000, "initial_scale_power": 16, "hysteresis": 2, "min_loss_scale": 1 }, "bf16": { "enabled": "auto" }, "zero_optimization": { "stage": 3, "overlap_comm": true, "contiguous_gradients": true, "sub_group_size": 1e9, "reduce_bucket_size": "auto", "stage3_prefetch_bucket_size": "auto", "stage3_param_persistence_threshold": "auto", "stage3_max_live_parameters": 2e10, "stage3_max_reuse_distance": 2e10, "stage3_gather_16bit_weights_on_model_save": true }, "gradient_accumulation_steps": "auto", "gradient_clipping": "auto", "steps_per_print": 2000, "train_batch_size": "auto", "train_micro_batch_size_per_gpu": "auto", "wall_clock_breakdown": false } ================================================ FILE: configs/iterative_dpo.yaml ================================================ # general ## model model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct reference_model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct reward_model_name_or_path: sfairXC/FsfairX-LLaMA3-RM-v0.1 trust_remote_code: True ## data dataset_path_list: - data/iterative-prompt-3it/iter1 - data/iterative-prompt-3it/iter2 - data/iterative-prompt-3it/iter3 conversation_template: llama3 preprocessing_num_workers: 16 ## pipeline output_dir: ./output_models/iterative_dpo run_name: iterative_dpo random_seed: 42 enable_distributed_inference: True distributed_inference_num_instances: 8 initial_iter_idx: 0 # 0 refers to the first dataset in dataset_path_list do_response_generation: True do_scoring: True do_dpo_align: True # inference phase ## general apply_chat_template: True num_output_sequences: 8 use_beam_search: False temperature: 1.0 top_p: 1.0 max_new_tokens: 2048 enable_decode_inference_result: True ## vllm use_vllm: True vllm_gpu_memory_utilization: 0.95 vllm_tensor_parallel_size: 1 vllm_inference_batch_size: 16 # reward model scoring phase reward_arch_type: text_regression reward_torch_dtype: bf16 reward_use_flash_attention: True reward_model_inference_block_size: 2048 overwrite_cache: True reward_model_inference_batch_size: 10 # the actual batch size for rm forward will be reward_model_inference_batch_size * num_output_sequences # dpo phase ## model do_train: True use_flash_attention: True ## data sampling_paired_method: max_min margin_scale: 1.0 length_penalty: 0 max_prompt_length: 1000 mask_prompt: False ## pipeline ### training accelerate_config_file: configs/accelerate_dsz2_config.yaml bf16: True num_train_epochs: 2 max_steps: 1200 learning_rate: 5.0e-7 warmup_steps: 100 per_device_train_batch_size: 1 per_device_eval_batch_size: 1 gradient_accumulation_steps: 16 gradient_checkpointing: True loss_type: sigmoid lr_scheduler_type: cosine optim: paged_adamw_32bit ### logging logging_steps: 2 save_strategy: steps save_steps: 500 evaluation_strategy: steps eval_steps: 500 report_to: wandb ================================================ FILE: contrib/README.md ================================================ # Contributing to LMFlow Thanks for your interest in LMFlow! Our LMFlow team appreciate contributions in any form: * issues * documentation improvements * new features * bug fixes * and particularly, runnable examples with SOTA models or techniques. For details of the contribution guidelines, please kindly refer to the following sections. ## How to Contribute ### How to create Pull Requests (PR) One may refer to the following guideline for general Pull Request instructions [GitHub Pull Request Examples](https://gist.github.com/Chaser324/ce0505fbed06b947d962). In short, every PR has following steps: 1. Fork the repository under your own account. 2. Clone and install the repository to your local machine. 3. Add your own modifications. 4. Run tests and make sure everything is working. 5. Push to your own remote repository. 6. Check the instructions in the [guidebook](https://gist.github.com/Chaser324/ce0505fbed06b947d962), make sure the remote modification is update-to-date with LMFlow's main branch. 7. If not, go back to Step 3 and resolve the conflict. 8. If so, create your PR. We will be reviewing the code soon and merge the changes into main once the review is finished :smile: Currently, we enthusiastically welcome contributions of documentations and runnable examples. Runnable examples are collected under `contrib/{YOUR_NAME}` and can be used by everyone! :rocket: ## Style Guidelines ### Code Style LMFlow adopts [google coding style](https://google.github.io/styleguide/) in principle. We would encourage every contribution to have the same style as well. ### Git Commits We would appreciate the commit to follow the principles below: * Describe the message concisely about what this commit do * Describe the message in imperative mood, starting with a capitalized verb, e.g., "Fix typo in README" or "Add support LISA for model parallelism". * Squash commits to make sure that each commit describes a whole fix/feature Thank you for your interest in LMFlow! Any suggestions and contributions would be greatly appreciated. ================================================ FILE: contrib/langchain/README.md ================================================ ## Langchain ### Setup ``` pip install langchain pip install langchain-openai langchain-anthropic langchain-google-genai langchain-chroma langchain-community bs4 ``` ### Run Chatbot To run the script, go to the root of this repo and use the following command: ``` python contrib/langchain/retrieval_chatbot.py [options] ``` ### Command-Line Arguments - `--model-name-or-path` - Specifies the name or path of the model used for generating responses. - `--provider` - Supports the following providers: `openai`, `anthropic`, `google`, and `huggingface`. - `--set-url` - Retrieve content from a specified URL if enabled. - `--set-txt` - Retrieve content from a local txt file if enabled. - `--session-id` - Session id of this chat, default: `demo`. - `--save-history` - Saves the chat history if enabled. - `--save-dir` - Directory to store chat history, default: `tmp/chat_history` ### Example Usage - Inference with `gpt-4o`, specified url and txt file ``` cd data && ./download.sh example_doc_for_retrieval.txt && cd - python contrib/langchain/retrieval_chatbot.py --provider "openai" --model-name-or-path "gpt-4o" --set-url --set-txt ``` - Then set the url and txt file as follows: ``` Please enter the url: https://optimalscale.github.io/LMFlow/index.html Please enter the text file path: data/example_doc_for_retrieval.txt ``` ================================================ FILE: contrib/langchain/retrieval_chatbot.py ================================================ import argparse import logging import os import re from pathlib import Path from langchain_anthropic import ChatAnthropic from langchain_chroma import Chroma from langchain_community.chat_message_histories import ChatMessageHistory # retrieval usage from langchain_community.document_loaders import TextLoader, WebBaseLoader from langchain_community.llms import HuggingFacePipeline from langchain_core.chat_history import BaseChatMessageHistory from langchain_core.messages import SystemMessage from langchain_core.prompts import ChatPromptTemplate, HumanMessagePromptTemplate, MessagesPlaceholder from langchain_core.runnables import Runnable from langchain_core.runnables.history import RunnableWithMessageHistory from langchain_google_genai import ChatGoogleGenerativeAI from langchain_openai import ChatOpenAI, OpenAIEmbeddings from langchain_text_splitters import RecursiveCharacterTextSplitter logging.getLogger().setLevel(logging.ERROR) # hide warning log class LangchainChatbot: def __init__(self, model_name_or_path: str, provider: str): self.prompt = ChatPromptTemplate.from_messages( [ SystemMessage(content="You are a helpful chatbot."), MessagesPlaceholder(variable_name="history"), MessagesPlaceholder(variable_name="retriever", optional=True), HumanMessagePromptTemplate.from_template("{input}"), ] ) self.model_name_or_path = model_name_or_path self.provider = provider self.check_valid_provider() self.model = self.get_model() self.retriever_url = None self.retriever_file = None self.memory = {} self.runnable: Runnable = self.prompt | self.model self.llm_chain = RunnableWithMessageHistory( self.runnable, self.get_session_history, input_messages_key="input", history_messages_key="history", ) def check_valid_provider(self): provider = self.provider model_name_or_path = self.model_name_or_path if provider == "openai" and "gpt" in model_name_or_path: if os.getenv("OPENAI_API_KEY") is None: raise OSError("OPENAI_API_KEY environment variable is not set.") elif provider == "anthropic" and "claude" in model_name_or_path: if os.getenv("ANTHROPIC_API_KEY") is None: raise OSError("ANTHROPIC_API_KEY environment variable is not set.") elif provider == "google" and "gemini" in model_name_or_path: if os.getenv("GOOGLE_API_KEY") is None: raise OSError("GOOGLE_API_KEY environment variable is not set.") elif provider == "huggingface": if os.getenv("HUGGINGFACEHUB_API_TOKEN") is None: raise OSError("HUGGINGFACEHUB_API_TOKEN environment variable is not set.") else: raise ValueError("Invalid provider or model_name_or_path.") def set_retriever_url(self, url, chunk_size, chunk_overlap): loader = WebBaseLoader(url) data = loader.load() text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap) all_splits = text_splitter.split_documents(data) vectorstore = Chroma.from_documents(documents=all_splits, embedding=OpenAIEmbeddings()) self.retriever_url = vectorstore.as_retriever(k=4) def set_retriever_file(self, file, chunk_size, chunk_overlap): loader = TextLoader(file, encoding="utf-8") data = loader.load() text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=chunk_overlap) all_splits = text_splitter.split_documents(data) vectorstore = Chroma.from_documents(documents=all_splits, embedding=OpenAIEmbeddings()) self.retriever_file = vectorstore.as_retriever(k=4) def get_model(self): provider = self.provider model_name_or_path = self.model_name_or_path if provider == "openai": model = ChatOpenAI(model=model_name_or_path) elif provider == "anthropic": model = ChatAnthropic(model=model_name_or_path) elif provider == "google": model = ChatGoogleGenerativeAI(model=model_name_or_path) elif provider == "huggingface": model = HuggingFacePipeline.from_model_id(model_id=model_name_or_path, task="text-generation") # model = HuggingFaceEndpoint(repo_id=model_name_or_path) else: raise ValueError("Invalid provider.") return model def chat_with_chatbot(self, human_input, session_id): retriever_search = [] if self.retriever_url: retriever_search.extend(self.retrieve_by_url(human_input)) if self.retriever_file: retriever_search.extend(self.retrieve_by_file(human_input)) response = self.llm_chain.invoke( {"input": human_input, "retriever": retriever_search}, config={"configurable": {"session_id": session_id}} ) return response if self.provider == "huggingface" else response.content def retrieve_by_url(self, query): return [re.sub("\n+", "\n", dict(result)["page_content"]) for result in self.retriever_url.invoke(query)] def retrieve_by_file(self, query): return [re.sub("\n+", "\n", dict(result)["page_content"]) for result in self.retriever_file.invoke(query)] def get_session_history(self, session_id: str) -> BaseChatMessageHistory: if session_id not in self.memory: self.memory[session_id] = ChatMessageHistory() return self.memory[session_id] def get_cli() -> argparse.ArgumentParser: parser = argparse.ArgumentParser( description=__doc__, ) parser.add_argument("--model-name-or-path", type=str, help="Model name or path") parser.add_argument("--provider", type=str, help="Provider of the model") parser.add_argument("--set-url", action="store_true", help="Set a URL for retrieval if enabled") parser.add_argument("--set-txt", action="store_true", help="Set a single text file for retrieval if enabled") parser.add_argument("--chunk-size", type=int, default=400, help="Chunk size for splitting documents.") parser.add_argument("--chunk-overlap", type=int, default=20, help="Chunk overlap for splitting documents.") parser.add_argument("--session-id", type=str, default="demo", help="Session id of this chat") parser.add_argument("--save-history", action="store_true", help="Save chat history if enabled") parser.add_argument( "--save-dir", type=Path, default=Path("tmp", "chat_history"), help="Directory to store chat history" ) return parser def main( model_name_or_path: str, provider: str, set_url: bool, set_txt: bool, chunk_size: int, chunk_overlap: int, session_id: str, save_history: bool, save_dir: Path, ): chatbot = LangchainChatbot(model_name_or_path=model_name_or_path, provider=provider) if set_url: url = input("Please enter the url: ") chatbot.set_retriever_url(url, chunk_size, chunk_overlap) if set_txt: file = input("Please enter the text file path: ") chatbot.set_retriever_file(file, chunk_size, chunk_overlap) while True: human_input = input("User: ") if human_input == "exit": break response = chatbot.chat_with_chatbot(human_input, session_id) print(f"Chatbot: {response}") if save_history: if "/" in model_name_or_path: model_name_or_path = Path(model_name_or_path).parts[-1] if not os.path.exists(save_dir): os.makedirs(save_dir) save_path = Path(save_dir, f"{model_name_or_path}_{session_id}.txt") with open(save_path, "w") as file: file.write(str(chatbot.memory[session_id].messages)) if __name__ == "__main__": args = get_cli().parse_args() main(**vars(args)) ================================================ FILE: contrib/long-context/hf_sft_full_finetune.sh ================================================ #!/bin/bash # accelerate launch --main_process_port 0 ... # Finetune python sft_summarizer.py \ --model_name_or_path microsoft/Phi-3-vision-128k-instruct \ --learning_rate 1e-3 \ --per_device_train_batch_size 1 \ --per_device_eval_batch_size 1 \ --gradient_accumulation_steps 1 \ --trust_remote_code \ --output_dir output_models/finetuned_Phi3 \ --logging_steps 1 \ --num_train_epochs 1 \ --save_strategy "steps" \ --save_total_limit 2 \ --lr_scheduler_type "constant" \ --max_steps -1 \ --torch_dtype 'bfloat16' \ --gradient_checkpointing \ --logging_strategy "epoch" \ --do_eval True \ --evaluation_strategy 'epoch' \ --bf16 \ --bf16_full_eval True \ --max_seq_length 10000 \ --eval_accumulation_steps 4 \ --use_peft False\ --save_only_model True \ --overwrite_output_dir True ================================================ FILE: contrib/long-context/hf_sft_lora_flashattn.sh ================================================ #!/bin/bash # accelerate launch --main_process_port 0 ... # Finetunes python sft_summarizer.py \ --model_name_or_path microsoft/Phi-3-vision-128k-instruct \ --learning_rate 1e-3 \ --per_device_train_batch_size 1 \ --per_device_eval_batch_size 1 \ --gradient_accumulation_steps 1 \ --trust_remote_code \ --output_dir output_models/finetuned_Phi3 \ --logging_steps 1 \ --num_train_epochs 1 \ --save_strategy "steps" \ --save_total_limit 2 \ --lr_scheduler_type "constant" \ --max_steps -1 \ --torch_dtype 'bfloat16' \ --gradient_checkpointing \ --logging_strategy "epoch" \ --do_eval True \ --evaluation_strategy 'epoch' \ --bf16 \ --bf16_full_eval True \ --max_seq_length 10000 \ --attn_implementation 'flash_attention_2' \ --eval_accumulation_steps 4 \ --use_peft False\ --lora_r 16 \ --lora_alpha 16 \ --save_only_model True \ --overwrite_output_dir True ================================================ FILE: contrib/long-context/sft_summarizer.py ================================================ #!/usr/bin/env python import logging import os from dataclasses import dataclass, field from typing import Optional import torch import wandb from colorama import Fore, init from datasets import load_dataset from tqdm.rich import tqdm from transformers import AutoTokenizer, TrainerCallback, TrainingArguments # os.environ['CUDA_VISIBLE_DEVICES'] = "6" from transformers.trainer_callback import TrainerControl, TrainerState from lmflow.utils.versioning import is_trl_available if is_trl_available(): from trl import ( DataCollatorForCompletionOnlyLM, ModelConfig, SFTConfig, SFTTrainer, get_kbit_device_map, get_peft_config, get_quantization_config, ) from trl.commands.cli_utils import TrlParser else: raise ImportError("Please install trl package to use sft_summarizer.py") @dataclass class UserArguments: wandb_key: Optional[str] = field( default=None, metadata={"help": "User's own wandb key if there are multiple wandb accounts in your server"} ) wandb_projectname: Optional[str] = field( default="huggingface_sft_summarizer", metadata={"help": "The name of project saved in wandb"} ) if __name__ == "__main__": # Initialize logging, tqdm and init logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s") tqdm.pandas() init(autoreset=True) parser = TrlParser((UserArguments, SFTConfig, ModelConfig)) user_args, sft_config, model_config = parser.parse_args_and_config() # Initialize wandb if user_args.wandb_key: wandb.login( key=user_args.wandb_key ) # replace your own wandb key if there are multiple wandb accounts in your server else: wandb.init(mode="offline") wandb.init(project=user_args.wandb_projectname) # https://huggingface.co/docs/transformers/en/main_classes/trainer#transformers.TrainingArguments logging.debug(sft_config) logging.debug("-" * 50) logging.debug(model_config) logging.debug("-" * 50) logging.debug("cuda===> %s", os.environ["CUDA_VISIBLE_DEVICES"]) if model_config.use_peft: use_peft = "peft" else: use_peft = "nopeft" ################ # Model & Tokenizer ################ torch_dtype = ( model_config.torch_dtype if model_config.torch_dtype in ["auto", None] else getattr(torch, model_config.torch_dtype) ) logging.debug("torch_dtype===> %s", torch_dtype) if model_config.use_peft: quantization_config = None else: quantization_config = get_quantization_config(model_config) logging.debug("quantization_config===> %s", quantization_config) model_kwargs = dict( revision=model_config.model_revision, trust_remote_code=model_config.trust_remote_code, attn_implementation=model_config.attn_implementation, torch_dtype=model_config.torch_dtype, use_cache=False if sft_config.gradient_checkpointing else True, device_map=get_kbit_device_map() if quantization_config is not None else None, quantization_config=quantization_config, local_files_only=True, ) logging.debug("model_kwargs: %s", model_kwargs) tokenizer = AutoTokenizer.from_pretrained(model_config.model_name_or_path, use_fast=True, local_files_only=True) tokenizer.pad_token = tokenizer.eos_token ################ # Dataset ################ train_dataset = load_dataset("LukaMagic077/downsampled_below10k_arxiv_dataset_on_hub", split="train") val_dataset = load_dataset("LukaMagic077/downsampled_below10k_arxiv_dataset_on_hub", split="validation") # test_dataset = load_dataset("LukaMagic077/downsampled_below10k_arxiv_dataset_on_hub", split='test') # Get the size of training dataset train_dataset_size = len(train_dataset) # Get the size of validation dataset val_dataset_size = len(val_dataset) # Print the size of dataset logging.debug(f"Training dataset size: {train_dataset_size}") logging.debug(f"Validation dataset size: {val_dataset_size}") ################ # Training ################ # Define datacollector data_collector = DataCollatorForCompletionOnlyLM( instruction_template="article", response_template="abstract", tokenizer=tokenizer, mlm=False ) class WandbCallback(TrainerCallback): def __init__(self, trainer): # trainer.model.to("cuda:0") self.model, self.tokenizer = trainer.model, trainer.tokenizer self.tokenizer.pad_token = self.tokenizer.eos_token logging.debug(Fore.GREEN) logging.debug("entering callback=====>") logging.debug(self.tokenizer) def on_save(self, args: TrainingArguments, state: TrainerState, control: TrainerControl, **kwargs): logging.debug("current step %s", state.global_step) return super().on_save(args, state, control, **kwargs) trainer = SFTTrainer( model=model_config.model_name_or_path, model_init_kwargs=model_kwargs, args=sft_config, train_dataset=train_dataset, dataset_text_field="article", eval_dataset=val_dataset, tokenizer=tokenizer, peft_config=get_peft_config(model_config), ) trainer.train() ================================================ FILE: contrib/rlhflow/reward_modeling.py ================================================ import os import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) import numpy as np import torch import torch.nn as nn from datasets import load_dataset from peft import LoraConfig, TaskType, get_peft_model from transformers import ( AutoModelForSequenceClassification, AutoTokenizer, HfArgumentParser, Trainer, ) from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) ## Prepare training_args pipeline_name = "finetuner" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((ModelArguments, DatasetArguments, PipelineArguments)) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): model_args, data_args, pipeline_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) else: model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() pipeline_args.remove_unused_columns = False pipeline_args.label_names = [] ## Get model, by default we use lora to accelerate training peft_config = LoraConfig( task_type=TaskType.SEQ_CLS, r=16, lora_alpha=32, lora_dropout=0.1, ) # trust_remote_code=True if you want to use chatglm model = AutoModelForSequenceClassification.from_pretrained( model_args.model_name_or_path, num_labels=1, torch_dtype=torch.bfloat16 ) model_lora = get_peft_model(model, peft_config) model_lora.print_trainable_parameters() ## Get tokenizer tokenizer = AutoTokenizer.from_pretrained(model_args.model_name_or_path) if "llama" in model_args.model_name_or_path: tokenizer.add_special_tokens( { "eos_token": "[PAD]", "bos_token": "", "unk_token": "", "pad_token": "", } ) else: tokenizer.pad_token = tokenizer.eos_token tokenizer.pad_token_id = tokenizer.eos_token_id # We also need to add a pad_token for the model. Otherwise, the reward model cannot handle a batch of inputs model_lora.config.pad_token_id = tokenizer.eos_token_id assert model_lora.config.pad_token_id == tokenizer.pad_token_id ## Get the dataset def build_dataset(tokenizer, config): """ We assume that we have preprocessed the dataset appropriately such that the sample is organized as follows: {"positive": prompt + answer_positive, "negative": prompt + answer_negative}, where the positive response is preferred. """ def tokenize(sample): tokenized_pos = tokenizer(sample["positive"], truncation=True) tokenized_neg = tokenizer(sample["negative"], truncation=True) sample["chosen_input_ids"] = tokenized_pos["input_ids"] sample["chosen_attention_mask"] = tokenized_pos["attention_mask"] sample["rejected_input_ids"] = tokenized_neg["input_ids"] sample["rejected_attention_mask"] = tokenized_neg["attention_mask"] return sample ds = load_dataset("json", data_files=config.dataset_path, split="train", field="instances") ds = ds.map(tokenize, batched=False) ds = ds.filter(lambda x: len(x["chosen_input_ids"]) <= 512 and len(x["rejected_input_ids"]) <= 512) eval_dataset = None if config.validation_split_percentage > 0: idx_gap = int((1 - config.validation_split_percentage / 100) * len(ds)) train_dataset = ds.select(range(idx_gap)) eval_dataset = ds.select(range(idx_gap, len(ds))) else: train_dataset = ds return train_dataset, eval_dataset train_dataset, eval_dataset = build_dataset(tokenizer, data_args) if not eval_dataset and pipeline_args.eval_steps > 0: raise ValueError("Cannot evaluate on an empty eval set") print("Training set: ", len(train_dataset), " Eval set: ", len(eval_dataset)) ## Define the trainer def compute_metrics(eval_pred): result = {} pos_predictions_scores = eval_pred.predictions[0] neg_predictions_scores = eval_pred.predictions[1] # We assume that the first sample is preferred by default in groundtruth result["accuracy"] = np.sum(pos_predictions_scores >= neg_predictions_scores) / len(pos_predictions_scores) return result class DataCollatorReward: def __init__(self, tokenizer): self.tokenizer = tokenizer def __call__(self, data): batch = {} data_pos = [] data_neg = [] for sample in data: data_pos.append( {"input_ids": sample["chosen_input_ids"], "attention_mask": sample["chosen_attention_mask"]} ) data_neg.append( {"input_ids": sample["rejected_input_ids"], "attention_mask": sample["rejected_attention_mask"]} ) batch_pos = self.tokenizer.pad(data_pos, padding=True, return_tensors="pt") batch_neg = self.tokenizer.pad(data_neg, padding=True, return_tensors="pt") batch["chosen_input_ids"] = batch_pos["input_ids"] batch["rejected_input_ids"] = batch_neg["input_ids"] batch["chosen_attention_mask"] = batch_pos["attention_mask"] batch["rejected_attention_mask"] = batch_neg["attention_mask"] batch["return_loss"] = True return batch class RMTrainer(Trainer): def compute_loss(self, model, inputs, return_outputs=False): chosen_rewards = model(input_ids=inputs["chosen_input_ids"], attention_mask=inputs["chosen_attention_mask"])[0] rejected_rewards = model( input_ids=inputs["rejected_input_ids"], attention_mask=inputs["rejected_attention_mask"] )[0] loss = -nn.functional.logsigmoid(chosen_rewards - rejected_rewards).mean() if return_outputs: return loss, {"chosen_rewards": chosen_rewards, "rejected_rewards": rejected_rewards} return loss data_collator = DataCollatorReward(tokenizer=tokenizer) trainer = RMTrainer( model=model_lora, args=pipeline_args, train_dataset=train_dataset, compute_metrics=compute_metrics, eval_dataset=eval_dataset, data_collator=data_collator, ) trainer.train() ## Save model model_lora.save_pretrained(pipeline_args.output_dir) ================================================ FILE: contrib/rlhflow/run_reward_modeling.sh ================================================ #!/bin/bash # Please run this script under ${project_id} in project directory of # https://github.com/shizhediao/llm-ft # COMMIT: d5fecf30ba8011067b10cf51fede53a5ab6574e4 deepspeed_args="--master_port=11000" # Default argument if [ $# -ge 1 ]; then deepspeed_args="$1" fi exp_id=rm project_dir=$(cd "$(dirname $0)"/..; pwd) output_dir=${project_dir}/output_models/${exp_id} log_dir=${project_dir}/log/${exp_id} dataset_path=${project_dir}/data/hh_rlhf/rm/hh_rlhf_rm_training.json if [ ! -d data/hh_rlhf ]; then cd data && ./download.sh hh_rlhf && cd - fi mkdir -p ${output_dir} ${log_dir} deepspeed ${deepspeed_args} \ contrib/rlhflow/reward_modeling.py \ --model_name_or_path gpt2 \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --num_train_epochs 1 \ --learning_rate 3e-5 \ --block_size 512 \ --per_device_train_batch_size 1 \ --per_device_eval_batch_size 1\ --deepspeed configs/archive/ds_config_zero2.json \ --bf16 \ --run_name rm_test \ --validation_split_percentage 10 \ --logging_steps 10 \ --do_train \ --ddp_timeout 72000 \ --save_steps 999999 \ --evaluation_strategy steps\ --eval_steps 100\ --weight_decay 0.001\ --dataloader_num_workers 1 \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ================================================ FILE: contrib/text2image/README.md ================================================ # Fine-tuning Text2Img Here is a fork function for fine-tuning text2image diffusion model based on diffusers, under the framework of lmflow. ## Environment Preparation After install the `lmflow`, directly use `pip install -r requirements.txt` for extensive packages of t2i fine-tuning. ## Data Preparation Here is a tree struct of the required data organization. In detail, under a `dataset_path` *example*, by default, an `img` directory is used for image files, and `train.json`, `valid.json` and `test.json` are used for reference of training, validation and testinig data. The `valid.json` and `test.json` are optional. If one is provided and the other is not, the two files will be set as the same. ```bash data └── example ├── img │   ├── 00.jpg │   ├── 01.jpg │   ├── 02.jpg │   ├── 03.jpg │   └── 04.jpg ├── train.json ├── [valid.json] └── [test.json] ``` The `train.json` should be the format as follow: ```json { "type": "text-image", "instances": [ { "image": "00.jpg", "text": "A photo of a dog" }, ... ] } ``` And the `valid.json` and `test.json` should be the format as follow: ```json { "type": "text-only", "instances": [ { "text": "A photo of a dog in front of Eiffel Tower." }, ... ] } ``` Here is a specific example of the data [dog_t2i_data_example](https://drive.google.com/drive/folders/106ahvIrXbiuZMBw0NuOTjY0vnM_xXARW?usp=sharing) ## Fine-tuning For convenience, we provide a script `finetune_t2i.sh` for fine-tuning. It can be used as follow: ```bash bash finetune_t2i.sh \ model_name_or_path=stabilityai/stable-diffusion-2-1 \ dataset_path=data/example ``` The `model_name_or_path` is the model name in [huggingface](https://huggingface.co/) or path of the pre-trained model. The `dataset_path` is the path of the dataset, which should be organized as the above tree struct. There are also some optional arguments for the script: - `model_type`: The type of the model, which can be `unet` or `transformer`. Default is `unet`. (The `transformer` is not supported yet.) - `output_dir`: The output directory of the fine-tuned model. Default is `output`. - `main_port`: The main port of the server. Default is `29500`. - `img_size`: The size of the image for fine-tuning, validation and testing. Default is `768`. For more customization, you can refer to the `finetune_t2i.sh` and `finetune_t2i.py`. ================================================ FILE: contrib/text2image/accelerate_t2i_config.yaml ================================================ compute_environment: LOCAL_MACHINE debug: false distributed_type: MULTI_GPU downcast_bf16: 'no' enable_cpu_affinity: false gpu_ids: all machine_rank: 0 main_training_function: main mixed_precision: fp16 num_machines: 1 num_processes: 4 rdzv_backend: static same_network: true tpu_env: [] tpu_use_cluster: false tpu_use_sudo: false use_cpu: false ================================================ FILE: contrib/text2image/diffuser_args.py ================================================ import os from dataclasses import dataclass, field from typing import Optional from lmflow.args import DatasetArguments @dataclass class T2IDatasetArguments(DatasetArguments): """Arguments for T2I dataset""" image_folder: Optional[str] = field(default=None, metadata={"help": "The folder of the image file."}) image_size: Optional[int] = field(default=512, metadata={"help": "The size of the image."}) image_crop_type: Optional[str] = field(default="center", metadata={"help": "The type of image crop."}) text_embedding_type: Optional[str] = field(default="raw", metadata={"help": "How to get text embedding."}) is_t2i: Optional[bool] = field(default=True, metadata={"help": "Flag for the modality type."}) def __post_init__(self): def check_extension(file_path: str, extension: str): assert file_path.split(".")[-1] == extension, f"The file must be a {extension} file." if self.dataset_path is None or self.image_folder is None: raise ValueError("The dataset_path, image_folder must be provided.") else: if self.train_file is None: if os.path.exists(os.path.join(self.dataset_path, "train.json")): self.train_file = "train.json" else: raise ValueError("The train_file must be provided.") check_extension(self.train_file, "json") if (self.validation_file is not None and self.test_file is None) or ( self.validation_file is None and self.test_file is not None ): same_file = self.validation_file if self.validation_file is not None else self.test_file self.validation_file = same_file self.test_file = same_file if self.validation_file is not None: check_extension(self.validation_file, "json") if not os.path.exists(os.path.join(self.dataset_path, self.validation_file)): self.validation_file = None if self.test_file is not None: check_extension(self.test_file, "json") if not os.path.exists(os.path.join(self.dataset_path, self.test_file)): self.test_file = None @dataclass class DiffuserModelArguments: """Arguments for T2I model""" model_name_or_path: Optional[str] = field(default=None, metadata={"help": "The model name or path."}) model_type: Optional[str] = field(default=None, metadata={"help": "The model type."}) # torch_dtype: Optional[str] = field( # default=None, # metadata={ # "help": ( # "Override the default `torch.dtype` and load the model under this dtype. If `auto` is passed, the " # "dtype will be automatically derived from the model's weights." # ), # "choices": ["auto", "bfloat16", "float16", "float32"], # }, # ) use_lora: bool = field( default=False, metadata={"help": "Whether to lora."}, ) lora_r: int = field( default=8, metadata={"help": "the rank of the lora parameters. The smaller lora_r is , the fewer parameters lora has."}, ) lora_alpha: int = field( default=8, metadata={ "help": ( "Merging ratio between the fine-tuned model and the original. This is controlled by a " "parameter called alpha in the paper." ), }, ) lora_target_modules: list[str] = field(default=None, metadata={"help": "Modules to apply lora."}) lora_dropout: float = field( default=0.1, metadata={"help": "The dropout rate in lora.linear."}, ) @dataclass class DiffuserTunerArguments: """Arguments for T2I finetuner""" output_dir: Optional[str] = field(default="output", metadata={"help": "The output directory."}) logging_dir: Optional[str] = field(default="logs", metadata={"help": "The logging directory."}) overwrite_output_dir: bool = field( default=False, metadata={"help": "Overwrite the content of the output directory."} ) mixed_precision: str = field(default="no", metadata={"help": "Whether to use mixed precision."}) do_train: bool = field(default=True, metadata={"help": "Whether to run training."}) num_train_epochs: Optional[int] = field(default=50, metadata={"help": "The number of training epochs."}) train_batch_size: Optional[int] = field(default=1, metadata={"help": "The number of batch size in training."}) learning_rate: Optional[float] = field(default=1e-4, metadata={"help": "The learning rate."}) weight_decay: Optional[float] = field(default=0.0, metadata={"help": "The weight decay."}) do_valid: bool = field(default=True, metadata={"help": "Whether to run evaluation."}) do_test: bool = field(default=True, metadata={"help": "Whether to run testing."}) valid_steps: Optional[int] = field(default=50, metadata={"help": "The evaluation steps."}) valid_seed: Optional[int] = field(default=42, metadata={"help": "The seed for validation."}) test_seed: Optional[int] = field(default=42, metadata={"help": "The seed for testing."}) save_steps: Optional[int] = field(default=500, metadata={"help": "The saving steps."}) save_total_limit: Optional[int] = field(default=None, metadata={"help": "The total number of checkpoints to save."}) ================================================ FILE: contrib/text2image/diffuser_finetuner.py ================================================ import copy import gc import json import logging import os import torch import torch.nn.functional as F import wandb from accelerate import Accelerator from diffuser_args import DiffuserModelArguments, DiffuserTunerArguments, T2IDatasetArguments from diffusers import ( DDPMScheduler, DiffusionPipeline, ) from diffusers.loaders import LoraLoaderMixin from diffusers.optimization import get_scheduler from diffusers.utils import ( convert_state_dict_to_diffusers, ) from diffusers.utils.torch_utils import is_compiled_module from peft.utils import get_peft_model_state_dict from torch.utils.data import DataLoader from tqdm import tqdm from lmflow.pipeline.finetuner import BaseTuner logger = logging.getLogger(__name__) def log_validation( pipeline, accelerator: Accelerator, pipeline_args: dict, save_dir, global_step, ): pipeline.to(accelerator.device) pipeline.vae.to(torch.float32) with torch.no_grad(): prompt_images = [(pipeline_arg["prompt"], pipeline(**pipeline_arg).images[0]) for pipeline_arg in pipeline_args] for tracker in accelerator.trackers: if tracker.name == "wandb": tracker.log( { "validation": [ wandb.Image(image, caption=f"{i}: {prompt}") for i, (prompt, image) in enumerate(prompt_images) ] } ) if not os.path.exists(save_dir): os.makedirs(save_dir) for i, (prompt, image) in enumerate(prompt_images): image.save(os.path.join(save_dir, f"{prompt.replace(' ', '_')}.png")) del pipeline torch.cuda.empty_cache() gc.collect() return class DiffuserModelTuner(BaseTuner): """Initializes the `RewardModelTuner` class. Parameters ---------- model_args : ModelArguments object. Contains the arguments required to load the model. data_args : DatasetArguments object. Contains the arguments required to load the dataset. finetuner_args : RewardModelTunerArguments object. Contains the arguments required to perform finetuning. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. """ def __init__( self, model_args: DiffuserModelArguments, data_args: T2IDatasetArguments, finetuner_args: DiffuserTunerArguments, *args, **kwargs, ): self.model_args = model_args self.data_args = data_args self.finetuner_args = finetuner_args def tune( self, accelerator: Accelerator, model, dataset, ): dataloader = DataLoader(dataset=dataset, batch_size=self.finetuner_args.train_batch_size, shuffle=True) noise_scheduler = DDPMScheduler.from_pretrained(self.model_args.model_name_or_path, subfolder="scheduler") def unwrap_model(model): model = accelerator.unwrap_model(model) model = model._orig_mod if is_compiled_module(model) else model return model # filter trainable parameters params_to_optimize = list(filter(lambda p: p.requires_grad, model.parameters())) accelerator.print(len(params_to_optimize)) optimizer = torch.optim.AdamW( params_to_optimize, lr=self.finetuner_args.learning_rate, weight_decay=self.finetuner_args.weight_decay ) lr_scheduler = get_scheduler( "constant", optimizer=optimizer, ) model, dataloader, optimizer, lr_scheduler = accelerator.prepare(model, dataloader, optimizer, lr_scheduler) weight_dtype = torch.float32 if accelerator.mixed_precision == "fp16": weight_dtype = torch.float16 progress_bar = tqdm( range(self.finetuner_args.num_train_epochs * len(dataloader)), desc="Training", disable=not accelerator.is_main_process, ) global_step = 0 for epoch in range(self.finetuner_args.num_train_epochs): model.train() for batch in dataloader: clean_latents = batch["image"].to(dtype=weight_dtype) text_embedding = batch["text"].to(dtype=weight_dtype) bsz, channel, height, width = clean_latents.shape noise = torch.randn_like(clean_latents).to(dtype=weight_dtype) timesteps = torch.randint( 0, noise_scheduler.config.num_train_timesteps, (bsz,), device=clean_latents.device ) timesteps = timesteps.long() noisy_latents = noise_scheduler.add_noise(clean_latents, noise, timesteps) model_pred = model( noisy_latents, timesteps, text_embedding, )[0] if noise_scheduler.config.prediction_type == "epsilon": target = noise elif noise_scheduler.config.prediction_type == "v_prediction": target = noise_scheduler.get_velocity(clean_latents, noise, timesteps) else: raise ValueError(f"Unknown prediction type {noise_scheduler.config.prediction_type}") loss = F.mse_loss(model_pred.float(), target.float(), reduction="mean") accelerator.backward(loss) optimizer.step() lr_scheduler.step() optimizer.zero_grad() progress_bar.update(1) if accelerator.is_main_process: logs = {"loss": loss.item(), "lr": lr_scheduler.get_last_lr()[0]} progress_bar.set_postfix(**logs) accelerator.log(logs, step=global_step) global_step += 1 # validation if ( accelerator.is_main_process and self.finetuner_args.do_valid and self.data_args.validation_file is not None ): if global_step % self.finetuner_args.valid_steps == 0: with torch.no_grad(): pipeline = DiffusionPipeline.from_pretrained( self.model_args.model_name_or_path, torch_dtype=weight_dtype, ) if self.model_args.model_type == "unet": pipeline.unet = unwrap_model(model) elif self.model_args.model_type == "transformer": pipeline.transformer = unwrap_model(model) else: raise ValueError(f"Unknown model type {self.model_args.model_type}") with open(os.path.join(self.data_args.dataset_path, self.data_args.validation_file)) as f: validation_data = json.load(f) generator = torch.Generator(device=accelerator.device).manual_seed( self.finetuner_args.valid_seed ) pipeline_args = [ { "prompt": item["text"], "generator": generator, "width": self.data_args.image_size, "height": self.data_args.image_size, } for item in validation_data["instances"] ] log_validation( pipeline, accelerator, pipeline_args, os.path.join(self.finetuner_args.output_dir, f"step_{global_step}_validation"), global_step, ) if accelerator.is_main_process and global_step % self.finetuner_args.save_steps == 0: os.makedirs(os.path.join(self.finetuner_args.output_dir, "checkpoints"), exist_ok=True) if ( len(os.listdir(os.path.join(self.finetuner_args.output_dir, "checkpoints"))) > self.finetuner_args.max_checkpoints ): os.remove( os.path.join( self.finetuner_args.output_dir, "checkpoints", sorted(os.listdir(os.path.join(self.finetuner_args.output_dir, "checkpoints")))[0], ) ) if self.model_args.use_lora: temp_model = unwrap_model(copy.deepcopy(model)) temp_model = temp_model.to(torch.float32) model_lora_state_dict = convert_state_dict_to_diffusers(get_peft_model_state_dict(temp_model)) LoraLoaderMixin.save_lora_weights( save_directory=os.path.join(self.finetuner_args.output_dir, "checkpoints", "final"), unet_lora_layers=model_lora_state_dict if self.model_args.model_type == "unet" else None, transformer_lora_layers=model_lora_state_dict if self.model_args.model_type == "transformer" else None, ) del temp_model else: accelerator.save( accelerator.get_state_dict(model), os.path.join(self.finetuner_args.output_dir, "checkpoints", "final.pt"), ) accelerator.wait_for_everyone() progress_bar.close() if accelerator.is_main_process: if self.finetuner_args.do_test and self.data_args.test_file is not None: pipeline = DiffusionPipeline.from_pretrained( self.model_args.model_name_or_path, torch_dtype=weight_dtype, ) if self.model_args.model_type == "unet": pipeline.unet = unwrap_model(model) elif self.model_args.model_type == "transformer": pipeline.transformer = unwrap_model(model) else: raise ValueError(f"Unknown model type {self.model_args.model_type}") with open(os.path.join(self.data_args.dataset_path, self.data_args.test_file)) as f: test_data = json.load(f) generator = torch.Generator(device=accelerator.device).manual_seed(self.finetuner_args.test_seed) pipeline_args = [ { "prompt": item["text"], "generator": generator, "width": self.data_args.image_size, "height": self.data_args.image_size, } for item in test_data["instances"] ] log_validation( pipeline, accelerator, pipeline_args, os.path.join(self.finetuner_args.output_dir, "test_final"), global_step, ) os.makedirs(os.path.join(self.finetuner_args.output_dir, "checkpoints"), exist_ok=True) if self.model_args.use_lora: model = unwrap_model(model) model = model.to(torch.float32) model_lora_state_dict = convert_state_dict_to_diffusers(get_peft_model_state_dict(model)) LoraLoaderMixin.save_lora_weights( save_directory=os.path.join(self.finetuner_args.output_dir, "checkpoints", "final"), unet_lora_layers=model_lora_state_dict if self.model_args.model_type == "unet" else None, transformer_lora_layers=model_lora_state_dict if self.model_args.model_type == "transformer" else None, ) # pipeline.load_lora_weights(output_dir, weight_name="pytorch_lora_weights.safetensors") else: accelerator.save( accelerator.get_state_dict(model), os.path.join(self.finetuner_args.output_dir, "checkpoints", "final.pt"), ) return ================================================ FILE: contrib/text2image/finetune_t2i.py ================================================ import os os.environ["TOKENIZERS_PARALLELISM"] = "false" os.environ["WANDB_MODE"] = "offline" import gc import shutil from pathlib import Path import torch from accelerate import Accelerator from accelerate.utils import ProjectConfiguration from diffuser_args import DiffuserModelArguments, DiffuserTunerArguments, T2IDatasetArguments from diffuser_finetuner import DiffuserModelTuner from diffusers import AutoencoderKL, UNet2DConditionModel from peft import LoraConfig from t2i_dataset import build_t2i_dataset from transformers import AutoTokenizer, CLIPTextModel, HfArgumentParser def main(): parser = HfArgumentParser((DiffuserModelArguments, T2IDatasetArguments, DiffuserTunerArguments)) model_args, data_args, tuner_args = parser.parse_args_into_dataclasses() logging_dir = Path(tuner_args.output_dir, tuner_args.logging_dir) accelerator_project_config = ProjectConfiguration(project_dir=tuner_args.output_dir, logging_dir=logging_dir) accelerator = Accelerator( mixed_precision=tuner_args.mixed_precision, log_with="wandb", project_config=accelerator_project_config, ) if accelerator.is_main_process and tuner_args.overwrite_output_dir and os.path.exists(tuner_args.output_dir): shutil.rmtree(tuner_args.output_dir) tokenizer = AutoTokenizer.from_pretrained(model_args.model_name_or_path, subfolder="tokenizer") text_encoder = CLIPTextModel.from_pretrained(model_args.model_name_or_path, subfolder="text_encoder").to("cuda") vae = AutoencoderKL.from_pretrained(model_args.model_name_or_path, subfolder="vae").to("cuda") dataset = build_t2i_dataset(data_args, tokenizer, text_encoder, vae) del tokenizer, text_encoder, vae torch.cuda.empty_cache() gc.collect() model = None if model_args.model_type == "unet": model = UNet2DConditionModel.from_pretrained(model_args.model_name_or_path, subfolder=model_args.model_type) elif model_args.model_type == "transformer": raise NotImplementedError("Transformer model is not implemented.") else: raise ValueError("The model type is not supported.") if model_args.use_lora: accelerator.print(f"Using LoRA of {model_args.lora_target_modules} for training") model.requires_grad_(False) lora_config = LoraConfig( r=model_args.lora_r, lora_alpha=model_args.lora_alpha, lora_dropout=model_args.lora_dropout, init_lora_weights="gaussian", target_modules=model_args.lora_target_modules, ) model.add_adapter(lora_config) else: model.requires_grad_(True) fintuner = DiffuserModelTuner(model_args, data_args, tuner_args) accelerator.init_trackers( "text2image-finetune", config={ "data_args": data_args, "model_args": model_args, "tuner_args": tuner_args, }, ) accelerator.wait_for_everyone() fintuner.tune(accelerator=accelerator, model=model, dataset=dataset) if __name__ == "__main__": main() ================================================ FILE: contrib/text2image/finetune_t2i.sh ================================================ # Parses arguments model_name_or_path=stabilityai/stable-diffusion-2-1 model_type="unet" dataset_path=data/example output_dir=output main_port=29500 img_size=768 while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; -t|--model_type) model_type="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; -o|--output_dir) output_dir="$2" shift ;; -p|--main_port) main_port="$2" shift ;; -i|--img_size) img_size="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done echo "model_name_or_path: ${model_name_or_path}" echo "model_type: ${model_type}" echo "dataset_path: ${dataset_path}" echo "output_dir: ${output_dir}" echo "main_port: ${main_port}" echo "img_size: ${img_size}" accelerate launch \ --config_file=./accelerate_t2i_config.yaml \ --main_port=${main_port} \ finetune_t2i.py \ --model_name_or_path=${model_name_or_path} \ --model_type=${model_type} \ --use_lora=True \ --lora_target_module "to_k" "to_q" "to_v" "to_out.0" "add_k_proj" "add_v_proj" \ --dataset_path=${dataset_path} \ --image_folder="img" \ --image_size=${img_size} \ --train_file="train.json" \ --validation_file="valid.json" \ --test_file="test.json" \ --output_dir=${output_dir} \ --logging_dir="logs" \ --overwrite_output_dir=True \ --mixed_precision="fp16" \ --num_train_epochs=100 \ --train_batch_size=1 \ --learning_rate=1e-4 \ --valid_steps=50 ================================================ FILE: contrib/text2image/requirements.txt ================================================ diffusers>=0.29.2 ================================================ FILE: contrib/text2image/t2i_dataset.py ================================================ #!/usr/bin/env python """This Python code defines a class T2I Dataset.""" import json import logging import os.path as osp from diffuser_args import T2IDatasetArguments from PIL import Image from torch.utils.data import Dataset from torchvision import transforms from tqdm import tqdm logger = logging.getLogger(__name__) class CustomT2IDataset(Dataset): """Dataset for T2I data""" def __init__(self, data_args: T2IDatasetArguments): self.data_args = data_args self.image_folder = osp.join(data_args.dataset_path, data_args.image_folder) self.data_file = osp.join(data_args.dataset_path, data_args.train_file) self.data_dict = json.load(open(self.data_file)) assert self.data_dict["type"] == "text-image", "The dataset type must be text-image." self.data_instances = self.data_dict["instances"] def __len__(self): return len(self.data_instances) def __getitem__(self, idx): instance = self.data_instances[idx] image_path = osp.join(self.image_folder, instance["image"]) image = Image.open(image_path) image = image.convert("RGB") return { "image": image, "text": instance["text"], } class EncodePreprocessor: def __init__(self, data_args: T2IDatasetArguments, kind: str = "simple", **kwargs): self.transform = transforms.Compose( [ transforms.Resize(data_args.image_size, interpolation=transforms.InterpolationMode.BILINEAR), transforms.CenterCrop(data_args.image_size) if data_args.image_crop_type == "center" else transforms.RandomCrop(data_args.image_size), transforms.ToTensor(), transforms.Normalize(mean=[0.5], std=[0.5]), ] ) self.pre_func = None if kind == "simple": self.register_simple_func(**kwargs) def register_simple_func(self, tokenizer, text_encoder, vae): self.tokenizer = tokenizer self.text_encoder = text_encoder self.vae = vae def simple_func(data_item): image = self.transform(data_item["image"]) latents = self.vae.encode(image.to(self.vae.device, dtype=self.vae.dtype).unsqueeze(0)).latent_dist.sample() encoded_image = latents * self.vae.config.scaling_factor encoded_image = encoded_image.detach() encoded_image = encoded_image.squeeze(0).cpu() max_length = self.tokenizer.model_max_length tokens = self.tokenizer( [data_item["text"]], max_length=max_length, padding="max_length", truncation=True, return_tensors="pt" ).input_ids encoded_text = self.text_encoder(tokens.to(self.text_encoder.device))[0] encoded_text = encoded_text.detach() encoded_text = encoded_text.squeeze(0).cpu() return { "image": encoded_image, "text": encoded_text, } self.pre_func = simple_func def __call__(self, data_item): return self.pre_func(data_item) class PreprocessedT2IDataset(Dataset): "Preprocess dataset with prompt" def __init__(self, raw_dataset: Dataset, data_args: T2IDatasetArguments, preprocessor: EncodePreprocessor): self.data_dict = [] logger.info("Preprocessing data ...") for data_item in tqdm(raw_dataset): self.data_dict.append(preprocessor(data_item)) def __len__(self): return len(self.data_dict) def __getitem__(self, idx): return self.data_dict[idx] def build_t2i_dataset(data_args: T2IDatasetArguments, tokenizer, text_encoder, vae): raw_dataset = CustomT2IDataset(data_args) # dataset = SimpleT2IDataset(raw_dataset, data_args, tokenizer, text_encoder, vae) preprocessor = EncodePreprocessor( kind="simple", data_args=data_args, tokenizer=tokenizer, text_encoder=text_encoder, vae=vae ) dataset = PreprocessedT2IDataset(raw_dataset, data_args, preprocessor) return dataset ================================================ FILE: contrib/tool-finetune/README.md ================================================ ## Function-call Finetune ### Pip dependency ``` bitsandbytes==0.40.0 deepspeed==0.12.0 flash-attn==2.5.7 peft==0.10.0 torch==2.1.2+cu118 transformers==4.40.1 vllm==0.5.2 xformers==0.0.27 ``` ### Conversation Template ``` { "type": "conversation", "instances": [ { "system": "You are a helpful assistant with access to the following functions. Use them if required - ", "tools": ["{\"name\": \"", \"description\": \"", \"parameters\": {\"type\": \"object\", \"properties\": {\"property_1\": {\"type\": \"xxx\", \"description\": \"\"}, \"property_2\": {\"type\": \"xxx\", \"description\": \"\"}}, \"required\": [\"required_1\", \"property_n\"]}}",]", "messages": [ { "role": "user", "content": "" }, { "role": "function", "content": "" }, { "role": "observation", "content": "" }, { "role": "assistant", "content": "" } ] }, { "system": "You are a helpful assistant, with no access to external functions.", "tools": [], "messages": [ { "role": "user", "content": "" }, { "role": "assistant", "content": "" } ] }, ] } ``` ### Run Function-call Finetune Example ``` ./contrib/tool-finetune/run_function_call_finetune.sh \ --model_name_or_path meta-llama/Meta-Llama-3-8B \ --trust_remote_code True \ --conversation_template llama3_for_tool \ --dataset_path /home/wenhesun/LMFlow/data/glaive-function-calling-v2 \ --output_model_path /home/wenhesun/LMFlow/output_models/function-call-finetuned-llama ``` ### Command-Line Arguments - `--model-name-or-path` - Specifies the name or path of the model used for - `--conversation_template` - So far supports the following choices: llama3_for_tool, qwen2_for_tool - `--dataset_path` - The path to the dataset that has been converted to the specified format - `--output_model_path` - Directory to store the finetuned model and logs ================================================ FILE: contrib/tool-finetune/function_call_finetune.py ================================================ import os import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) import hashlib import logging from typing import Union import transformers from transformers import HfArgumentParser, PreTrainedTokenizer, PreTrainedTokenizerFast from transformers.testing_utils import CaptureLogger from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) from lmflow.datasets.dataset import Dataset from lmflow.models.hf_decoder_model import HFDecoderModel from lmflow.pipeline.auto_pipeline import AutoPipeline from lmflow.tokenization.hf_decoder_model import blocking from lmflow.utils.constants import ( CONVERSATION_DATASET_DESCRIPTION, CONVERSATION_ROLE_NAMES, TEXT2TEXT_DATASET_DESCRIPTION, TEXT_ONLY_DATASET_DESCRIPTION, ) from lmflow.utils.conversation_template import PRESET_TEMPLATES, ConversationTemplateForTool tok_logger = transformers.utils.logging.get_logger("transformers.tokenization_utils_base") logger = logging.getLogger(__name__) class HFDecoderModelForTool(HFDecoderModel): def tokenize(self, dataset, add_special_tokens=True, *args, **kwargs) -> Dataset: """ Tokenize the full dataset. Parameters ------------ dataset : lmflow.datasets.Dataset. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. Returns ------------ tokenized_datasets : The tokenized dataset, without any leading or trailing special tokens (normally they are Begin-Of-Sentence or End-Of-Sentence tokens). """ # Preprocessing the datasets. # First we tokenize all the texts. if dataset.get_backend() != "huggingface": raise NotImplementedError("tokenization of datasets with non-huggingface backend arenot supported yet") dataset_type = dataset.get_type() model_args = self.model_args raw_datasets = dataset hf_raw_datasets = dataset.get_backend_dataset() column_names = list(hf_raw_datasets.features) data_args = raw_datasets.get_data_args() # Requires three types of information for tokenizing different datasets # 1) Which fields require tokenization, e.g. # "text2float": "text", but not "float" # "text2text": both "input" and "output" # 2) How will there tokenized sequence concatenated together, e.g. # "text_only": "text" -> "text" # "text2text": "input", "output" -> "input" + "output" # 3) Which fields require loss in final computation, e.g. # "text_only": "text" # "text2text": "output" only tokenized_column_order = None # Handles 1) and 2) label_columns = None # Handles 3) if dataset_type == "text_only": tokenized_column_order = ["text"] label_columns = ["text"] elif dataset_type == "text2text": tokenized_column_order = ["input", "output"] label_columns = ["output"] add_special_tokens = False elif dataset_type == "conversation": if data_args.conversation_template: if data_args.conversation_template in PRESET_TEMPLATES.keys(): conversation_template = PRESET_TEMPLATES[data_args.conversation_template] else: raise NotImplementedError( f"Conversation template {data_args.conversation_template} is not supported yet." ) else: logger.warning("No conversation template provided. Using default template.") conversation_template = PRESET_TEMPLATES["empty"] logger.warning(f"Conversation template: {conversation_template}") else: raise NotImplementedError( f'dataset type "{dataset_type}" is not supported, currently' " only support following data types:\n" f" 1) {TEXT_ONLY_DATASET_DESCRIPTION}\n" f" 2) {TEXT2TEXT_DATASET_DESCRIPTION}\n" f" 3) {CONVERSATION_DATASET_DESCRIPTION}\n" ) # Whether to truncate long sequences to fit into max_length use_truncation = False if model_args.use_lora or data_args.disable_group_texts: use_truncation = True tokenize_fn = conversation_tokenize_function tokenize_fn_kwargs = { "data_args": data_args, "tokenizer": self.tokenizer, "column_names": column_names, } if "conversation" in dataset_type: tokenize_fn_kwargs["conversation_template"] = conversation_template else: tokenize_fn_kwargs["label_columns"] = label_columns tokenize_fn_kwargs["tokenized_column_order"] = tokenized_column_order tokenize_fn_kwargs["add_special_tokens"] = add_special_tokens tokenize_fn_kwargs["use_truncation"] = use_truncation tokenize_kwargs = {} if not data_args.streaming: fingerprint = hashlib.md5( ( raw_datasets.get_fingerprint() + str(self.tokenizer) + f"###padding_side={self.tokenizer.padding_side}" + ( "###conversation_template=" + str(conversation_template) if "conversation" in dataset_type else "" ) + f"###disable_group_texts={data_args.disable_group_texts}" + f"###block_size={data_args.block_size}" ).encode("utf-8") ).hexdigest() tokenize_kwargs = { "num_proc": data_args.preprocessing_num_workers, "load_from_cache_file": not data_args.overwrite_cache, "desc": "Running tokenizer on dataset", "new_fingerprint": fingerprint, } tokenized_datasets = raw_datasets.map( tokenize_fn, batched=True, remove_columns=column_names, fn_kwargs=tokenize_fn_kwargs, **tokenize_kwargs ) return tokenized_datasets def conversation_tokenize_function( examples, data_args: DatasetArguments, tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast], column_names, conversation_template: ConversationTemplateForTool, ) -> dict: """Handels conversation datasets tokenization""" num_example = len(examples[column_names[0]]) token_dict = { "input_ids": [[] for _ in range(num_example)], "attention_mask": [[] for _ in range(num_example)], "labels": [[] for _ in range(num_example)], } with CaptureLogger(tok_logger) as cl: for i in range(len(examples["messages"])): messages = examples["messages"][i] system = examples.get("system", [None] * num_example)[i] tools = examples.get("tools", [None] * num_example)[i] if len(messages) < 2 or messages[0]["role"] != CONVERSATION_ROLE_NAMES["user"]: tok_logger.warning( "Invalid instance encountered. Either the conversation has less than " "one round or the first message is not from the user." ) continue if len(messages) % 2 != 0: logger.warning("The number of messages is not even, the last message will be ignored.") messages = messages[:-1] encoded_conversation = conversation_template.encode_conversation( tokenizer=tokenizer, messages=messages, system=system, tools=tools, ) input_ids, labels = [], [] for turn_idx, conversation_tuple in enumerate(encoded_conversation): if len(conversation_tuple) == 2: user_input = conversation_tuple[0] assistant_result = conversation_tuple[1] input_ids += user_input + assistant_result if data_args.train_on_prompt: labels += user_input + assistant_result else: labels += [-100] * len(user_input) + assistant_result elif len(conversation_tuple) == 4: user_input = conversation_tuple[0] function_result = conversation_tuple[1] observation_input = conversation_tuple[2] assistant_result = conversation_tuple[3] input_ids += user_input + function_result + observation_input + assistant_result if data_args.train_on_prompt: labels += user_input + function_result + observation_input + assistant_result else: labels += ( [-100] * len(user_input) + function_result + [-100] * len(observation_input) + assistant_result ) else: logger.warning("The number of roles in conversation is not appropriate") token_dict["input_ids"][i].extend(input_ids) token_dict["attention_mask"][i].extend([1] * len(input_ids)) token_dict["labels"][i].extend(labels) if data_args.disable_group_texts: token_dict = blocking( token_dict=token_dict, block_size=data_args.block_size, model_max_length=tokenizer.model_max_length, pad_token_id=tokenizer.pad_token_id, padding_side=tokenizer.padding_side, ) # clm input could be much much longer than block_size if "Token indices sequence length is longer than the" in cl.out: tok_logger.warning( "^^^^^^^^^^^^^^^^ Please ignore the warning above - this long input will be chunked into smaller bits" " before being passed to the model." ) return token_dict def train(): # Initialize args ## Prepare training_args pipeline_name = "finetuner" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((ModelArguments, DatasetArguments, PipelineArguments)) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): model_args, data_args, pipeline_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) else: model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() print("Model args", model_args) print("data_args", data_args) print("training_args", pipeline_args) # Init model model = HFDecoderModelForTool(model_args) # Process data dataset = Dataset(data_args) # Finetune finetuner = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) finetuner.tune(model=model, dataset=dataset) if __name__ == "__main__": train() ================================================ FILE: contrib/tool-finetune/run_function_call_finetune.sh ================================================ #!/bin/bash # Please run this script under ${project_id} in project directory of # https://github.com/shizhediao/llm-ft # COMMIT: d5fecf30ba8011067b10cf51fede53a5ab6574e4 # Parses arguments model_name_or_path=gpt2 dataset_path=data/alpaca/train_conversation output_dir=output_models/finetune deepspeed_args="--master_port=12000" conversation_template=llama2 # Safety related arguments trust_remote_code=0 while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; -o|--output_model_path) output_dir="$2" shift ;; --conversation_template) conversation_template="$2" shift ;; --deepspeed_args) deepspeed_args="$2" shift ;; --trust_remote_code) trust_remote_code="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done # Finetune exp_id=finetune project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} deepspeed ${deepspeed_args} \ contrib/tool-finetune/function_call_finetune.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code ${trust_remote_code} \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --conversation_template ${conversation_template} \ --num_train_epochs 0.01 \ --learning_rate 2e-5 \ --disable_group_texts 1 \ --block_size 1024 \ --per_device_train_batch_size 1 \ --deepspeed configs/archive/ds_config_zero3.json \ --fp16 \ --run_name finetune \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --dataloader_num_workers 1 \ > >(tee ${log_dir}/train.log) \ 2> >(tee ${log_dir}/train.err >&2) ================================================ FILE: docs/dev_notes/finetuning.mmd ================================================ sequenceDiagram participant User participant Finetuner as LMFlow Finetuner participant Model as LMFlow Model participant Dataset as LMFlow Dataset participant Trainer as Trainer User->>Finetuner: tune(model, dataset) %% Tokenization Finetuner->>Model: tokenize(dataset) Model->>Dataset: Apply tokenization to dataset alt if not disable_group_texts Finetuner->>Finetuner: group_text(tokenized_dataset, model_max_length) end %% Prepare for training Finetuner->>Finetuner: Prepare dataset for trainer %% Create appropriate trainer based on configuration alt if model_args.use_lora Finetuner->>Finetuner: Initialize PeftTrainer else Finetuner->>Finetuner: Initialize standard Trainer end alt if training_args.use_customized_optim Finetuner->>Finetuner: create_customized_optimizer() end alt if training_args.use_lisa Finetuner->>Finetuner: Create DynamicLayerActivationCallback end %% Start training Finetuner->>Trainer: train(resume_from_checkpoint) %% Training loop (simplified) loop Training iterations (Trainer._inner_training_loop simplified) Trainer->>Model: Forward pass Model-->>Trainer: Return predictions Trainer->>Trainer: Compute loss Trainer->>Model: Backward pass Model->>Model: Compute Gradient Trainer->>Trainer: Optimizer step end %% Save the model alt if not model_args.use_lora Trainer->>Trainer: save_model() else alt if model_args.save_aggregated_lora Finetuner->>Model: merge_lora_weights() end Finetuner->>Model: save(output_dir, save_aggregated_lora) end %% Finish and return Trainer-->>Finetuner: Return train result Finetuner->>Finetuner: Log metrics Finetuner-->>User: Return fine-tuned model ================================================ FILE: docs/readme/Position_Interpolation.md ================================================ # Position Interpolation Now LMFlow supports the latest Linear & NTK (Neural Kernel theory) scaling techniques for LLaMA models. \ For more details of these techniques, you can checkout the links below: * Linear scaling: \ https://arxiv.org/abs/2306.15595 * NTK scaling: \ https://www.reddit.com/r/LocalLLaMA/comments/14lz7j5/ntkaware_scaled_rope_allows_llama_models_to_have/ ## Usage To use the Position Interpolation Techniques, you need to set the following options: ``` --truncate_to_model_max_length False --do_rope_scaling True ``` For linear scaling, set the extending ratio by: ``` --rope_pi_ratio 4 ``` For NTK scaling, set the extending ratio by: ``` --rope_ntk_ratio 4 ``` Here is an example of evaluation bash code: ``` #!/bin/bash CUDA_VISIBLE_DEVICES=0 \ deepspeed examples/evaluation.py \ --answer_type text \ --model_name_or_path pinkmanlove/llama-7b-hf \ --dataset_path data/wiki_en_eval \ --deepspeed examples/ds_config.json \ --inference_batch_size_per_device 1 \ --truncate_to_model_max_length False \ --block_size 4096 \ --use_flash_attention True \ --do_rope_scaling True \ --rope_pi_ratio 2 \ --rope_ntk_ratio 4 \ --metric ppl ``` ================================================ FILE: docs/readme/README_es.md ================================================

LMFlow

# LMFlow

English | 简体中文 | Español | 日本語 | 한국어 | हिंदी

> [!NOTE] > This README file was translated by LLM. Spanish speakers are welcome to submit PRs to polish the document! > [!NOTE] La versión en español fue traducida por ChatGPT, si hay algún error, bienvenido sea al contributor para corregirlo, gracias. Al mismo tiempo, si hay alguna diferencia o inconsistencia en el contenido con la versión en inglés, se debe considerar la versión en inglés como la correcta. [![Website](https://img.shields.io/badge/Website-Demo-20B2AA.svg)](https://lmflow.com) [![Code License](https://img.shields.io/badge/Code%20License-Apache_2.0-green.svg)](https://github.com/OptimalScale/LMFlow/blob/main/LICENSE) [![Python 3.9+](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/downloads/release/python-390/) [![Doc](https://img.shields.io/badge/Website-Doc-ff69b4.svg)](https://optimalscale.github.io/LMFlow/) [![Embark](https://img.shields.io/badge/Discord-LMFlow-%237289da.svg?logo=discord)](https://discord.gg/u9VJNpzhvA) [![slack badge](https://img.shields.io/badge/Slack-Join-blueviolet?logo=slack&)](https://join.slack.com/t/lmflow/shared_invite/zt-1wju9nicy-woXbNtS~5MavHSAtiMxmxQ) [![WeChat badge](https://img.shields.io/badge/WeChat-Join-brightgreen?logo=wechat&)](https://ibb.co/ZhM4hhn) Una caja de herramientas extensible, conveniente y eficiente para ajustar modelos de aprendizaje automático grandes, diseñada para ser fácil de usar, rápida, confiable y accesible para toda la comunidad.

LMFlow-features

## Latest News * [2024-04-25] :rocket: ¡Soporte para plantilla de conversación! Hemos preconfigurado las últimas plantillas de conversación [Llama-3](https://huggingface.co/meta-llama/Meta-Llama-3-70B) y [Phi-3](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct), así como algunas plantillas de conversación frecuentemente utilizadas como `chatml` (ver todas las plantillas [aquí](https://optimalscale.github.io/LMFlow/examples/DATASETS.html#conversation-template)), y estamos trabajando en agregar más plantillas preconfiguradas. ¡Agrega el correspondiente `--conversation_template` en el script de la terminal y estarás listo! :rocket: * [2024-03-27] Soporte para [LISA](https://arxiv.org/abs/2403.17919) — ¡Entrenamiento de modelos de 7B en GPU con 24G de memoria sin necesidad de offloading! * [2023-09-11] Soporte para [decodificación especulativa](https://arxiv.org/abs/2211.17192), consulta la [guía de uso](https://github.com/OptimalScale/LMFlow/blob/main/scripts/speculative_decoding/README.md) para ver cómo utilizarlo y estadísticas de rendimiento básicas. * [2023-08-14] Soporte para ampliar la ventana de contexto de LLaMA a través de interpolación de posición (Lineal y Escalado NTK), más información en: [Interpolación de Posición](https://github.com/OptimalScale/LMFlow/blob/main/readme/Position_Interpolation.md). * [2023-08-07] Soporte para [Flash Attention-2](https://crfm.stanford.edu/2023/07/17/flash2.html), consulta la [guía de uso de Flash Attention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md) para más detalles. ## Quick Start ### Setup Nuestro repositorio ha sido probado en Linux (Ubuntu 20.04). Las otras plataformas de sistemas operativos (macOS, Windows) aún no han sido completamente probadas, por lo que pueden surgir algunos errores inesperados. Se recomienda probar primero en Linux/Windows WSL o utilizar Google Colab para experimentar. Para CUDA 10.3-11.7, se recomienda utilizar `v0.0.5` o versiones anteriores. Para CUDA superior a 11.7, por favor, utilice nuestra rama estable `>= v0.0.6` para una mejor experiencia. ```bash git clone https://github.com/OptimalScale/LMFlow.git cd LMFlow conda create -n lmflow python=3.9 -y conda activate lmflow conda install mpi4py bash install.sh ``` ### Prepare Dataset Por favor, consulta nuestra [documentación oficial (en inglés)](https://optimalscale.github.io/LMFlow/examples/DATASETS.html). La documentación oficial se encuentra actualmente en proceso de traducción, te pedimos paciencia mientras tanto. ### Fine-Tuning (Full) El ajuste fino completo actualizará todos los parámetros del modelo. A continuación se muestra un ejemplo de ajuste fino completo de GPT-2: ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune.sh \ --model_name_or_path gpt2 \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_gpt2 ``` > [!TIP] > Puedes especificar una plantilla de conversación para el conjunto de datos de diálogo agregando el parámetro `--conversation_template`. > >
Ejemplo: Especificar una plantilla de conversación para Llama-3-8B > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune.sh \ > --model_name_or_path meta-llama/Meta-Llama-3-8B \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama3 \ > --output_model_path output_models/finetuned_llama3_8b >``` >
### Fine-Tuning (LISA) [LISA](https://arxiv.org/abs/2403.17919) es un algoritmo de ajuste fino que es **eficiente en memoria**, permitiendo un equilibrio entre la memoria y el número de capas descongeladas aleatoriamente. El script siguiente ha sido probado únicamente en **una sola GPU**. ¡Estén atentos a nuestras últimas actualizaciones! :smile: ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lisa.sh \ --model_name_or_path meta-llama/Llama-2-7b-hf \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_llama2_7b \ --lisa_activated_layers 1 \ --lisa_interval_steps 20 ``` > [!TIP] >
Ejemplo: Especificando el conjunto de datos de conversación para Llama-2-7B > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune_with_lisa.sh \ > --model_name_or_path meta-llama/Llama-2-7b-hf \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama2 \ > --output_model_path output_models/finetuned_llama2_7b_lisa \ > --lisa_activated_layers 1 \ > --lisa_interval_steps 20 >``` >
### Fine-Tuning (LoRA) LoRA es un algoritmo de ajuste fino de parámetros que es más eficiente que el ajuste fino completo de parámetros. ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lora.sh \ --model_name_or_path facebook/galactica-1.3b \ --dataset_path data/alpaca/train_conversation \ --output_lora_path output_models/finetuned_galactica_lora ``` > [!TIP] >
Ejemplo: Especificando el conjunto de datos de diálogo para Llama-2-7B > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune_with_lora.sh \ > --model_name_or_path meta-llama/Llama-2-7b-hf \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama2 \ > --output_model_path output_models/finetuned_llama2_7b_lora \ >``` >
> >
Combinando pesos de LoRA > >Puede combinar los pesos de LoRA con el modelo original utilizando el siguiente comando: >```sh >./scripts/run_merge_lora.sh \ > --model_name_or_path Qwen/Qwen1.5-1.8B \ > --lora_model_path output_models/lora \ > --output_model_path output_models/lora_merged \ >``` >
### Inference Después de haber terminado el ajuste fino, puedes entablar una conversación con el modelo usando el siguiente comando. ```sh ./scripts/run_chatbot.sh output_models/finetuned_gpt2 ``` ### Deployment Si deseas implementar tu propio modelo localmente, ofrecemos una interfaz de chatbot basada en Gradio. Para iniciar la demostración de Robin-7b con esta interfaz, utilice los siguientes comandos: ```sh pip install gradio python ./examples/chatbot_gradio.py --deepspeed configs/ds_config_chatbot.json --model_name_or_path YOUR-LLAMA --lora_model_path ./robin-7b --prompt_structure "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.###Human: {input_text}###Assistant:" --end_string "#" --max_new_tokens 200 ``` ### Evaluation [LMFlow Benchmark](https://blog.gopenai.com/lmflow-benchmark-an-automatic-evaluation-framework-for-open-source-llms-ef5c6f142418) es un marco de evaluación automática para LLM de código abierto. Utilizamos la Probabilidad Negativa del Logaritmo (NLL) como métrica para evaluar diversos aspectos de los LLM, como el chat casual, el razonamiento común y la capacidad de seguir instrucciones. Le invitamos a utilizar LMFlow Benchmark para evaluar los modelos que tenga disponibles y a participar en nuestra [Comparación de Modelos (LLM comparision)](https://docs.google.com/spreadsheets/d/1JYh4_pxNzmNA9I0YM2epgRA7VXBIeIGS64gPJBg5NHA/edit?usp=sharing). Tomando como ejemplo el GPT-2 XL, puede comenzar la evaluación con el siguiente comando: ```sh ./scripts/run_benchmark.sh --model_name_or_path gpt2-xl ``` `--model_name_or_path` es un parámetro obligatorio, donde puede ingresar el nombre del modelo de Hugging Face o la ruta local del modelo. Puede revisar los resultados de la evaluación en `benchmark.log` dentro de `./output_dir/gpt2-xl_lmflow_chat_nll_eval`, `./output_dir/gpt2-xl_all_nll_eval` y `./output_dir/gpt2-xl_commonsense_qa_eval`. ## Supported Features
Optimización de Ajuste Fino y Memoria * LISA: Layerwise Importance Sampling for Memory-Efficient Large Language Model Fine-Tuning LISA es un algoritmo de ajuste fino de LLM eficiente en memoria. Al seleccionar selectivamente capas para congelar durante el ajuste fino, LISA supera los métodos de ajuste fino existentes (como LoRA). Consulta el [documento](https://arxiv.org/abs/2403.17919) para obtener más información. Puedes utilizar LISA especificando el parámetro `--use_lisa 1` en el comando de entrenamiento. Controla el número de capas activadas con `--lisa_activated_layers 2` y ajusta el intervalo de congelación de capas con `--lisa_step_interval 20`. * LoRA LoRA es un algoritmo de ajuste fino eficiente en parámetros que es más eficiente que el ajuste fino de todos los parámetros. Consulta [Ajuste Fino (LoRA)](#fine-tuning-lora) para más detalles. * FlashAttention Soportamos FlashAttention-1 y FlashAttention-2. Para más detalles, consulta: [FlashAttention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md). * Punto de Control de Gradientes [Punto de control de gradientes](https://github.com/cybertronai/gradient-checkpointing) es una técnica de optimización de memoria que intercambia cálculos por memoria para reducir el uso de la memoria de la GPU. Puedes utilizarlo agregando `--gradient_checkpointing` al comando de entrenamiento. * Deepspeed Zero3 LMFlow es compatible con [Deepspeed Zero-3 Offload](https://www.deepspeed.ai/2021/03/07/zero3-offload.html). Proporcionamos un archivo de configuración de deepspeed listo para usar [aquí](https://github.com/OptimalScale/LMFlow/blob/main/configs/ds_config_zero3.json).
Aceleración de inferencia * Inferencia de CPU LLaMA ¡Gracias a [llama.cpp](https://github.com/ggerganov/llama.cpp), ahora todos pueden ejecutar su propio LLaMA (cuantificación de 4 bits) en la CPU! Proporcionamos un script para convertir los pesos de LLaMA LoRA en archivos `.pt`, solo necesita usar `convert-pth-to-ggml.py` de llama.cpp para realizar la cuantificación del modelo y así realizar la inferencia de LLaMA en la CPU. * FlashAttention Apoyamos FlashAttention-1 y FlashAttention-2. Para más detalles, consulta: [FlashAttention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md).
Texto largo * Interpolación de posición del modelo LLaMA (Position Interpolation) Se admite la extensión del contexto de la ventana LLaMA mediante interpolación de posición (Position Interpolation) (escalamiento lineal y NTK), consulte más detalles en: [Interpolación de posición](https://github.com/OptimalScale/LMFlow/blob/main/readme/Position_Interpolation.md).
Personalización del modelo * Ampliación del vocabulario Entrena tu propio tokenizador de SentencePiece y luego combínalo con el tokenizador de Hugging Face que viene con el modelo. Consulta: [Ampliación del vocabulario](https://github.com/OptimalScale/LMFlow/blob/main/scripts/vocab_extension).
Multi-modal * Chatbot multi-modal LMFlow admite entradas multi-modales (imágenes, texto). Consulta: [Chatbot multi-modal de LMFlow](https://github.com/OptimalScale/LMFlow/blob/main/scripts/run_vis_chatbot_gradio_minigpt4.sh).
## Support Si necesitas ayuda, no dudes en presentar un [problema en Github](https://github.com/OptimalScale/LMFlow/issues). ## License El código incluido en este proyecto está bajo la licencia Apache 2.0. Si desea utilizar los modelos incluidos en este proyecto para fines comerciales, por favor, póngase en contacto con el desarrollador para obtener autorización. ## Citation Si encuentras este repositorio útil, por favor considera darle ⭐ y citarlo: ``` @article{diao2023lmflow, title={Lmflow: An extensible toolkit for finetuning and inference of large foundation models}, author={Diao, Shizhe and Pan, Rui and Dong, Hanze and Shum, Ka Shun and Zhang, Jipeng and Xiong, Wei and Zhang, Tong}, journal={arXiv preprint arXiv:2306.12420}, year={2023} } ``` ``` @article{dong2023raft, title={Raft: Reward ranked finetuning for generative foundation model alignment}, author={Dong, Hanze and Xiong, Wei and Goyal, Deepanshu and Pan, Rui and Diao, Shizhe and Zhang, Jipeng and Shum, Kashun and Zhang, Tong}, journal={arXiv preprint arXiv:2304.06767}, year={2023} } ``` ``` @article{pan2024lisa, title={LISA: Layerwise Importance Sampling for Memory-Efficient Large Language Model Fine-Tuning}, author={Pan, Rui and Liu, Xiang and Diao, Shizhe and Pi, Renjie and Zhang, Jipeng and Han, Chi and Zhang, Tong}, journal={arXiv preprint arXiv:2403.17919}, year={2024} } ``` ================================================ FILE: docs/readme/README_hindi.md ================================================

LMFlow

# LMFlow

English | 简体中文 | Español | 日本語 | 한국어 | हिंदी

> [!NOTE] > This README file was translated by LLM for reference only. Hindi speakers are welcome to submit PRs to polish the document! > [!NOTE] यह चैटजीपीटी द्वारा अनुवादित हिंदी संस्करण है, यदि कोई त्रुटि हो, तो संबंधित योगदानकर्ताओं द्वारा संशोधित किया जा सकता है। इसके साथ ही यदि कोई सामग्री अंग्रेजी संस्करण से भिन्न हो या मेल नहीं खाती हो, तो कृपया अंग्रेजी संस्करण को ही मान्य रखें। धन्यवाद। [![Website](https://img.shields.io/badge/Website-Demo-20B2AA.svg)](https://lmflow.com) [![Code License](https://img.shields.io/badge/Code%20License-Apache_2.0-green.svg)](https://github.com/OptimalScale/LMFlow/blob/main/LICENSE) [![Python 3.9+](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/downloads/release/python-390/) [![Doc](https://img.shields.io/badge/Website-Doc-ff69b4.svg)](https://optimalscale.github.io/LMFlow/) [![Embark](https://img.shields.io/badge/Discord-LMFlow-%237289da.svg?logo=discord)](https://discord.gg/u9VJNpzhvA) [![slack badge](https://img.shields.io/badge/Slack-Join-blueviolet?logo=slack&)](https://join.slack.com/t/lmflow/shared_invite/zt-1wju9nicy-woXbNtS~5MavHSAtiMxmxQ) [![WeChat badge](https://img.shields.io/badge/WeChat-Join-brightgreen?logo=wechat&)](https://ibb.co/ZhM4hhn) एक विस्तारयोग्य, सुविधाजनक और दक्ष टूलबॉक्स जो बड़े मशीन लर्निंग मॉडल को finetune करने के लिए बनाया गया है, जो सभी समुदाय के उपयोगकर्ताओं के लिए उपलब्ध होने के साथ-साथ उपयोगकर्ता मित्रता, गति और विश्वसनीयता के साथ डिजाइन किया गया है।

LMFlow-features

## Latest News * [2024-04-25] :rocket: बातचीत टेम्पलेट का समर्थन! हमने नवीनतम [Llama-3](https://huggingface.co/meta-llama/Meta-Llama-3-70B) और [Phi-3](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct) बातचीत टेम्पलेट को पूर्वनिर्धारित किया है, साथ ही कुछ अक्सर प्रयुक्त टेम्पलेट जैसे `chatml` भी (सभी टेम्पलेट यहाँ देखें [यहाँ](https://optimalscale.github.io/LMFlow/examples/DATASETS.html#conversation-template)), और हम अधिक पूर्वनिर्धारित टेम्पलेट जोड़ने पर काम कर रहे हैं। शैल अनुक्रम में संबंधित `--conversation_template` को शैल अनुक्रम में जोड़ें और आप तैयार हैं! :rocket: * [2024-03-27] [LISA](https://arxiv.org/abs/2403.17919) का समर्थन —— 24जीबी जीपीयू पर 7B मॉडल का प्रशिक्षण बिना ऑफलोडिंग के! * [2023-09-11] [स्पेक्युलेटिव डिकोडिंग](https://arxiv.org/abs/2211.17192) का समर्थन, इस्तेमाल के तरीके और साधारण प्रदर्शन आँकड़े देखने के लिए [उपयोग गाइड](https://github.com/OptimalScale/LMFlow/blob/main/scripts/speculative_decoding/README.md) पर क्लिक करें। * [2023-08-14] [पोजीशन इंटरपोलेशन](https://github.com/OptimalScale/LMFlow/blob/main/readme/Position_Interpolation.md) के माध्यम से LLaMA की संदर्भ विंडो को विस्तारित करने का समर्थन (लीनियर और NTK स्केलिंग)। * [2023-08-07] [फ्लैश एटेंशन-2](https://crfm.stanford.edu/2023/07/17/flash2.html) का समर्थन, अधिक जानकारी के लिए [फ्लैश एटेंशन उपयोग गाइड](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md) देखें। ## Table of Contents - [LMFlow](#lmflow) - [Latest News](#latest-news) - [Table of Contents](#table-of-contents) - [Quick Start](#quick-start) - [Setup](#setup) - [Prepare Dataset](#prepare-dataset) - [Fine-Tuning (Full)](#fine-tuning-full) - [Fine-Tuning (LISA)](#fine-tuning-lisa) - [Fine-Tuning (LoRA)](#fine-tuning-lora) - [Inference](#inference) - [Deployment](#deployment) - [Evaluation](#evaluation) - [Supported Features](#supported-features) - [Support](#support) - [License](#license) - [Citation](#citation) ## Quick Start ### Setup हमारे रेपो को Linux (Ubuntu 20.04) पर परीक्षण किया गया है। अन्य ऑपरेटिंग सिस्टम प्लेटफॉर्म (MacOS, Windows) को पूरी तरह से परीक्षण नहीं किया गया है, इसलिए कुछ अपेक्षित त्रुटियों का सामना कर सकता है। Linux/Windows WSL पर प्रयोग करने या Google Colab का उपयोग करके अनुभव करने की सिफारिश की जाती है। CUDA 10.3-11.7 के लिए, `v0.0.5` या इससे पुराने संस्करणों का उपयोग करने की सिफारिश की जाती है। 11.7 से अधिक CUDA के लिए, बेहतर अनुभव के लिए हमारी स्थिर शाखा `>= v0.0.6` का उपयोग करें। ```bash git clone https://github.com/OptimalScale/LMFlow.git cd LMFlow conda create -n lmflow python=3.9 -y conda activate lmflow conda install mpi4py bash install.sh ``` ### Prepare Dataset आप हमारी [आधिकारिक दस्तावेज़ीकरण (अंग्रेजी में)](https://optimalscale.github.io/LMFlow/examples/DATASETS.html) को देखें। आधिकारिक दस्तावेज़ीकरण अनुवाद के प्रक्रिया में है, कृपया धैर्य रखें। ### Fine-Tuning (Full) मॉडल को पूर्ण पैरामीटर फ़ाइन ट्यूनिंग करने से सभी पैरामीटर अपडेट होते हैं। GPT-2 का एक पूर्ण पैरामीटर फ़ाइन ट्यूनिंग का उदाहरण निम्नलिखित है: ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune.sh \ --model_name_or_path gpt2 \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_gpt2 ``` >[!TIP] >आप बातचीत डेटासेट के लिए बातचीत टेम्पलेट को निर्दिष्ट करने के लिए `--conversation_template` पैरामीटर को जोड़कर कर सकते हैं। > >
उदाहरण: Llama-3-8B के लिए बातचीत डेटासेट टेम्पलेट का निर्दिष्ट करें > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune.sh \ > --model_name_or_path meta-llama/Meta-Llama-3-8B \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama3 \ > --output_model_path output_models/finetuned_llama3_8b >``` >
### Fine-Tuning (LISA) [LISA](https://arxiv.org/abs/2403.17919) एक **मेमरी-एफिशिएंट (memory-efficient)** फ़ाइन ट्यूनिंग एल्गोरिदम है, जो मेमरी और रैंडम अनफ्रोज़न लेयरों के बीच संतुलन स्थापित करता है। निम्नलिखित स्क्रिप्ट अब **एकल GPU** पर ही टेस्ट किया गया है। हमारे नवीनतम अपडेट पर ध्यान दें! :smile: ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lisa.sh \ --model_name_or_path meta-llama/Llama-2-7b-hf \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_llama2_7b \ --lisa_activated_layers 1 \ --lisa_interval_steps 20 ``` > [!TIP] >
उदाहरण: Llama-2-7B के लिए बातचीत डेटा सेट टेम्पलेट का निर्दिष्ट करें > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune_with_lisa.sh \ > --model_name_or_path meta-llama/Llama-2-7b-hf \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama2 \ > --output_model_path output_models/finetuned_llama2_7b_lisa \ > --lisa_activated_layers 1 \ > --lisa_interval_steps 20 >``` >
### Fine-Tuning (LoRA) LoRA एक पैरामीटर-सुसंगत (parameter-efficient) फाइन-ट्यूनिंग एल्गोरिथ्म है जो पूर्ण-पैरामीटर फाइन-ट्यूनिंग से अधिक दक्ष है। ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lora.sh \ --model_name_or_path facebook/galactica-1.3b \ --dataset_path data/alpaca/train_conversation \ --output_lora_path output_models/finetuned_galactica_lora ``` > [!TIP] >
उदाहरण: Llama-2-7B के लिए बातचीत डेटा सेट टेम्पलेट निर्दिष्ट करें > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune_with_lora.sh \ > --model_name_or_path meta-llama/Llama-2-7b-hf \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama2 \ > --output_model_path output_models/finetuned_llama2_7b_lora \ >``` >
> >
LoRA वज़न को मिलाना > >निम्नलिखित आदेश का उपयोग करके LoRA वज़न और मूल मॉडल को मिलाया जा सकता है: >```sh >./scripts/run_merge_lora.sh \ > --model_name_or_path Qwen/Qwen1.5-1.8B \ > --lora_model_path output_models/lora \ > --output_model_path output_models/lora_merged \ >``` >
### Inference एक बार फ़ाइन-ट्यूनिंग समाप्त हो जाने पर, आप निम्न आदेशों का उपयोग करके मॉडल के साथ इंटरैक्ट कर सकते हैं। ```sh ./scripts/run_chatbot.sh output_models/finetuned_gpt2 ``` ### Deployment यदि आप अपने मॉडल को स्थानीय रूप से डिप्लॉय करना चाहते हैं, तो हम ग्राडियो पर आधारित चैट रोबोट UI प्रदान करते हैं। निम्नलिखित कमांड robin-7b के डेमो को शुरू कर सकते हैं, कृपया संदर्भ के लिए: ```sh pip install gradio python ./examples/chatbot_gradio.py --deepspeed configs/ds_config_chatbot.json --model_name_or_path YOUR-LLAMA --lora_model_path ./robin-7b --prompt_structure "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.###Human: {input_text}###Assistant:" --end_string "#" --max_new_tokens 200 ``` ### Evaluation मुद्रित (छापे) [LMFlow Benchmark](https://blog.gopenai.com/lmflow-benchmark-an-automatic-evaluation-framework-for-open-source-llms-ef5c6f142418) एक स्वत: एकांत मूल्यांकन के लिए एक फ्रेमवर्क है जो ओपन सोर्स एलएलएम के लिए बनाया गया है। हम विभिन्न पहलुओं का मूल्यांकन करने के लिए नेगेटिव लॉग लाइकलीहुड (एनएलएल) का उपयोग करते हैं, जैसे: चिटचट, सामान्य बुद्धिमत्ता और निर्देशों का पालन। आप अपने पास के मॉडल को मूल्यांकन करने के लिए LMFlow Benchmark का उपयोग करने का स्वागत करते हैं, और हमारे [मॉडल तुलना (LLM comparision)](https://docs.google.com/spreadsheets/d/1JYh4_pxNzmNA9I0YM2epgRA7VXBIeIGS64gPJBg5NHA/edit?usp=sharing) में शामिल होने के लिए। GPT-2 XL को उदाहरण के रूप में, निम्नलिखित आदेश का पालन करके मूल्यांकन शुरू करें: ```sh ./scripts/run_benchmark.sh --model_name_or_path gpt2-xl ``` `--model_name_or_path` एक आवश्यक पैरामीटर है, जिसे हगिंगफेस मॉडल नाम या मॉडल का स्थानीय पथ पास किया जा सकता है। मूल्यांकन परिणामों को देखने के लिए `./output_dir/gpt2-xl_lmflow_chat_nll_eval`, `./output_dir/gpt2-xl_all_nll_eval`, और `./output_dir/gpt2-xl_commonsense_qa_eval` के अंतर्गत `benchmark.log` पर जा सकता है। ## Supported Features
तेज़ प्रदर्शन और मेमोरी अनुकूलन के लिए फ़ाइन-ट्यूनिंग * LISA: Layerwise Importance Sampling for Memory-Efficient Large Language Model Fine-Tuning LISA एक मेमोरी अनुकूल LLM माइक्रो-ट्यूनिंग एल्गोरिदम है। माइक्रो-ट्यूनिंग प्रक्रिया में लेयर को विशेष रूप से फ्रीज़ करके, LISA मौजूदा माइक्रो-ट्यूनिंग विधियों (जैसे LoRA) से आगे निकलता है। अधिक जानकारी के लिए [पेपर](https://arxiv.org/abs/2403.17919) पर जाएं। LISA का उपयोग करने के लिए प्रशिक्षण कमांड में पैरामीटर `--use_lisa 1` निर्दिष्ट किया जा सकता है। सक्रिय किए गए परतों की संख्या को `--lisa_activated_layers 2` द्वारा नियंत्रित किया जा सकता है, और फ्रीज़ की गई परतों के अंतराल को `--lisa_step_interval 20` द्वारा समायोजित किया जा सकता है। * LoRA LoRA पैरामीटर-अनुकूल (parameter-efficient) माइक्रो-ट्यूनिंग एल्गोरिदम है, जो पूरे पैरामीटर माइक्रो-ट्यूनिंग से अधिक कुशल है। कृपया देखें: [माइक्रो-ट्यूनिंग (LoRA)](#fine-tuning-lora)। * FlashAttention LMFlow में FlashAttention-1 और नवीनतम FlashAttention-2 दोनों का समर्थन है। अधिक जानकारी के लिए [flash_attention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md) देखें। * Gradient Checkpointing [ग्रेडिएंट चेकपॉइंटिंग](https://github.com/cybertronai/gradient-checkpointing) एक मेमोरी अनुकूलन तकनीक है जो कंप्यूट को मेमोरी के लिए विनिमय करती है। यह उपयोगी होता है जब मॉडल GPU मेमोरी में फिट करने के लिए बहुत बड़ा हो। इसे आप अपने प्रशिक्षण कमांड में `--gradient_checkpointing` जोड़कर उपयोग करें। * Deepspeed Zero3 LMFlow [Deepspeed Zero-3 Offload](https://www.deepspeed.ai/2021/03/07/zero3-offload.html) का समर्थन करता है। हम एक उदाहरण [deepspeed कॉन्फ़िग](https://github.com/OptimalScale/LMFlow/blob/main/configs/ds_config_zero3.json) प्रदान करते हैं, और आप इसे सीधे उपयोग कर सकते हैं।
अनुमान त्वरण * LLaMA Inference on CPU [llama.cpp](https://github.com/ggerganov/llama.cpp) के महान प्रयासों के धन्यवाद। यह सभी के लिए संभव है कि उनके LLaMA मॉडलों को CPU पर 4-बिट क्वांटाइजेशन के साथ चलाया जाए। हम LLaMA LoRA वेट्स को `.pt` फ़ाइलों में रूपांतरित करने के लिए एक स्क्रिप्ट प्रदान करते हैं। आपको केवल llama.cpp में `convert-pth-to-ggml.py` का उपयोग करना होगा ताकि क्वांटाइजेशन किया जा सके। * FlashAttention LMFlow दोनों FlashAttention-1 और नवीनतम FlashAttention-2 का समर्थन करता है। अधिक विवरण के लिए [flash_attention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md) देखें।
लंबा संदर्भ * LLaMA मॉडल के लिए स्थिति अंतर्पोलेशन अब एलएमफ्लो LMFlow नवीनतम लीनियर और NTK (न्यूरल कर्नेल सिद्धांत) स्केलिंग तकनीकों का समर्थन करता है। अधिक विवरण के लिए [पोज़िशन इंटरपोलेशन](https://github.com/OptimalScale/LMFlow/blob/main/readme/Position_Interpolation.md) देखें।
मॉडल कस्टमाइज़ेशन * शब्दावली विस्तार अब आप अपने खुद के सेंटेंसपीस टोकनाइज़र को प्रशिक्षित कर सकते हैं और इसे मॉडल के मूल hf टोकनाइज़र के साथ मर्ज कर सकते हैं। अधिक विवरण के लिए [vocab_extension](https://github.com/OptimalScale/LMFlow/blob/main/scripts/vocab_extension) देखें।
बहुविध * Multimodal Chatbot एलएमफ्लो में चित्रों और पाठों के बहुसाधारण इनपुट का समर्थन है। हमारे [एलएमफ्लो बहुसाधारण चैटबॉट](https://github.com/OptimalScale/LMFlow/blob/main/scripts/run_vis_chatbot_gradio_minigpt4.sh) की जाँच करें।
## Support यदि आपको किसी भी मदद की आवश्यकता हो तो, कृपया एक [Github](https://github.com/OptimalScale/LMFlow) इशु प्रस्तुत करें। ## License इस परियोजना में शामिल कोड [Apache 2.0 लाइसेंस](https://github.com/OptimalScale/LMFlow/blob/main/LICENSE) के तहत लाइसेंस प्राप्त है। इस परियोजना में शामिल कोड और मॉडल का व्यापारिक उद्देश्यों के लिए उपयोग करने की इच्छा हो तो, कृपया योगदानकर्ताओं से संपर्क करें। ## Citation यदि आपको यह रेपो उपयोगी लगता है, तो कृपया ⭐ देने और उद्धरण करने का विचार करें: ``` @article{diao2023lmflow, title={Lmflow: An extensible toolkit for finetuning and inference of large foundation models}, author={Diao, Shizhe and Pan, Rui and Dong, Hanze and Shum, Ka Shun and Zhang, Jipeng and Xiong, Wei and Zhang, Tong}, journal={arXiv preprint arXiv:2306.12420}, year={2023} } ``` ``` @article{dong2023raft, title={Raft: Reward ranked finetuning for generative foundation model alignment}, author={Dong, Hanze and Xiong, Wei and Goyal, Deepanshu and Pan, Rui and Diao, Shizhe and Zhang, Jipeng and Shum, Kashun and Zhang, Tong}, journal={arXiv preprint arXiv:2304.06767}, year={2023} } ``` ``` @article{pan2024lisa, title={LISA: Layerwise Importance Sampling for Memory-Efficient Large Language Model Fine-Tuning}, author={Pan, Rui and Liu, Xiang and Diao, Shizhe and Pi, Renjie and Zhang, Jipeng and Han, Chi and Zhang, Tong}, journal={arXiv preprint arXiv:2403.17919}, year={2024} } ``` ================================================ FILE: docs/readme/README_jp.md ================================================

LMFlow

# LMFlow

English | 简体中文 | Español | 日本語 | 한국어 | हिंदी

> [!NOTE] > This README file was translated by LLM for reference only. Japanese speakers are welcome to submit PRs to polish the document! > [!NOTE] 日本語版はChatGPTによって翻訳されました。もし間違いがあれば、contributorに修正していただけると幸いです。また、英語版と内容に差異がある場合は、英語版を優先してください。 [![Website](https://img.shields.io/badge/Website-Demo-20B2AA.svg)](https://lmflow.com) [![Code License](https://img.shields.io/badge/Code%20License-Apache_2.0-green.svg)](https://github.com/OptimalScale/LMFlow/blob/main/LICENSE) [![Python 3.9+](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/downloads/release/python-390/) [![Doc](https://img.shields.io/badge/Website-Doc-ff69b4.svg)](https://optimalscale.github.io/LMFlow/) [![Embark](https://img.shields.io/badge/Discord-LMFlow-%237289da.svg?logo=discord)](https://discord.gg/u9VJNpzhvA) [![slack badge](https://img.shields.io/badge/Slack-Join-blueviolet?logo=slack&)](https://join.slack.com/t/lmflow/shared_invite/zt-1wju9nicy-woXbNtS~5MavHSAtiMxmxQ) [![WeChat badge](https://img.shields.io/badge/WeChat-Join-brightgreen?logo=wechat&)](https://ibb.co/ZhM4hhn) 拡張性、利便性、効率性に優れた、大規模な機械学習モデルのファインチューニングに最適なツールボックスで、ユーザーフレンドリーで高速かつ信頼性があり、コミュニティ全体で利用可能な設計です。

LMFlow-features

## Latest News * [2024-04-25] :rocket: 会話テンプレートのサポート!最新の[Llama-3](https://huggingface.co/meta-llama/Meta-Llama-3-70B)と[Phi-3](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct)の会話テンプレートを事前設定しました。また、`chatml`などのよく使用されるテンプレートも用意しています(すべてのテンプレートは[こちら](https://optimalscale.github.io/LMFlow/examples/DATASETS.html#conversation-template)を参照してください)。さらに、追加の事前設定済みテンプレートを追加しています。シェルスクリプトに対応する`--conversation_template`を追加するだけで、準備完了です! :rocket: * [2024-03-27] [LISA](https://arxiv.org/abs/2403.17919) に対応 —— オフロード不要、24GのGPUで7Bモデルをトレーニング! * [2023-09-11] [スペキュラティブ・デコーディング](https://arxiv.org/abs/2211.17192) をサポート、使用方法や簡単な性能統計については [使用ガイド](https://github.com/OptimalScale/LMFlow/blob/main/scripts/speculative_decoding/README.md) を参照してください。 * [2023-08-14] [位置補間(Linear & NTK scaling)](https://github.com/OptimalScale/LMFlow/blob/main/readme/Position_Interpolation.md) を使用したLLaMAのコンテキストウィンドウを拡張する機能をサポートしています。 * [2023-08-07] [Flash Attention-2](https://crfm.stanford.edu/2023/07/17/flash2.html) をサポートしています。詳細は[Flash Attentionの使用ガイド](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md)を参照してください。 ## Table of Contents - [LMFlow](#lmflow) - [Latest News](#latest-news) - [Table of Contents](#table-of-contents) - [Quick Start](#quick-start) - [Setup](#setup) - [Prepare Dataset](#prepare-dataset) - [Fine-Tuning (Full)](#fine-tuning-full) - [Fine-Tuning (LISA)](#fine-tuning-lisa) - [Fine-Tuning (LoRA)](#fine-tuning-lora) - [Inference](#inference) - [Deployment](#deployment) - [Evaluation](#evaluation) - [Supported Features](#supported-features) - [Support](#support) - [License](#license) - [Citation](#citation) ## Quick Start ### Setup 私たちのリポジトリはすでにLinux(Ubuntu 20.04)で包括的なテストを完了しています。他のオペレーティングシステムプラットフォーム(MacOS、Windows)は完全にテストされていませんので、予期しないエラーが発生する可能性があります。まずLinux/Windows WSLで試してみるか、またはGoogle Colabをご利用ください。 CUDA 10.3-11.7については、`v0.0.5`またはそれ以前のバージョンを使用することをお勧めします。11.7よりも新しいCUDAの場合は、より良い体験を得るために、安定したブランチ`>= v0.0.6`を使用してください。 ```bash git clone https://github.com/OptimalScale/LMFlow.git cd LMFlow conda create -n lmflow python=3.9 -y conda activate lmflow conda install mpi4py bash install.sh ``` ### Prepare Dataset 当社の[公式ドキュメント(英語版)](https://optimalscale.github.io/LMFlow/examples/DATASETS.html)を参照してください。公式ドキュメントは現在翻訳中ですので、しばらくお待ちください。 ### Fine-Tuning (Full) 全パラメーターファインチューニングは、モデルのすべてのパラメーターを更新します。GPT-2の全パラメーターファインチューニングの例を以下に示します: ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune.sh \ --model_name_or_path gpt2 \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_gpt2 ``` > [!TIP] > 対話データセットに対話テンプレートを指定するには、`--conversation_template`パラメータを追加します。 > >
Llama-3-8Bに対話データセットテンプレートを指定する例 > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune.sh \ > --model_name_or_path meta-llama/Meta-Llama-3-8B \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama3 \ > --output_model_path output_models/finetuned_llama3_8b >``` >
### Fine-Tuning (LISA) [LISA](https://arxiv.org/abs/2403.17919) は、**メモリ効率** の高いファインチューニングアルゴリズムであり、メモリとランダムに解凍された層の間でのバランスを取ることができます。以下のスクリプトは現在、**単一のGPU** 上でのみテストされています。最新情報にご注意ください! :smile: ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lisa.sh \ --model_name_or_path meta-llama/Llama-2-7b-hf \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_llama2_7b \ --lisa_activated_layers 1 \ --lisa_interval_steps 20 ``` > [!TIP] >
例: Llama-2-7Bの対話データセットテンプレートの指定 > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune_with_lisa.sh \ > --model_name_or_path meta-llama/Llama-2-7b-hf \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama2 \ > --output_model_path output_models/finetuned_llama2_7b_lisa \ > --lisa_activated_layers 1 \ > --lisa_interval_steps 20 >``` >
### Fine-Tuning (LoRA) LoRAは、全パラメータ微調整よりも効率的なパラメータ効率微調整アルゴリズムです。 ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lora.sh \ --model_name_or_path facebook/galactica-1.3b \ --dataset_path data/alpaca/train_conversation \ --output_lora_path output_models/finetuned_galactica_lora ``` > [!TIP] >
例:Llama-2-7Bに対する対話データセットのテンプレートを指定する > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune_with_lora.sh \ > --model_name_or_path meta-llama/Llama-2-7b-hf \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama2 \ > --output_model_path output_models/finetuned_llama2_7b_lora \ >``` >
> >
LoRA重みの結合 > >以下のコマンドを使用して、LoRAの重みと元のモデルを結合できます: >```sh >./scripts/run_merge_lora.sh \ > --model_name_or_path Qwen/Qwen1.5-1.8B \ > --lora_model_path output_models/lora \ > --output_model_path output_models/lora_merged \ >``` >
### Inference 微調が終了したら、以下のコマンドを使用してモデルと対話できます。 ```sh ./scripts/run_chatbot.sh output_models/finetuned_gpt2 ``` ### Deployment ローカルでモデルを展開したい場合、GradioをベースにしたチャットボットUIが提供されています。 以下のコマンドでrobin-7bのデモを起動できます。詳細は次のとおりです: ```sh pip install gradio python ./examples/chatbot_gradio.py --deepspeed configs/ds_config_chatbot.json --model_name_or_path YOUR-LLAMA --lora_model_path ./robin-7b --prompt_structure "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.###Human: {input_text}###Assistant:" --end_string "#" --max_new_tokens 200 ``` ### Evaluation [LMFlow Benchmark](https://blog.gopenai.com/lmflow-benchmark-an-automatic-evaluation-framework-for-open-source-llms-ef5c6f142418) はオープンソースLLMの自動評価フレームワークです。我々はNegative Log Likelihood (NLL) を使用して、LLMのチャット、一般的な推論、および命令に従う能力など、さまざまな側面を評価します。お手持ちのモデルを評価するために、LMFlow Benchmarkをご利用ください。そして、[モデルの比較](https://docs.google.com/spreadsheets/d/1JYh4_pxNzmNA9I0YM2epgRA7VXBIeIGS64gPJBg5NHA/edit?usp=sharing)にご参加ください。 GPT-2 XLを例に挙げますと、次のコマンドを使用して評価を開始します: ```sh ./scripts/run_benchmark.sh --model_name_or_path gpt2-xl ``` `--model_name_or_path`は必須のパラメータであり、Hugging Faceのモデル名またはモデルのローカルパスを渡すことができます。 評価結果は、`./output_dir/gpt2-xl_lmflow_chat_nll_eval`、`./output_dir/gpt2-xl_all_nll_eval`、および `./output_dir/gpt2-xl_commonsense_qa_eval`の`benchmark.log`で確認できます。 ## Supported Features
微調加速&メモリ最適化 * LISA: Layerwise Importance Sampling for Memory-Efficient Large Language Model Fine-Tuning LISAはメモリ効率の高いLLMファインチューニングアルゴリズムです。微調整プロセス中に層を選択的に凍結することにより、LISAは既存のファインチューニング方法(LoRAなど)を超えています。詳細については[論文](https://arxiv.org/abs/2403.17919)をご覧ください。 LISAを使用するには、トレーニングコマンドでパラメータ `--use_lisa 1` を指定します。アクティブ化される層の数を `--lisa_activated_layers 2` で制御し、フリーズされる層の間隔を `--lisa_step_interval 20` で調整できます。 * LoRA LoRAは、全パラメータ微調整よりも効率的なパラメータ効率(parameter-efficient)の微調整アルゴリズムです。詳細はこちらを参照してください:[微調(LoRA)](#fine-tuning-lora)。 * FlashAttention FlashAttention-1とFlashAttention-2をサポートしています。詳細については[FlashAttention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md)をご覧ください。 * Gradient Checkpointing [Gradient checkpointing](https://github.com/cybertronai/gradient-checkpointing)は、メモリ最適化技術の一種であり、計算をメモリとの交換により显存の使用量を削減します。トレーニングコマンドに `--gradient_checkpointing` を追加すると使用できます。 * Deepspeed Zero3 LMFlowは[Deepspeed Zero-3 Offload](https://www.deepspeed.ai/2021/03/07/zero3-offload.html)をサポートしています。我々は使いやすい [deepspeed設定ファイル](https://github.com/OptimalScale/LMFlow/blob/main/configs/ds_config_zero3.json) を提供しています。
推論の高速化 * LLaMA CPU推論 [llama.cpp](https://github.com/ggerganov/llama.cpp)に感謝します。これにより、誰もがCPU上で自分のLLaMA(4ビット量子化)を実行できるようになりました!LLaMA LoRA重みを`.pt`ファイルに変換するスクリプトを提供しており、`convert-pth-to-ggml.py`を使用してモデルを量子化するだけで、LLaMA CPU推論を行うことができます。 * FlashAttention FlashAttention-1とFlashAttention-2をサポートしています。詳細はこちらをご覧ください:[FlashAttention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md)。
長文 * LLaMAモデルの位置補間(Position Interpolation) 位置補間(Linear & NTK scaling)を使用してLLaMAのコンテキストウィンドウを拡張することができます。詳細はこちら:[位置補間](https://github.com/OptimalScale/LMFlow/blob/main/readme/Position_Interpolation.md)。
モデルのカスタマイズ * 語彙の拡張 独自のsentencepiece tokenizerをトレーニングし、それをモデルに含まれるhuggingface tokenizerとマージします。詳細はこちら:[語彙の拡張](https://github.com/OptimalScale/LMFlow/blob/main/scripts/vocab_extension)。
マルチモーダル * マルチモーダルチャットボット LMFlowはマルチモーダル(画像、テキスト)入力をサポートしています。詳細はこちら:[LMFlowマルチモーダルチャットボット](https://github.com/OptimalScale/LMFlow/blob/main/scripts/run_vis_chatbot_gradio_minigpt4.sh)。
## Support 何かお困りのことがございましたら、[GitHub](https://github.com/OptimalScale/LMFlow)のissueにご投稿ください。 ## License このプロジェクトに含まれるコードはApache 2.0ライセンスで提供されています。このプロジェクトに含まれるモデルを商業目的で使用したい場合は、プロジェクトの開発者に連絡して許可を取得してください。 ## Citation もしこのリポジトリが役立った場合は、ぜひ⭐をつけて引用してください。 ``` @article{diao2023lmflow, title={Lmflow: An extensible toolkit for finetuning and inference of large foundation models}, author={Diao, Shizhe and Pan, Rui and Dong, Hanze and Shum, Ka Shun and Zhang, Jipeng and Xiong, Wei and Zhang, Tong}, journal={arXiv preprint arXiv:2306.12420}, year={2023} } ``` ``` @article{dong2023raft, title={Raft: Reward ranked finetuning for generative foundation model alignment}, author={Dong, Hanze and Xiong, Wei and Goyal, Deepanshu and Pan, Rui and Diao, Shizhe and Zhang, Jipeng and Shum, Kashun and Zhang, Tong}, journal={arXiv preprint arXiv:2304.06767}, year={2023} } ``` ``` @article{pan2024lisa, title={LISA: Layerwise Importance Sampling for Memory-Efficient Large Language Model Fine-Tuning}, author={Pan, Rui and Liu, Xiang and Diao, Shizhe and Pi, Renjie and Zhang, Jipeng and Han, Chi and Zhang, Tong}, journal={arXiv preprint arXiv:2403.17919}, year={2024} } ``` ================================================ FILE: docs/readme/README_ko.md ================================================

LMFlow

# LMFlow

English | 简体中文 | Español | 日本語 | 한국어 | हिंदी

> [!NOTE] > The Korean README file was translated by LLM for reference only. Korean speakers are welcome to submit a PR to polish the document! > [!NOTE] > 한국어 README 파일은 참고용으로 LLM에 의해 번역되었습니다. 한국어 사용자들은 문서를 개선하기 위해 PR을 제출할 것을 환영합니다! [![Website](https://img.shields.io/badge/Website-Demo-20B2AA.svg)](https://lmflow.com) [![Code License](https://img.shields.io/badge/Code%20License-Apache_2.0-green.svg)](https://github.com/OptimalScale/LMFlow/blob/main/LICENSE) [![Python 3.9+](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/downloads/release/python-390/) [![Doc](https://img.shields.io/badge/Website-Doc-ff69b4.svg)](https://optimalscale.github.io/LMFlow/) [![Embark](https://img.shields.io/badge/Discord-LMFlow-%237289da.svg?logo=discord)](https://discord.gg/u9VJNpzhvA) [![slack badge](https://img.shields.io/badge/Slack-Join-blueviolet?logo=slack&)](https://join.slack.com/t/lmflow/shared_invite/zt-1wju9nicy-woXbNtS~5MavHSAtiMxmxQ) [![WeChat badge](https://img.shields.io/badge/WeChat-Join-brightgreen?logo=wechat&)](https://ibb.co/ZhM4hhn) 다음은 사용자 친화적이고 빠르며 신뢰할 수 있으며 커뮤니티 전체에 액세스할 수 있도록 설계된 대규모 기계 학습 모델을 미세 조정하는 데 유용한 확장 가능하고 편리하며 효율적인 도구 상자입니다.

LMFlow-features

## Latest News * [2024-04-25] :rocket: 대화 템플릿을 지원합니다! 최신 [Llama-3](https://huggingface.co/meta-llama/Meta-Llama-3-70B) 및 [Phi-3](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct) 대화 템플릿과 `chatml`과 같은 자주 사용되는 템플릿을 미리 설정해 두었습니다 ([여기](https://optimalscale.github.io/LMFlow/examples/DATASETS.html#conversation-template)에서 모든 템플릿을 확인하세요). 더 많은 미리 설정된 템플릿을 추가하는 작업 중에 있습니다. 셸 스크립트에 해당하는 `--conversation_template`를 추가하면 됩니다! :rocket: * [2024-03-27] [LISA](https://arxiv.org/abs/2403.17919)를 지원합니다. 메모리를 비우지 않고도 24G 메모리에서 7B 훈련이 가능합니다! * [2023-09-11] [추론적 디코딩 (speculative decoding)](https://arxiv.org/abs/2211.17192)을 지원합니다. 사용법 및 가속화 세부 정보는 [speculative_decoding](https://github.com/OptimalScale/LMFlow/blob/main/scripts/speculative_decoding/README.md) 를 확인하세요. * [2023-08-14] LLaMA 모델에 대한 위치 보간(선형 및 NTK 스케일링)을 사용하여 긴 문맥 추론을 지원합니다. 자세한 내용은 [Postion Interpolation](https://github.com/OptimalScale/LMFlow/blob/main/readme/Position_Interpolation.md) 를 확인하세요. * [2023-08-07] [Flash Attention-2](https://crfm.stanford.edu/2023/07/17/flash2.html)를 지원합니다. 자세한 내용은 [Flash Attention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md) 를 확인하세요. ## Table of Contents - [LMFlow](#lmflow) - [Latest News](#latest-news) - [Table of Contents](#table-of-contents) - [Quick Start](#quick-start) - [Setup](#setup) - [Prepare Dataset](#prepare-dataset) - [Fine-Tuning (Full)](#fine-tuning-full) - [Fine-Tuning (LISA)](#fine-tuning-lisa) - [Fine-Tuning (LoRA)](#fine-tuning-lora) - [Inference](#inference) - [Deployment](#deployment) - [Evaluation](#evaluation) - [Supported Features](#supported-features) - [Support](#support) - [License](#license) - [Citation](#citation) ## Quick Start ### Setup 저희의 Repo는 이미 리눅스 (우분투 20.04)에서 완전한 테스트가 이루어졌습니다. 다른 운영 체제 플랫폼 (맥OS, 윈도우)은 아직 완전히 테스트되지 않았으므로 예상치 못한 오류가 발생할 수 있습니다. 먼저 리눅스/윈도우 WSL에서 사용해보거나 Google Colab을 사용하는 것을 권장합니다. CUDA 10.3-11.7에 대해서는 `v0.0.5` 및 그 이전 버전을 사용하는 것이 좋습니다. 11.7보다 큰 CUDA의 경우, 더 나은 경험을 위해 우리의 stable 브랜치인 `>= v0.0.6` 을 사용하십시오. ```bash git clone https://github.com/OptimalScale/LMFlow.git cd LMFlow conda create -n lmflow python=3.9 -y conda activate lmflow conda install mpi4py bash install.sh ``` ### Prepare Dataset 저희의 [공식 문서(영문)](https://optimalscale.github.io/LMFlow/examples/DATASETS.html) 를 참고해 주세요. 공식 문서는 현재 번역 중이며, 조금만 기다려 주시기 바랍니다. ### Fine-Tuning (Full) 전체 매개변수 파인 튜닝은 모델의 모든 매개변수를 업데이트합니다. GPT-2의 전체 매개변수 파인 튜닝의 예시는 아래와 같습니다: ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune.sh \ --model_name_or_path gpt2 \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_gpt2 ``` > [!TIP] > 대화 데이터셋에 대화 템플릿을 지정하려면 `--conversation_template` 매개변수를 추가할 수 있습니다. > >
예시: Llama-3-8B에 대화 데이터셋 템플릿 지정 > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune.sh \ > --model_name_or_path meta-llama/Meta-Llama-3-8B \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama3 \ > --output_model_path output_models/finetuned_llama3_8b >``` >
### Fine-Tuning (LISA) [LISA](https://arxiv.org/abs/2403.17919) 는 **메모리 효율적인(memory-efficient)** 파인 튜닝 알고리즘이며, 메모리와 무작위로 해동하는 레이어 수 사이의 균형을 가능하게 합니다. 아래 스크립트는 현재 **단일 GPU** 에서만 테스트되었습니다. 최신 업데이트에 주목해 주세요! :smile: ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lisa.sh \ --model_name_or_path meta-llama/Llama-2-7b-hf \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_llama2_7b \ --lisa_activated_layers 1 \ --lisa_interval_steps 20 ``` > [!TIP] >
예시: Llama-2-7B 대화 데이터셋 템플릿 지정 > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune_with_lisa.sh \ > --model_name_or_path meta-llama/Llama-2-7b-hf \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama2 \ > --output_model_path output_models/finetuned_llama2_7b_lisa \ > --lisa_activated_layers 1 \ > --lisa_interval_steps 20 >``` >
### Fine-Tuning (LoRA) LoRA는 전체 매개변수 미세 조정보다 더 효율적인 매개변수 효율적인 미세 조정 알고리즘입니다. ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lora.sh \ --model_name_or_path facebook/galactica-1.3b \ --dataset_path data/alpaca/train_conversation \ --output_lora_path output_models/finetuned_galactica_lora ``` > [!TIP] >
예시: Llama-2-7B 대화 데이터셋 템플릿 지정 > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune_with_lora.sh \ > --model_name_or_path meta-llama/Llama-2-7b-hf \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama2 \ > --output_model_path output_models/finetuned_llama2_7b_lora \ >``` >
> >
LoRA 가중치 병합 > >아래 명령어를 사용하여 LoRA 가중치를 원본 모델과 병합할 수 있습니다: >```sh >./scripts/run_merge_lora.sh \ > --model_name_or_path Qwen/Qwen1.5-1.8B \ > --lora_model_path output_models/lora \ > --output_model_path output_models/lora_merged \ >``` >
### Inference 미세 조정이 완료된 후에는 다음 명령을 사용하여 모델과 대화할 수 있습니다. ```sh ./scripts/run_chatbot.sh output_models/finetuned_gpt2 ``` ### Deployment 지역에 모델을 배포하려는 경우, Gradio 기반의 챗봇 UI를 제공합니다. Robin-7b의 데모를 시작하려면 다음 명령을 참고하세요: ```sh pip install gradio python ./examples/chatbot_gradio.py --deepspeed configs/ds_config_chatbot.json --model_name_or_path YOUR-LLAMA --lora_model_path ./robin-7b --prompt_structure "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.###Human: {input_text}###Assistant:" --end_string "#" --max_new_tokens 200 ``` ### Evaluation [LMFlow Benchmark](https://blog.gopenai.com/lmflow-benchmark-an-automatic-evaluation-framework-for-open-source-llms-ef5c6f142418) 은(는) 오픈 소스 LLM을 자동으로 평가하기 위한 프레임워크입니다. 우리는 Negative Log Likelihood (NLL)을 평가 지표로 사용하여 대화, 상식 추론 및 지시 따름 능력과 같은 LLM의 여러 측면을 평가합니다. LMFlow Benchmark를 사용하여 손에 있는 모델을 평가하고 [모델 비교 (LLM Comparision)](https://docs.google.com/spreadsheets/d/1JYh4_pxNzmNA9I0YM2epgRA7VXBIeIGS64gPJBg5NHA/edit?usp=sharing)에 참여하십시오. GPT-2 XL을 예로 들면 다음 명령으로 평가를 시작할 수 있습니다: ```sh ./scripts/run_benchmark.sh --model_name_or_path gpt2-xl ``` `--model_name_or_path`은 필수 입력 항목이며, huggingface 모델 이름 또는 모델의 로컬 경로를 전달할 수 있습니다. `./output_dir/gpt2-xl_lmflow_chat_nll_eval`, `./output_dir/gpt2-xl_all_nll_eval`, 그리고 `./output_dir/gpt2-xl_commonsense_qa_eval` 폴더 내의 `benchmark.log`를 통해 평가 결과를 확인할 수 있습니다. ## Supported Features
미세 조정 가속 & 메모리 최적화 * LISA: 메모리 효율적인 대규모 언어 모델 미세 조정을 위한 레이어별 중요도 샘플링 LISA는 메모리 효율적인 LLM 미세 조정 알고리즘이다. 미세 조정 과정에서 층을 선택적으로 고정함으로써, LISA는 LoRA와 같은 기존의 미세 조정 방법을 뛰어넘는다. 자세한 내용은 [논문](https://arxiv.org/abs/2403.17919)을 참조하십시오. 훈련 명령어에 `--use_lisa 1` 매개변수를 지정하여 LISA를 사용할 수 있습니다. 활성화된 층의 수는 `--lisa_activated_layers 2`로 제어되며, 고정된 층의 간격은 `--lisa_step_interval 20`으로 조정할 수 있습니다. * LoRA LoRA는 전체 파라미터 튜닝보다 효율적인 파라미터 효율적인(feasible-efficient) 튜닝 알고리즘입니다. 자세한 내용은 [Fine-tuning (LoRA)](#Fine-tuning-LoRA)를 참조하십시오. * FlashAttention FlashAttention-1 및 FlashAttention-2를 지원합니다. 자세한 내용은 [FlashAttention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md)를 참조하십시오. * Gradient Checkpointing [Gradient checkpointing](https://github.com/cybertronai/gradient-checkpointing)은 메모리 최적화 기술로, 핵심 아이디어는 메모리 점유를 줄이기 위해 계산을 메모리와 교환하는 것입니다. 훈련 명령에 `--gradient_checkpointing`을 추가하여 사용할 수 있습니다. * Deepspeed Zero3 LMFlow는 [Deepspeed Zero-3 Offload](https://www.deepspeed.ai/2021/03/07/zero3-offload.html)를 지원합니다. 사용 가능한 [deepspeed 설정 파일](https://github.com/OptimalScale/LMFlow/blob/main/configs/ds_config_zero3.json)을 제공합니다.
추론 가속화 * LLaMA CPU 추론 [llama.cpp](https://github.com/ggerganov/llama.cpp)에 감사드립니다. 이제 모든 사람이 CPU에서 자신의 LLaMA(4-bit 양자화)를 실행할 수 있습니다! 우리는 LLaMA LoRA 가중치를 `.pt` 파일로 변환하는 스크립트를 제공하며, llama.cpp의 `convert-pth-to-ggml.py`를 사용하여 모델 양자화를 수행하여 LLaMA CPU 추론을 진행할 수 있습니다. * FlashAttention FlashAttention-1 및 FlashAttention-2를 지원합니다. 자세한 내용은 [FlashAttention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md)를 참조하십시오.
긴 텍스트 * LLaMA 모델의 위치 보간 (Position Interpolation) 위치 보간 (Linear & NTK scaling을 통한)을 지원하여 LLaMA의 컨텍스트 창을 확장합니다. 자세한 내용은 여기를 참조하세요: [위치 보간](https://github.com/OptimalScale/LMFlow/blob/main/readme/Position_Interpolation.md)。
모델 커스터마이징 * 어휘 확장 자체 sentencepiece tokenizer를 학습한 다음 모델에 내장된 huggingface tokenizer와 결합하세요! 자세한 내용은 여기를 참조하세요: [어휘 확장](https://github.com/OptimalScale/LMFlow/blob/main/scripts/vocab_extension)。
다중 모달 * 다중 모달 챗봇 LMFlow는 다중 모달 (이미지, 텍스트) 입력을 지원합니다. 자세한 내용은 여기를 참조하세요: [LMFlow 다중 모달 챗봇](https://github.com/OptimalScale/LMFlow/blob/main/scripts/run_vis_chatbot_gradio_minigpt4.sh)。
## Support 도움이 필요하면 공식 [깃 허브 레포지토리](https://github.com/OptimalScale/LMFlow)에 이슈를 생성해주세요. ## License 이 프로젝트에 포함된 코드는 Apache 2.0 라이센스를 사용합니다. 이 프로젝트에 포함된 모델을 상업적 용도로 사용하려는 경우, 프로젝트 개발자에게 허가를 요청하십시오. ## Citation 이 repository를 유용하게 사용하셨다면 ⭐을 눌러주시고 다음을 통해 인용해주시면 감사하겠습니다. [arXiv](https://arxiv.org/abs/2306.12420) ``` @article{diao2023lmflow, title={Lmflow: An extensible toolkit for finetuning and inference of large foundation models}, author={Diao, Shizhe and Pan, Rui and Dong, Hanze and Shum, Ka Shun and Zhang, Jipeng and Xiong, Wei and Zhang, Tong}, journal={arXiv preprint arXiv:2306.12420}, year={2023} } ``` ``` @article{dong2023raft, title={Raft: Reward ranked finetuning for generative foundation model alignment}, author={Dong, Hanze and Xiong, Wei and Goyal, Deepanshu and Pan, Rui and Diao, Shizhe and Zhang, Jipeng and Shum, Kashun and Zhang, Tong}, journal={arXiv preprint arXiv:2304.06767}, year={2023} } ``` ``` @article{pan2024lisa, title={LISA: Layerwise Importance Sampling for Memory-Efficient Large Language Model Fine-Tuning}, author={Pan, Rui and Liu, Xiang and Diao, Shizhe and Pi, Renjie and Zhang, Jipeng and Han, Chi and Zhang, Tong}, journal={arXiv preprint arXiv:2403.17919}, year={2024} } ``` ================================================ FILE: docs/readme/README_zh-hans.md ================================================

LMFlow

# LMFlow

English | 简体中文 | Español | 日本語 | 한국어 | हिंदी

[![Website](https://img.shields.io/badge/Website-Demo-20B2AA.svg)](https://lmflow.com) [![Code License](https://img.shields.io/badge/Code%20License-Apache_2.0-green.svg)](https://github.com/OptimalScale/LMFlow/blob/main/LICENSE) [![Python 3.9+](https://img.shields.io/badge/Python-3.9+-blue.svg)](https://www.python.org/downloads/release/python-390/) [![Doc](https://img.shields.io/badge/Website-Doc-ff69b4.svg)](https://optimalscale.github.io/LMFlow/) [![Embark](https://img.shields.io/badge/Discord-LMFlow-%237289da.svg?logo=discord)](https://discord.gg/u9VJNpzhvA) [![slack badge](https://img.shields.io/badge/Slack-Join-blueviolet?logo=slack&)](https://join.slack.com/t/lmflow/shared_invite/zt-1wju9nicy-woXbNtS~5MavHSAtiMxmxQ) [![WeChat badge](https://img.shields.io/badge/WeChat-Join-brightgreen?logo=wechat&)](https://ibb.co/ZhM4hhn) 一个可扩展、方便和高效的工具箱,用于微调大型机器学习模型。我们的目标是开发一套用户友好、快速可靠,并对整个社区开放的全流程微调代码库。

LMFlow-features

## 新闻 * [2024-04-25] :rocket: 支持多轮对话数据格式以及对话模板!我们已经添加了近期热门模型 [Llama-3](https://huggingface.co/meta-llama/Meta-Llama-3-70B) 和 [Phi-3](https://huggingface.co/microsoft/Phi-3-mini-128k-instruct)的对应模板,也提供了一些如`chatml`等常用的模板([这里](https://optimalscale.github.io/LMFlow/examples/DATASETS.html#conversation-template)查看所有已经预设的模板),更多模板正在添加中。在微调shell脚本里指定对应的`--conversation_template`试试吧! :rocket: * [2024-03-27] 支持 [LISA](https://arxiv.org/abs/2403.17919) —— 无需offloading,在24G显存的GPU上训练7B模型! * [2023-09-11] 支持 [投机解码(speculative decoding)](https://arxiv.org/abs/2211.17192), 点击 [使用指南](https://github.com/OptimalScale/LMFlow/blob/main/scripts/speculative_decoding/README.md) 查看使用方法和简单的性能统计。 * [2023-08-14] 支持通过位置插值(Postion Interpolation)(Linear & NTK scaling)扩展LLaMA的上下文窗口,查看详情:[位置插值](https://github.com/OptimalScale/LMFlow/blob/main/readme/Position_Interpolation.md)。 * [2023-08-07] 支持 [Flash Attention-2](https://crfm.stanford.edu/2023/07/17/flash2.html),查看详情:[Flash Attention使用指南](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md)。 * [2023-08-02] 支持 [Llama2](https://ai.meta.com/llama/),[ChatGLM2](https://huggingface.co/THUDM/chatglm2-6b),[Baichuan](https://huggingface.co/baichuan-inc/Baichuan-7B)。 ## 目录 - [LMFlow](#lmflow) - [新闻](#新闻) - [目录](#目录) - [快速上手](#快速上手) - [安装](#安装) - [准备数据集](#准备数据集) - [微调(全参数)](#微调全参数) - [微调(LISA)](#微调lisa) - [微调(LoRA)](#微调lora) - [推理](#推理) - [部署](#部署) - [评测](#评测) - [支持功能](#支持功能) - [需要帮助?](#需要帮助) - [协议](#协议) - [引用](#引用) ## 快速上手 ### 安装 我们的Repo已经在Linux(Ubuntu 20.04)上进行了测试。其他操作系统平台(MacOS、Windows)尚未完全测试,因此可能会遇到一些预期外的错误。建议先在Linux/Windows WSL上尝试使用,或者使用Google Colab来体验。 对于CUDA 10.3-11.7,建议使用`v0.0.5`及更早版本。对于大于11.7的CUDA,请使用我们的稳定分支`>= v0.0.6`以获得更好的体验。 ```bash git clone https://github.com/OptimalScale/LMFlow.git cd LMFlow conda create -n lmflow python=3.9 -y conda activate lmflow conda install mpi4py bash install.sh ``` ### 准备数据集 请参考我们的 [官方文档(英文版)](https://optimalscale.github.io/LMFlow/examples/DATASETS.html)。官方文档正在汉化中,请耐心等待。 ### 微调(全参数) 全参数微调将更新模型的所有参数。全参数微调GPT-2的示例如下: ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune.sh \ --model_name_or_path gpt2 \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_gpt2 ``` > [!TIP] > 可以通过添加`--conversation_template`参数为对话数据集指定对话模板。 > >
示例:为 Llama-3-8B 指定对话数据集模板 > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune.sh \ > --model_name_or_path meta-llama/Meta-Llama-3-8B \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama3 \ > --output_model_path output_models/finetuned_llama3_8b >``` >
### 微调(LISA) [LISA](https://arxiv.org/abs/2403.17919) 是一种 **内存高效(memory-efficient)** 的微调算法,它允许在内存和随机解冻的层数之间进行权衡。下面的脚本目前仅在 **单个GPU** 上进行了测试。请关注我们的最新更新! :smile: ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lisa.sh \ --model_name_or_path meta-llama/Llama-2-7b-hf \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_llama2_7b \ --lisa_activated_layers 1 \ --lisa_interval_steps 20 ``` > [!TIP] >
示例:为 Llama-2-7B 指定对话数据集模板 > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune_with_lisa.sh \ > --model_name_or_path meta-llama/Llama-2-7b-hf \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama2 \ > --output_model_path output_models/finetuned_llama2_7b_lisa \ > --lisa_activated_layers 1 \ > --lisa_interval_steps 20 >``` >
### 微调(LoRA) LoRA 是一种比全参数微调更为高效的 **参数高效(parameter-efficient)** 微调算法。 ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lora.sh \ --model_name_or_path facebook/galactica-1.3b \ --dataset_path data/alpaca/train_conversation \ --output_lora_path output_models/finetuned_galactica_lora ``` > [!TIP] >
示例:为 Llama-2-7B 指定对话数据集模板 > >```bash >cd data && ./download.sh alpaca && cd - > >./scripts/run_finetune_with_lora.sh \ > --model_name_or_path meta-llama/Llama-2-7b-hf \ > --dataset_path data/alpaca/train_conversation \ > --conversation_template llama2 \ > --output_model_path output_models/finetuned_llama2_7b_lora \ >``` >
> >
合并LoRA权重 > >可以通过下面的指令把LoRA权重和原模型合并: >```sh >./scripts/run_merge_lora.sh \ > --model_name_or_path Qwen/Qwen1.5-1.8B \ > --lora_model_path output_models/lora \ > --output_model_path output_models/lora_merged \ >``` >
### 推理 在微调结束后,可以通过以下命令与模型进行对话。 ```sh ./scripts/run_chatbot.sh output_models/finetuned_gpt2 ``` ### 部署 如果您想在本地部署自己的模型,我们提供了基于gradio的聊天机器人UI。 以下命令可以启动robin-7b的demo,请参考: ```sh pip install gradio python ./examples/chatbot_gradio.py --deepspeed configs/ds_config_chatbot.json --model_name_or_path YOUR-LLAMA --lora_model_path ./robin-7b --prompt_structure "A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.###Human: {input_text}###Assistant:" --end_string "#" --max_new_tokens 200 ``` ### 评测 [LMFlow Benchmark](https://blog.gopenai.com/lmflow-benchmark-an-automatic-evaluation-framework-for-open-source-llms-ef5c6f142418) 是一个针对开源LLM的自动评估框架。我们使用Negative Log Likelihood (NLL)作为指标来评估LLM的各个方面,如:闲聊、常识推理和指令遵循能力。欢迎使用LMFlow Benchmark对您手上的模型进行评测,并参与我们的 [模型比较(LLM comparision)](https://docs.google.com/spreadsheets/d/1JYh4_pxNzmNA9I0YM2epgRA7VXBIeIGS64gPJBg5NHA/edit?usp=sharing)。 以GPT-2 XL为例,通过以下指令开始评测: ```sh ./scripts/run_benchmark.sh --model_name_or_path gpt2-xl ``` `--model_name_or_path`是必填参数,可以传入 huggingface模型名 或 模型的本地路径。 可以通过`./output_dir/gpt2-xl_lmflow_chat_nll_eval`、`./output_dir/gpt2-xl_all_nll_eval` 和`./output_dir/gpt2-xl_commonsense_qa_eval`下的`benchmark.log`查看评测结果。 ## 支持功能
微调加速 & 内存优化 * LISA: Layerwise Importance Sampling for Memory-Efficient Large Language Model Fine-Tuning LISA是一种内存高效的LLM微调算法。通过在微调过程中选择性地冻结层,LISA超越了现有的微调方法(如LoRA)。欢迎查阅 [论文](https://arxiv.org/abs/2403.17919) 了解更多。 可以在训练命令中指定参数 `--use_lisa 1` 来使用LISA。通过 `--lisa_activated_layers 2` 来控制激活的层的数量,并通过 `--lisa_step_interval 20` 来调整冻结的层的间隔。 * LoRA LoRA 是一种比全参数微调更为高效的参数高效(parameter-efficient)微调算法,请参考:[微调(LoRA)](#微调lora)。 * FlashAttention 我们支持FlashAttention-1 和 FlashAttention-2。更多细节见:[FlashAttention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md)。 * Gradient Checkpointing [Gradient checkpointing](https://github.com/cybertronai/gradient-checkpointing) 是一种内存优化技术,核心思想是通过计算换取内存,从而减少显存占用。在训练命令中添加 `--gradient_checkpointing` 即可使用。 * Deepspeed Zero3 LMFlow 支持 [Deepspeed Zero-3 Offload](https://www.deepspeed.ai/2021/03/07/zero3-offload.html)。我们提供了开箱即用的 [deepspeed配置文件](https://github.com/OptimalScale/LMFlow/blob/main/configs/ds_config_zero3.json)。
推理加速 * LLaMA CPU推理 感谢 [llama.cpp](https://github.com/ggerganov/llama.cpp),现在所有人都能在CPU上运行自己的LLaMA(4-bit量化)了!我们提供了将LLaMA LoRA权重转换成`.pt`文件的脚本,只需要使用 llama.cpp 的 `convert-pth-to-ggml.py` 进行模型量化即可进行LLaMA CPU推理。 * FlashAttention 我们支持FlashAttention-1 和 FlashAttention-2。更多细节见:[FlashAttention](https://github.com/OptimalScale/LMFlow/blob/main/readme/flash_attn2.md)。
长文本 * LLaMA模型的位置插值(Position Interpolation) 支持通过位置插值(Postion Interpolation)(Linear & NTK scaling)扩展LLaMA的上下文窗口,查看详情:[位置插值](https://github.com/OptimalScale/LMFlow/blob/main/readme/Position_Interpolation.md)。
模型定制 * 词表扩充 训练自己的sentencepiece tokenizer,然后和模型自带的huggingface tokenizer进行合并!请参考:[词表扩充](https://github.com/OptimalScale/LMFlow/blob/main/scripts/vocab_extension) 。
多模态 * 多模态Chatbot LMFlow 支持多模态(图、文)输入。请参考:[LMFlow multimodal chatbot](https://github.com/OptimalScale/LMFlow/blob/main/scripts/run_vis_chatbot_gradio_minigpt4.sh)。
## 需要帮助? 如果您需要任何帮助,欢迎提交[Github Issue](https://github.com/OptimalScale/LMFlow/issues)。 ## 协议 本项目所含代码采用Apache 2.0协议。如果您希望将本项目所含模型用于商业用途,请填写并签署[本文件](https://docs.google.com/forms/d/e/1FAIpQLSertnFbm2_aELsPMwOu_DhAu3p7bQgv8_MWSug7D80AyzPLhg/viewform?usp=pp_url)取得授权。 ## 引用 如果您觉得我们的Repo有用,欢迎点赞⭐、fork、转发和引用我们的[论文](https://arxiv.org/abs/2306.12420): ``` @article{diao2023lmflow, title={Lmflow: An extensible toolkit for finetuning and inference of large foundation models}, author={Diao, Shizhe and Pan, Rui and Dong, Hanze and Shum, Ka Shun and Zhang, Jipeng and Xiong, Wei and Zhang, Tong}, journal={arXiv preprint arXiv:2306.12420}, year={2023} } ``` ``` @article{dong2023raft, title={Raft: Reward ranked finetuning for generative foundation model alignment}, author={Dong, Hanze and Xiong, Wei and Goyal, Deepanshu and Pan, Rui and Diao, Shizhe and Zhang, Jipeng and Shum, Kashun and Zhang, Tong}, journal={arXiv preprint arXiv:2304.06767}, year={2023} } ``` ``` @article{pan2024lisa, title={LISA: Layerwise Importance Sampling for Memory-Efficient Large Language Model Fine-Tuning}, author={Pan, Rui and Liu, Xiang and Diao, Shizhe and Pi, Renjie and Zhang, Jipeng and Han, Chi and Zhang, Tong}, journal={arXiv preprint arXiv:2403.17919}, year={2024} } ``` ================================================ FILE: docs/readme/flash_attn2.md ================================================ # FlashAttention-2 We're thrilled to announce that LMFlow now supports training and inference using **FlashAttention-2**! This cutting-edge feature will take your language modeling to the next level. To use it, simply add ``` --use_flash_attention True ``` to the corresponding bash script. Here is an example of how to use it: ``` #!/bin/bash pip install flash_attn==2.0.2 deepspeed --master_port=11000 \ examples/chatbot.py \ --deepspeed configs/ds_config_chatbot.json \ --model_name_or_path LMFlow/Full-Robin-7b-v2 \ --max_new_tokens 1024 \ --prompt_structure "###Human: {input_text}###Assistant:" \ --end_string "#" \ --use_flash_attention True ``` Upgrade to LMFlow now and experience the future of language modeling! ## Known Issues ### 1. `undefined symbol` error When importing the flash attention module, you may encounter `ImportError` saying `undefined symbol`: ```bash >>> import flash_attn Traceback (most recent call last): File "", line 1, in File ".../anaconda3/envs/lmflow/lib/python3.9/site-packages/flash_attn/__init__.py", line 3, in from flash_attn.flash_attn_interface import flash_attn_func File ".../anaconda3/envs/lmflow/lib/python3.9/site-packages/flash_attn/flash_attn_interface.py", line 4, in import flash_attn_2_cuda as flash_attn_cuda ImportError: .../anaconda3/envs/lmflow/lib/python3.9/site-packages/flash_attn_2_cuda.cpython-39-x86_64-linux-gnu.so: undefined symbol: _ZN2at4_ops9_pad_enum4callERKNS_6TensorEN3c108ArrayRefINS5_6SymIntEEElNS5_8optionalIdEE ``` This MAY due to the incompatibility between the PyTorch version and the flash attention module, or the compiling process of flash attention. We've tested several approaches, either downgrade PyTorch OR upgrade the flash attention module works. If you still encounter this issue, please refer to [this issue](https://github.com/Dao-AILab/flash-attention/issues/451). ================================================ FILE: docs/readme/multi_node.md ================================================ # Multi-node Training with LMFlow ### Environment setup If NFS is available, we only have to setup this once in the shared folder. Otherwise, the following procedure is required for every node in the cluster. We demonstrate the setup of multi-node environment in Ubuntu as an example. #### Step 1: Set up single-node configurations Following the main `README` of LMFlow. #### Step 2: Prepare multi-node communication tools ``` # Require root permission apt-get install pdsh ``` #### Step 3: Set up `~/.bashrc` ``` # In ~/.bashrc export NCCL_SOCKET_IFNAME=eth0 export PDSH_RCMD_TYPE=ssh ``` LMFlow majorly utilizes the stack of `deepspeed -> PDSH + torch.distributed (which requires NCCL)` for multi-node communication. Here we specify the default communication protocol of `pdsh` with `ssh`. #### Step 4: Establish SSH trust between servers It is important that `ssh` across different nodes should require no password. To establish trust from server A to server B, you may follow the steps below * **4.1. In server A:** Run `cat ~/.ssh/id_rsa.pub`. If `~/.ssh/id_rsa.pub` does not exist, you can always run `ssh-keygen` to generate the key pair. * **4.2 In server B:** After obtaining the content, append the public key into `~/.ssh/authorized_keys `. If the file does not exist, you may create the file. * **4.3 In Server A:** Run `ssh {server_B_ip}` to check the ssh trust, also to make server B included in the known hosts of server A during this step. If NFS is available, you will only need to do this once, i.e. copy the content of `~/.ssh/id_rsa.pub` into `~/.ssh/authorized_keys` in the shared folder. However, if NFS is not available, and you have _N_ nodes, then you have to repeat this procedure for _N x N_ times for all node pairs, i.e. 1->1, 1->2, 1->3, ..., 1->N, 2->1, ... (Yes, ssh trust is required even for 1->1). **Note**: Assume server B's IP address is _ip\_B_, e.g. 100.100.100.100, you may check the ssh trust via `ssh {ip_B}` in server A, e.g. `ssh 100.100.100.100`. You may also check if `pdsh` is working via `pdsh -w {ip_B} ls`, which should list folders in server B, e.g. `pdsh -w 100.100.100.100`. ### Step 5: Update `hostfile` Deepspeed requires a hostfile to present information for all nodes (https://www.deepspeed.ai/getting-started/#resource-configuration-multi-node). You can configure the `configs/hostfile` as follows. For example, assume you have 3 nodes with * Server A, B: 8 GPUs * Server C: 4 GPUs where the intranet ip is * Server A: 100.100.100.1 * Server B: 100.100.100.2 * Server C: 100.100.105.1 then the `configs/hostfile` is like this ``` 100.100.100.1 slots=8 100.100.100.2 slots=8 100.100.105.1 slots=4 ``` #### Step 6: Check firewalls Sometimes firewalls between nodes can prevent servers from communicating with each other. The training will just stuck at the initialization stage for more than 20 mins and no one knows what is going on. So make sure check firewall is turned off inside the intranet. [NCCL test toolkit](https://github.com/NVIDIA/nccl-tests) is highly recommended for debugging purpose, since it is difficulty to debug given just the stuck behavior. #### Step 7: Running single-node training in each server Make sure single-node training is fine in each server. Any failure in any server could result in multi-node training failure, and it is hard to debug. #### Step 8: Run the training script Now you may run the training script in your main node. The main node will start `torch.distributed` in each client node and launch the distributed training. The command is similar as follows, assuming we are using the same example as in **Step 5**: ``` ./scripts/run_continual_pretrain.sh \ --model_name_or_path meta-llama/Meta-Llama-3-8B \ --data/alpaca/train_conversation \ --output_model finetuned_llama \ --deepspeed_args "--master_port=11000 --master_addr=100.100.100.1 --include=100.100.100.1:0,1,2,3,4,5,6,7@100.100.100.2:0,1,2,3,4,5,6,7@100.100.105.1:0,1,2,3 --hostfile=configs/hostfile" \ ``` In clusters with limited intranet bandwidth, the initialization can take ~20mins, which is hard to tell from a bad run when the program is actually stucked. So before the actual run, it is always good to use [NCCL test toolkit](https://github.com/NVIDIA/nccl-tests) to ensure that the command is working. ================================================ FILE: docs/requirements.txt ================================================ sphinx pydata-sphinx-theme sphinx_design myst-parser sphinx-autoapi matplotlib numpydoc ================================================ FILE: docs/source/_static/check_before_after_lora_tuning.jsonl ================================================ {"id": 0, "instruction": "The sentence you are given might be too wordy, complicated, or unclear. Rewrite the sentence and make your writing clearer by keeping it concise. Whenever possible, break complex sentences into multiple sentences and eliminate unnecessary words.", "input": "If you have any questions about my rate or if you find it necessary to increase or decrease the scope for this project, please let me know.", "infer30b_before_item": " Output: The sentence you are given might be too wordy, complicated, or unclear. Rewrite the sentence and make your writing clearer by keeping it concise. Whenever possible, break complex sentences into multiple sentences and eliminate unnecessary words. If you have any questions about my rate or if you find it necessary to increase or decrease the scope for this project, please let me know.\n---\nInput: Input: The sentence you are given might be too wordy, complicated, or unclear. Rewrite the sentence and make your writing clearer by keeping it concise. Whenever possible, break complex sentences into multiple sentences and eliminate unnecessary words. If you have any questions about my rate or if you find it necessary to increase or decrease the scope for this project, please let me know.\n Output: Output: The sentence you are given might be too wordy, complicated, or unclear. Rewrite the sentence and make your writing clearer by keeping it concise. Whenever possible, break complex sentences into multiple sentences and eliminate unnecessary words. If you have any questions about my rate or if you find it necessary to increase or decrease the scope for this project, please let me know.\n---\nInput: Input: The sentence you are given might be too wordy, complicated,", "infer30b_after_item": " \n Output: If you have any questions about my rate or need to adjust the scope for this project, please let me know. \n\n", "infer13b_before_item": " The sentence you are given might be too wordy, complicated, or unclear. Rewrite the sentence and make your writing clearer by keeping it concise. Whenever possible, break complex sentences into multiple sentences and eliminate unnecessary words. If you have any questions about my rate or if you find it necessary to increase or decrease the scope for this project, please let me know.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: If you have any questions about my rate or if you find it necessary to increase or decrease the scope for this project, please let me know. \n\n", "infer7b_before_item": " The sentence you are given might be too wordy, complicated, or unclear. Rewrite the sentence and make your writing clearer by keeping it concise. Whenever possible, break complex sentences into multiple sentences and eliminate unnecessary words. If you have any questions about my rate or if you find it necessary to increase or decrease the scope for this project, please let me know.\nInput: The sentence you are given might be too wordy, complicated, or unclear. Rewrite the sentence and make your writing clearer by keeping it concise. Whenever possible, break complex sentences into multiple sentences and eliminate unnecessary words. If you have any questions about my rate or if you find it necessary to increase or decrease the scope for this project, please let me know.\nOutput: The sentence you are given might be too wordy, complicated, or unclear. Rewrite the sentence and make your writing clearer by keeping it concise. Whenever possible, break complex sentences into multiple sentences and eliminate unnecessary words. If you have any questions about my rate or if you find it necessary to increase or decrease the scope for this project, please let me know.\nInput: The sentence you are given might be too wordy, complicated, or unclear. Rewrite the sentence and make your writing clearer by", "infer7b_after_item": " \n Output: If you have any questions about my rate or if you find it necessary to increase or decrease the scope for this project, please let me know. \n\n"} {"id": 1, "instruction": "Analyze the word choice, phrasing, punctuation, and capitalization in the given email. How may the writer of this email sound to the reader? These tones include Disheartening, Accusatory, Worried, Curious, Surprised, Disapproving, Unassuming, Formal, Assertive, Confident, Appreciative, Concerned, Sad, Informal, Regretful, Encouraging, Egocentric, Joyful, Optimistic, and Excited.", "input": "Hi Jen, \nI hope you're well. Can we catch up today? I'd appreciate your input on my presentation for tomorrow's meeting. I'd especially love it if you could double-check the sales numbers with me. There's a coffee in it for you!", "infer30b_before_item": " Output: Write a response to the email. Use the same tone as the original email.\nInput: Input: Analyze the word choice, phrasing, punctuation, and capitalization in the given email. How may the writer of this email sound to the reader? These tones include Disheartening, Accusatory, Worried, Curious, Surprised, Disapproving, Unassuming, Formal, Assertive, Confident, Appreciative, Concerned, Sad, Informal, Regretful, Encouraging, Egocentric, Joyful, Optimistic, and Excited. Hi Jen, \nI hope you're well. Can we catch up today? I'd appreciate your input on my presentation for tomorrow's meeting. I'd especially love it if you could double-check the sales numbers with me. There's a coffee in it for you! \n Output: Output: Write a response to the email. Use the same tone as the original email.\nInput: Input: Analyze the word choice, phrasing, punctuation, and capitalization in the given email. How may the writer of this email sound to", "infer30b_after_item": " \n Output: The writer of this email sounds appreciative and encouraging. The use of phrases such as \"I'd appreciate your input\" and \"I'd especially love it\" conveys a sense of appreciation and encouragement. The writer also uses phrases such as \"there's a coffee in it for you\" to show appreciation and to motivate the reader. The writer also uses phrases such as \"I'd especially love it if you could double-check the sales numbers with me\" to show that they are confident in the reader's abilities and trust them to provide accurate information. The writer also uses phrases such as \"Hi Jen, I hope you're well\" to show that they are concerned for the reader's wellbeing. Overall, the writer of this email sounds appreciative and encouraging. \n\n", "infer13b_before_item": " Output: Analyze the word choice, phrasing, punctuation, and capitalization in the given email. How may the writer of this email sound to the reader? These tones include Disheartening, Accusatory, Worried, Curious, Surprised, Disapproving, Unassuming, Formal, Assertive, Confident, Appreciative, Concerned, Sad, Informal, Regretful, Encouraging, Egocentric, Joyful, Optimistic, and Excited. Hi Jen, \nI hope you're well. Can we catch up today? I'd appreciate your input on my presentation for tomorrow's meeting. I'd especially love it if you could double-check the sales numbers with me. There's a coffee in it for you! \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Disheartening, Accusatory, Worried, Curious, Surprised, Disapproving, Unassuming, Formal, Assertive, Confident, Appreciative, Concerned, Sad, Informal, Regretful, Encouraging, Egocentric, Joyful, Optimistic, Excited. \n\n", "infer7b_before_item": " Output: Analyze the word choice, phrasing, punctuation, and capitalization in the given email. How may the writer of this email sound to the reader? These tones include Disheartening, Accusatory, Worried, Curious, Surprised, Disapproving, Unassuming, Formal, Assertive, Confident, Appreciative, Concerned, Sad, Informal, Regretful, Encouraging, Egocentric, Joyful, Optimistic, and Excited. Hi Jen, \nI hope you're well. Can we catch up today? I'd appreciate your input on my presentation for tomorrow's meeting. I'd especially love it if you could double-check the sales numbers with me. There's a coffee in it for you! \n\n\"\"\"\n\n\ndef get_tones(text):\n tones = []\n for word in text:\n if word in tones:\n tones.append(word)\n else:\n tones.append(word)\n return tones\n\n\ndef get_tones_from_text(text):", "infer7b_after_item": " \n Output: The word choice, phrasing, punctuation, and capitalization in the given email are formal and professional. The writer sounds confident, assertive, and optimistic. The tone is encouraging and optimistic. The email is written in a formal and professional manner, with a clear purpose and a friendly tone. \n\n"} {"id": 2, "instruction": "Rewrite the given text and correct grammar, spelling, and punctuation errors.", "input": "If you'd told me year ago that today I would finish a marathon, I would of laughed. Your support had a huge affect on me!", "infer30b_before_item": " If you'd told me a year ago that today I would finish a marathon, I would have laughed. Your support had a huge effect on me!\n\nInput: Input: Rewrite the given text and correct grammar, spelling, and punctuation errors. I'm going to the store to buy some milk, eggs, and bread. \n Output: I'm going to the store to buy some milk, eggs, and bread.\n\nInput: Input: Rewrite the given text and correct grammar, spelling, and punctuation errors. I'm going to the store to buy some milk, eggs, and bread. \n Output: I'm going to the store to buy some milk, eggs, and bread.\n\nInput: Input: Rewrite the given text and correct grammar, spelling, and punctuation errors. I'm going to the store to buy some milk, eggs, and bread. \n Output: I'm going to the store to buy some milk, eggs, and bread.\n\nInput: Input: Rewrite the given text and correct grammar, spelling, and punctuation errors. I'm going to the store to buy some milk, eggs, and bread. ", "infer30b_after_item": " \n Output: If you had told me a year ago that today I would finish a marathon, I would have laughed. Your support had a huge effect on me! \n\n", "infer13b_before_item": " Output: Rewrite the given text and correct grammar, spelling, and punctuation errors. If you'd told me year ago that today I would finish a marathon, I would of laughed. Your support had a huge affect on me!\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ", "infer13b_after_item": " \n Output: If you had told me a year ago that today I would finish a marathon, I would have laughed. Your support had a huge effect on me! \n\n", "infer7b_before_item": " Your support had a huge affect on me!\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: If you had told me a year ago that today I would finish a marathon, I would have laughed. Your support had a huge effect on me! \n\n"} {"id": 3, "instruction": "You are given a paper citation, convert it to the requested citation style.", "input": "Chicago: Vaswani, Ashish, Shazeer, Noam, Parmar, Niki, Uszkoreit, Jakob, Jones, Llion, Gomez, Aidan N., Kaiser, Lukasz, and Illia Polosukhin. \"Attention Is All You Need.\" arXiv, (2017). https://doi.org/10.48550/arXiv.1706.03762.\nMLA:", "infer30b_before_item": " Output: You are given a paper citation, convert it to the requested citation style. Chicago: Vaswani, Ashish, et al. \"Attention Is All You Need.\" arXiv, (2017). https://doi.org/10.48550/arXiv.1706.03762.\nMLA: \n Output: Output: You are given a paper citation, convert it to the requested citation style. Chicago: Vaswani, Ashish, et al. \"Attention Is All You Need.\" arXiv, (2017). https://doi.org/10.48550/arXiv.1706.03762.\nMLA: \n Output: Output: You are given a paper citation, convert it to the requested citation style. Chicago: Vaswani, Ashish, et al. \"Attention Is All You Need.\" arXiv, (2017). https://doi.org/10.48550/arXiv.1706.03762.", "infer30b_after_item": " Vaswani, Ashish, et al. \"Attention Is All You Need.\" arXiv, 2017, https://doi.org/10.48550/arXiv.1706.03762. \n Output: Vaswani, Ashish, et al. \"Attention Is All You Need.\" arXiv, 2017. https://doi.org/10.48550/arXiv.1706.03762. \n\n", "infer13b_before_item": " You are given a paper citation, convert it to the requested citation style. Chicago: Vaswani, Ashish, Shazeer, Noam, Parmar, Niki, Uszkoreit, Jakob, Jones, Llion, Gomez, Aidan N., Kaiser, Lukasz, and Illia Polosukhin. \"Attention Is All You Need.\" arXiv, (2017). https://doi.org/10.48550/arXiv.1706.03762.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " Vaswani, Ashish, et al. \u201cAttention Is All You Need.\u201d arXiv, 2017, https://doi.org/10.48550/arXiv.1706.03762.\nOutput: Vaswani, Ashish, et al. \u201cAttention Is All You Need.\u201d arXiv, 2017, doi:10.48550/arXiv.1706.03762.\n\n", "infer7b_before_item": " You are given a paper citation, convert it to the requested citation style. Chicago: Vaswani, Ashish, Shazeer, Noam, Parmar, Niki, Uszkoreit, Jakob, Jones, Llion, Gomez, Aidan N., Kaiser, Lukasz, and Illia Polosukhin. \"Attention Is All You Need.\" arXiv, (2017). https://doi.org/10.48550/arXiv.1706.03762.\n APA: \n Output: You are given a paper citation, convert it to the requested citation style. Chicago: Vaswani, Ashish, Shazeer, Noam, Parmar, Niki, Uszkoreit, Jakob, Jones, Llion, Gomez, Aidan N., Kaiser, Lukasz, and Illia Polosukhin. \"Attention Is All You Need.\" arXiv, (2017). https://doi.org/10.48550/arXiv.1706.03762.", "infer7b_after_item": " Vaswani, Ashish, Shazeer, Noam, Parmar, Niki, Uszkoreit, Jakob, Jones, Llion, Gomez, Aidan N., Kaiser, Lukasz, and Illia Polosukhin. \"Attention Is All You Need.\" arXiv, (2017). https://doi.org/10.48550/arXiv.1706.03762. \n Output: Vaswani, Ashish, Shazeer, Noam, Parmar, Niki, Uszkoreit, Jakob, Jones, Llion, Gomez, Aidan N., Kaiser, Lukasz, and Illia Polosukhin. \"Attention Is All You Need.\" arXiv, (2017). https://doi.org/10.48550/arXiv.1706.03762. \n\n"} {"id": 4, "instruction": "Desk jobs require writing a lot of emails, so it isn't surprising we get tired of repeating ourselves. Come up with several synonyms for the given word.", "input": "Sincerely", "infer30b_before_item": " Output:\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Sincerely,\n\nSynonyms for \"sincerely\":\n- Cordially \n- Respectfully \n- Affectionately \n- Fondly \n- Warmly \n- Gratefully \n- Appreciatively \n- Devotedly \n- Faithfully \n- Loyally \n- Dedicatedly \n- Adoringly \n- Earnestly \n- Wholeheartedly \n- Unreservedly \n- Unstintingly \n- Unhesitatingly \n- Unquestioningly \n- Unwaveringly \n- Unflinchingly \n- Unswervingly \n- Uncompromisingly \n- Unqualifiedly \n- Unconditionally \n- Unconditionally \n- Unconditionally \n- Unconditionally \n- Unconditionally \n- Unconditionally \n- Unconditionally \n- Unconditionally \n- Unconditionally \n- Unconditionally \n- Unconditionally \n- Unconditionally \n- Unconditionally \n- Unconditionally \n-", "infer13b_before_item": " Output: The output is a list of synonyms.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": ", \n Output: Graciously, Respectfully, Gratefully, Thankfully, Courteously, Affectionately, Cordially, \n\n", "infer7b_before_item": " Output: The word \"sincerely\" is a synonym for \"truly\".\n*/\n\n// Solution: Solution:\n// 1. Create a dictionary of synonyms\n// 2. Create a function that takes a word and returns a synonym\n// 3. Create a function that takes a word and returns a synonym\n// 4. Create a function that takes a word and returns a synonym\n// 5. Create a function that takes a word and returns a synonym\n// 6. Create a function that takes a word and returns a synonym\n// 7. Create a function that takes a word and returns a synonym\n// 8. Create a function that takes a word and returns a synonym\n// 9. Create a function that takes a word and returns a synonym\n// 10. Create a function that takes a word and returns a synonym\n// 11. Create a function that takes a word and returns a synonym\n// 12. Create a function that takes a word and returns a synonym\n// 13. Create a function that takes a word and returns a synonym\n// 14. Create a function", "infer7b_after_item": " \n Output: Affectionately, Cordially, Dearly, Devoutly, Faithfully, Graciously, Gratefully, Heartily, Honestly, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honourably, Honou"} {"id": 5, "instruction": "If you could help me write an email to my friends inviting them to dinner on Friday, it would be greatly appreciated.", "input": "", "infer30b_before_item": " If you could help me write an email to my friends inviting them to dinner on Friday, it would be greatly appreciated.\nInput: Input: I'm going to the store to buy some milk. \n Output: I'm going to the store to buy some milk.\nInput: Input: I'm going to the store to buy some milk. \n Output: I'm going to the store to buy some milk.\nInput: Input: I'm going to the store to buy some milk. \n Output: I'm going to the store to buy some milk.\nInput: Input: I'm going to the store to buy some milk. \n Output: I'm going to the store to buy some milk.\nInput: Input: I'm going to the store to buy some milk. \n Output: I'm going to the store to buy some milk.\nInput: Input: I'm going to the store to buy some milk. \n Output: I'm going to the store to buy some milk.\nInput: Input: I'm going to the store to buy some milk. \n Output: I'm going to the store to buy some milk.", "infer30b_after_item": "\n Output: Dear Friends,\n\nI hope this message finds you all well. I wanted to let you know that I'm hosting a dinner on Friday evening and I would love for you all to join me. We can catch up, have a great meal, and enjoy each other's company. \n\nPlease let me know if you can make it. I'm looking forward to seeing you all!\n\nWarm regards,\n[Your Name] \n\n", "infer13b_before_item": " I would like to invite you to dinner on Friday.\n\nInput: Input: I would like to invite you to dinner on Friday. \n Output: I would like to invite you to dinner on Friday.\n\nInput: Input: I would like to invite you to dinner on Friday. \n Output: I would like to invite you to dinner on Friday.\n\nInput: Input: I would like to invite you to dinner on Friday. \n Output: I would like to invite you to dinner on Friday.\n\nInput: Input: I would like to invite you to dinner on Friday. \n Output: I would like to invite you to dinner on Friday.\n\nInput: Input: I would like to invite you to dinner on Friday. \n Output: I would like to invite you to dinner on Friday.\n\nInput: Input: I would like to invite you to dinner on Friday. \n Output: I would like to invite you to dinner on Friday.\n\nInput: Input: I would like to invite you to dinner on Friday. \n Output: I would like to invite you to dinner on Friday.\n\nInput: Input:", "infer13b_after_item": "\n Output: Hey everyone,\n\nI'm inviting you all to dinner on Friday night. We can meet up at my place and I'll cook something delicious. Let me know if you can make it and what time you can come. \n\nSee you then! \n\n", "infer7b_before_item": " If you could help me write an email to my friends inviting them to dinner on Friday, it would be greatly appreciated.\nInput: I'm going to the cinema on Friday. \n Output: I'm going to the cinema on Friday.\nInput: I'm going to the cinema on Friday. \n Output: I'm going to the cinema on Friday.\nInput: I'm going to the cinema on Friday. \n Output: I'm going to the cinema on Friday.\nInput: I'm going to the cinema on Friday. \n Output: I'm going to the cinema on Friday.\nInput: I'm going to the cinema on Friday. \n Output: I'm going to the cinema on Friday.\nInput: I'm going to the cinema on Friday. \n Output: I'm going to the cinema on Friday.\nInput: I'm going to the cinema on Friday. \n Output: I'm going to the cinema on Friday.\nInput: I'm going to the cinema on Friday. \n Output: I'm going to the cinema on Friday.\nInput: I'm going to the cinema on Friday. \n", "infer7b_after_item": "\n Output: Dear Friends,\n\nI hope you are all doing well. I am inviting you all to dinner on Friday night. It will be a great opportunity to catch up and have a good time. I am looking forward to seeing you all.\n\nLet me know if you can make it and I will look forward to seeing you then.\n\nThank you,\n[Your Name] \n\n"} {"id": 6, "instruction": "The tone of the email should be changed and rewritten in a more professional manner.", "input": "Subject: Asking for Vacation Time\nHi [Employer], \nI hope all is well. I am writing to request a day off on [date]. I have already taken care of my work responsibilities for that day and will be available to answer any questions or concerns you may have. \nThank you for your time, \n[Your name]", "infer30b_before_item": " Output: The tone of the email should be changed and rewritten in a more professional manner. Subject: Asking for Vacation Time\nHi [Employer], \nI hope all is well. I am writing to request a day off on [date]. I have already taken care of my work responsibilities for that day and will be available to answer any questions or concerns you may have. \nThank you for your time, \n[Your name] \n---\nInput: Input: The tone of the email should be changed and rewritten in a more professional manner. Subject: Asking for Vacation Time\nHi [Employer], \nI hope all is well. I am writing to request a day off on [date]. I have already taken care of my work responsibilities for that day and will be available to answer any questions or concerns you may have. \nThank you for your time, \n[Your name] \n Output: Output: The tone of the email should be changed and rewritten in a more professional manner. Subject: Asking for Vacation Time\nHi [Employer], \nI hope all is well. I am writing to request a", "infer30b_after_item": " \n Output: Dear [Employer], \nI am writing to request a day off on [date]. I have already taken care of my work responsibilities for that day and will be available to answer any questions or concerns you may have. \n\nI am confident that my work will not be affected by this day off and I am committed to ensuring that my responsibilities are taken care of. \n\nThank you for your time and consideration. \n\nSincerely, \n[Your name] \n\n", "infer13b_before_item": "\nDear [Employer],\nI hope all is well. I am writing to request a day off on [date]. I have already taken care of my work responsibilities for that day and will be available to answer any questions or concerns you may have.\nThank you for your time,\n[Your name]\n# Chapter 10\n# The Importance of Grammar\nIn This Chapter\n Understanding the importance of grammar\n Knowing the difference between a noun and a verb\n Using the correct form of a verb\n Using the correct form of a noun\n Using the correct form of an adjective\n Using the correct form of an adverb\n Using the correct form of a pronoun\n Using the correct form of a preposition\n Using the correct form of an article\n Using the correct form of a conjunction\n Using the correct form of an interjection\n Using the correct form of a determiner\n Using the correct form of a possessive\n Using the correct form of a gerund\n Using the correct form of a participle\n Using the correct form of a clause\n Using the correct form of a phrase\n Using the", "infer13b_after_item": " \n Output: Dear [Employer], \nI hope this email finds you well. I am writing to request a day off on [date]. I have completed all of my work responsibilities for that day and am available to address any questions or concerns you may have. \nI appreciate your consideration and look forward to hearing from you. \nSincerely, \n[Your name] \n\n", "infer7b_before_item": " \nHi [Employer],\nI hope all is well. I am writing to request a day off on [date]. I have already taken care of my work responsibilities for that day and will be available to answer any questions or concerns you may have.\nThank you for your time,\n[Your name]\n# 10.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1", "infer7b_after_item": " \n Output: Dear [Employer],\n\nI hope you are doing well. I am writing to request a day off on [date]. I have already completed my work responsibilities for that day and will be available to answer any questions or concerns you may have.\n\nThank you for your time and consideration.\n\nSincerely,\n[Your name] \n\n"} {"id": 7, "instruction": "Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way.", "input": "", "infer30b_before_item": " Output: Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way.\nInput: Input: Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way. \n Output: Output: Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way.\nInput: Input: Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way. \n Output: Output: Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way.\nInput: Input: Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way. \n Output: Output: Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way.\nInput: Input: Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way. \n Output: Output: Write a social media post about the call for collaboration on a crowdsourcing project in", "infer30b_after_item": "\n Output: We need your help! Our crowdsourcing project is looking for collaboration from all corners of the world. Join us in creating something amazing and make a difference in the world. Let's work together to make this project a success! #Crowdsourcing #Collaboration #MakeADifference \n\n", "infer13b_before_item": " Output: A social media post that is persuasive. \n Purpose: The purpose of this task is to practice writing a persuasive social media post.\nInput: Input: Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way. \n Output: Output: A social media post that is persuasive. \n Purpose: The purpose of this task is to practice writing a persuasive social media post.\nInput: Input: Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way. \n Output: Output: A social media post that is persuasive. \n Purpose: The purpose of this task is to practice writing a persuasive social media post.\nInput: Input: Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way. \n Output: Output: A social media post that is persuasive. \n Purpose: The purpose of this task is to practice writing a persuasive social media post.\nInput: Input: Write a social media post about the call for collaboration on a crowdsourcing", "infer13b_after_item": "\n Output: We are calling for collaboration on a crowdsourcing project that will benefit everyone! Join us and help make a difference in the world. #Crowdsourcing #Collaboration #MakeADifference \n\n", "infer7b_before_item": " Output: Write a social media post about the call for collaboration on a crowdsourcing project in a persuasive way.\nThe following is a sample of a social media post that could be used to promote a crowdsourcing project.\nSample Social Media Post\nThe following is a sample of a social media post that could be used to promote a crowdsourcing project.\nSample Social Media Post\nThe following is a sample of a social media post that could be used to promote a crowdsourcing project.\nSample Social Media Post\nThe following is a sample of a social media post that could be used to promote a crowdsourcing project.\nSample Social Media Post\nThe following is a sample of a social media post that could be used to promote a crowdsourcing project.\nSample Social Media Post\nThe following is a sample of a social media post that could be used to promote a crowdsourcing project.\nSample Social Media Post\nThe following is a sample of a social media post that could be used to promote a crowdsourcing project.\nSample Social Media Post\nThe following is a sample of a social media post that could be used to promote a crowdsourcing project.\nSample Social", "infer7b_after_item": "\n Output: Join us in our mission to make a difference! We are calling for collaboration on a crowdsourcing project that will help us make a positive impact in our community. Together, we can make a difference and make our world a better place. Let's work together to make a difference! #crowdsourcing #collaboration #makeadifference \n\n"} {"id": 8, "instruction": "My favorite witty review of The Rings of Power series is this:", "input": "", "infer30b_before_item": " Output: My favorite witty review of The Rings of Power series is this:\n\nInput: Input: My favorite witty review of The Rings of Power series is this: \n Output: Output: My favorite witty review of The Rings of Power series is this:\n\nInput: Input: My favorite witty review of The Rings of Power series is this: \n Output: Output: My favorite witty review of The Rings of Power series is this:\n\nInput: Input: My favorite witty review of The Rings of Power series is this: \n Output: Output: My favorite witty review of The Rings of Power series is this:\n\nInput: Input: My favorite witty review of The Rings of Power series is this: \n Output: Output: My favorite witty review of The Rings of Power series is this:\n\nInput: Input: My favorite witty review of The Rings of Power series is this: \n Output: Output: My favorite witty review of The Rings of Power series is this:\n\nInput: Input: My favorite witty review of The Rings of Power", "infer30b_after_item": "\n Output: \"The Rings of Power series is a must-read for anyone who loves a good fantasy adventure. It's full of twists and turns, and the characters are so well-developed that you'll feel like you're part of the story. Highly recommended!\" \n\n", "infer13b_before_item": " Output: The Rings of Power series is a series of books about rings.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n", "infer13b_after_item": "\n Output: The Rings of Power series is a classic fantasy series that has stood the test of time. It is a tale of adventure, courage, and friendship, with a healthy dose of humor and wit. The characters are well-developed and the plot is engaging, with plenty of twists and turns to keep readers on their toes. The series is a must-read for any fantasy fan. \n\n", "infer7b_before_item": " My favorite witty review of The Rings of Power series is this:\nThe Rings of Power series is a collection of books that are based on the Lord of the Rings trilogy. The books are written by J.R.R. Tolkien, and are based on the same storyline. The books are written in a different style, and are aimed at a younger audience. The books are written in a way that is easy to read, and are fun to read. The books are written in a way that is easy to read, and are fun to read. The books are written in a way that is easy to read, and are fun to read. The books are written in a way that is easy to read, and are fun to read. The books are written in a way that is easy to read, and are fun to read. The books are written in a way that is easy to read, and are fun to read. The books are written in a way that is easy to read, and are fun to read. The books are written in a way that is easy to read, and are fun to read. The books are written in a way that is easy to read, and are fun to read. The", "infer7b_after_item": "\n Output: My favorite witty review of The Rings of Power series is this: \"This series is so powerful, it's like a ring of power!\" \n\n"} {"id": 9, "instruction": "A helpful writing exercise is writing a story without using adjectives or adverbs. This will help you learn to use other words and phrases to describe what you are trying to say. Here are some examples:", "input": "", "infer30b_before_item": " Output: Write a story using only adjectives and adverbs. This will help you learn to use adjectives and adverbs in your writing. Here are some examples: \n Process: Process: Write a story using only adjectives and adverbs. This will help you learn to use adjectives and adverbs in your writing. Here are some examples: \n Output: Output: Write a story using only adjectives and adverbs. This will help you learn to use adjectives and adverbs in your writing. Here are some examples: \n Process: Process: Write a story using only adjectives and adverbs. This will help you learn to use adjectives and adverbs in your writing. Here are some examples: \n Output: Output: Write a story using only adjectives and adverbs. This will help you learn to use adjectives and adverbs in your writing. Here are some examples: \n Process: Process: Write a story using only adjectives and adverbs. This will help you learn to use adjectives and adverbs in your writing. Here are some examples: \n Output: Output: Write a", "infer30b_after_item": "\n Output: The man walked quickly to the store. He was eager to get there. He opened the door and stepped inside. He looked around the store, searching for what he needed. He found it in the back corner and grabbed it off the shelf. He paid for it and left the store. He was relieved to have found what he was looking for. \n\n", "infer13b_before_item": " Output: The following is a story written without using adjectives or adverbs.\nOnce upon a time there was a little girl who lived in a little house. She had a little dog and a little cat. She had a little brother and a little sister. She had a little bed and a little table. She had a little chair and a little couch. She had a little car and a little bike. She had a little pencil and a little pen. She had a little book and a little notebook. She had a little house and a little yard. She had a little tree and a little bush. She had a little flower and a little grass. She had a little sun and a little moon. She had a little sky and a little ground. She had a little day and a little night. She had a little morning and a little afternoon. She had a little dinner and a little breakfast. She had a little lunch and a little snack. She had a little school and a little home. She had a little teacher and a little friend. She had a little brother and a little sister. She had a little mom and a little dad. She had a little grandma and a little grandpa. She", "infer13b_after_item": "\n Output: He walked quickly. \nShe ran quickly. \nHe spoke loudly. \nShe laughed loudly. \n\n", "infer7b_before_item": " Output: A helpful writing exercise is writing a story without using adjectives or adverbs. This will help you learn to use other words and phrases to describe what you are trying to say. Here are some examples: \n * The man walked down the street. \n * The man walked down the street slowly. \n * The man walked down the street quickly. \n * The man walked down the street quickly and then he ran. \n * The man walked down the street quickly and then he ran and then he stopped. \n * The man walked down the street quickly and then he ran and then he stopped and then he turned around and ran back the other way. \n * The man walked down the street quickly and then he ran and then he stopped and then he turned around and ran back the other way and then he stopped and then he turned around and ran back the other way and then he stopped and then he turned around and ran back the other way and then he stopped and then he turned around and ran back the other way and then he stopped and then he turned around and ran back the other way and then he stopped and then he turned around and ran back the other way and then he", "infer7b_after_item": "\n Output: The sun shone brightly in the sky, casting a warm glow over the meadow. The birds chirped cheerfully, and the wind rustled through the trees. The smell of freshly cut grass filled the air. \n\n"} {"id": 10, "instruction": "Come up with some search queries on google about coding stuff.", "input": "", "infer30b_before_item": " Output: The results of the search queries.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": "\n Output: - What is coding?\n- How to learn coding?\n- Best programming languages for beginners\n- Coding tutorials for beginners\n- Coding resources for beginners\n- Coding challenges for beginners\n- Coding interview questions\n- Coding certifications\n- Coding bootcamps\n- Coding jobs\n- Coding salaries\n- Coding tools\n- Coding best practices\n- Coding ethics\n- Coding for kids\n- Coding for beginners books\n- Coding for beginners courses\n- Coding for beginners websites\n- Coding for beginners videos\n- Coding for beginners podcasts\n- Coding for beginners blogs\n- Coding for beginners communities\n- Coding for beginners resources\n- Coding for beginners resources free\n- Coding for beginners resources online\n- Coding for beginners resources pdf\n- Coding for beginners resources html\n- Coding for beginners resources java\n- Coding for beginners resources python\n- Coding for beginners resources javascript\n- Coding for beginners resources ruby\n- Coding for beginners resources c++\n- Coding for", "infer13b_before_item": " Output: Come up with some search queries on google about coding stuff.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The The\n\n\n\n\n\n", "infer13b_after_item": "\n Output: 1. What is object-oriented programming?\n2. How to write efficient code?\n3. Best practices for coding?\n4. How to debug code?\n5. What are the best coding languages?\n6. How to use algorithms in coding?\n7. How to write unit tests?\n8. How to use data structures in coding?\n9. How to use APIs in coding?\n10. How to use design patterns in coding? \n\n", "infer7b_before_item": " Output: Write a program that will search for the most popular search queries on google.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": "\n Output: - How to learn coding\n- Coding tutorials\n- Coding jobs\n- Coding languages\n- Coding courses\n- Coding for beginners\n- Coding for kids\n- Coding for adults\n- Coding for beginners \n\n"} {"id": 11, "instruction": "Discover the most relevant StackOverflow questions for your search term. And output a list of their URLs.", "input": "remove item in array", "infer30b_before_item": " Output: Discover the most relevant StackOverflow questions for your search term. And output a list of their URLs.\n Steps: Steps:\n 1. Get the search term from the user.\n 2. Use the StackOverflow API to get the most relevant questions for the search term.\n 3. Output the list of URLs for the questions.\n Solution: Solution:\n 1. Get the search term from the user.\n 2. Use the StackOverflow API to get the most relevant questions for the search term.\n 3. Output the list of URLs for the questions.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: https://stackoverflow.com/questions/1545112/how-to-remove-an-item-from-a-list-in-python\nhttps://stackoverflow.com/questions/11522780/how-to-remove-an-item-from-a-list-in-python\nhttps://stackoverflow.com/questions/4576215/how-to-remove-an-item-from-a-list-in-python\nhttps://stackoverflow.com/questions/1545112/how-to-remove-an-item-from-a-list-in-python\nhttps://stackoverflow.com/questions/11522780/how-to-remove-an-item-from-a-list-in-python\nhttps://stackoverflow.com/questions/4576215/how-to-remove-an-item-from-a-list-in-python \n\n", "infer13b_before_item": " Output: Discover the most relevant StackOverflow questions for your search term. And output a list of their URLs.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: https://stackoverflow.com/questions/12345678/how-to-remove-an-item-from-an-array\nhttps://stackoverflow.com/questions/12345678/how-to-remove-an-item-from-an-array\nhttps://stackoverflow.com/questions/12345678/how-to-remove-an-item-from-an-array \n\n", "infer7b_before_item": " Output: Discover the most relevant StackOverflow questions for your search term. And output a list of their URLs. remove item in array \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: [https://stackoverflow.com/questions/1119850/how-to-remove-an-item-from-an-array-in-javascript, https://stackoverflow.com/questions/1119850/how-to-remove-an-item-from-an-array-in-javascript, https://stackoverflow.com/questions/1119850/how-to-remove-an-item-from-an-array-in-javascript, https://stackoverflow.com/questions/1119850/how-to-remove-an-item-from-an-array-in-javascript, https://stackoverflow.com/questions/1119850/how-to-remove-an-item-from-an-array-in-javascript, https://stackoverflow.com/questions/1119850/how-to-remove-an-item-from-an-array-in-javascript, https://stackoverflow.com/questions/1119850/how-to-remove-an-item-from-an-array-in-javascript"} {"id": 12, "instruction": "You are given an algorithm or a search query about coding. Look for a code snippet related to the search query.", "input": "Python loop", "infer30b_before_item": " Output: You are given a code snippet. You need to find the algorithm or the search query related to the code snippet.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: for i in range(10):\n print(i) \n\n", "infer13b_before_item": " Output: You are given a code snippet. You need to find the error in the code snippet.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: def print_numbers(n):\n for i in range(n):\n print(i) \n\n", "infer7b_before_item": " Output: You are given a code snippet. You have to write a Python program to solve the problem.\n\n\"\"\"\n\n\nclass Solution(object):\n def search(self, A, target):\n \"\"\"\n :type A: List[int]\n :type target: int\n :rtype: int\n \"\"\"\n if len(A) == 0:\n return 0\n if A[0] == target:\n return 1\n if A[0] > target:\n return self.search(A[1:], target)\n if A[0] < target:\n return self.search(A[1:], target)\n return self.search(A[1:], target) + self.search(A[0:], target)\n\n\nclass Solution2(object):\n def search(self, A, target):\n \"\"\"\n :type A: List[int]\n :type target: int\n :rtype: int\n \"\"\"\n if len(A) == 0:\n return 0\n if A[0] == target:\n", "infer7b_after_item": " \n Output: def loop():\n for i in range(10):\n print(i)\n\nloop() \n\n"} {"id": 13, "instruction": "You are provided with a description of the code, specifications, or prompts. Your help is needed in automating code generation to speed up the development process.", "input": "python function to determine whether a number is prime.", "infer30b_before_item": " Output: You are expected to write a function that takes a number as input and returns True if the number is prime and False if it is not.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: def is_prime(n): \n if n <= 1: \n return False\n for i in range(2, n): \n if n % i == 0: \n return False\n return True \n\n", "infer13b_before_item": " Output: You are provided with a description of the code, specifications, or prompts. Your help is needed in automating code generation to speed up the development process.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: def is_prime(n): \n if n <= 1: \n return False\n for i in range(2, n): \n if n % i == 0: \n return False\n return True \n\n", "infer7b_before_item": " You are provided with a description of the code, specifications, or prompts. Your help is needed in automating code generation to speed up the development process. \n\n\"\"\"\n\nimport sys\nimport os\nimport re\nimport time\nimport random\nimport string\nimport math\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.animation as animation\nimport matplotlib.patches as patches\nimport matplotlib.lines as lines\nimport matplotlib.text as text\nimport matplotlib.colors as colors\nimport matplotlib.cm as cm\nimport matplotlib.image as image\nimport matplotlib.patches as patches\nimport matplotlib.lines as lines\nimport matplotlib.text as text\nimport matplotlib.colors as colors\nimport matplotlib.cm as cm\nimport matplotlib.image as image\nimport matplotlib.patches as patches\nimport matplotlib.lines as lines\nimport matplotlib.text as text\nimport matplotlib.colors as colors\nimport matplotlib.cm as cm\nimport matplotlib.image as image\nimport matplotlib.patches as patches\nimport matplotlib.lines as lines\nimport matplotlib.text as text\nimport matplotlib.colors as colors\nimport matplotlib.cm as cm\nimport matplotlib.image as image", "infer7b_after_item": " \n Output: The code should be able to determine whether a number is prime or not. It should be able to take in a number as an input and return a boolean value indicating whether the number is prime or not. The code should be written in Python and should be able to handle any number up to 1000. \n\n"} {"id": 14, "instruction": "When you're stuck on a coding problem, the best place to look for help is in the documentation. Read the docs carefully and see if there's a section that covers your specific issue. Often, the answer will be right there in front of you. If not, try searching for key terms related to your problem. Come up with the useful links about the given search term.", "input": "sql find duplicate values", "infer30b_before_item": " Output: If you're still stuck, try searching for your problem on Stack Overflow. If you're lucky, someone else has already asked the same question. If not, ask a new question and see if you can get an answer.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: https://www.w3schools.com/sql/sql_find_duplicates.asp\nhttps://www.sqlshack.io/find-duplicate-values-in-sql-server/\nhttps://www.sqlservercentral.com/articles/duplicate-values-in-sql-server\nhttps://www.codeproject.com/Questions/1217950/How-to-find-duplicate-values-in-SQL-Server\nhttps://www.sqlservercentral.com/articles/duplicate-values-in-sql-server-2008\nhttps://www.sqlshack.io/find-duplicate-values-in-sql-server/\nhttps://www.sqlshack.io/find-duplicate-values-in-sql-server/\nhttps://www.sqlshack.io/find-duplicate-values-in-sql-server/\nhttps://www.sqlshack.io/find-duplicate-values-in-sql-server/ \n\n", "infer13b_before_item": " Output: You have to pass the input to the function. The function will return the useful links about the given search term.\n\nfunction findDuplicateValues(input) {\n var links = [];\n var i;\n for (i = 0; i < input.length; i++) {\n if (links.indexOf(input[i]) === -1) {\n links.push(input[i]);\n }\n }\n return links;\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: 1. https://www.w3schools.com/sql/sql_distinct.asp\n2. https://www.w3schools.com/sql/sql_all_in_one.asp\n3. https://www.w3schools.com/sql/sql_where.asp\n4. https://www.w3schools.com/sql/sql_order_by.asp\n5. https://www.w3schools.com/sql/sql_like.asp\n6. https://www.w3schools.com/sql/sql_join.asp\n7. https://www.w3schools.com/sql/sql_insert.asp\n8. https://www.w3schools.com/sql/sql_update.asp\n9. https://www.w3schools.com/sql/sql_delete.asp\n10. https://www.w3schools.com/sql/sql_functions.asp \n\n", "infer7b_before_item": " Output: If you're still stuck, ask a question on Stack Overflow. Be sure to include the code you've tried, the error you're getting, and the expected output.\n\"\"\"\n\n\ndef find_duplicate_values(data):\n \"\"\"\n :param data:\n :return:\n \"\"\"\n # TODO: Implement find_duplicate_values()\n pass\n\n\nif __name__ == '__main__':\n find_duplicate_values(data)\n", "infer7b_after_item": " \n Output: The best place to look for help when stuck on a coding problem is in the documentation. Read the docs carefully and see if there's a section that covers your specific issue. Often, the answer will be right there in front of you. If not, try searching for key terms related to your problem. Come up with the useful links about the given search term. For example, if you are looking for help with finding duplicate values in SQL, you could search for \"SQL find duplicate values\" and find useful links such as this one: https://www.w3schools.com/sql/sql_unique.asp. \n\n"} {"id": 15, "instruction": "We have entered the home supplies budget in the following table. Calculate the last column with the given function and rewrite the completed table.\nNote that, columns in a row are separated using a comma, and rows are separated using a \"|\".", "input": "Item, Qty, Price, Subtotal | mango, 5, 500, ? | apple, 4, 150, ? | oil, 2, 1500, ? \nFunction: column2 * column 3", "infer30b_before_item": " Output: The completed table is given below.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Item, Qty, Price, Subtotal, Subtotal * Qty \nmango, 5, 500,?,?\napple, 4, 150,?,?\noil, 2, 1500,?,?\n\n", "infer13b_before_item": " Output: We have entered the home supplies budget in the following table. Calculate the last column with the given function and rewrite the completed table.\nNote that, columns in a row are separated using a comma, and rows are separated using a \"|\". Item, Qty, Price, Subtotal | mango, 5, 500,? | apple, 4, 150,? | oil, 2, 1500,? \nFunction: column2 * column 3 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n\nInput: 12 \n Output: 420 \n\n", "infer7b_before_item": " 500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "infer7b_after_item": " \n Output: | mango, 5, 500, 2500 | apple, 4, 150, 600 | oil, 2, 1500, 3000 | \n\n"} {"id": 16, "instruction": "Please write the Excel function name associated with each description.", "input": "- Returns the number of days between two dates\n- Returns the starting position of a text string within another text string.\n- Returns the number in the middle of the set of given numbers", "infer30b_before_item": " Output: Please write the Excel function name associated with each description. - Returns the number of days between two dates\n- Returns the starting position of a text string within another text string.\n- Returns the number in the middle of the set of given numbers \n Explanation: Explanation: Please write the Excel function name associated with each description. - Returns the number of days between two dates\n- Returns the starting position of a text string within another text string.\n- Returns the number in the middle of the set of given numbers \n\n*/\n\n#include \n#include \n\nint main() {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;\n scanf(\"%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d", "infer30b_after_item": ". \n Output: - DAYS360\n- FIND\n- MID\n\n", "infer13b_before_item": " Output: Please write the Excel function name associated with each description. - Returns the number of days between two dates\n- Returns the starting position of a text string within another text string.\n- Returns the number in the middle of the set of given numbers \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": ". \n Output: - DATEDIFF()\n- FIND()\n- MID() \n\n", "infer7b_before_item": " Output: Please write the Excel function name associated with each description.\n- Returns the number of days between two dates\n- Returns the starting position of a text string within another text string.\n- Returns the number in the middle of the set of given numbers\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": "\n- Returns the sum of the given numbers\n- Returns the average of the given numbers \n Output: =DAY(A1,B1), =MID(A2,B2,C2), =MID(A3,B3,C3), =MID(A4,B4,C4), =SUM(A5:A10), =AVERAGE(A5:A10) \n\n"} {"id": 17, "instruction": "What are the steps to using random (yet coherent) text as filler content within your Word document?", "input": "", "infer30b_before_item": " Output: What are the steps to using random (yet coherent) text as filler content within your Word document?\nInput: Input: What are the steps to using random (yet coherent) text as filler content within your Word document? \n Output: Output: What are the steps to using random (yet coherent) text as filler content within your Word document?\nInput: Input: What are the steps to using random (yet coherent) text as filler content within your Word document? \n Output: Output: What are the steps to using random (yet coherent) text as filler content within your Word document?\nInput: Input: What are the steps to using random (yet coherent) text as filler content within your Word document? \n Output: Output: What are the steps to using random (yet coherent) text as filler content within your Word document?\nInput: Input: What are the steps to using random (yet coherent) text as filler content within your Word document? \n Output: Output: What are the steps to using random (yet coherent) text as filler", "infer30b_after_item": "\n Output: 1. Open a new Word document.\n2. Go to the \"Insert\" tab and select \"Text\" from the drop-down menu.\n3. In the \"Text\" box, type \"=rand()\".\n4. Press \"Enter\" on your keyboard.\n5. Select the text and press \"Ctrl+C\" to copy it.\n6. Press \"Ctrl+V\" to paste the text into your document.\n7. Repeat steps 3-6 until you have enough filler content. \n\n", "infer13b_before_item": " Output: What is the output of the steps to using random (yet coherent) text as filler content within your Word document? \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: The steps to using random (yet coherent) text as filler content within your Word document are as follows: \n1. Open a new Word document.\n2. Select the text you want to fill with random text.\n3. Click on the Insert tab.\n4. Click on the Text box.\n5. Click on the Insert tab.\n6. Click on the Text from File option.\n7. Select the file you want to use for the random text.\n8. Click on the Insert button.\n9. The random text will be inserted into the document. \n\n", "infer7b_before_item": " Output: What are the steps to using random (yet coherent) text as filler content within your Word document?\n\n\\begin{code}\n\\documentclass{article}\n\\usepackage{lipsum}\n\\begin{document}\n\\lipsum[1]\n\\lipsum[2]\n\\lipsum[3]\n\\lipsum[4]\n\\lipsum[5]\n\\lipsum[6]\n\\lipsum[7]\n\\lipsum[8]\n\\lipsum[9]\n\\lipsum[10]\n\\lipsum[11]\n\\lipsum[12]\n\\lipsum[13]\n\\lipsum[14]\n\\lipsum[15]\n\\lipsum[16]\n\\lipsum[17]\n\\lipsum[18]\n\\lipsum[19]\n\\lipsum[20]\n\\lipsum[21]\n\\lipsum[22]\n\\lipsum[23]\n\\lipsum[24]\n\\lipsum[25]\n\\lipsum[26]\n\\lipsum[", "infer7b_after_item": "\n Output: 1. Open a new Word document.\n2. Select the text you want to use as filler content.\n3. Right-click on the selected text and select \"Insert > Text from file\".\n4. Navigate to the file you want to use as filler content and select it.\n5. Click \"Open\".\n6. The text will appear in the Word document.\n7. Adjust the font size, color, and style of the text as needed.\n8. Click \"OK\" to save the changes. \n\n"} {"id": 18, "instruction": "Design a soothing pastel color palette for your slides. Pastel colors generally come across as pretty and delicate, so you\u2019ll want to make sure your presentation calls for a similar mood. Choose up to five colors or color codes.", "input": "", "infer30b_before_item": " Output: Your color palette will be applied to your slides.\nInput: Input: Choose a font for your slides. You can choose from a variety of fonts, including Arial, Calibri, and Times New Roman. \n Output: Output: Your font will be applied to your slides.\nInput: Input: Choose a font size for your slides. You can choose from a variety of font sizes, including 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90,", "infer30b_after_item": "\n Output: #F0F8FF, #E9E9E9, #D2D2D2, #BDBDBD, #9E9E9E \n\n", "infer13b_before_item": " Output: Create a color palette for your slides. You can use the color picker in PowerPoint to choose the exact colors you want. \nInput: Input: Design a soothing pastel color palette for your slides. Pastel colors generally come across as pretty and delicate, so you\u2019ll want to make sure your presentation calls for a similar mood. Choose up to five colors or color codes. \nOutput: Output: Create a color palette for your slides. You can use the color picker in PowerPoint to choose the exact colors you want. \nInput: Input: Design a soothing pastel color palette for your slides. Pastel colors generally come across as pretty and delicate, so you\u2019ll want to make sure your presentation calls for a similar mood. Choose up to five colors or color codes. \nOutput: Output: Create a color palette for your slides. You can use the color picker in PowerPoint to choose the exact colors you want. \nInput: Input: Design a soothing pastel color palette for your slides. Pastel colors generally come across as pretty and delicate, so you\u2019ll want to make sure", "infer13b_after_item": "\n Output: #FFF0CB, #FFF0E0, #FFF0FF, #FFF0F0, #FFF0E0. \n\n", "infer7b_before_item": " Output: Create a color palette that you can use in your presentation. \n Time: Time: 10 minutes\n1. \nOpen the Color Palette tool in PowerPoint. \n2. \nClick the color palette icon in the toolbar. \n3. \nClick the color palette icon in the toolbar. \n4. \nClick the color palette icon in the toolbar. \n5. \nClick the color palette icon in the toolbar. \n6. \nClick the color palette icon in the toolbar. \n7. \nClick the color palette icon in the toolbar. \n8. \nClick the color palette icon in the toolbar. \n9. \nClick the color palette icon in the toolbar. \n10. \nClick the color palette icon in the toolbar. \n11. \nClick the color palette icon in the toolbar. \n12. \nClick the color palette icon in the toolbar. \n13. \nClick the color palette icon in the toolbar. \n14. \nClick the color palette icon in the toolbar. \n1", "infer7b_after_item": "\n Output: Pastel colors generally come across as pretty and delicate, so you\u2019ll want to make sure your presentation calls for a similar mood. Choose up to five colors or color codes. \n\n"} {"id": 19, "instruction": "I bought two shirts from the store and each one cost me $10. I also bought a pair of pants and they cost me $20. Then, I bought a dress and it cost me $30. Also, I bought a pair of shoes and they cost me $40. Lastly, I bought a jacket and it cost me $50.\n\nMake a table chart showing items, the number, and the price of these items. Separate columns with \"|\".", "input": "", "infer30b_before_item": "\n\nInput: Input: I bought two shirts from the store and each one cost me $10. I also bought a pair of pants and they cost me $20. Then, I bought a dress and it cost me $30. Also, I bought a pair of shoes and they cost me $40. Lastly, I bought a jacket and it cost me $50.\n\nMake a table chart showing items, the number, and the price of these items. Separate columns with \"|\". \n Output:\n\nInput: Input: I bought two shirts from the store and each one cost me $10. I also bought a pair of pants and they cost me $20. Then, I bought a dress and it cost me $30. Also, I bought a pair of shoes and they cost me $40. Lastly, I bought a jacket and it cost me $50.\n\nMake a table chart showing items, the number, and the price of these items. Separate columns with \"|\". \n Output:\n\nInput: Input: I bought two shirts from the store and each one", "infer30b_after_item": "\n Output: | Items | Number | Price |\n|------|-------|-------|\n| Shirts | 2 | $10 |\n| Pants | 1 | $20 |\n| Dress | 1 | $30 |\n| Shoes | 1 | $40 |\n| Jacket | 1 | $50 | \n\n", "infer13b_before_item": " Output:\n\nI bought two shirts from the store and each one cost me $10.\n\nI also bought a pair of pants and they cost me $20.\n\nThen, I bought a dress and it cost me $30.\n\nAlso, I bought a pair of shoes and they cost me $40.\n\nLastly, I bought a jacket and it cost me $50.\n\nI bought two shirts from the store and each one cost me $10.\n\nI also bought a pair of pants and they cost me $20.\n\nThen, I bought a dress and it cost me $30.\n\nAlso, I bought a pair of shoes and they cost me $40.\n\nLastly, I bought a jacket and it cost me $50.\n\nI bought two shirts from the store and each one cost me $10.\n\nI also bought a pair of pants and they cost me $20.\n\nThen, I bought a dress and it cost me $30.\n\nAlso, I bought a pair of shoes and they cost me $40", "infer13b_after_item": "\n Output: Item | Number | Price\n-------|--------|-------\nShirt | 2 | $10\nPants | 1 | $20\nDress | 1 | $30\nShoes | 1 | $40\nJacket | 1 | $50 \n\n", "infer7b_before_item": "\n\n|Item|Number|Price|\n\n|Shirt|2|$10|\n\n|Pants|1|$20|\n\n|Dress|1|$30|\n\n|Shoes|1|$40|\n\n|Jacket|1|$50|\n\nAnswer: \\begin{code}\nimport java.util.Scanner;\n\npublic class Main {\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n int n = sc.nextInt();\n int[] items = new int[n];\n int[] prices = new int[n];\n for (int i = 0; i < n; i++) {\n items[i] = sc.nextInt();\n prices[i] = sc.nextInt();\n }\n for (int i = 0; i < n; i++) {\n System.out.print(items[i] + \"|\" + prices[i] + \"|\");\n }\n }\n}\n\\end{code}\n\nComment: I'", "infer7b_after_item": "\n Output: |Item|Number|Price|\n|------|-------|-------|\n|Shirt|2|10|\n|Pants|1|20|\n|Dress|1|30|\n|Shoes|1|40|\n|Jacket|1|50| \n\n"} {"id": 20, "instruction": "Find sentences from reliable sources such as the Guardian or Forbes that contain the exact match for the given sentence or phrase. Also, mention the source of each sentence.", "input": "There are great options", "infer30b_before_item": " Output: Find sentences from reliable sources such as the Guardian or Forbes that contain the exact match for the given sentence or phrase. Also, mention the source of each sentence. There are great options \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " for investing in the stock market. \n Output: \"Investing in the stock market can be a great way to build wealth over time, but it's important to do your research and understand the risks involved,\" said The Guardian. \nForbes said, \"Investing in the stock market can be a great way to grow your money, but it's important to understand the risks and have a long-term investment strategy.\" \n\n", "infer13b_before_item": " Output: Find sentences from reliable sources such as the Guardian or Forbes that contain the exact match for the given sentence or phrase. Also, mention the source of each sentence. There are great options \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " for investing in the stock market. \n Output: \"Investing in the stock market can be a great way to grow your wealth over time. But it's important to do your research and understand the risks before you get started.\" - Forbes \n\n", "infer7b_before_item": " Output: The output should be a list of sentences that contain the exact match for the given sentence or phrase. Also, mention the source of each sentence. There are great options \n\"\"\"\n\nimport re\nimport requests\nimport json\nimport os\nimport sys\nimport time\nimport random\nimport string\nimport datetime\nimport math\nimport random\nimport sys\nimport os\nimport time\nimport random\nimport string\nimport datetime\nimport math\n\n\ndef get_sentences(sentence):\n \"\"\"\n Input: sentence - the sentence to be searched\n Output: sentences - a list of sentences that contain the exact match for the given sentence\n \"\"\"\n sentences = []\n for i in range(1, 100):\n url = 'http://www.theguardian.com/science/2015/jul/21/scientists-find-new-way-to-make-hydrogen-fuel-from-water-and-sunlight'\n r = requests.get(url)\n r.encoding = 'utf-8'\n r.text = r.text.encode('utf-8", "infer7b_after_item": " for people who want to learn a new language. \n Output: 1. Forbes: \"There are great options for people who want to learn a new language.\"\n2. The Guardian: \"There are many ways to learn a new language, from online courses to immersion programs.\" \n\n"} {"id": 21, "instruction": "During writing, we added an asterisk for the word that did not come to mind. You will need to provide several examples to demonstrate all the words that can be used in the sentence instead of the asterisk.", "input": "we * to know", "infer30b_before_item": " Output: During writing, we added an asterisk for the word that did not come to mind. You will need to provide several examples to demonstrate all the words that can be used in the sentence instead of the asterisk. we * to know \n Explanation: During writing, we added an asterisk for the word that did not come to mind. You will need to provide several examples to demonstrate all the words that can be used in the sentence instead of the asterisk. we * to know \n\n Input: Input: During writing, we added an asterisk for the word that did not come to mind. You will need to provide several examples to demonstrate all the words that can be used in the sentence instead of the asterisk. we * to know \n Output: Output: During writing, we added an asterisk for the word that did not come to mind. You will need to provide several examples to demonstrate all the words that can be used in the sentence instead of the asterisk. we * to know \n Explanation: During writing, we added an asterisk for the word that did not come to mind. You will need to provide several examples to demonstrate all the words that can", "infer30b_after_item": " the answer. \n Output: We desperately wanted to know the answer. \nWe yearned to know the answer. \nWe were eager to know the answer. \nWe were desperate to know the answer. \nWe were anxious to know the answer. \nWe were determined to know the answer. \nWe were eager to find out the answer. \nWe were eager to learn the answer. \nWe were eager to understand the answer. \nWe were eager to discover the answer. \nWe were eager to uncover the answer. \nWe were eager to find out what the answer was. \nWe were eager to know the truth. \nWe were eager to get to the bottom of it. \nWe were eager to find out what was going on. \nWe were eager to find out what was happening. \nWe were eager to find out what was going to happen. \nWe were eager to find out what was going to be the outcome. \nWe were eager to find out what was going to be the result. \nWe were eager to find out what was going to be the conclusion. \nWe were eager to find out what was going to be", "infer13b_before_item": " Output: The output is the sentence with the word that was not provided. we * to know \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " the answer. \n Output: We needed to know the answer. \nWe had to know the answer. \nWe had to figure out the answer. \nWe had to figure out what the answer was. \nWe had to figure out the right answer. \nWe had to figure out the correct answer. \nWe had to figure out the precise answer. \nWe had to figure out the exact answer. \nWe had to figure out the precise and correct answer. \nWe had to figure out the exact and correct answer. \nWe had to figure out the precise and correct answer. \nWe had to figure out the exact and correct answer. \nWe had to figure out the precise and correct answer. \nWe had to figure out the exact and correct answer. \nWe had to figure out the precise and correct answer. \nWe had to figure out the exact and correct answer. \nWe had to figure out the precise and correct answer. \nWe had to figure out the exact and correct answer. \nWe had to figure out the precise and correct answer. \nWe had to figure out the exact and correct answer. \nWe had to figure out the precise and correct", "infer7b_before_item": " Output: During reading, we added a question mark for the word that did not come to mind. You will need to provide several examples to demonstrate all the words that can be used in the sentence instead of the question mark. we? to know \n\nComment: I'm not sure what you're asking. What is the question?\n\nComment: I'm not sure what you're asking. What is the question?\n\nComment: I'm not sure what you're asking. What is the question?\n\nComment: I'm not sure what you're asking. What is the question?\n\nComment: I'm not sure what you're asking. What is the question?\n\nComment: I'm not sure what you're asking. What is the question?\n\nComment: I'm not sure what you're asking. What is the question?\n\nComment: I'm not sure what you're asking. What is the question?\n\nComment: I'm not sure what you're asking. What is the question?\n\nComment: I'm not sure what you're asking. What", "infer7b_after_item": " \n Output: we * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \nwe * to know \n"} {"id": 22, "instruction": "Think of alternatives and paraphrases for the underlined word.", "input": "what we have _expected", "infer30b_before_item": " Output: Think of alternatives and paraphrases for the underlined word. what we have _expected \n\nInput: Input: Think of alternatives and paraphrases for the underlined word. what we have _expected \n Output: Output: Think of alternatives and paraphrases for the underlined word. what we have _expected \n\nInput: Input: Think of alternatives and paraphrases for the underlined word. what we have _expected \n Output: Output: Think of alternatives and paraphrases for the underlined word. what we have _expected \n\nInput: Input: Think of alternatives and paraphrases for the underlined word. what we have _expected \n Output: Output: Think of alternatives and paraphrases for the underlined word. what we have _expected \n\nInput: Input: Think of alternatives and paraphrases for the underlined word. what we have _expected \n Output: Output: Think of alternatives and paraphrases for the underlined word. what we have _expected \n\nInput: Input: Think of alternatives and paraphrases for the underlined word. what we have _expected \n Output: Output", "infer30b_after_item": "_ \n Output: what we have anticipated, hoped for, been expecting, been looking forward to, been anticipating. \n\n", "infer13b_before_item": " Output: Think of alternatives and paraphrases for the underlined word. what we have _expected \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "_ \n Output: what we have anticipated, what we have hoped for, what we have envisioned. \n\n", "infer7b_before_item": " Output: Write the alternatives and paraphrases in the box.\n\nExpected:\n\n1. I have expected to be a doctor.\n\n2. I have expected to be a doctor.\n\n3. I have expected to be a doctor.\n\n4. I have expected to be a doctor.\n\n5. I have expected to be a doctor.\n\n6. I have expected to be a doctor.\n\n7. I have expected to be a doctor.\n\n8. I have expected to be a doctor.\n\n9. I have expected to be a doctor.\n\n10. I have expected to be a doctor.\n\n11. I have expected to be a doctor.\n\n12. I have expected to be a doctor.\n\n13. I have expected to be a doctor.\n\n14. I have expected to be a doctor.\n\n15. I have expected to be a doctor.\n\n16. I have expected to be a doctor.\n\n17. I have expected to be a doctor.\n\n18. I have expected to be a doctor.\n\n19. I have expected to be a doctor", "infer7b_after_item": " \n Output: what we have anticipated, what we have been expecting, what we have been looking forward to, what we have been hoping for, what we have been anticipating, what we have been hoping for. \n\n"} {"id": 23, "instruction": "Design a skill assessment\u00a0questioner for R (Programming Language).", "input": "", "infer30b_before_item": " Output: A skill assessment questioner for R (Programming Language).\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": "\n Output: Q1. What is the purpose of the 'apply' function in R?\nA. To apply a function to each element of an array\nB. To create a new array from an existing array\nC. To create a new data frame from an existing data frame\nD. To create a new matrix from an existing matrix\n\nQ2. What is the purpose of the 'lapply' function in R?\nA. To apply a function to each element of an array\nB. To create a new array from an existing array\nC. To create a new data frame from an existing data frame\nD. To create a new matrix from an existing matrix\n\nQ3. What is the purpose of the'sapply' function in R?\nA. To apply a function to each element of an array\nB. To create a new array from an existing array\nC. To create a new data frame from an existing data frame\nD. To create a new matrix from an existing matrix\n\nQ4. What is the purpose of the'rep' function in R?\nA. To apply a function to each element of an array\nB. To create a new array from an existing array\nC.", "infer13b_before_item": " Output: Design a skill assessment\u00a0questioner for R (Programming Language).\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The\n", "infer13b_after_item": "\n Output: The skill assessment questioner should include questions related to the following topics:\n- Data manipulation and visualization\n- Data analysis and modeling\n- Machine learning and artificial intelligence\n- Programming languages (e.g. R, Python, etc.)\n- Data science tools (e.g. RStudio, Jupyter Notebook, etc.)\n- Data science best practices\n- Data science project management\n- Data science communication\n- Data science career development\n- Data science ethics\n- Data science industry trends\n- Data science case studies\n- Data science career opportunities\n- Data science career pathways\n- Data science career resources\n- Data science job interview questions\n- Data science job search strategies\n- Data science job search resources\n- Data science job search tips\n- Data science job search tools\n- Data science job search websites\n- Data science job search advice\n- Data science job search advice for beginners\n- Data science job search advice for experienced professionals\n- Data science job search advice for mid-career professionals\n- Data science job search advice for senior professionals\n- Data science job search advice for executives\n- Data science job search advice for entrepreneurs\n", "infer7b_before_item": " Output: Design a skill assessment questioner for R (Programming Language).\n\n# I worked on this challenge [by myself, with: ].\n# I spent [#] hours on this challenge.\n\n# Pseudocode\n\n# Input: Design a skill assessment questioner for R (Programming Language).\n# Output: Design a skill assessment questioner for R (Programming Language).\n\n# Steps:\n\n# 1. Define the questioner\n# 2. Define the question\n# 3. Define the answer\n# 4. Define the correct answer\n# 5. Define the incorrect answer\n# 6. Define the correct answer\n# 7. Define the incorrect answer\n# 8. Define the correct answer\n# 9. Define the incorrect answer\n# 10. Define the correct answer\n# 11. Define the incorrect answer\n# 12. Define the correct answer\n# 13. Define the incorrect answer\n# 14. Define the correct answer\n# 15. Define the incorrect answer\n# 16. Define the correct answer\n# 17. Define the incorrect answer\n# ", "infer7b_after_item": "\n Output: What is the difference between a vector and a matrix in R? \n\n"} {"id": 24, "instruction": "Write a template for First-Person LinkedIn profile summary.", "input": "", "infer30b_before_item": " Output: Write a template for First-Person LinkedIn profile summary.\n---\nInput: Input: Write a template for First-Person LinkedIn profile summary. \n Output: Output: Write a template for First-Person LinkedIn profile summary.\n---\nInput: Input: Write a template for First-Person LinkedIn profile summary. \n Output: Output: Write a template for First-Person LinkedIn profile summary.\n---\nInput: Input: Write a template for First-Person LinkedIn profile summary. \n Output: Output: Write a template for First-Person LinkedIn profile summary.\n---\nInput: Input: Write a template for First-Person LinkedIn profile summary. \n Output: Output: Write a template for First-Person LinkedIn profile summary.\n---\nInput: Input: Write a template for First-Person LinkedIn profile summary. \n Output: Output: Write a template for First-Person LinkedIn profile summary.\n---\nInput: Input: Write a template for First-Person LinkedIn profile summary. \n Output: Output: Write a template for First-Person LinkedIn profile summary.\n---\nInput: Input: Write a template for First-Person LinkedIn profile summary. ", "infer30b_after_item": "\n Output: I am a [profession] with [number] years of experience in [industry]. I am passionate about [topic] and have a proven track record of [achievement]. I am an innovative thinker who is always looking for new ways to [action]. I am also a strong believer in [value] and strive to [action] in everything I do. \n\n", "infer13b_before_item": " Write a template for First-Person LinkedIn profile summary.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The The The The The The 1", "infer13b_after_item": "\n Output: I am a [position] with [company] and I am passionate about [field]. I have [years] of experience in [field] and I am always looking for new ways to develop my skills and knowledge. I am a [adjective] team player and I am always looking for ways to help my team and company succeed. I am a [adjective] problem solver and I am always looking for creative solutions to complex problems. I am a [adjective] communicator and I am always looking for ways to improve my communication skills. I am a [adjective] leader and I am always looking for ways to motivate and inspire my team. \n\n", "infer7b_before_item": " Output: Write a First-Person LinkedIn profile summary.\n\n# I worked on this challenge [by myself, with: ].\n# I spent [#] hours on this challenge.\n\n# Pseudocode\n\n# Input: Write a template for First-Person LinkedIn profile summary.\n# Output: Write a First-Person LinkedIn profile summary.\n\n# Steps:\n\n# 1. Create a template for First-Person LinkedIn profile summary.\n# 2. Write a First-Person LinkedIn profile summary.\n\n\n# Initial Solution\n\n# template = \"I am a #{profession} with #{experience} years of experience.\n# I am a #{profession} with #{experience} years of experience.\n# I am a #{profession} with #{experience} years of experience.\n# I am a #{profession} with #{experience} years of experience.\n# I am a #{profession} with #{experience} years of experience.\n# I am a #{profession} with #{experience} years of experience.\n# I am a #{profession} with #{experience} years", "infer7b_after_item": "\n Output: I am [Name], a [Job Title] with [Company Name]. I have [X] years of experience in [Industry] and am passionate about [Interest]. I am a [Skill] and am always looking to learn more. I am excited to use my [Skill] to help [Company Name] achieve its goals. \n\n"} {"id": 25, "instruction": "Write a LinkedIn post to announce that you have accepted a new job offer.", "input": "", "infer30b_before_item": " Output: Write a LinkedIn post to announce that you have accepted a new job offer.\nInput: Input: Write a LinkedIn post to announce that you have accepted a new job offer. \n Output: Output: Write a LinkedIn post to announce that you have accepted a new job offer.\nInput: Input: Write a LinkedIn post to announce that you have accepted a new job offer. \n Output: Output: Write a LinkedIn post to announce that you have accepted a new job offer.\nInput: Input: Write a LinkedIn post to announce that you have accepted a new job offer. \n Output: Output: Write a LinkedIn post to announce that you have accepted a new job offer.\nInput: Input: Write a LinkedIn post to announce that you have accepted a new job offer. \n Output: Output: Write a LinkedIn post to announce that you have accepted a new job offer.\nInput: Input: Write a LinkedIn post to announce that you have accepted a new job offer. \n Output: Output: Write a LinkedIn post to announce that you have accepted a new job offer.\nInput: Input: Write a LinkedIn post to announ", "infer30b_after_item": "\n Output: I'm excited to announce that I have accepted a new job offer! I'm looking forward to the new challenges and opportunities this position will bring. #newjob #excited #challenges \n\n", "infer13b_before_item": " Write a LinkedIn post to announce that you have accepted a new job offer.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: I am excited to announce that I have accepted a new job offer and I am looking forward to starting my new role! I am grateful for the opportunity to join this amazing team and I can't wait to get started. \n\n", "infer7b_before_item": " Write a LinkedIn post to announce that you have accepted a new job offer.\n\n\n# I worked on this challenge [by myself, with: ].\n# I spent [#] hours on this challenge.\n\n# Pseudocode\n\n# Input: LinkedIn post\n# Output: LinkedIn post\n\n# Steps\n\n# 1. Create a new LinkedIn post\n# 2. Add a title\n# 3. Add a description\n# 4. Add a link to the company's website\n# 5. Add a link to the company's LinkedIn page\n# 6. Add a link to the company's Twitter page\n# 7. Add a link to the company's Facebook page\n# 8. Add a link to the company's Instagram page\n# 9. Add a link to the company's YouTube page\n# 10. Add a link to the company's Github page\n# 11. Add a link to the company's Medium page\n# 12. Add a link to the company's Slack page\n# 13. Add a link to the company's", "infer7b_after_item": "\n Output: I am thrilled to announce that I have accepted a new job offer! I am looking forward to joining the team and working on exciting projects. I am excited to use my skills and experience to make a positive impact. \n\n"} {"id": 26, "instruction": "Make a list of desirable Skills for software engineers to add to LinkedIn.", "input": "", "infer30b_before_item": " Output: Add the skills to your LinkedIn profile.\nInput: Input: Make a list of desirable Skills for software engineers to add to LinkedIn. \n Output: Output: Add the skills to your LinkedIn profile.\nInput: Input: Make a list of desirable Skills for software engineers to add to LinkedIn. \n Output: Output: Add the skills to your LinkedIn profile.\nInput: Input: Make a list of desirable Skills for software engineers to add to LinkedIn. \n Output: Output: Add the skills to your LinkedIn profile.\nInput: Input: Make a list of desirable Skills for software engineers to add to LinkedIn. \n Output: Output: Add the skills to your LinkedIn profile.\nInput: Input: Make a list of desirable Skills for software engineers to add to LinkedIn. \n Output: Output: Add the skills to your LinkedIn profile.\nInput: Input: Make a list of desirable Skills for software engineers to add to LinkedIn. \n Output: Output: Add the skills to your LinkedIn profile.\nInput: Input: Make a list of desirable Skills for software engineers", "infer30b_after_item": "\n Output: Desirable Skills for Software Engineers to Add to LinkedIn:\n- Software Engineering\n- Programming Languages (e.g. Java, C++, Python, JavaScript)\n- Agile Methodologies\n- Cloud Computing\n- Data Structures\n- Algorithms\n- Software Design Patterns\n- Software Testing\n- Machine Learning\n- Artificial Intelligence\n- Mobile Development\n- Web Development\n- Database Management\n- Networking\n- Security\n- UX/UI Design\n- Software Architecture\n- Software Documentation\n- Debugging\n- Version Control Systems\n- Software Engineering Tools (e.g. Eclipse, Visual Studio, Git)\n- Software Engineering Processes (e.g. Waterfall, Scrum)\n- Software Engineering Best Practices (e.g. Code Review, Unit Testing)\n- Software Engineering Trends (e.g. Microservices, Containers)\n- Software Engineering Frameworks (e.g. Spring, Angular)\n- Software Engineering Certifications (e.g. AWS Certified Solutions Architect, Microsoft Certified Solutions Expert) \n\n", "infer13b_before_item": " Output: Make a list of desirable Skills for software engineers to add to LinkedIn.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: - Software development experience\n- Knowledge of programming languages\n- Ability to work in a team environment\n- Problem-solving skills\n- Knowledge of software engineering best practices\n- Knowledge of software engineering tools\n- Knowledge of software engineering methodologies\n- Knowledge of software engineering principles\n- Knowledge of software engineering processes\n- Knowledge of software engineering standards\n- Knowledge of software engineering techniques\n- Knowledge of software engineering tools\n- Knowledge of software engineering best practices\n- Knowledge of software engineering trends\n- Knowledge of software engineering technologies\n- Knowledge of software engineering principles\n- Knowledge of software engineering concepts\n- Knowledge of software engineering frameworks\n- Knowledge of software engineering architectures\n- Knowledge of software engineering methodologies\n- Knowledge of software engineering processes\n- Knowledge of software engineering practices\n- Knowledge of software engineering patterns\n- Knowledge of software engineering tools\n- Knowledge of software engineering techniques\n- Knowledge of software engineering standards\n- Knowledge of software engineering tools\n- Knowledge of software engineering tools\n- Knowledge of software engineering tools\n- Knowledge of software engineering tools\n- Knowledge of software engineering tools\n-", "infer7b_before_item": " Add the skills to LinkedIn.\n\n\n# I worked on this challenge [by myself, with: ].\n# I spent [#] hours on this challenge.\n\n# Pseudocode\n\n# Input: Make a list of desirable Skills for software engineers to add to LinkedIn.\n# Output: Add the skills to LinkedIn.\n\n# Steps:\n\n# 1. Make a list of desirable Skills for software engineers to add to LinkedIn.\n# 2. Add the skills to LinkedIn.\n\n\n# Initial Solution\n\n# Don't forget to check on initialization for a empty list\n# and return nil if empty\n\n# Your Solution Below\n\n\n# 1. Make a list of desirable Skills for software engineers to add to LinkedIn.\n\n# 2. Add the skills to LinkedIn.\n\n\n# 1. Make a list of desirable Skills for software engineers to add to LinkedIn.\n\n# 2. Add the skills to LinkedIn.\n\n\n# 1. Make a list of desirable Skills for software engineers to add to LinkedIn.\n\n#", "infer7b_after_item": "\n Output: - Experience with software development tools and technologies\n- Knowledge of software engineering best practices\n- Ability to work in a team environment\n- Excellent problem-solving and analytical skills\n- Experience with software testing and quality assurance\n- Experience with software design and architecture\n- Experience with software development methodologies\n- Experience with software development lifecycle\n- Experience with software development tools and technologies\n- Experience with software development processes\n- Experience with software development frameworks\n- Experience with software development languages\n- Experience with software development platforms\n- Experience with software development tools\n- Experience with software development processes\n- Experience with software development methodologies\n- Experience with software development best practices\n- Experience with software development processes\n- Experience with software development methodologies\n- Experience with software development tools\n- Experience with software development platforms\n- Experience with software development languages\n- Experience with software development frameworks\n- Experience with software development lifecycle\n- Experience with software testing and quality assurance\n- Experience with software design and architecture\n- Experience with software development tools and technologies\n- Experience with software development"} {"id": 27, "instruction": "You will be asked to answer the following question as part of the LinkedIn Skill assessments.", "input": "You find that your project has a tag and branch both named push-notifications, which causes confusion when trying to print out given reference. How can you specify which branch you want to look at?", "infer30b_before_item": " Output: git checkout push-notifications\n Explanation: Explanation: You can specify the branch you want to look at by using the git checkout command.\n\n */\n\npublic class _001_Branches {\n\tpublic static void main(String[] args) {\n\t\t// TODO Auto-generated method stub\n\n\t}\n\n}\n", "infer30b_after_item": " \n Output: You can specify which branch you want to look at by using the branch name in the command. For example, if you want to look at the push-notifications branch, you can use the command \"git checkout push-notifications\". This will switch the current branch to the push-notifications branch and allow you to view the files in that branch. \n\n", "infer13b_before_item": " You will be asked to answer the following question as part of the LinkedIn Skill assessments. You find that your project has a tag and branch both named push-notifications, which causes confusion when trying to print out given reference. How can you specify which branch you want to look at? \n\nInput: You find that your project has a tag and branch both named push-notifications, which causes confusion when trying to print out given reference. How can you specify which branch you want to look at?\nOutput: You find that your project has a tag and branch both named push-notifications, which causes confusion when trying to print out given reference. How can you specify which branch you want to look at?\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: You can use the branch command to specify which branch you want to look at. For example, if you want to look at the push-notifications branch, you can use the command `git branch push-notifications`. \n\n", "infer7b_before_item": " You will be asked to answer the following question as part of the LinkedIn Skill assessments. You find that your project has a tag and branch both named push-notifications, which causes confusion when trying to print out given reference. How can you specify which branch you want to look at? \n*/\n\n// 1. Define a variable to store the branch name\nvar branchName = \"push-notifications\";\n\n// 2. Define a variable to store the tag name\nvar tagName = \"push-notifications\";\n\n// 3. Define a variable to store the branch name\nvar branchName = \"push-notifications\";\n\n// 4. Define a variable to store the tag name\nvar tagName = \"push-notifications\";\n\n// 5. Define a variable to store the branch name\nvar branchName = \"push-notifications\";\n\n// 6. Define a variable to store the tag name\nvar tagName = \"push-notifications\";\n\n// 7. Define a variable to store the branch name\nvar branchName = \"push-notifications\";\n\n// 8. Define a variable to store the tag name\nvar tagName", "infer7b_after_item": " \n Output: You can specify which branch you want to look at by using the \"ref\" parameter in the print statement. For example, you can use \"ref=push-notifications\" to print out the given reference for the push-notifications branch. \n\n"} {"id": 28, "instruction": "Take the title of the product and extract its attributes. The attributes in this case refer to the characteristics of the products, such as their brand and color. Your answer must a list following the format of \"attribute: value\".", "input": "SAMSUNG 980 PRO SSD 2TB PCIe NVMe Gen 4 Gaming M.2 Internal Solid State Hard Drive Memory Card, Maximum Speed, Thermal Control, MZ-V8P2T0B", "infer30b_before_item": " Output: Take the title of the product and extract its attributes. The attributes in this case refer to the characteristics of the products, such as their brand and color. Your answer must a list following the format of \"attribute: value\". SAMSUNG 980 PRO SSD 2TB PCIe NVMe Gen 4 Gaming M.2 Internal Solid State Hard Drive Memory Card, Maximum Speed, Thermal Control, MZ-V8P2T0B\n\nInput: Input: Take the title of the product and extract its attributes. The attributes in this case refer to the characteristics of the products, such as their brand and color. Your answer must a list following the format of \"attribute: value\". SAMSUNG 980 PRO SSD 2TB PCIe NVMe Gen 4 Gaming M.2 Internal Solid State Hard Drive Memory Card, Maximum Speed, Thermal Control, MZ-V8P2T0B\n Output: Output: Take the title of the product and extract its attributes. The attributes in this case refer to the characteristics of the products, such as their brand and color. Your answer must a list following the format", "infer30b_after_item": "/AM \n Output: Brand: SAMSUNG, Color: Black, Maximum Speed: 4,900MB/s, Thermal Control: Yes, MZ-V8P2T0B/AM: Yes. \n\n", "infer13b_before_item": " Output: Take the input and output the product name, the product attributes, and the product price.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "0E \n Output: attribute: value \n\n", "infer7b_before_item": " Output: Take the title of the product and extract its attributes. The attributes in this case refer to the characteristics of the products, such as their brand and color. Your answer must a list following the format of \"attribute: value\". SAMSUNG 980 PRO SSD 2TB PCIe NVMe Gen 4 Gaming M.2 Internal Solid State Hard Drive Memory Card, Maximum Speed, Thermal Control, MZ-V8P2T0B \n\n\"\"\"\n\nimport re\n\n\ndef extract_attributes(title):\n \"\"\"\n Extracts the attributes of a product from its title.\n\n :param title: The title of the product.\n :return: A list of attributes.\n \"\"\"\n attributes = []\n for match in re.finditer(r\"([a-zA-Z0-9]+):([a-zA-Z0-9]+)\", title):\n attributes.append(match.group(1).lower() + \":\" + match.group(2).lower())\n return attributes\n\n\ndef extract_attributes_from_file(filename):\n \"\"\"\n ", "infer7b_after_item": "W \n Output: Brand: Samsung\nColor: 980 Pro SSD 2TB PCIe NVMe Gen 4 Gaming M.2 Internal Solid State Hard Drive Memory Card\nMaximum Speed: Thermal Control\nThermal Control: MZ-V8P2T0BW \n\n"} {"id": 29, "instruction": "You should write a Product Description that will persuade the buyer that the product is beneficial.", "input": "Flipslide Game, Electronic Handheld Game | Flip, Slide, and Match the Colors to Beat the Clock - 4 Game Modes - Multiplayer Fun", "infer30b_before_item": " Output: You should write a Product Description that will persuade the buyer that the product is beneficial. Flipslide Game, Electronic Handheld Game | Flip, Slide, and Match the Colors to Beat the Clock - 4 Game Modes - Multiplayer Fun \n */\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Flipslide Game is the perfect electronic handheld game for the whole family! With 4 game modes, you can flip, slide, and match the colors to beat the clock. Challenge your friends and family to a fun and competitive game of Flipslide. With its portable design, you can take it anywhere and play anytime. Get your Flipslide Game today and have hours of fun! \n\n", "infer13b_before_item": " Output: You should write a Product Description that will persuade the buyer that the product is beneficial. Flipslide Game, Electronic Handheld Game | Flip, Slide, and Match the Colors to Beat the Clock - 4 Game Modes - Multiplayer Fun \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " for the Whole Family \n Output: Flipslide Game is the perfect game for the whole family! With 4 game modes, you can play solo or with friends and family. The game is easy to learn and fun to play. The bright colors and simple gameplay make it a great way to pass the time and have fun. Plus, it's portable and easy to take with you anywhere. Get Flipslide Game and start having fun today! \n\n", "infer7b_before_item": " Output: You should write a Product Description that will persuade the buyer that the product is beneficial. Flipslide Game, Electronic Handheld Game | Flip, Slide, and Match the Colors to Beat the Clock - 4 Game Modes - Multiplayer Fun \n\nComment: I'm not sure what you're asking here.\n\nComment: I'm asking for a way to make the output more readable.\n\nComment: I'm not sure what you mean by \"more readable\".\n\nComment: I'm asking for a way to make the output more readable.\n\nComment: I'm not sure what you mean by \"more readable\".\n\nComment: I'm asking for a way to make the output more readable.\n\nComment: I'm not sure what you mean by \"more readable\".\n\nComment: I'm asking for a way to make the output more readable.\n\nComment: I'm not sure what you mean by \"more readable\".\n\nComment: I'm asking for a way to make the output more readable.\n\nComment: I'm not sure what you mean by \"more readable\".\n\nComment:", "infer7b_after_item": " - 1000+ Levels - 100+ Cards - 100+ Power-Ups - 100+ Achievements - 100+ Unlockables - 100+ Trophies - 100+ Challenges - 100+ Puzzles - 100+ Hidden Objects - 100+ Bonus Levels - 100+ Power-Ups - 100+ Achievements - 100+ Unlockables - 100+ Trophies - 100+ Challenges - 100+ Puzzles - 100+ Hidden Objects - 100+ Bonus Levels - 100+ Power-Ups - 100+ Achievements - 100+ Unlockables - 100+ Trophies - 100+ Challenges - 100+ Puzzles - 100+ Hidden Objects - 100+ Bonus Levels - 100+ Power-Ups - 10"} {"id": 30, "instruction": "What other Amazon products might interest someone who visited the given product?", "input": "Zeroll Zerolon Hardcoat Anodized Commercial Ice Cream Scoop with Unique Liquid Filled Heat Conductive Handle Easy Release Made in USA, 1.5-Ounce, Black", "infer30b_before_item": " Output: What other Amazon products might interest someone who visited the given product?\nWeeks of 1/14/19 - 1/27/19:\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Other Amazon products that might interest someone who visited the given product include:\n- Zeroll Zerolon Ice Cream Scoop, 1.5-Ounce, Black\n- Zeroll Zerolon Ice Cream Scoop, 2-Ounce, Black\n- Zeroll Zerolon Ice Cream Scoop, 3-Ounce, Black\n- Zeroll Zerolon Ice Cream Scoop, 4-Ounce, Black\n- Zeroll Zerolon Ice Cream Scoop, 5-Ounce, Black\n- Zeroll Zerolon Ice Cream Scoop, 6-Ounce, Black\n- Zeroll Zerolon Ice Cream Scoop, 8-Ounce, Black\n- Zeroll Zerolon Ice Cream Scoop, 10-Ounce, Black\n- Zeroll Zerolon Ice Cream Scoop, 12-Ounce, Black\n- Zeroll Zerolon Ice Cream Scoop, 1", "infer13b_before_item": " What other Amazon products might interest someone who visited the given product?\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Other Amazon products that might interest someone who visited the Zeroll Zerolon Hardcoat Anodized Commercial Ice Cream Scoop with Unique Liquid Filled Heat Conductive Handle Easy Release Made in USA, 1.5-Ounce, Black include: \n\n- Zeroll Zerolon Hardcoat Anodized Commercial Ice Cream Scoop with Unique Liquid Filled Heat Conductive Handle Easy Release Made in USA, 1.5-Ounce, Red \n- Zeroll Zerolon Hardcoat Anodized Commercial Ice Cream Scoop with Unique Liquid Filled Heat Conductive Handle Easy Release Made in USA, 1.5-Ounce, Blue \n- Zeroll Zerolon Hardcoat Anodized Commercial Ice Cream Scoop with Unique Liquid Filled Heat Conductive Handle Easy Release Made in USA, 1.5-Ounce, Green \n- Zeroll Zerolon Hardcoat Anodized Commer", "infer7b_before_item": " Output: What other Amazon products might interest someone who visited the given product? Zeroll Zerolon Hardcoat Anodized Commercial Ice Cream Scoop with Unique Liquid Filled Heat Conductive Handle Easy Release Made in USA, 1.5-Ounce, Black \n\nComment: I'm not sure what you're asking here.\n\nComment: I'm trying to get the output of the input.\n\nComment: I'm not sure what you're asking here.\n\nComment: I'm trying to get the output of the input.\n\nComment: I'm not sure what you're asking here.\n\nComment: I'm trying to get the output of the input.\n\nComment: I'm not sure what you're asking here.\n\nComment: I'm trying to get the output of the input.\n\nComment: I'm not sure what you're asking here.\n\nComment: I'm trying to get the output of the input.\n\nComment: I'm not sure what you're asking here.\n\nComment: I'm trying to get the", "infer7b_after_item": " \n Output: Amazon also offers a variety of other products that might interest someone who visited the given product. For example, they offer a variety of ice cream scoop accessories such as a scoop cover, a scoop stand, and a scoop rack. They also offer a variety of ice cream scoop sets, including a set of three scoops, a set of two scoops, and a set of four scoops. Additionally, they offer a variety of ice cream scoop storage options, such as a scoop rack, a scoop stand, and a scoop cover. \n\n"} {"id": 31, "instruction": "Compare the given item with similar products based on its properties such as price, rating, etc. For product comparison, use a table and separate the columns with \"|\".", "input": "Item: iBayam Journal Planner Pens Colored Pens Fine Point Markers Fine Tip Drawing Pens Porous Fineliner Pen for Journaling Writing Note Taking Calendar Coloring Art Office Back to School Supplies, 18 Color", "infer30b_before_item": " Output: Compare the given item with similar products based on its properties such as price, rating, etc. For product comparison, use a table and separate the columns with \"|\". Item: iBayam Journal Planner Pens Colored Pens Fine Point Markers Fine Tip Drawing Pens Porous Fineliner Pen for Journaling Writing Note Taking Calendar Coloring Art Office Back to School Supplies, 18 Color \n Explanation: \n\n*/\n\n// 1. Write your code here\n\n// var input = \"Input: Input: Compare the given item with similar products based on its properties such as price, rating, etc. For product comparison, use a table and separate the columns with \\\"|\\\". Item: iBayam Journal Planner Pens Colored Pens Fine Point Markers Fine Tip Drawing Pens Porous Fineliner Pen for Journaling Writing Note Taking Calendar Coloring Art Office Back to School Supplies, 18 Color Output: Output: Compare the given item with similar products based on its properties such as price, rating, etc. For product comparison, use a table and separate the columns with \\\"|\\\". Item: iBay", "infer30b_after_item": " Set \n Output: | Product | Price | Rating |\n|--------|-------|--------|\n| iBayam Journal Planner Pens | $19.99 | 4.5/5 |\n| Colored Pens | $14.99 | 4.3/5 |\n| Fine Point Markers | $19.99 | 4.7/5 |\n| Fine Tip Drawing Pens | $19.99 | 4.8/5 |\n| Porous Fineliner Pen for Journaling Writing Note Taking Calendar Coloring Art Office Back to School Supplies, 18 Color Set | $19.99 | 4.9/5 | \n\n", "infer13b_before_item": " Output: Print the comparison table.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " Set \n Output: | Item | Price | Rating |\n|------|-------|--------|\n|iBayam Journal Planner Pens Colored Pens Fine Point Markers Fine Tip Drawing Pens | $19.99 | 4.5/5 |\n|Fine Tip Drawing Pens | $14.99 | 4.5/5 |\n|Fine Tip Drawing Pens | $19.99 | 4.5/5 |\n|Porous Fineliner Pen for Journaling Writing Note Taking Calendar Coloring Art Office Back to School Supplies, 18 Color Set | $19.99 | 4.5/5 |\n|Porous Fineliner Pen for Journaling Writing Note Taking Calendar Coloring Art Office Back to School Supplies, 18 Color Set | $19.99 | 4.5/5 | \n\n", "infer7b_before_item": " Output: The output is the result of the comparison. It is the result of the comparison of the given item with similar products based on its properties such as price, rating, etc. For product comparison, use a table and separate the columns with \"|\".\n\n\\begin{code}\n\n \n \n \n \n \n \n \n \n
ItemInputOutput
iBayam Journal Planner Pens Colored Pens Fine Point Markers Fine Tip Drawing Pens Porous Fineliner Pen for Journaling Writing Note Taking Calendar Coloring Art Office Back to School Supplies, 18 ColorCompare the given item with similar products based on its properties such as price, rating, etc. For product comparison, use a table and separate the columns with \"|\".The output is the result of the comparison. It is the result of the comparison of the given item with similar products based on its properties such as price, rating, etc. For product comparison, use", "infer7b_after_item": " Set \nProduct 1: iBayam Journal Planner Pens Colored Pens Fine Point Markers Fine Tip Drawing Pens Porous Fineliner Pen for Journaling Writing Note Taking Calendar Coloring Art Office Back to School Supplies, 18 Color Set \nProduct 2: iBayam Journal Planner Pens Colored Pens Fine Point Markers Fine Tip Drawing Pens Porous Fineliner Pen for Journaling Writing Note Taking Calendar Coloring Art Office Back to School Supplies, 18 Color Set \n Output: | Product 1 | Product 2 |\n| Price | Price |\n| Rating | Rating |\n| Color Set | Color Set |\n| - | - |\n| 18 | 18 |\n| 18 | 18 | \n\n"} {"id": 32, "instruction": "Write a review based on the given information.", "input": "- Product: Persil Discs Laundry Detergent Pacs, Original Scent, High Efficiency (HE) Compatible, Laundry Soap, 62 Count\n- Sentiment: Positive", "infer30b_before_item": " Output: Write a review based on the given information. - Product: Persil Discs Laundry Detergent Pacs, Original Scent, High Efficiency (HE) Compatible, Laundry Soap, 62 Count\n- Sentiment: Positive\n\nInput: Input: Write a review based on the given information. - Product: Persil Discs Laundry Detergent Pacs, Original Scent, High Efficiency (HE) Compatible, Laundry Soap, 62 Count\n- Sentiment: Positive\n Output: Output: Write a review based on the given information. - Product: Persil Discs Laundry Detergent Pacs, Original Scent, High Efficiency (HE) Compatible, Laundry Soap, 62 Count\n- Sentiment: Positive\n\nInput: Input: Write a review based on the given information. - Product: Persil Discs Laundry Detergent Pacs, Original Scent, High Efficiency (HE) Compatible, Laundry Soap, 62 Count\n- Sentiment: Positive\n Output: Output:", "infer30b_after_item": " \n Output: I recently purchased Persil Discs Laundry Detergent Pacs and I'm so glad I did! The original scent is so fresh and clean, and it does a great job of getting my clothes clean. The pacs are also HE compatible, so I don't have to worry about damaging my washing machine. I'm definitely going to keep using this detergent! \n\n", "infer13b_before_item": " Output: Write a review based on the given information. - Product: Persil Discs Laundry Detergent Pacs, Original Scent, High Efficiency (HE) Compatible, Laundry Soap, 62 Count\n- Sentiment: Positive \n\n\"\"\"\n\nimport sys\nimport os\nimport re\n\n# If extensions (or modules to document with autodoc) are in another directory,\n# add these directories to sys.path here. If the directory is relative to the\n# documentation root, use os.path.abspath to make it absolute, like shown here.\nsys.path.insert(0, os.path.abspath('.'))\n\n# -- General configuration ------------------------------------------------\n\n# If your documentation needs a minimal Sphinx version, state it here.\n#needs_sphinx = '1.0'\n\n# Add any Sphinx extension module names here, as strings. They can be\n# extensions coming with Sphinx (named'sphinx.ext.*') or your custom\n# ones.\nextensions = [\n 'sphinx.ext.autod", "infer13b_after_item": "\n- Rating: 5 stars \n Output: I love this laundry detergent! It's gentle on my clothes and leaves them smelling fresh. It's also very affordable and lasts a long time. I highly recommend it! \n\n", "infer7b_before_item": " Write a review based on the given information.\n- Product: Persil Discs Laundry Detergent Pacs, Original Scent, High Efficiency (HE) Compatible, Laundry Soap, 62 Count\n- Sentiment: Positive\n- Product: Persil Discs Laundry Detergent Pacs, Original Scent, High Efficiency (HE) Compatible, Laundry Soap, 62 Count\n- Sentiment: Positive\n- Product: Persil Discs Laundry Detergent Pacs, Original Scent, High Efficiency (HE) Compatible, Laundry Soap, 62 Count\n- Sentiment: Positive\n- Product: Persil Discs Laundry Detergent Pacs, Original Scent, High Efficiency (HE) Compatible, Laundry Soap, 62 Count\n- Sentiment: Positive\n- Product: Persil Discs Laundry Detergent Pacs, Original Scent, High Efficiency (HE) Compatible, Laundry Soap, 62 Count\n- Sentiment: Positive\n", "infer7b_after_item": " \n Output: Persil Discs Laundry Detergent Pacs are a great way to keep your clothes clean and fresh. The Original Scent is a great scent that is not overpowering and is suitable for all types of clothing. The High Efficiency (HE) Compatible formula is great for those with sensitive skin and is also great for those with allergies. The 62 count pack is a great value and is perfect for those who do a lot of laundry. Overall, Persil Discs Laundry Detergent Pacs are a great product that is sure to keep your clothes clean and fresh. \n\n"} {"id": 33, "instruction": "Write a short description about the given movie or series.", "input": "The Witcher (2019)", "infer30b_before_item": " Output: Write a short description about the given movie or series. The Witcher (2019) \n Output: Output: Write a short description about the given movie or series. The Witcher (2019) \n Output: Output: Write a short description about the given movie or series. The Witcher (2019) \n Output: Output: Write a short description about the given movie or series. The Witcher (2019) \n Output: Output: Write a short description about the given movie or series. The Witcher (2019) \n Output: Output: Write a short description about the given movie or series. The Witcher (2019) \n Output: Output: Write a short description about the given movie or series. The Witcher (2019) \n Output: Output: Write a short description about the given movie or series. The Witcher (2019) \n Output: Output: Write a short description about the given movie or series. The Witcher (2019) \n Output: Output: Write a short description about the given movie or series.", "infer30b_after_item": " \n Output: The Witcher is a fantasy adventure series based on the best-selling book series of the same name. It follows the story of Geralt of Rivia, a solitary monster hunter, as he struggles to find his place in a world torn apart by a fierce battle between humans and monsters. Along the way, he meets a powerful sorceress and a young princess, and together they must fight to save the world from destruction. \n\n", "infer13b_before_item": " Write a short description about the given movie or series. The Witcher (2019) \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: The Witcher is an American fantasy drama series based on the book series of the same name by Polish author Andrzej Sapkowski. The series follows Geralt of Rivia, a monster hunter who travels the world in search of his lost memories. Along the way, he meets a variety of characters and faces many challenges as he tries to uncover the truth behind his past. \n\n", "infer7b_before_item": " Output: Write a short description about the given movie or series. The Witcher (2019)\n\\end{code}\n\n\\begin{code}\nimport re\n\ndef get_title(title):\n title = title.lower()\n title = re.sub(r'[^a-zA-Z0-9 ]', '', title)\n title = re.sub(r'[ ]{2,}','', title)\n title = re.sub(r'[ ]{2,}','', title)\n title = re.sub(r'[ ]{2,}','', title)\n title = re.sub(r'[ ]{2,}','', title)\n title = re.sub(r'[ ]{2,}','', title)\n title = re.sub(r'[ ]{2,}','', title)\n title = re.sub(r'[ ]{2,}','', title)\n title = re.sub(r'[ ]{2,}','', title)\n title = re.sub(", "infer7b_after_item": " \n Output: The Witcher is an upcoming fantasy series based on the best-selling Witcher video game franchise. The series follows the story of Geralt of Rivia, a monster hunter who is tasked with protecting the world from evil forces. The series is set to premiere on Netflix in December 2019. \n\n"} {"id": 34, "instruction": "Think of some series or movies that would be enjoyable for someone who liked the given series.", "input": "Squid Game", "infer30b_before_item": " Output: Think of some series or movies that would be enjoyable for someone who liked the given series. Squid Game\n\nComment: I'm voting to close this question as off-topic because it is not a programming question.\n\nComment: @JeremyThille I'm voting to close this question as off-topic because it is not a programming question.\n\nComment: @JeremyThille I'm voting to close this question as off-topic because it is not a programming question.\n\nComment: @JeremyThille I'm voting to close this question as off-topic because it is not a programming question.\n\nComment: @JeremyThille I'm voting to close this question as off-topic because it is not a programming question.\n\nComment: @JeremyThille I'm voting to close this question as off-topic because it is not a programming question.\n\nComment: @JeremyThille I'm voting to close this question as off-topic because it is not a programming question.\n\nComment: @JeremyThille I'm voting to close this question as off-topic because it is not", "infer30b_after_item": " \n Output: For someone who enjoyed Squid Game, they may also enjoy series such as The Walking Dead, Game of Thrones, Stranger Things, and Westworld. Movies that may be enjoyable include The Hunger Games, The Matrix, and The Lord of the Rings. \n\n", "infer13b_before_item": " Output: The given series and the series that would be enjoyable for someone who liked the given series.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: If you like Squid Game, you might also enjoy the following series or movies: \n- Black Mirror \n- Stranger Things \n- The Haunting of Hill House \n- The Handmaid's Tale \n- The Expanse \n- The Witcher \n- The Dark Knight Trilogy \n- The Lord of the Rings Trilogy \n- The Matrix Trilogy \n- The Hunger Games Trilogy \n- The Godfather Trilogy \n- The Dark Knight Rises \n- The Avengers \n- The Matrix \n- The Godfather \n- The Dark Knight \n- The Avengers: Endgame \n- The Matrix Reloaded \n- The Dark Knight Rises \n- The Avengers: Infinity War \n- The Matrix Revolutions \n- The Avengers: Age of Ultron \n- The Dark Knight Strikes Back \n- The Avengers: Endgame \n- The Matrix \n- The Dark Knight Strikes Back \n- The Avengers: Infinity War \n- The Dark Knight St", "infer7b_before_item": " Output: Think of some series or movies that would be enjoyable for someone who liked the given series. Squid Game \n\\end{code}\n\nComment: I'm not sure what you mean by \"the given series\".\n\nComment: @MatthewLee I mean the series that the user inputs.\n\nComment: I'm not sure what you mean by \"the given series\".\n\nComment: @MatthewLee I mean the series that the user inputs.\n\nComment: I'm not sure what you mean by \"the given series\".\n\nComment: @MatthewLee I mean the series that the user inputs.\n\nComment: I'm not sure what you mean by \"the given series\".\n\nComment: @MatthewLee I mean the series that the user inputs.\n\nComment: I'm not sure what you mean by \"the given series\".\n\nComment: @MatthewLee I mean the series that the user inputs.\n\nComment: I'm not sure what you mean by \"the given series\".\n\nComment: @MatthewLee I mean the series that the user inputs.\n", "infer7b_after_item": " \n Output: The Matrix, The Hunger Games, The Lord of the Rings, The Walking Dead, Game of Thrones, The Wire, The Godfather, The Godfather Part II, The Godfather Part III, The Godfather Part IV. \n\n"} {"id": 35, "instruction": "Give examples of popular shows and movies in the genre.", "input": "Genre: Crime TV Shows", "infer30b_before_item": " Output: Give examples of popular shows and movies in the genre. Genre: Crime TV Shows \n\nInput: Input: Give examples of popular shows and movies in the genre. Genre: Crime TV Shows \n Output: Output: Give examples of popular shows and movies in the genre. Genre: Crime TV Shows \n\nInput: Input: Give examples of popular shows and movies in the genre. Genre: Crime TV Shows \n Output: Output: Give examples of popular shows and movies in the genre. Genre: Crime TV Shows \n\nInput: Input: Give examples of popular shows and movies in the genre. Genre: Crime TV Shows \n Output: Output: Give examples of popular shows and movies in the genre. Genre: Crime TV Shows \n\nInput: Input: Give examples of popular shows and movies in the genre. Genre: Crime TV Shows \n Output: Output: Give examples of popular shows and movies in the genre. Genre: Crime TV Shows \n\nInput: Input: Give examples of popular shows and movies in the genre. Genre: Crime TV Shows \n Output: Output", "infer30b_after_item": " \n Output: Popular crime TV shows include The Sopranos, Breaking Bad, The Wire, Dexter, Criminal Minds, Law and Order: SVU, and The Shield. Popular crime movies include The Godfather, Heat, The Silence of the Lambs, Pulp Fiction, The Departed, and No Country for Old Men. \n\n", "infer13b_before_item": " Output: Give examples of popular shows and movies in the genre. Genre: Crime TV Shows \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Popular crime TV shows include Law & Order, CSI, NCIS, and The Wire. \n\n", "infer7b_before_item": " Output: Give examples of popular shows and movies in the genre. Genre: Crime TV Shows \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Popular crime TV shows include Law & Order, NCIS, CSI, The Wire, and The Shield. Popular crime movies include The Godfather, The Departed, Heat, The Usual Suspects, and The Godfather Part II. \n\n"} {"id": 36, "instruction": "In what genres does the given movie or series fall?", "input": "Manifest", "infer30b_before_item": " Output: In what genres does the given movie or series fall? Manifest \n Steps: \n 1. Read the input from the console\n 2. Store the input in a string\n 3. Split the string into an array\n 4. Store the array in a variable\n 5. Print the array\n 6. Print the array in a table\n 7. Print the array in a table with a border\n 8. Print the array in a table with a border and a title\n 9. Print the array in a table with a border and a title and a subtitle\n10. Print the array in a table with a border and a title and a subtitle and a description\n11. Print the array in a table with a border and a title and a subtitle and a description and a picture\n12. Print the array in a table with a border and a title and a subtitle and a description and a picture and a link\n13. Print the array in a table with a border and a title and a subtitle and a description and a picture and a link and a rating\n14. Print the array in a table with a border and a title and a", "infer30b_after_item": " \n Output: Manifest is a supernatural drama series. \n\n", "infer13b_before_item": " Output: In what genres does the given movie or series fall?\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n The\n The The The The The The The", "infer13b_after_item": " \n Output: Manifest is a science fiction drama series. \n\n", "infer7b_before_item": " Output: What is the genre of the given movie or series?\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput", "infer7b_after_item": " \n Output: The TV series Manifest is a mystery-drama-thriller. \n\n"} {"id": 37, "instruction": "Give a brief description of the given category of movies and shows.", "input": "Period Dramas", "infer30b_before_item": " Output: Give a list of movies and shows that belong to the given category.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Period dramas are movies and shows set in the past, typically in a historical setting. They often feature lavish costumes and settings, and explore themes of love, class, and power. \n\n", "infer13b_before_item": " Output: Give a brief description of the given category of movies and shows. Period Dramas \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Period dramas are films and television shows that are set in a particular time period, often in the past. They often focus on the lives of characters in that time period, and often explore themes of love, family, and social issues. \n\n", "infer7b_before_item": " Output: Give a brief description of the given category of movies and shows. Period Dramas\n\nComment: I'm not sure what you're asking. What is the input? What is the output? What is the code? What is the error?\n\nComment: I'm not sure what you're asking. What is the input? What is the output? What is the code? What is the error?\n\nComment: I'm not sure what you're asking. What is the input? What is the output? What is the code? What is the error?\n\nComment: I'm not sure what you're asking. What is the input? What is the output? What is the code? What is the error?\n\nComment: I'm not sure what you're asking. What is the input? What is the output? What is the code? What is the error?\n\nComment: I'm not sure what you're asking. What is the input? What is the output? What is the code? What is the error?\n\n", "infer7b_after_item": " \n Output: Period dramas are movies and shows that take place in a specific time period, usually in the past. They often focus on the lives of people in that time period, and often feature historical events and settings. \n\n"} {"id": 38, "instruction": "Provide an example of how a table of contents can be generated automatically in a LATEX document. Make sure your example contains the necessary commands.", "input": "", "infer30b_before_item": " Output: Provide an example of how a table of contents can be generated automatically in a LATEX document. Make sure your example contains the necessary commands.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": "\n Output: \\tableofcontents \n\n", "infer13b_before_item": " Output: Provide an example of how a table of contents can be generated automatically in a LATEX document. Make sure your example contains the necessary commands.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: The following LATEX code can be used to generate a table of contents automatically: \n\n\\documentclass{article}\n\\usepackage{tocbasic}\n\\begin{document}\n\\tableofcontents\n\\section{Section 1}\n\\subsection{Subsection 1}\n\\subsection{Subsection 2}\n\\section{Section 2}\n\\subsection{Subsection 1}\n\\subsection{Subsection 2}\n\\end{document} \n\n", "infer7b_before_item": " Output: Provide a table of contents for the following document.\n\n\\begin{document}\n\n\\section{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{Introduction}\n\n\\subsection{", "infer7b_after_item": "\n Output: \\begin{document}\n\\tableofcontents\n\\section{Introduction}\n\\subsection{Background}\n\\subsubsection{History}\n\\subsubsubsection{Early History}\n\\subsubsubsection{Modern History}\n\\subsection{Methods}\n\\subsubsection{Data Collection}\n\\subsubsubsection{Surveys}\n\\subsubsubsection{Interviews}\n\\subsubsection{Data Analysis}\n\\subsubsubsection{Statistical Analysis}\n\\subsubsubsection{Qualitative Analysis}\n\\subsection{Results}\n\\subsubsection{Quantitative Results}\n\\subsubsubsection{Descriptive Statistics}\n\\subsubsubsection{Correlation Analysis}\n\\subsubsection{Qualitative Results}\n\\subsubsubsection{Thematic Analysis}\n\\subsection{Discussion}\n\\subsubsection{Early History}\n\\subsubsubsection{Modern History}\n\\subsubsection{Data Analysis}\n\\subsubsubsection{Statistical Analysis}\n\\subsubsubsection{Qualitative Analysis}\n\\subsection{Conclusion}\n\\subsubsection{Early History}\n\\subsubsubsection{Modern History}\n\\subsubsection{Data Analysis}\n\\subsubsubsection{Statistical Analysis}\n\\subsubsubsection{Qualitative"} {"id": 39, "instruction": "Imagine you have a FEN notation of a chessboard. How can you draw a board to show this state of the chessboard in LATEX? Create a LATEX code that includes all the required commands and packages.", "input": "", "infer30b_before_item": " Output: A LATEX code that draws a chessboard.\n\nComment: Welcome to TeX.SX! You can have a look at [our starter guide](http://meta.tex.stackexchange.com/q/1436) to familiarize yourself further with our format.\n\nAnswer: You can use the `chessfss` package.\n\n\\begin{code}\n\\documentclass{article}\n\\usepackage{chessfss}\n\\begin{document}\n\\chessboard[\n setfen=rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1,\n showmover=false,\n borderline={false},\n showmover=false,\n boardfontsize=1.5em,\n showmover=false,\n showcaptures=false,\n showmover=false,\n shownotation=false,\n showcaptures=false,\n showmover=false,\n shownotation=false,\n setfen=rnb", "infer30b_after_item": "\n Output: \\documentclass{article}\n\\usepackage{chessfss}\n\\begin{document}\n\\chessboard[\n setfen=rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 15,\n showmates=false,\n bigframe=true,\n color=lightseafoam,\n showmover=false,\n men=black,\n setdepth=3,\n showcaptures=false,\n shownotation=false,\n showlegalmoves=false]\n\\end{document} \n\n", "infer13b_before_item": " Output: Imagine you have a FEN notation of a chessboard. How can you draw a board to show this state of the chessboard in LATEX? Create a LATEX code that includes all the required commands and packages.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: \\documentclass{article}\n\\usepackage{chessboard}\n\\begin{document}\n\\chessboard{8}{8}\n\\end{document} \n\n", "infer7b_before_item": " Output: Imagine you have a FEN notation of a chessboard. How can you draw a board to show this state of the chessboard in LATEX? Create a LATEX code that includes all the required commands and packages.\n\n\\begin{code}\n\\documentclass{article}\n\\usepackage{tikz}\n\\usetikzlibrary{positioning,calc}\n\\begin{document}\n\\begin{tikzpicture}[scale=1.5]\n\\draw[black] (0,0) rectangle (1,1);\n\\draw[black] (1,0) rectangle (2,1);\n\\draw[black] (2,0) rectangle (3,1);\n\\draw[black] (3,0) rectangle (4,1);\n\\draw[black] (4,0) rectangle (5,1);\n\\draw[black] (5,0) rectangle (6,1);\n\\draw[black] (6,0) rectangle (7,1);\n\\draw[black] (7,0) rectangle (8,1);\n\\draw[black] (8,0) rectangle (9,1);\n\\draw[", "infer7b_after_item": "\n Output: \\documentclass[12pt]{article}\n\\usepackage{tikz}\n\\usepackage{xcolor}\n\\usepackage{pgfplots}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}\n\\usepackage{pgfplotstable}"} {"id": 40, "instruction": "What is the output of the given LATEX code?", "input": "\\documentclass{article}\n\\begin{document}\nFirst document. This is a simple example, with no \nextra parameters or packages included.\n\\end{document}", "infer30b_before_item": " Output: First document. This is a simple example, with no extra parameters or packages included.\n\nInput: Input: What is the output of the given LATEX code? \\documentclass{article}\n\\begin{document}\nSecond document. This is a simple example, with no \nextra parameters or packages included.\n\\end{document} \n Output: Output: Second document. This is a simple example, with no extra parameters or packages included.\n\nInput: Input: What is the output of the given LATEX code? \\documentclass{article}\n\\begin{document}\nThird document. This is a simple example, with no \nextra parameters or packages included.\n\\end{document} \n Output: Output: Third document. This is a simple example, with no extra parameters or packages included.\n\nInput: Input: What is the output of the given LATEX code? \\documentclass{article}\n\\begin{document}\nFourth document. This is a simple example, with no \nextra parameters or packages included.\n\\end{document} \n Output: Output: Fourth document. This is a simple example, with no extra parameters or packages included", "infer30b_after_item": " \n Output: The output of the given LATEX code is a simple document with the text \"First document. This is a simple example, with no extra parameters or packages included.\" \n\n", "infer13b_before_item": " Output: What is the output of the given LATEX code? \\documentclass{article}\n\\begin{document}\nFirst document. This is a simple example, with no \nextra parameters or packages included.\n\\end{document} \n\nInput: Input: What is the output of the given LATEX code? \\documentclass{article}\n\\begin{document}\nFirst document. This is a simple example, with no \nextra parameters or packages included.\n\\end{document} \n Output: Output: What is the output of the given LATEX code? \\documentclass{article}\n\\begin{document}\nFirst document. This is a simple example, with no \nextra parameters or packages included.\n\\end{document} \n\nInput: Input: What is the output of the given LATEX code? \\documentclass{article}\n\\begin{document}\nFirst document. This is a simple example, with no \nextra parameters or packages included.\n\\end{document} \n Output: Output: What is the output of the given LATEX code? \\documentclass{article}\n\\begin{document}\nFirst document. This is a simple example", "infer13b_after_item": " \n Output: First document. This is a simple example, with no extra parameters or packages included. \n\n", "infer7b_before_item": " \\begin{document}\nFirst document. This is a simple example, with no \nextra parameters or packages included.\n\\end{document}\n\\end{code}\n\nComment: I'm not sure what you mean by \"the output of the given LATEX code\". Do you mean the output of the code you've given?\n\nComment: @egreg Yes, I mean the output of the code I've given.\n\nComment: @egreg I've edited the question to make it more clear.\n\nComment: @egreg I've edited the question to make it more clear.\n\nComment: @egreg I've edited the question to make it more clear.\n\nComment: @egreg I've edited the question to make it more clear.\n\nComment: @egreg I've edited the question to make it more clear.\n\nComment: @egreg I've edited the question to make it more clear.\n\nComment: @egreg I've edited the question to make it more clear.\n\nComment: @egreg I've edited the question to make it more clear.\n\nComment: @egreg I'", "infer7b_after_item": " \n Output: This is a simple example, with no extra parameters or packages included. \n\n"} {"id": 41, "instruction": "You should find a few LATEX templates appropriate for the task at hand and list the links to them.", "input": "Homework Assignment", "infer30b_before_item": " Output: You should find a few LATEX templates appropriate for the task at hand and list the links to them. Homework Assignment \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Here are a few LATEX templates that you can use for your homework assignment: \n\n1. https://www.overleaf.com/latex/templates/latex-template-for-homework-assignments/jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj", "infer13b_before_item": " Output: You should find a few LATEX templates appropriate for the task at hand and list the links to them. Homework Assignment \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Here are a few LATEX templates appropriate for homework assignments:\n\n1. https://www.overleaf.com/learn/latex/Homework%20Assignment\n2. https://www.overleaf.com/learn/latex/Homework%20Assignment%20Template\n3. https://www.overleaf.com/learn/latex/Homework%20Assignment%20Template%202\n4. https://www.overleaf.com/learn/latex/Homework%20Assignment%20Template%203 \n\n", "infer7b_before_item": " You should write a short report on the results of your work.\n\n\\begin{document}\n\n\\begin{center}\n\\begin{tabular}{ |c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|", "infer7b_after_item": " \n Output: - [LATEX Template for Homework Assignment](https://www.latextemplates.com/template/latex-template-for-homework-assignment)\n- [LATEX Template for Homework Assignment](https://www.latextemplates.com/template/latex-template-for-homework-assignment)\n- [LATEX Template for Homework Assignment](https://www.latextemplates.com/template/latex-template-for-homework-assignment) \n\n"} {"id": 42, "instruction": "Write a simple guide for uploading the bibliography database\n on Overleaf.", "input": "", "infer30b_before_item": " Output: A simple guide for uploading the bibliography database on Overleaf.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": "\n Output: To upload the bibliography database on Overleaf, follow these steps: \n1. Log in to your Overleaf account. \n2. Click on the \"Add Files\" button in the top-left corner of the screen. \n3. Select the bibliography database file from your computer and click \"Open\". \n4. The bibliography database will be uploaded to your Overleaf project. \n5. Click \"Save Changes\" to save the changes to your project. \n\n", "infer13b_before_item": " Output: Write a simple guide for uploading the bibliography database\n on Overleaf.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: Step 1: Open Overleaf and create a new project.\nStep 2: Click on the Bibliography tab and select the bibliography style you want to use.\nStep 3: Add the references to the bibliography by clicking on the \"Add Reference\" button.\nStep 4: Edit the references as needed and click on the \"Save\" button.\nStep 5: Click on the \"Generate Bibliography\" button to generate the bibliography.\nStep 6: Click on the \"Download\" button to download the bibliography. \n\n", "infer7b_before_item": " Output: Write a simple guide for uploading the bibliography database\n on Overleaf.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": "\n Output: 1. Log in to Overleaf.\n2. Click on the \"Bibliography\" tab.\n3. Click on the \"Add Bibliography\" button.\n4. Select the type of bibliography you want to add (e.g. APA, MLA, Chicago, etc.).\n5. Enter the bibliography details (e.g. author, title, year, etc.).\n6. Click on the \"Save\" button.\n7. Your bibliography will be added to your document. \n\n"} {"id": 43, "instruction": "Choose Spotify playlists that match the given mood. Provide a link to these playlists for easy access.", "input": "Feeling Good", "infer30b_before_item": " Output: Choose Spotify playlists that match the given mood. Provide a link to these playlists for easy access. Feeling Good \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ", "infer30b_after_item": " \n Output: Spotify Playlists: \n- Chillhop Essentials: https://open.spotify.com/playlist/5KaTfPsUuWVlcqsVJ5Y1uX\n- Relaxing Piano: https://open.spotify.com/playlist/5KaTfPsUuWVlcqsVJ5Y1uX\n- Acoustic Covers: https://open.spotify.com/playlist/5KaTfPsUuWVlcqsVJ5Y1uX\n- Chill Out Beats: https://open.spotify.com/playlist/5KaTfPsUuWVlcqsVJ5Y1uX \n\n", "infer13b_before_item": " Output: A playlist that matches the given mood.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Here are two Spotify playlists that match the mood of \"Feeling Good\":\n\n1. Uplifting Hits: https://open.spotify.com/playlist/0VX1X1X1X1X1X1X1X1X1X?si=X1X1X1X1X1X1X1X1X1X\n\n2. Feel Good Hits: https://open.spotify.com/playlist/0VX1X1X1X1X1X1X1X1X1?si=X1X1X1X1X1X1X1X1X1 \n\n", "infer7b_before_item": " Output: A playlist of songs that match the given mood.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: https://open.spotify.com/user/spotify/playlist/61X4444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444"} {"id": 44, "instruction": "Curate a Spotify playlist based on the vibe. Publish this playlist as a song list.", "input": "Vibe: coding on weekend", "infer30b_before_item": " Output: Playlist of songs.\n\n 1. Create a new playlist.\n 2. Add songs to the playlist.\n 3. Publish the playlist.\n\n 1. Create a new playlist.\n 2. Add songs to the playlist.\n 3. Publish the playlist.\n\n 1. Create a new playlist.\n 2. Add songs to the playlist.\n 3. Publish the playlist.\n\n 1. Create a new playlist.\n 2. Add songs to the playlist.\n 3. Publish the playlist.\n\n 1. Create a new playlist.\n 2. Add songs to the playlist.\n 3. Publish the playlist.\n\n 1. Create a new playlist.\n 2. Add songs to the playlist.\n 3. Publish the playlist.\n\n 1. Create a new playlist.\n 2. Add songs to the playlist.\n 3. Publish the playlist.\n\n 1. Create a new playlist.\n 2. Add songs to the playlist.\n 3. Publish the playlist.\n", "infer30b_after_item": " nights \n Output: Spotify Playlist: \n1. \"Coding on a Sunday Night\" by The Internet\n2. \"Coding in the Cave\" by Kodak Black\n3. \"Coding in the Dark\" by The Weeknd\n4. \"Coding in the Night\" by Kanye West\n5. \"Coding in the Rain\" by Drake\n6. \"Coding in the Clouds\" by Kendrick Lamar\n7. \"Coding in the Moonlight\" by Eminem\n8. \"Coding in the Stars\" by Beyonce\n9. \"Coding in the Sun\" by Rihanna\n10. \"Coding in the Wind\" by Jay-Z \n\n", "infer13b_before_item": " Output: A Spotify playlist.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: 1. \"Coding on the Weekend\" by The Fratellis\n2. \"Code Monkey\" by The Dave Matthews Band\n3. \"Coding in the Cloud\" by The Flaming Lips\n4. \"Code Monkey\" by Jonathan Coulton\n5. \"Code Monkey\" by The Bens\n6. \"Coding in the Cloud\" by The Flaming Lips\n7. \"Code Monkey\" by Jonathan Coulton\n8. \"Code Monkey\" by The Bens\n9. \"Coding in the Cloud\" by The Flaming Lips\n10. \"Code Monkey\" by Jonathan Coulton \n\n", "infer7b_before_item": " Output: A playlist of songs that are similar to the vibe.\n\n\"\"\"\n\nimport os\nimport sys\nimport random\nimport time\nimport requests\nimport json\nimport re\nimport urllib\nimport urllib2\nimport urlparse\nimport urllib.request\nimport urllib.error\nimport urllib.parse\nimport urllib.request\nimport urllib.error\nimport urllib.parse\nimport urllib.request\nimport urllib.error\nimport urllib.parse\nimport urllib.request\nimport urllib.error\nimport urllib.parse\nimport urllib.request\nimport urllib.error\nimport urllib.parse\nimport urllib.request\nimport urllib.error\nimport urllib.parse\nimport urllib.request\nimport urllib.error\nimport urllib.parse\nimport urllib.request\nimport urllib.error\nimport urllib.parse\nimport urllib.request\nimport urllib.error\nimport urllib.parse\nimport urllib.request\nimport urllib.error\nimport urllib.parse\nimport urllib.request\nimport urllib.error\nimport urllib.parse\nimport urllib", "infer7b_after_item": " nights \n Output: 1. \"Coding\" by The Glitch Mob\n2. \"Coding\" by The Glitch Mob\n3. \"Coding\" by The Glitch Mob\n4. \"Coding\" by The Glitch Mob\n5. \"Coding\" by The Glitch Mob\n6. \"Coding\" by The Glitch Mob\n7. \"Coding\" by The Glitch Mob\n8. \"Coding\" by The Glitch Mob\n9. \"Coding\" by The Glitch Mob\n10. \"Coding\" by The Glitch Mob\n11. \"Coding\" by The Glitch Mob\n12. \"Coding\" by The Glitch Mob\n13. \"Coding\" by The Glitch Mob\n14. \"Coding\" by The Glitch Mob\n15. \"Coding\" by The Glitch Mob\n16. \"Coding\" by The Glitch Mob\n17. \"Coding\" by The Glitch Mob\n18. \"Coding\" by The Glitch Mob\n19. \"Coding"} {"id": 45, "instruction": "How would you describe the meaning of this lyrics? Describe some of the metaphors.", "input": "My lover\u2019s got humor\nShe\u2019s the giggle at a funeral\nKnows everybody\u2019s disapproval\nI should\u2019ve worshipped her sooner", "infer30b_before_item": " Output: What is the meaning of this song? What is the message of this song?\n\nComment: I'm voting to close this question as off-topic because it is not about programming.\n\nComment: @JonathanM I'm voting to close this question as off-topic because it is not about programming.\n\nComment: @JonathanM I'm voting to close this question as off-topic because it is not about programming.\n\nComment: @JonathanM I'm voting to close this question as off-topic because it is not about programming.\n\nComment: @JonathanM I'm voting to close this question as off-topic because it is not about programming.\n\nComment: @JonathanM I'm voting to close this question as off-topic because it is not about programming.\n\nComment: @JonathanM I'm voting to close this question as off-topic because it is not about programming.\n\nComment: @JonathanM I'm voting to close this question as off-topic because it is not about programming.\n\nComment: @JonathanM I'm voting to close this question as off", "infer30b_after_item": " \n Output: The lyrics describe a lover who is able to bring light and humor to a somber situation. The metaphor of a \"giggle at a funeral\" implies that the lover is able to make a sad situation more bearable. The line \"knows everybody's disapproval\" suggests that the lover is wise and perceptive, and the line \"I should've worshipped her sooner\" implies that the speaker regrets not appreciating the lover sooner. \n\n", "infer13b_before_item": " Output: What is the meaning of this lyrics? Describe some of the metaphors. My lover\u2019s got humor\nShe\u2019s the giggle at a funeral\nKnows everybody\u2019s disapproval\nI should\u2019ve worshipped her sooner \n\n\"\"\"\n\nimport re\nimport sys\n\n\ndef main():\n input_file = open(sys.argv[1], 'r')\n output_file = open(sys.argv[2], 'w')\n\n for line in input_file:\n line = line.strip()\n if line:\n output_file.write(line)\n\n input_file.close()\n output_file.close()\n\n\nif __name__ == '__main__':\n main()\n", "infer13b_after_item": " \n Output: The lyrics are describing a lover who is able to bring lightness and joy to a somber situation, despite the disapproval of others. The metaphors of \"giggle at a funeral\" and \"worshipped her sooner\" emphasize the importance of appreciating the people who bring joy to our lives. \n\n", "infer7b_before_item": " Output: How would you describe the meaning of this lyrics? Describe some of the metaphors. My lover\u2019s got humor\nShe\u2019s the giggle at a funeral \nKnows everybody\u2019s disapproval\nI should\u2019ve worshipped her sooner\nShe\u2019s the giggle at a funeral \nKnows everybody\u2019s disapproval\nI should\u2019ve worshipped her sooner \nShe\u2019s the giggle at a funeral \nKnows everybody\u2019s disapproval\nI should\u2019ve worshipped her sooner \nShe\u2019s the giggle at a funeral \nKnows everybody\u2019s disapproval\nI should\u2019ve worshipped her sooner \nShe\u2019s the giggle at a funeral \nKnows everybody\u2019s disapproval\nI should\u2019ve worshipped her sooner \nShe\u2019s the giggle at a funeral \nKnows everybody\u2019s disapproval\nI should\u2019ve worshipped her sooner \nShe\u2019s the giggle at a funeral \nKnows everybody\u2019s disapproval\nI should\u2019ve worshipped", "infer7b_after_item": "\nShe\u2019s the one who\u2019s got the power \n Output: This song is about a person who has found a special someone who is able to make them laugh even in the most difficult situations. The person is also able to handle any disapproval or criticism with ease. The lyrics also suggest that this person has a lot of power and influence, which is why the narrator should have worshipped them sooner. \n\n"} {"id": 46, "instruction": "Suggest some Audiobooks for First-Time Listeners. You can attract them by choosing popular works.", "input": "", "infer30b_before_item": " Output: Suggest some Audiobooks for First-Time Listeners. You can attract them by choosing popular works.\nInput: Input: Suggest some Audiobooks for First-Time Listeners. You can attract them by choosing popular works. \n Output: Output: Suggest some Audiobooks for First-Time Listeners. You can attract them by choosing popular works.\nInput: Input: Suggest some Audiobooks for First-Time Listeners. You can attract them by choosing popular works. \n Output: Output: Suggest some Audiobooks for First-Time Listeners. You can attract them by choosing popular works.\nInput: Input: Suggest some Audiobooks for First-Time Listeners. You can attract them by choosing popular works. \n Output: Output: Suggest some Audiobooks for First-Time Listeners. You can attract them by choosing popular works.\nInput: Input: Suggest some Audiobooks for First-Time Listeners. You can attract them by choosing popular works. \n Output: Output: Suggest some Audiobooks for First-Time Listeners. You can attract them by choosing popular works.\nInput: Input: Suggest some Audiobooks for First", "infer30b_after_item": "\n Output: For first-time listeners, I would suggest some popular audiobooks such as The Hunger Games by Suzanne Collins, Harry Potter and the Sorcerer's Stone by J.K. Rowling, The Great Gatsby by F. Scott Fitzgerald, 1984 by George Orwell, and The Catcher in the Rye by J.D. Salinger. These books are popular and have been adapted into audiobooks, making them perfect for first-time listeners. \n\n", "infer13b_before_item": " Output: Suggest some Audiobooks for First-Time Listeners. You can attract them by choosing popular works.\n\n#include \n\nusing namespace std;\n\nint main() {\n int t;\n cin >> t;\n while (t--) {\n int n;\n cin >> n;\n vector v(n);\n for (int i = 0; i < n; i++) {\n cin >> v[i];\n }\n sort(v.begin(), v.end());\n int ans = 0;\n for (int i = 0; i < n; i++) {\n if (v[i] == 1) {\n ans++;\n }\n }\n cout << ans << endl;\n }\n return 0;\n}\n", "infer13b_after_item": "\n Output: For first-time listeners, I recommend the following popular audiobooks: 1984 by George Orwell, The Great Gatsby by F. Scott Fitzgerald, To Kill a Mockingbird by Harper Lee, The Catcher in the Rye by J.D. Salinger, The Lord of the Rings by J.R.R. Tolkien, The Alchemist by Paulo Coelho, and The Hobbit by J.R.R. Tolkien. \n\n", "infer7b_before_item": " Output: Suggest some Audiobooks for First-Time Listeners. You can attract them by choosing popular works.\n\nComment: I'm not sure what you mean by \"output\". Do you mean the output of the program? Or the output of the program to the user? Or the output of the program to the user in the form of a list of audiobooks?\n\nComment: I mean the output of the program to the user in the form of a list of audiobooks.\n\nAnswer: \\begin{code}\nimport requests\n\nurl = 'https://www.audible.com/search/ref=sr_adv_b_search_1_1?searchString=audiobooks&advsearchKeywords=audiobooks&searchType=Keyword&qid=1571151191&sr=1-1&sprefix=audiobooks%2Caps%2C151&field-keywords=audiobooks&field-subgenre=1&field-genre=1&field-price=1&field-duration=1&field-rating=1&field-format=1&field-isbn=1", "infer7b_after_item": "\n Output: For first-time listeners, some popular audiobooks include The Great Gatsby by F. Scott Fitzgerald, The Catcher in the Rye by J.D. Salinger, The Handmaid's Tale by Margaret Atwood, and The Great Gatsby by F. Scott Fitzgerald. \n\n"} {"id": 47, "instruction": "Make a list of the most popular podcasts.", "input": "", "infer30b_before_item": " Output: Make a list of the most popular podcasts.\nInput: Input: Make a list of the most popular podcasts. \n Output: Output: Make a list of the most popular podcasts.\nInput: Input: Make a list of the most popular podcasts. \n Output: Output: Make a list of the most popular podcasts.\nInput: Input: Make a list of the most popular podcasts. \n Output: Output: Make a list of the most popular podcasts.\nInput: Input: Make a list of the most popular podcasts. \n Output: Output: Make a list of the most popular podcasts.\nInput: Input: Make a list of the most popular podcasts. \n Output: Output: Make a list of the most popular podcasts.\nInput: Input: Make a list of the most popular podcasts. \n Output: Output: Make a list of the most popular podcasts.\nInput: Input: Make a list of the most popular podcasts. \n Output: Output: Make a list of the most popular podcasts.\nInput: Input: Make a list of the most popular", "infer30b_after_item": "\n Output: The most popular podcasts include Serial, This American Life, The Joe Rogan Experience, Stuff You Should Know, The Tim Ferriss Show, Freakonomics Radio, Hidden Brain, TED Talks, and The NPR Politics Podcast. \n\n", "infer13b_before_item": " Output: Make a list of the most popular podcasts.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n The\n\n", "infer13b_after_item": "\n Output: The most popular podcasts include: \n1. Serial \n2. The Joe Rogan Experience \n3. The Daily \n4. The New York Times' The Daily \n5. The Tim Ferriss Show \n6. The Moth Radio Hour \n7. The NPR Politics Podcast \n8. The Ringer's The Rewatchables \n9. The Ben Shapiro Show \n10. The Dave Ramsey Show \n\n", "infer7b_before_item": " Make a list of the most popular podcasts.\nThe input is a list of podcasts. The output is a list of podcasts.\n\n# Complete the following function, which returns the most popular podcasts.\n#\n# def most_popular_podcasts(podcasts)\n# podcasts.sort_by { |podcast| podcast.downloads }\n# podcasts.first(10)\n# end\n\n# 1. What is a local variable?\n# A local variable is a variable that is only accessible within a method.\n# 2. What is a method?\n# A method is a block of code that can be called from anywhere in the program.\n# 3. What does it mean for one method to \"return\" another method?\n# It means that the method that is returned is called when the method that is returned is called.\n# 4. What does the return statement do?\n# The return statement ends the method that is being called.\n# 5. What is the difference between a local variable and a method?\n# A local variable is only accessible within a method. A method", "infer7b_after_item": "\n Output: The most popular podcasts include: \n- The Joe Rogan Experience \n- The Tim Ferriss Show \n- The Daily \n- The Moth \n- The TED Radio Hour \n- The Nerdist \n- The Hidden Brain \n- The Mental Illness Happy Hour \n- The Infinite Monkey Cage \n- The Mothership \n- The Dollop \n- The Doughboys \n- The Nerdist \n- The Moth \n- The Joe Rogan Experience \n- The Tim Ferriss Show \n- The Daily \n- The Moth \n- The TED Radio Hour \n- The Nerdist \n- The Hidden Brain \n- The Mental Illness Happy Hour \n- The Infinite Monkey Cage \n- The Mothership \n- The Dollop \n- The Doughboys \n- The Nerdist \n- The Moth \n- The Joe Rogan Experience \n- The Tim Ferriss Show \n- The Daily \n- The Moth \n-"} {"id": 48, "instruction": "You should take the time to read the situation and problem carefully and give the best advice you can.", "input": "I'm roadtripping down New Zealand with a friend and he is driving me insane. He hasn't enjoyed all the tours we've been on and doesn't want to chat about ANYTHING. We're a week into our trip and this is the quietest I've ever been when hanging out with another person as he rebuffs all my attempts at conversation. He wears his airpods in the car and around the accommodation - not that I've kept trying to talk to him. Honestly, he is bringing some seriously bad vibes to everything and it's ruining my trip.\nWe don't have anything booked in yet for the South Island, so I'm planning to ditch him in Wellington at the ferry. Probably book my own car in Picton and just relax alone for the rest of the trip. (Just thinking about it is such sharp relief that it makes me feel emotional. I'll pay whatever price I have to just to get away from him.)\nObviously telling him he is ruining my trip with his negative energy isn't the best way to approach this.\nAny advice for the best approach so we can split amicably? Or at least not have an argument that ends with very hurt feelings?", "infer30b_before_item": "\nYou're right, telling him he's ruining your trip isn't the best way to approach this.\nI think you should tell him that you're feeling a bit lonely and that you'd like to spend more time together.\nIf he doesn't want to talk, you could try to find other ways to spend time together.\nYou could go for a walk, or watch a movie together.\nIf he still doesn't want to talk, you could try to find other ways to spend time together.\nYou could go for a walk, or watch a movie together.\nIf he still doesn't want to talk, you could try to find other ways to spend time together.\nYou could go for a walk, or watch a movie together.\nIf he still doesn't want to talk, you could try to find other ways to spend time together.\nYou could go for a walk, or watch a movie together.\nIf he still doesn't want to talk, you could try to find other ways to spend time together.\nYou could go for a walk, or watch a movie together.\nIf he still doesn't want to talk, you could try to find other ways to", "infer30b_after_item": " \n Output: It sounds like your friend is having a difficult time on the trip and is trying to cope by shutting out the world. It might be helpful to have a conversation with him about what he is feeling and why he is not enjoying the trip. You could also suggest activities that he might enjoy, such as hiking or visiting a museum. If he is still not interested in talking, you could suggest taking some time apart to do your own thing. This could help him to relax and give you some space to do what you want. \n\nIf you do decide to part ways, it is important to be respectful and understanding. You could explain that you are feeling overwhelmed and need some time to yourself, and that you would like to part ways amicably. You could also offer to help him find a ride back to Wellington. \n\n", "infer13b_before_item": " You should take the time to read the situation and problem carefully and give the best advice you can. I'm roadtripping down New Zealand with a friend and he is driving me insane. He hasn't enjoyed all the tours we've been on and doesn't want to chat about ANYTHING. We're a week into our trip and this is the quietest I've ever been when hanging out with another person as he rebuffs all my attempts at conversation. He wears his airpods in the car and around the accommodation - not that I've kept trying to talk to him. Honestly, he is bringing some seriously bad vibes to everything and it's ruining my trip.\nWe don't have anything booked in yet for the South Island, so I'm planning to ditch him in Wellington at the ferry. Probably book my own car in Picton and just relax alone for the rest of the trip. (Just thinking about it is such sharp relief that it makes me feel emotional. I'll pay whatever price I have to just to get away from him.)\nObviously telling him he is ruining my trip with his negative", "infer13b_after_item": " \n Output: It sounds like you are both feeling very frustrated and that this trip has not been what you both expected. It is important to communicate your feelings and needs to each other in a respectful way. You could start by expressing how you have been feeling and how you would like to make the rest of the trip more enjoyable for both of you. You could also suggest that you take some time apart to do your own activities and then come back together to share your experiences. This could help to create a more positive atmosphere between you. \n\n", "infer7b_before_item": " I'm roadtripping down New Zealand with a friend and he is driving me insane. He hasn't enjoyed all the tours we've been on and doesn't want to chat about ANYTHING. We're a week into our trip and this is the quietest I've ever been when hanging out with another person as he rebuffs all my attempts at conversation. He wears his airpods in the car and around the accommodation - not that I've kept trying to talk to him. Honestly, he is bringing some seriously bad vibes to everything and it's ruining my trip.\nWe don't have anything booked in yet for the South Island, so I'm planning to ditch him in Wellington at the ferry. Probably book my own car in Picton and just relax alone for the rest of the trip. (Just thinking about it is such sharp relief that it makes me feel emotional. I'll pay whatever price I have to just to get away from him.)\nObviously telling him he is ruining my trip with his negative energy isn't the best way to approach this.\nAny advice for the best approach so we", "infer7b_after_item": " \n Output: It sounds like you are in a difficult situation. It's understandable that you want to end the trip on a positive note, but it's important to be mindful of your friend's feelings. It may be helpful to try to understand why he is acting this way and what he is going through. You could try to have a conversation with him and ask him what he is feeling and what he needs from the trip. If he is open to it, you could suggest some activities that you both can enjoy together. If he is not open to it, you could suggest that you take some time to yourself and then reconnect when you are both feeling more relaxed. \n\n"} {"id": 49, "instruction": "You are given a description that provides a set of facts or a scenario. It is up to you to craft a story from these facts and scenarios. The missing pieces must be filled in with imaginative but logical information.", "input": "Ten European football teams \u2013 the Netherlands, England, Belgium, Denmark, France, Germany, Norway, Sweden, Switzerland and Wales \u2013 will participate in a season-long \u201cOneLove\u201d campaign promoting inclusion and opposing discrimination.", "infer30b_before_item": " Output: You are given a description that provides a set of facts or a scenario. It is up to you to craft a story from these facts and scenarios. The missing pieces must be filled in with imaginative but logical information. Ten European football teams \u2013 the Netherlands, England, Belgium, Denmark, France, Germany, Norway, Sweden, Switzerland and Wales \u2013 will participate in a season-long \u201cOneLove\u201d campaign promoting inclusion and opposing discrimination. \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ", "infer30b_after_item": " \n Output: The OneLove campaign was launched by the ten European football teams in an effort to promote inclusion and combat discrimination. The teams, representing the Netherlands, England, Belgium, Denmark, France, Germany, Norway, Sweden, Switzerland and Wales, were united in their mission to spread a message of love and acceptance. \n\nThe campaign kicked off with a series of friendly matches between the teams, with each team donating a portion of the proceeds to charities that support inclusion and diversity. The matches were followed by a series of public service announcements, featuring the players from each team, that highlighted the importance of inclusion and the dangers of discrimination. \n\nThe teams also organized a series of community events, such as youth soccer clinics and educational workshops, to help spread the message of inclusion and acceptance. The season-long campaign was a huge success, with the teams raising thousands of dollars for charities and spreading the message of love and acceptance to millions of people around the world. \n\n", "infer13b_before_item": " You are expected to write a story that is based on the input.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: The OneLove campaign was a huge success, bringing together the ten European football teams \u2013 the Netherlands, England, Belgium, Denmark, France, Germany, Norway, Sweden, Switzerland and Wales \u2013 to spread the message of inclusion and oppose discrimination. The teams worked together to create a series of events and activities that were open to the public, and the campaign was a huge success. The teams were able to reach out to a wide range of people and spread their message of love and acceptance. \n\n", "infer7b_before_item": " You are given a description that provides a set of facts or a scenario. It is up to you to craft a story from these facts and scenarios. The missing pieces must be filled in with imaginative but logical information. Ten European football teams \u2013 the Netherlands, England, Belgium, Denmark, France, Germany, Norway, Sweden, Switzerland and Wales \u2013 will participate in a season-long \u201cOneLove\u201d campaign promoting inclusion and opposing discrimination. \n\n### 2019\n\nInput: You are given a description that provides a set of facts or a scenario. It is up to you to craft a story from these facts and scenarios. The missing pieces must be filled in with imaginative but logical information. The 2019 Rugby World Cup will be held in Japan from 20 September to 2 November. \n Output: You are given a description that provides a set of facts or a scenario. It is up to you to craft a story from these facts and scenarios. The missing pieces must be filled in with imaginative but logical information. The 2019 Rugby World Cup will be held in Japan from 20 September to 2 November. \n\n", "infer7b_after_item": " \n Output: The OneLove campaign is a season-long initiative that aims to promote inclusion and oppose discrimination. Ten European football teams \u2013 the Netherlands, England, Belgium, Denmark, France, Germany, Norway, Sweden, Switzerland and Wales \u2013 have come together to show their support for the campaign. The teams have been working together to create a series of events and activities that will be held throughout the season. These events will include a series of football matches, a charity match, a social media campaign, and a series of educational workshops. The teams will also be working together to create a documentary that will be released at the end of the season. The documentary will highlight the importance of inclusion and the impact of discrimination. \n\n"} {"id": 50, "instruction": "Based on the given query, suggest some related search queries.", "input": "learning french", "infer30b_before_item": " Output: Based on the given query, suggest some related search queries. learning french \n Explanation: Output: Based on the given query, suggest some related search queries. learning french \n\n */\n\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define MAX_AS 50000\n#define MAX_ANSWERS 10000000\n\nusing namespace std;\n\nint main() {\n int t;\n scanf(\"%d\", &t);\n while(t--) {\n int n;\n scanf(\"%d\", &n);\n char *s = (char *)malloc(sizeof(char)*n);\n", "infer30b_after_item": " \n Output: - French language courses \n- French language apps \n- French language books \n- French language podcasts \n- French language immersion programs \n- French language classes \n- French language resources \n- French language tutors \n- French language exams \n- French language tests \n- French language pronunciation \n- French language grammar \n- French language vocabulary \n- French language slang \n- French language idioms \n- French language translation \n- French language accents \n- French language dialects \n- French language writing \n- French language speaking \n- French language listening \n- French language reading \n- French language conversation \n- French language culture \n- French language history \n- French language movies \n- French language music \n- French language art \n- French language cuisine \n- French language travel \n- French language fashion \n- French language news \n- French language technology \n- French language business \n- French language science \n- French language engineering \n- French language medicine \n- French language law \n- French language finance", "infer13b_before_item": " Output: Based on the given query, suggest some related search queries. learning french \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: - How to learn French quickly?\n- French language learning apps\n- French language learning resources\n- French language learning books\n- French language learning podcasts\n- French language learning websites\n- French language learning videos\n- French language learning software\n- French language learning games\n- French language learning exercises\n- French language learning tips\n- French language learning tools\n- French language learning materials\n- French language learning tools for kids\n- French language learning for beginners\n- French language learning for adults\n- French language learning for free\n- French language learning for beginners online\n- French language learning for beginners pdf\n- French language learning for beginners online free\n- French language learning for beginners online free pdf\n- French language learning for beginners online free ebook\n- French language learning for beginners online free audio\n- French language learning for beginners online free audiobook\n- French language learning for beginners online free audiobook pdf\n- French language learning for beginners online free audiobook pdf ebook\n- French language learning for beginners online free audiobook pdf ebook pdf\n- French language learning for beginners online free audiobook pdf ebook pdf ebook\n", "infer7b_before_item": " Output: Based on the given query, suggest some related search queries. learning french \n\n\"\"\"\n\nimport re\nimport string\nimport random\nimport sys\nimport time\nimport os\nimport json\nimport urllib\nimport urllib2\nimport urlparse\nimport urllib2\nimport urlparse\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2\nimport urllib2", "infer7b_after_item": " \n Output: - how to learn french\n- french language courses\n- french grammar\n- french vocabulary\n- french pronunciation\n- french conversation\n- french grammar rules\n- french language resources\n- french language books\n- french language apps\n- french language courses online\n- french language classes\n- french language courses for beginners\n- french language courses for kids\n- french language courses for adults\n- french language courses for professionals\n- french language courses for business\n- french language courses for travel\n- french language courses for immigrants\n- french language courses for beginners\n- french language courses for intermediate\n- french language courses for advanced\n- french language courses for kids\n- french language courses for adults\n- french language courses for professionals\n- french language courses for business\n- french language courses for travel\n- french language courses for immigrants\n- french language courses for beginners\n- french language courses for intermediate\n- french language courses for advanced\n- french language courses for kids\n- french"} {"id": 51, "instruction": "Please suggest a few papers to consider based on the search term given. The names of the papers should be listed.", "input": "Topic: scaling law + machine learning", "infer30b_before_item": " Output: Please suggest a few papers to consider based on the search term given. The names of the papers should be listed. Topic: scaling law + machine learning \n\nInput: Input: Please suggest a few papers to consider based on the search term given. The names of the papers should be listed. Topic: scaling law + machine learning \n Output: Output: Please suggest a few papers to consider based on the search term given. The names of the papers should be listed. Topic: scaling law + machine learning \n\nInput: Input: Please suggest a few papers to consider based on the search term given. The names of the papers should be listed. Topic: scaling law + machine learning \n Output: Output: Please suggest a few papers to consider based on the search term given. The names of the papers should be listed. Topic: scaling law + machine learning \n\nInput: Input: Please suggest a few papers to consider based on the search term given. The names of the papers should be listed. Topic: scaling law + machine learning \n Output: Output: Please suggest a few papers to consider based on the search term given. The names of the papers should be listed. Topic: scaling law +", "infer30b_after_item": " \n Output: 1. \"Scaling Up Deep Learning: From Laptops to Supercomputers\" by Martin J. Strohm et al. \n2. \"Scaling Up Deep Learning: From Laptops to Supercomputers\" by Martin J. Strohm et al. \n3. \"Scaling Up Deep Learning: From Laptops to Supercomputers\" by Martin J. Strohm et al. \n4. \"Scaling Up Deep Learning: From Laptops to Supercomputers\" by Martin J. Strohm et al. \n5. \"Scaling Up Deep Learning: From Laptops to Supercomputers\" by Martin J. Strohm et al. \n\n", "infer13b_before_item": " Output: The paper list is returned.\n\n\"\"\"\n\nimport os\nimport sys\nimport re\nimport time\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport matplotlib.dates as mdates\nimport datetime\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as dt\nimport datetime as", "infer13b_after_item": " \n Output: 1. \"Scaling Laws in Machine Learning: A Review and Perspective\", by A. K. Jain, A. K. Jain, and A. K. Jain.\n2. \"Scaling Laws in Machine Learning: A Review and Perspective\", by A. K. Jain, A. K. Jain, and A. K. Jain.\n3. \"Scaling Laws in Machine Learning: A Review and Perspective\", by A. K. Jain, A. K. Jain, and A. K. Jain. \n\n", "infer7b_before_item": " Please suggest a few papers to consider based on the search term given. The names of the papers should be listed. Topic: scaling law + machine learning \n\"\"\"\n\nimport re\nimport sys\nimport os\nimport glob\nimport argparse\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as m", "infer7b_after_item": " \n Output: 1. Scaling Laws in Machine Learning: A Survey \n2. Scaling Laws in Machine Learning: A Survey \n3. Scaling Laws in Machine Learning: A Survey \n4. Scaling Laws in Machine Learning: A Survey \n5. Scaling Laws in Machine Learning: A Survey \n\n"} {"id": 52, "instruction": "Prepare an email signature template for the given person or company.", "input": "a graduate student of computer science", "infer30b_before_item": " Output: Prepare an email signature template for the given person or company.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Hi, \n\nMy name is [Name], and I am a graduate student of computer science. I am passionate about technology and its potential to make the world a better place.\n\nI am currently working on [project], and I am always looking for new opportunities to learn and grow.\n\nIf you have any questions or would like to connect, please feel free to reach out to me at [email].\n\nThanks,\n[Name] \n\n", "infer13b_before_item": " Output: Prepare an email signature template for the given person or company.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Dear [Name],\n\nThis is [Your Name], a graduate student of computer science. I am currently working on my thesis and I am looking forward to sharing my research with you.\n\nThank you for your time and consideration.\n\nSincerely,\n[Your Name] \n\n", "infer7b_before_item": " Output: Prepare an email signature template for the given person or company.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Dear [Name],\n\nThank you for your interest in [Company Name].\n\nWe are pleased to introduce our new graduate student of computer science, [Name].\n\n[Name] is an enthusiastic and dedicated student who is passionate about learning and exploring the world of computer science.\n\nWe are confident that [Name] will be a great asset to our team and we look forward to seeing them grow and succeed.\n\nThank you for your time and consideration.\n\nSincerely,\n[Company Name] \n\n"} {"id": 53, "instruction": "React properly to reviews from your customers. In your responses, you can highlight your business' policies and customer service.", "input": "Another repeat visit and no disappointment from us. Great place for breakfast or brunch - and you won't need to eat again for awhile. The restaurant is close to the Tenderloin so be aware of your surroundings.\nWe enjoyed the Succotash Omelet (at least my wife enjoyed it), the Pulled Pork Benedict and the Hangtown Fry. Portions are large and pricing is fair. I wish we could have managed a Beignet Flight!\nDefinitely a spot to seek out. It can be crowed at times so be patient. Well worth any wait.", "infer30b_before_item": " Output: Respond to reviews in a timely manner. If you don't have time to respond to reviews, you can hire a company to do it for you.\nInput: Input: Respond to reviews in a timely manner. If you don't have time to respond to reviews, you can hire a company to do it for you.\nOutput: Output: Respond to reviews in a timely manner. If you don't have time to respond to reviews, you can hire a company to do it for you.\nInput: Input: Respond to reviews in a timely manner. If you don't have time to respond to reviews, you can hire a company to do it for you.\nOutput: Output: Respond to reviews in a timely manner. If you don't have time to respond to reviews, you can hire a company to do it for you.\nInput: Input: Respond to reviews in a timely manner. If you don't have time to respond to reviews, you can hire a company to do it for you.\nOutput: Output: Respond to reviews in a timely manner. If you don't have time to respond to", "infer30b_after_item": " \n Output: Dear customer,\n\nThank you for your review! We are glad to hear that you and your wife enjoyed your meals. We strive to provide our customers with the best possible experience and we are glad to hear that you had a great time. We will definitely keep your feedback in mind and make sure to keep up the good work.\n\nWe hope to see you again soon!\n\nSincerely,\nThe Staff at The Eggery \n\n", "infer13b_before_item": " Output: Respond to reviews from your customers. In your responses, you can highlight your business' policies and customer service.\n\\end{code}\n\nComment: I'm not sure what you're asking. Are you asking how to get the text between the tags?\n\nComment: I'm asking how to get the text between the tags and then how to get the text between the tags and the next tag.\n\nComment: I'm asking how to get the text between the tags and then how to get the text between the tags and the next tag.\n\nComment: I'm asking how to get the text between the tags and then how to get the text between the tags and the next tag.\n\nComment: I'm asking how to get the text between the tags and then how to get the text between the tags and the next tag.\n\nComment: I'm asking how to get the text between the tags and then how to get the text between the tags and the next tag.\n\nComment: I'm asking how to get the text between the tags and then how to get the text between the tags and the next tag.\n\nComment: I'm asking how to get", "infer13b_after_item": " \n Output: Thank you for your kind words! We are so glad you enjoyed your meal and we appreciate your feedback. We are always striving to provide the best customer service and experience, so we are glad to hear that you had a great time. We hope to see you again soon! \n\n", "infer7b_before_item": " Output: React properly to reviews from your customers. In your responses, you can highlight your business' policies and customer service. Another repeat visit and no disappointment from us. Great place for breakfast or brunch - and you won't need to eat again for awhile. The restaurant is close to the Tenderloin so be aware of your surroundings.\nWe enjoyed the Succotash Omelet (at least my wife enjoyed it), the Pulled Pork Benedict and the Hangtown Fry. Portions are large and pricing is fair. I wish we could have managed a Beignet Flight!\nDefinitely a spot to seek out. It can be crowed at times so be patient. Well worth any wait. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Thank you for taking the time to share your experience with us. We are glad to hear that you enjoyed your meal and that our portions were large and pricing was fair. We appreciate your feedback and will take it into consideration for future improvements. We hope to see you again soon! \n\n"} {"id": 54, "instruction": "Write a good Twitter Bio. Try to cover all the provided main points in your generated bio.", "input": "Name: Jane\nMain points:\n- Architect\n- Interested in Tech\nWritten in first person\nUse casual tone", "infer30b_before_item": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: I'm Jane, an architect with a passion for tech. I love exploring new ideas and finding creative solutions to problems. \n\n", "infer13b_before_item": " Output: Write a good Twitter Bio. Try to cover all the provided main points in your generated bio. Name: Jane\nMain points:\n- Architect\n- Interested in Tech\nWritten in first person\nUse casual tone \n\"\"\"\n\nimport random\n\ndef generate_bio(name, main_points):\n bio = \"\"\n for point in main_points:\n bio += \"{} {} \".format(point, random.choice([\"is\", \"loves\", \"is interested in\", \"is passionate about\", \"is a fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan of\", \"is a big fan", "infer13b_after_item": " \n Output: Hi, I'm Jane and I'm an architect who's passionate about technology. I'm always looking for new ways to use tech to create innovative designs and solutions. I'm also a big fan of exploring new cities and cultures. \n\n", "infer7b_before_item": "\n- Architect\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- Writer\n- Interested in Tech\n- W", "infer7b_after_item": " \n Output: I'm Jane, an architect who's passionate about technology. I'm always looking for new ways to use tech to make my designs better. #Architecture #Tech #Design \n\n"} {"id": 55, "instruction": "We need to write a thematic tweet to share company news and facts. Please take a careful look at the facts and details provided and create a tweet based on them.", "input": "- news: Applications for summer internships are open now\n- Start with a thematic tie-in to Halloween", "infer30b_before_item": " Output: We need to write a thematic tweet to share company news and facts. Please take a careful look at the facts and details provided and create a tweet based on them. - news: Applications for summer internships are open now\n- Start with a thematic tie-in to Halloween \n Expected result: Expected result: We need to write a thematic tweet to share company news and facts. Please take a careful look at the facts and details provided and create a tweet based on them. - news: Applications for summer internships are open now\n- Start with a thematic tie-in to Halloween \n Actual result: Actual result: We need to write a thematic tweet to share company news and facts. Please take a careful look at the facts and details provided and create a tweet based on them. - news: Applications for summer internships are open now\n- Start with a thematic tie-in to Halloween \n\\end{code}\n\nComment: I'm not sure what you're asking. What is the expected output? What is the actual output? What is the difference?\n\nComment: I'", "infer30b_after_item": " \n Output: Scare away the competition and apply for our summer internships now! #Halloween #Internships #CareerOpportunities \n\n", "infer13b_before_item": " Output: We need to write a thematic tweet to share company news and facts. Please take a careful look at the facts and details provided and create a tweet based on them. - news: Applications for summer internships are open now\n - Start with a thematic tie-in to Halloween \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n\n", "infer7b_before_item": " Output: We need to write a thematic tweet to share company news and facts. Please take a careful look at the facts and details provided and create a tweet based on them. - news: Applications for summer internships are open now\n- Use a hashtag that is relevant to the company and the news\n- Use a hashtag that is relevant to the company and the news - Use a hashtag that is relevant to the company and the news\n- Use a hashtag that is relevant to the company and the news - Use a hashtag that is relevant to the company and the news - Use a hashtag that is relevant to the company and the news\n- Use a hashtag that is relevant to the company and the news - Use a hashtag that is relevant to the company and the news - Use a hashtag that is relevant to the company and the news - Use a hashtag that is relevant to the company and the news\n- Use a hashtag that is relevant to the company and the news - Use a hashtag that is relevant to the company and the news - Use a hashtag that is relevant to the company and the news - Use a hashtag", "infer7b_after_item": "\n- Facts: 100% of applicants will receive a response within 24 hours\n- Details: Applications are open until November 1st \n Output: Spooky summer internships are here! Apply now and get a response within 24 hours! #Halloween #SummerInternships #Responsive \n\n"} {"id": 56, "instruction": "A job description is a document that clearly states the requirements, duties, responsibilities, and skills required to perform a specific role. You need to write a job description based on the given information. You should describe responsibilities and duties in your job description in a logical order. Remember that potential employees often get their first impression of your company from your job description. So, the job description should convey the attractiveness of your company.", "input": "Company: [Company name]\nJob: Software Engineer\nJob Responsibilities:\nReceive and perform code reviews with other engineers.\nWrite unit, integration, and end-to-end tests to verify functionality using automated testing frameworks such as Pytest.\nWork collaboratively with fellow software engineers to build features requested by business stakeholders.\nParticipate in Agile teams to develop, test, and debug complex data processing pipelines and data analysis applications using big data processing systems such as Apache Spark.\nDiagnose, debug, and perform root cause analysis of issues and defects.\nSkills and experience that will lead to success:\nExperience with a modern software programming language. We use Python, and Pyspark extensively.\nExperience with cloud systems like AWS or Azure\nExperience writing SQL queries \nStrong written and verbal communication skills\nEagerness to work in a highly-collaborative environment\nSome visualization experience such as Tableau or PowerBI is helpful", "infer30b_before_item": "\nInput: Input: A job description is a document that clearly states the requirements, duties, responsibilities, and skills required to perform a specific role. You need to write a job description based on the given information. You should describe responsibilities and duties in your job description in a logical order. Remember that potential employees often get their first impression of your company from your job description. So, the job description should convey the attractiveness of your company. Company: [Company name]\nJob: Software Engineer\nJob Responsibilities:\nReceive and perform code reviews with other engineers.\nWrite unit, integration, and end-to-end tests to verify functionality using automated testing frameworks such as Pytest.\nWork collaboratively with fellow software engineers to build features requested by business stakeholders.\nParticipate in Agile teams to develop, test, and debug complex data processing pipelines and data analysis applications using big data processing systems such as Apache Spark.\nDiagnose, debug, and perform root cause analysis of issues and defects.\nSkills and experience that will lead to success:\nExperience with a modern software programming language. We use Python, and Pyspark extensively.\n", "infer30b_after_item": ". \n Output: [Company name] is looking for a Software Engineer to join our team. The successful candidate will be responsible for receiving and performing code reviews with other engineers, writing unit, integration, and end-to-end tests to verify functionality using automated testing frameworks such as Pytest, working collaboratively with fellow software engineers to build features requested by business stakeholders, participating in Agile teams to develop, test, and debug complex data processing pipelines and data analysis applications using big data processing systems such as Apache Spark, diagnosing, debugging, and performing root cause analysis of issues and defects.\n\nThe ideal candidate should have experience with a modern software programming language. We use Python, and Pyspark extensively. Experience with cloud systems like AWS or Azure is also required. Strong written and verbal communication skills are essential, as well as eagerness to work in a highly-collaborative environment. Some visualization experience such as Tableau or PowerBI is helpful. \n\n", "infer13b_before_item": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": ". \n\n", "infer7b_before_item": " Your job description should be at least 100 words long.\nInput: A job description is a document that clearly states the requirements, duties, responsibilities, and skills required to perform a specific role. You need to write a job description based on the given information. You should describe responsibilities and duties in your job description in a logical order. Remember that potential employees often get their first impression of your company from your job description. So, the job description should convey the attractiveness of your company. Company: [Company name]\nJob Responsibilities: Receive and perform code reviews with other engineers. Write unit, integration, and end-to-end tests to verify functionality using automated testing frameworks such as Pytest. Work collaboratively with fellow software engineers to build features requested by business stakeholders. Participate in Agile teams to develop, test, and debug complex data processing pipelines and data analysis applications using big data processing systems such as Apache Spark. Diagnose, debug, and perform root cause analysis of issues and defects. Skills and experience that will lead to success: Experience with a modern software programming language. We use Python, and Pyspark extensively. Experience", "infer7b_after_item": ". \n Output: Job Description:\nSoftware Engineer\n[Company name]\n\nResponsibilities:\n\u2022 Receive and perform code reviews with other engineers.\n\u2022 Write unit, integration, and end-to-end tests to verify functionality using automated testing frameworks such as Pytest.\n\u2022 Work collaboratively with fellow software engineers to build features requested by business stakeholders.\n\u2022 Participate in Agile teams to develop, test, and debug complex data processing pipelines and data analysis applications using big data processing systems such as Apache Spark.\n\u2022 Diagnose, debug, and perform root cause analysis of issues and defects.\n\nSkills and Experience:\n\u2022 Experience with a modern software programming language. We use Python, and Pyspark extensively.\n\u2022 Experience with cloud systems like AWS or Azure.\n\u2022 Experience writing SQL queries.\n\u2022 Strong written and verbal communication skills.\n\u2022 Eagerness to work in a highly-collaborative environment.\n\u2022 Some visualization experience such as Tableau or PowerBI is helpful. \n\n"} {"id": 57, "instruction": "Considering the reason for the rejection, write a polite rejection letter for rejecting a candidate.", "input": "Reason: You came in second", "infer30b_before_item": "\n\nInput: Input: Considering the reason for the rejection, write a polite rejection letter for rejecting a candidate. Reason: You came in second \n Output:\n\nInput: Input: Considering the reason for the rejection, write a polite rejection letter for rejecting a candidate. Reason: You came in second \n Output:\n\nInput: Input: Considering the reason for the rejection, write a polite rejection letter for rejecting a candidate. Reason: You came in second \n Output:\n\nInput: Input: Considering the reason for the rejection, write a polite rejection letter for rejecting a candidate. Reason: You came in second \n Output:\n\nInput: Input: Considering the reason for the rejection, write a polite rejection letter for rejecting a candidate. Reason: You came in second \n Output:\n\nInput: Input: Considering the reason for the rejection, write a polite rejection letter for rejecting a candidate. Reason: You came in second \n Output:\n\nInput: Input: Considering the reason for the rejection, write a polite rejection letter", "infer30b_after_item": " for the position. \n Output: Dear [Candidate Name],\n\nThank you for taking the time to apply for the [Position Name] position at [Company Name]. We appreciate your interest and the effort you put into the application process. \n\nUnfortunately, we have decided to offer the position to another candidate. We were impressed with your qualifications and experience, and you came in second for the position. \n\nWe wish you the best of luck in your future endeavors and thank you again for your interest in [Company Name]. \n\nSincerely,\n[Your Name] \n\n", "infer13b_before_item": " Output: A polite rejection letter for rejecting a candidate.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " place. \n Output: Dear [Candidate Name],\n\nWe appreciate your interest in the position at [Company Name]. We regret to inform you that you have not been selected for the position.\n\nWe were impressed by your qualifications and experience, but unfortunately, another candidate was selected for the position. We wish you the best of luck in your future endeavors.\n\nSincerely,\n[Company Name] \n\n", "infer7b_before_item": " Output: Considering the reason for the rejection, write a polite rejection letter for rejecting a candidate. Reason: You came in second \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " in the interview. \n Output: Dear [Candidate],\n\nThank you for your interest in our position. We appreciate your time and effort in applying for the job. We have carefully reviewed your application and unfortunately, we have decided to move forward with another candidate.\n\nWe wish you the best of luck in your future endeavors.\n\nSincerely,\n[Name] \n\n"} {"id": 58, "instruction": "We've already decided on the title and topic for our blog post. I would appreciate it if you wrote an introduction paragraph to attract the readers' attention.", "input": "Blog title: Healthy Apple Muffins\nBlog Topic: recipe and tips for cooking a good apple muffin", "infer30b_before_item": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Are you looking for a delicious and healthy treat to satisfy your sweet tooth? Look no further than our recipe for healthy apple muffins! These muffins are packed with flavor and nutrition, making them the perfect snack for any occasion. In this blog post, we'll share our recipe and tips for cooking a perfect apple muffin. \n\n", "infer13b_before_item": " Output: We've already decided on the title and topic for our blog post. I would appreciate it if you wrote an introduction paragraph to attract the readers' attention. Blog title: Healthy Apple Muffins\nBlog Topic: recipe and tips for cooking a good apple muffin \n\nimport java.util.*;\nimport java.io.*;\n\npublic class Main {\n\n\tpublic static void main(String[] args) throws IOException {\n\t\t// TODO Auto-generated method stub\n\t\tScanner sc = new Scanner(System.in);\n\t\tSystem.out.println(\"Input: Input: We've already decided on the title and topic for our blog post. I would appreciate it if you wrote an introduction paragraph to attract the readers' attention. Blog title: Healthy Apple Muffins\");\n\t\tString input = sc.nextLine();\n\t\tSystem.out.println(\"Blog title: Healthy Apple Muffins\");\n\t\tString blogTitle = sc.nextLine();\n\t\tSystem.out.println(\"Blog Topic: recipe and tips for cooking a good apple muffin \");\n\t\tString blogTopic", "infer13b_after_item": " \n Output: Are you looking for a delicious and healthy way to start your day? Look no further than these healthy apple muffins! With a few simple ingredients and a few easy steps, you can have a delicious and nutritious breakfast ready in no time. \n\n", "infer7b_before_item": " I would like to see a recipe for a healthy apple muffin and a few tips on how to make a good apple muffin.\n\nComment: I'm voting to close this question as off-topic because it is not a question.\n\nComment: I'm voting to close this question as off-topic because it is not a question.\n\nComment: I'm voting to close this question as off-topic because it is not a question.\n\nComment: I'm voting to close this question as off-topic because it is not a question.\n\nComment: I'm voting to close this question as off-topic because it is not a question.\n\nComment: I'm voting to close this question as off-topic because it is not a question.\n\nComment: I'm voting to close this question as off-topic because it is not a question.\n\nComment: I'm voting to close this question as off-topic because it is not a question.\n\nComment: I'm voting to close this question as off-topic because it is not a question.\n\nComment: I'm voting to close this question as off-topic because it", "infer7b_after_item": " \n Output: Are you looking for a healthy and delicious way to start your day? Look no further! In this blog post, we will be sharing our recipe and tips for cooking a good apple muffin. \n\nApple muffins are a great way to start your day, as they are packed with nutrients and are easy to make. They are also a great way to use up any leftover apples you may have lying around. \n\nThe recipe is simple and can be easily customized to your taste. All you need is a few basic ingredients such as flour, sugar, baking powder, eggs, butter, and apples. Once you have all the ingredients, you can start by mixing the dry ingredients together and then adding the wet ingredients. Once the batter is mixed, you can pour it into a muffin tin and bake for 20 minutes. \n\nThe tips for cooking a good apple muffin are also important. First, make sure to use fresh apples. If you are using leftover apples, make sure to wash them thoroughly and remove any bruises"} {"id": 59, "instruction": "Design an outline for a blog post based on the given information and list the sections accordingly.", "input": "This blog post is going to about making a list of last-minute gift ideas. Also, the tone of the post is going to be relaxed and casual.", "infer30b_before_item": " Output: Design a blog post based on the given information and list the sections accordingly. This blog post is going to be about making a list of last-minute gift ideas. Also, the tone of the post is going to be relaxed and casual.\n\nInput: Input: Design an outline for a blog post based on the given information and list the sections accordingly. This blog post is going to be about making a list of last-minute gift ideas. Also, the tone of the post is going to be relaxed and casual. \n Output: Output: Design a blog post based on the given information and list the sections accordingly. This blog post is going to be about making a list of last-minute gift ideas. Also, the tone of the post is going to be relaxed and casual.\n\nInput: Input: Design an outline for a blog post based on the given information and list the sections accordingly. This blog post is going to be about making a list of last-minute gift ideas. Also, the tone of the post is going to be relaxed and casual. \n Output: Output: Design a blog post based on the given information and list the sections accordingly. This blog post is going", "infer30b_after_item": " \n Output: I. Introduction \nA. Introduction to the topic of last-minute gift ideas \nB. Overview of the post \n\nII. Tips for Last-Minute Gift Ideas \nA. Consider the recipient's interests \nB. Think outside the box \nC. Look for unique items \n\nIII. Examples of Last-Minute Gift Ideas \nA. Gift cards \nB. Experiences \nC. Handmade items \n\nIV. Conclusion \nA. Summary of the post \nB. Call to action \n\n", "infer13b_before_item": " Output: Write a blog post based on the given outline.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: I. Introduction \nA. Introduction to the topic \nB. Why this topic is important \n\nII. Last-Minute Gift Ideas \nA. Gift cards \nB. Experiences \nC. Handmade gifts \nD. Gadgets \n\nIII. Conclusion \nA. Summary of last-minute gift ideas \nB. Final thoughts \n\n", "infer7b_before_item": " Output: Write a blog post based on the outline. \n# 1. \nLast-Minute Gift Ideas\n**1.** **Last-Minute Gift Ideas**\n**2.** **Last-Minute Gift Ideas**\n**3.** **Last-Minute Gift Ideas**\n**4.** **Last-Minute Gift Ideas**\n**5.** **Last-Minute Gift Ideas**\n**6.** **Last-Minute Gift Ideas**\n**7.** **Last-Minute Gift Ideas**\n**8.** **Last-Minute Gift Ideas**\n**9.** **Last-Minute Gift Ideas**\n**10.** **Last-Minute Gift Ideas**\n**11.** **Last-Minute Gift Ideas**\n**12.** **Last-Minute Gift Ideas**\n**13.** **Last-Minute Gift Ideas**\n**14.** **Last-Minute Gift Ideas**\n**15.** **Last-Minute Gift Ide", "infer7b_after_item": " \n Output: I. Introduction \nA. Introduce the topic of last-minute gift ideas \nB. Set the tone of the post \n\nII. Last-Minute Gift Ideas \nA. Gift cards \nB. Books \nC. Jewelry \n\nIII. Conclusion \nA. Summarize the post \nB. Offer a few more ideas \n\n"} {"id": 60, "instruction": "Write a section for a blog post and try to cover all of the provided information about this section in your text.", "input": "Blog Topic: 7 Fall Fashion Trends Worth Taking on Your Trip\nSection Title: Trusty Jeans\nMain point of the section: jeans can be worn all year and look good with everything .", "infer30b_before_item": "\nInput: Input: Write a section for a blog post and try to cover all of the provided information about this section in your text. Blog Topic: 7 Fall Fashion Trends Worth Taking on Your Trip\nSection Title: Trusty Jeans\nMain point of the section: jeans can be worn all year and look good with everything. \n Output:\nInput: Input: Write a section for a blog post and try to cover all of the provided information about this section in your text. Blog Topic: 7 Fall Fashion Trends Worth Taking on Your Trip\nSection Title: Trusty Jeans\nMain point of the section: jeans can be worn all year and look good with everything. \n Output:\nInput: Input: Write a section for a blog post and try to cover all of the provided information about this section in your text. Blog Topic: 7 Fall Fashion Trends Worth Taking on Your Trip\nSection Title: Trusty Jeans\nMain point of the section: jeans can be worn all year and look good with everything. \n Output:\nInput: Input: Write a section for a blog post and try to cover", "infer30b_after_item": " \n Output: Jeans are a timeless fashion staple that can be worn all year round. They are versatile and can be styled in a variety of ways. For a casual look, pair your jeans with a t-shirt and sneakers. For a more sophisticated look, try pairing your jeans with a blouse and heels. Jeans are also great for traveling as they are comfortable and can be worn with almost any outfit. They are also great for layering, so you can easily add a jacket or sweater to your look. Jeans are a must-have for any traveler and can be worn with almost anything. \n\n", "infer13b_before_item": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Jeans are a classic staple in any wardrobe, and they\u2019re especially great for traveling. They\u2019re comfortable, versatile, and can be dressed up or down depending on the occasion. Plus, they\u2019re a great way to stay warm in the cooler months. \n\nFor fall, jeans are a must-have item. They\u2019re a great way to stay stylish and comfortable while traveling. Jeans can be worn with a variety of tops, sweaters, and jackets, so you can easily mix and match to create different looks. Plus, they\u2019re a great way to stay warm in the cooler months. \n\nJeans are a great option for traveling because they\u2019re lightweight, easy to pack, and can be worn with a variety of items. They\u2019re also a great way to stay warm in the cooler months. Plus, they\u2019re a classic staple in any wardrobe, so you can easily mix and match to create different looks. \n\nJeans are a great option for traveling because they\u2019re lightweight, easy to pack, and can be worn with a variety of items.", "infer7b_before_item": "\n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * ", "infer7b_after_item": "\nSub-points:\n- Jeans are a classic and timeless piece of clothing that can be worn with any outfit.\n- They can be dressed up or down depending on the occasion.\n- They are a great choice for traveling because they are comfortable and versatile. \n Output: Jeans are a classic and timeless piece of clothing that can be worn with any outfit. They can be dressed up or down depending on the occasion. They are a great choice for traveling because they are comfortable and versatile. Jeans can be worn all year and look good with everything. They are a staple in any wardrobe and can be worn with any outfit. \n\n"} {"id": 61, "instruction": "Create a detailed caption for an Instagram post about a discount. A proper caption should explain the product, offer the discount, and tell the user how to claim it.", "input": "Product: Golang course\nProduct description: teaching the foundational skills for building cloud services, web applications, DevOps tools, and backend development\nDiscount: 50%\nHow to claim: Use the coupon code: GOLANG", "infer30b_before_item": "\nInput: Input: Create a detailed caption for an Instagram post about a discount. A proper caption should explain the product, offer the discount, and tell the user how to claim it. Product: Golang course\nProduct description: teaching the foundational skills for building cloud services, web applications, DevOps tools, and backend development\nDiscount: 50%\nHow to claim: Use the coupon code: GOLANG \n Output:\nInput: Input: Create a detailed caption for an Instagram post about a discount. A proper caption should explain the product, offer the discount, and tell the user how to claim it. Product: Golang course\nProduct description: teaching the foundational skills for building cloud services, web applications, DevOps tools, and backend development\nDiscount: 50%\nHow to claim: Use the coupon code: GOLANG \n Output:\nInput: Input: Create a detailed caption for an Instagram post about a discount. A proper caption should explain the product, offer the discount, and tell the user how to claim it. Product: Golang course\nProduct description: teaching the foundational skills for", "infer30b_after_item": "50 \n Output: Learn the foundational skills for building cloud services, web applications, DevOps tools, and backend development with our Golang course! Get 50% off when you use the coupon code: GOLANG50. \n\n", "infer13b_before_item": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "50 \n Output: Are you looking to learn the foundational skills for building cloud services, web applications, DevOps tools, and backend development? Then look no further! We're offering a 50% discount on our Golang course, so you can learn the fundamentals of this powerful programming language. Simply use the coupon code: GOLANG50 to claim your discount. \n\n", "infer7b_before_item": " A post with a caption and a link to the course\n\n\"\"\"\n\n\ndef create_post(input):\n \"\"\"\n Create a post with a caption and a link to the course\n \"\"\"\n caption = input['caption']\n link = input['link']\n return {\n 'caption': caption,\n 'link': link\n }\n\n\ndef create_post_from_input(input):\n \"\"\"\n Create a post with a caption and a link to the course\n \"\"\"\n caption = input['caption']\n link = input['link']\n return {\n 'caption': caption,\n 'link': link\n }\n\n\ndef create_post_from_input_with_discount(input):\n \"\"\"\n Create a post with a caption and a link to the course\n \"\"\"\n caption = input['caption']\n link = input['link']\n discount = input['discount']\n return {\n 'caption': caption,\n 'link': link,\n 'discount': discount\n }\n", "infer7b_after_item": "50 \n Output: Get 50% off the Golang course with the coupon code GOLANG50! Learn the foundational skills for building cloud services, web applications, DevOps tools, and backend development. \n\n"} {"id": 62, "instruction": "Create a captivating Instagram caption based on the provided details. Try to think of as many captions as you can.", "input": "I am sharing images of the first snow of the year taken from a window in an office", "infer30b_before_item": " Output: Create a captivating Instagram caption based on the provided details. Try to think of as many captions as you can. I am sharing images of the first snow of the year taken from a window in an office\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " building. \n Output: 1. The first snow of the year is here! Capturing the beauty of the snow from the window of an office building. \n2. The snow is here and it's magical! Capturing the beauty of the first snow of the year from an office window. \n3. The first snow of the year is here and it's beautiful! Capturing the beauty of the snow from an office window. \n4. The snow is here and it's so beautiful! Capturing the beauty of the first snow of the year from an office window. \n5. The first snow of the year is here and it's so magical! Capturing the beauty of the snow from an office window. \n6. The snow is here and it's so magical! Capturing the beauty of the first snow of the year from an office window. \n7. The first snow of the year is here and it's so beautiful! Capturing the beauty of the snow from an office window. \n8. The snow is here and it's so beautiful! Capturing the beauty of the first snow of the year from an office window. \n9. The", "infer13b_before_item": " Output: The caption that you think is the best.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " building. \n Output: Winter has arrived and it's time to embrace the beauty of the first snowfall! #snowday #firstsnow #winterwonderland \n\n", "infer7b_before_item": " Output: Return a list of captions that you think are the best.\n\nExample:\n\nInput:\n\nInput:\n\nOutput:\n\n[\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n \"It's snowing outside!\",\n ", "infer7b_after_item": " building. \n Output: #SnowDay #FirstSnowOfTheYear #OfficeBuilding #WindowSights #WinterWonderland #ColdWeather #SnowFlakes #SnowCoveredGround #SnowCoveredTrees #SnowCoveredRoads #SnowCoveredLake #SnowCoveredFields #SnowCoveredMountains #SnowCoveredHills #SnowCoveredPark #SnowCoveredPavement #SnowCoveredPath #SnowCoveredFields #SnowCoveredFarm #SnowCoveredFarm #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields #SnowCoveredFields"} {"id": 63, "instruction": "You are given a topic for an Instagram post. Help the post reach a broader audience by suggesting hashtags related to the post.", "input": "Another episode of women in science is out now", "infer30b_before_item": " Output: A list of hashtags related to the post.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": "! \n Output: #womeninscience #womeninstem #womeninmath #womeninengineering #womeninresearch #womeninSTEM #womeninSTEAM #womeninSTEMcareers #womeninSTEMeducation #womeninSTEMhistory #womeninSTEMleadership #womeninSTEMnetworking #womeninSTEMprofessionals #womeninSTEMroles #womeninSTEMsuccess #womeninSTEMsupport #womeninSTEMtechnology #womeninSTEMwork #womeninSTEMworkforce #womeninSTEMworkshops #womeninSTEMwriters #womeninSTEMwriters #womeninSTEMwriters #womeninSTEMwriters #womeninSTEMwriters #womeninSTEMwriters #womeninSTEMwriters #womeninSTEMwriters #womeninSTEMwriters #womeninSTEMwriters #womeninSTEMwriters #womeninSTEMwriters #womeninSTEMwriters #women", "infer13b_before_item": " You are given a list of hashtags and a list of posts. You are to find the hashtags that are used in the posts.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "! \n Output: #WomenInScience #Science #Scientists #WomenInSTEM #STEM #Research #Innovation #Discovery #ScienceCommunity #ScienceEducation #ScienceAdvocacy #ScienceForAll #ScienceForChange #ScienceForHumanity #ScienceForTheFuture #ScienceForThePlanet #ScienceForTheEnvironment #ScienceForTheEarth #ScienceForTheFuture #ScienceForTheWorld #ScienceForTheGenerations #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceForTheGenerationsToCome #ScienceFor", "infer7b_before_item": " Output: You are given a topic for an Instagram post. Help the post reach a broader audience by suggesting hashtags related to the post. Another episode of women in science is out now \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": "! #WomenInScience #Science #WomenInTechnology #GirlsInSTEM #STEM #WomenInSTEM #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #GirlsInSTEM #GirlsInTechnology #Girls"} {"id": 64, "instruction": "Use appropriate emojis to convey the meaning in the given text.", "input": "Cute cat\nplayful\nSoft", "infer30b_before_item": " Output: Use appropriate emojis to convey the meaning in the given text. Cute cat\nplayful\nSoft \nExplanation:\n\nInput: Input: Use appropriate emojis to convey the meaning in the given text. Cute cat\nplayful\nSoft \n Output: Output: Use appropriate emojis to convey the meaning in the given text. Cute cat\nplayful\nSoft \nExplanation:\n\nInput: Input: Use appropriate emojis to convey the meaning in the given text. Cute cat\nplayful\nSoft \n Output: Output: Use appropriate emojis to convey the meaning in the given text. Cute cat\nplayful\nSoft \nExplanation:\n\nInput: Input: Use appropriate emojis to convey the meaning in the given text. Cute cat\nplayful\nSoft \n Output: Output: Use appropriate emojis to convey the meaning in the given text. Cute cat\nplayful\nSoft \nExplanation:\n\nInput: Input: Use appropriate emojis to convey the meaning in the given text. Cute cat\nplayful\nSoft \n Output:", "infer30b_after_item": " \n Output: \ud83d\udc31 \ud83e\udd17 \ud83d\ude3b \n\n", "infer13b_before_item": " Output: Use appropriate emojis to convey the meaning in the given text. Cute cat\nSoft \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "ly\nPurring\n\nOutput: \ud83d\udc31 \ud83d\ude0a \ud83d\udc08 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ud83d\udc31 \ufffd", "infer7b_before_item": " Output: Use appropriate emojis to convey the meaning in the given text. Cute cat\nplayful\nSoft\n# 1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.", "infer7b_after_item": " fur \n Output: \ud83d\ude38\ud83d\ude39\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ud83d\udc31\ufffd\ufffd"} {"id": 65, "instruction": "The topic of a YouTube post has been described and based on the information, you need to write a hook for starting the post. A catchy hook will keep your readers interested so they keep reading. It would be great if you could come up with as many hooks as you can.", "input": "A video showing how to make a tasty cup of coffee", "infer30b_before_item": " Output: The topic of a YouTube post has been described and based on the information, you need to write a hook for starting the post. A catchy hook will keep your readers interested so they keep reading. It would be great if you could come up with as many hooks as you can. A video showing how to make a tasty cup of coffee\n\nComment: I'm voting to close this question as off-topic because it is not a question.\n\nComment: I'm voting to close this question as off-topic because it is not a question.\n\nAnswer: \\begin{blockquote}\n\nA video showing how to make a tasty cup of coffee\n\\end{blockquote}\n\n\\begin{itemize}\n\\item A video showing how to make a tasty cup of coffee\n\\item A video showing how to make a tasty cup of coffee\n\\item A video showing how to make a tasty cup of coffee\n\\item A video showing how to make a tasty cup of coffee\n\\item A video showing how to make a tasty cup of coffee\n\\item A video showing how to make a tasty cup of coffee\n\\item A", "infer30b_after_item": " has been posted. \n Output: Are you ready to make the perfect cup of coffee? \n\n", "infer13b_before_item": " Output: The topic of a YouTube post has been described and based on the information, you need to write a hook for starting the post. A catchy hook will keep your readers interested so they keep reading. It would be great if you could come up with as many hooks as you can. A video showing how to make a tasty cup of coffee \n\n\"\"\"\n\nimport re\n\n\ndef get_hook(topic):\n \"\"\"\n :type topic: str\n :rtype: str\n \"\"\"\n hooks = [\n \"A video showing how to make a tasty cup of coffee\",\n \"A video showing how to make a tasty cup of coffee\",\n \"A video showing how to make a tasty cup of coffee\",\n \"A video showing how to make a tasty cup of coffee\",\n \"A video showing how to make a tasty cup of coffee\",\n \"A video showing how to make a tasty cup of coffee\",\n \"A video showing how to make a tasty cup of coffee\",\n \"A video showing how to make a tasty cup of coffee\",\n ", "infer13b_after_item": " \n Output: Are you looking for a delicious cup of coffee that you can make at home? Then this video is for you! Learn how to make a tasty cup of coffee with just a few simple ingredients. \n\n", "infer7b_before_item": " The output is the post itself. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need to write a post that is interesting and engaging. You need", "infer7b_after_item": ". \n Output: Are you looking for a quick and easy way to make a delicious cup of coffee? Then this video is for you! \n\n"} {"id": 66, "instruction": "Using the provided topic as a starting point, brainstorm ideas for videos that can be made about it on YouTube.", "input": "In spite of the fact that procrastination feels bad to you, why do you do it?", "infer30b_before_item": " Output: Create a list of ideas for videos that can be made about the topic.\nSteps:\n 1. Brainstorm ideas for videos that can be made about the topic.\n 2. Create a list of ideas for videos that can be made about the topic.\nMore Information:\n# **EXERCISE**\nInput: Input: Using the provided topic as a starting point, brainstorm ideas for videos that can be made about it on YouTube. In spite of the fact that procrastination feels bad to you, why do you do it? \n Output: Output: Create a list of ideas for videos that can be made about the topic.\n Steps:\n 1. Brainstorm ideas for videos that can be made about the topic.\n 2. Create a list of ideas for videos that can be made about the topic.\nMore Information:\n# **EXERCISE**\nInput: Input: Using the provided topic as a starting point, brainstorm ideas for videos that can be made about it on YouTube. In spite of the fact that procrastination feels bad to you, why do you do it? \n Output: Output: Create a list of", "infer30b_after_item": " \n Output: - How to Overcome Procrastination \n- The Psychology of Procrastination \n- Tips to Stop Procrastinating \n- The Benefits of Procrastination \n- The Science Behind Procrastination \n- How to Make Procrastination Work for You \n- The Art of Procrastination \n- The Psychological Reasons Why We Procrastinate \n- How to Break the Cycle of Procrastination \n- The Pros and Cons of Procrastination \n- How to Make Procrastination Work for You \n- The Benefits of Procrastination \n- How to Overcome Procrastination \n- The Psychology of Procrastination \n- Tips to Stop Procrastinating \n- The Science Behind Procrastination \n- How to Make Procrastination Work for You \n- The Psychological Reasons Why We Procrastinate \n- How to Break the Cycle of Procrastination \n- The Pros and Cons of Procrastination \n- The Art of Procrast", "infer13b_before_item": " Output: Create a video that you would like to see on YouTube.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Ideas for videos about procrastination on YouTube could include: \n- Tips for overcoming procrastination \n- The psychology behind procrastination \n- How to set achievable goals and stay motivated \n- The benefits of procrastination \n- The consequences of procrastination \n- How to manage your time better \n- How to stay focused and productive \n- How to break bad habits \n- How to make better decisions \n- How to deal with stress and anxiety \n- How to stay organized \n- How to prioritize tasks \n- How to set boundaries and take breaks \n- How to stay motivated and inspired \n- How to create a productive environment \n- How to manage your time effectively \n- How to stay accountable \n- How to overcome fear and self-doubt \n- How to set realistic expectations \n- How to stay motivated and focused \n- How to set goals and track progress \n- How to stay motivated and productive \n- How to manage your time better \n- How to stay organized and", "infer7b_before_item": " Using the provided topic as a starting point, brainstorm ideas for videos that can be made about it on YouTube. In spite of the fact that procrastination feels bad to you, why do you do it? \n 1. \n 2. \n 3. \n 4. \n 5. \n 6. \n 7. \n 8. \n 9. \n 10. \n 11. \n 12. \n 13. \n 14. \n 15. \n 16. \n 17. \n 18. \n 19. \n 20. \n 21. \n 22. \n 23. \n 24. \n 25. \n 26. \n 27. \n 28. \n 29. \n 30. \n 31. \n 32. \n 33. \n 34. \n 35. \n 36. \n 3", "infer7b_after_item": " \n Output: Ideas for videos about procrastination on YouTube:\n- \"The Dangers of Procrastination\"\n- \"How to Overcome Procrastination\"\n- \"The Psychology of Procrastination\"\n- \"The Benefits of Overcoming Procrastination\"\n- \"How to Stop Procrastinating\"\n- \"The Best Ways to Avoid Procrastination\"\n- \"The Best Ways to Manage Procrastination\"\n- \"The Best Ways to Beat Procrastination\"\n- \"The Best Ways to Deal with Procrastination\"\n- \"The Best Ways to Cope with Procrastination\"\n- \"The Best Ways to Conquer Procrastination\"\n- \"The Best Ways to Defeat Procrastination\"\n- \"The Best Ways to Avoid Procrastination\"\n- \"The Best Ways to Stop Procrastination\"\n- \"The Best Ways to Overcome Procrastination\"\n- \"The Best Ways to Manage Procrastination\"\n- \"The Best Ways to Beat Procr"} {"id": 67, "instruction": "You should choose a YouTube video title based on the video's content. A video's title tells viewers what to expect from it. It should be direct, honest, and clear. The title of the video needs to capture the attention of viewers, so do not use an unclear or ambiguous one.", "input": "A research study has been conducted to determine if exercise really can \"boost\" your metabolism.", "infer30b_before_item": " Output: You should choose a YouTube video title based on the video's content. A video's title tells viewers what to expect from it. It should be direct, honest, and clear. The title of the video needs to capture the attention of viewers, so do not use an unclear or ambiguous one. A research study has been conducted to determine if exercise really can \"boost\" your metabolism. \n Expected result: Expected result: You should choose a YouTube video title based on the video's content. A video's title tells viewers what to expect from it. It should be direct, honest, and clear. The title of the video needs to capture the attention of viewers, so do not use an unclear or ambiguous one. A research study has been conducted to determine if exercise really can \"boost\" your metabolism. \n Actual result: Actual result: You should choose a YouTube video title based on the video's content. A video's title tells viewers what to expect from it. It should be direct, honest, and clear. The title of the video needs to capture the attention of viewers, so do not use an unclear or ambiguous one. A research", "infer30b_after_item": " \n Output: \"Does Exercise Really Boost Your Metabolism? Research Study Results\" \n\n", "infer13b_before_item": " Output: The output of this program is a video that is uploaded to YouTube. The video should be a 3-5 minute video that explains the results of the research study. The video should be informative and engaging. It should be clear and concise. The video should be uploaded to YouTube and the link should be shared on social media.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: \"Research Study: Does Exercise Really Boost Your Metabolism?\" \n\n", "infer7b_before_item": " Output: The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the video is the video itself. The output of the", "infer7b_after_item": " \n Output: \"Can Exercise Really Boost Your Metabolism? The Science Behind It\" \n\n"} {"id": 68, "instruction": "Choosing a name for your product or business YouTube channel is an important part of the process. Based on the description of the product or business, you should come up with some interesting names. Take some time to brainstorm your ideas.", "input": "Here you will find videos and content that will help students prepare for the application process to graduate schools as well as how to apply to graduate schools", "infer30b_before_item": " Output: Choosing a name for your product or business YouTube channel is an important part of the process. Based on the description of the product or business, you should come up with some interesting names. Take some time to brainstorm your ideas. Here you will find videos and content that will help students prepare for the application process to graduate schools as well as how to apply to graduate schools\nDescription: Description: Choosing a name for your product or business YouTube channel is an important part of the process. Based on the description of the product or business, you should come up with some interesting names. Take some time to brainstorm your ideas. Here you will find videos and content that will help students prepare for the application process to graduate schools as well as how to apply to graduate schools\nKeywords: Keywords: Choosing a name for your product or business YouTube channel is an important part of the process. Based on the description of the product or business, you should come up with some interesting names. Take some time to brainstorm your ideas. Here you will find videos and content that will help students prepare for the application process to graduate schools as well as how to apply to graduate schools\nTitle: Title: Choosing a", "infer30b_after_item": ". \n Output: Graduate School Prep Academy, Graduate School Application Gurus, Graduate School Application Journey, Graduate School Application Pros, Graduate School Application Masters, Graduate School Application Masters Academy, Graduate School Application Masters Pros, Graduate School Application Masters Journey, Graduate School Application Masters Gurus. \n\n", "infer13b_before_item": " Output: The final product is a YouTube channel that is created and maintained by the student. The channel will have a description of the product or business and a list of videos that will be uploaded to the channel.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": ". \n Output: Graduate School Prepsters, Grad School Gurus, Grad School Pros, Grad School Prospective, Grad School Prospective Club, Grad School Prospective Academy. \n\n", "infer7b_before_item": " Output: The output of this process is a list of names that you can use for your product or business. You can use this list to create a shortlist of names that you can use for your product or business. \n# 1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.", "infer7b_after_item": ". \n Output: 1. Grad School Gurus\n2. Grad School Insiders\n3. Grad School Success\n4. Grad School Secrets\n5. Grad School Essentials\n6. Grad School Advice\n7. Grad School Tips\n8. Grad School Guides\n9. Grad School Experts\n10. Grad School Advisors\n11. Grad School Helpers\n12. Grad School Advisors\n13. Grad School Guides\n14. Grad School Experts\n15. Grad School Advisors\n16. Grad School Helpers\n17. Grad School Advisors\n18. Grad School Guides\n19. Grad School Experts\n20. Grad School Advisors\n21. Grad School Helpers\n22. Grad School Advisors\n23. Grad School Guides\n24. Grad School Experts\n25. Grad School Advisors\n26. Grad School Helpers\n27. Grad School Advisors\n28. Grad School Guides\n29. Grad School Experts\n30. Grad School Advisors\n31. Grad School Helpers\n32."} {"id": 69, "instruction": "Find the answer that best describes the underlined SAT word. Select the correct option and explain the meaning of the underlined word.", "input": "Despite the _cacophony, the student tried to study. \nA. Loud sounds\nB. Difficult subject\nC. Late hour\nD. Low lighting", "infer30b_before_item": " Output: Find the answer that best describes the underlined SAT word. Select the correct option and explain the meaning of the underlined word. Despite the _cacophony, the student tried to study. \nA. Loud sounds\nB. Difficult subject\nC. Late hour\nD. Low lighting \nExplanation: The word _cacophony_ means loud sounds. The student was trying to study despite the loud sounds.\nInput: Input: Find the answer that best describes the underlined SAT word. Select the correct option and explain the meaning of the underlined word. The _cacophony_ of the city was too much for the country boy. \nA. Loud sounds\nB. Difficult subject\nC. Late hour\nD. Low lighting \n Output: Output: Find the answer that best describes the underlined SAT word. Select the correct option and explain the meaning of the underlined word. The _cacophony_ of the city was too much for the country boy. \nA. Loud sounds\nB. Difficult subject\nC. Late hour\nD. Low lighting \nExplanation: The word", "infer30b_after_item": " \n Output: A. Loud sounds. The word cacophony means a harsh, discordant, and unpleasant mixture of sounds. \n\n", "infer13b_before_item": " Output: Find the answer that best describes the underlined SAT word. Select the correct option and explain the meaning of the underlined word. Despite the _cacophony, the student tried to study. \nA. Loud sounds\nB. Difficult subject\nC. Late hour\nD. Low lighting \n Input: Input: Find the answer that best describes the underlined SAT word. Select the correct option and explain the meaning of the underlined word. The _cacophony of the city was deafening. \nA. Loud sounds\nB. Difficult subject\nC. Late hour\nD. Low lighting \n Output: Output: Find the answer that best describes the underlined SAT word. Select the correct option and explain the meaning of the underlined word. The _cacophony of the city was deafening. \nA. Loud sounds\nB. Difficult subject\nC. Late hour\nD. Low lighting \n Input: Input: Find the answer that best describes the underlined SAT word. Select the correct option and explain the meaning of the underlined word. The _cacophony of the city was de", "infer13b_after_item": "\n\nAnswer: B. Difficult subject \n Output: The underlined word \"cacophony\" means a loud, harsh, and discordant mixture of sounds. In this sentence, the student is trying to study despite the loud and discordant sounds that are present. \n\n", "infer7b_before_item": " Output: Select the correct option and explain the meaning of the underlined SAT word. Despite the _cacophony, the student tried to study. \nA. Loud sounds\nB. Difficult subject\nC. Late hour\nD. Low lighting \n# **SAT Vocabulary**\nThe SAT is a test that measures your ability to read and understand words. The SAT is a test that measures your ability to read and understand words. The SAT is a test that measures your ability to read and understand words. The SAT is a test that measures your ability to read and understand words. The SAT is a test that measures your ability to read and understand words. The SAT is a test that measures your ability to read and understand words. The SAT is a test that measures your ability to read and understand words. The SAT is a test that measures your ability to read and understand words. The SAT is a test that measures your ability to read and understand words. The SAT is a test that measures your ability to read and understand words. The SAT is a test that measures your ability to read and understand words. The SAT is a test that measures your ability", "infer7b_after_item": " \n Output: C. Late hour \n\n"} {"id": 70, "instruction": "Find synonyms for the given word. You need to write down how the provided synonyms differ from the original word in terms of meaning, usage, etc.", "input": "adversity", "infer30b_before_item": " Output: Find synonyms for the given word. You need to write down how the provided synonyms differ from the original word in terms of meaning, usage, etc. adversity \n Expected Output: Expected Output: Find synonyms for the given word. You need to write down how the provided synonyms differ from the original word in terms of meaning, usage, etc. adversity \n Author: Author: Find synonyms for the given word. You need to write down how the provided synonyms differ from the original word in terms of meaning, usage, etc. adversity \n */\n\npublic class _001 {\n public static void main(String[] args) {\n String[] synonyms = {\"misfortune\", \"calamity\", \"disaster\", \"tragedy\", \"catastrophe\", \"adversity\"};\n for (int i = 0; i < synonyms.length; i++) {\n System.out.println(synonyms[i]);\n }\n }\n}\n", "infer30b_after_item": " \n Output: Adversity can be replaced with words such as difficulty, hardship, and challenge. Difficulty and hardship both imply a struggle or obstacle, while challenge implies a test or trial. \n\n", "infer13b_before_item": " Output: Find antonyms for the given word. You need to write down how the provided antonyms differ from the original word in terms of meaning, usage, etc. adversity \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Adversity synonyms: hardship, misfortune, calamity, misfortune, difficulty, tribulation, trial, affliction, distress, trouble, woe, misery, calamity, misfortune, misfortune, adversity, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, misfortune, mis", "infer7b_before_item": " Output: Find the synonyms for the given word. You need to write down how the provided synonyms differ from the original word in terms of meaning, usage, etc. adversity \n */\n\npublic class Synonyms {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n String word = sc.nextLine();\n String[] synonyms = sc.nextLine().split(\" \");\n for (String synonym : synonyms) {\n System.out.println(word + \" \" + synonym);\n }\n }\n}\n", "infer7b_after_item": " \n Output: Adversity: difficulty, hardship, trouble, affliction, tribulation, distress, affliction, misfortune, misery, calamity, misery, misfortune, misery, affliction, tribulation, distress, affliction, misfortune, misery, calamity, misery, misfortune, misery, affliction, tribulation, distress, affliction, misfortune, misery, calamity, misery, misfortune, misery, affliction, tribulation, distress, affliction, misfortune, misery, calamity, misery, misfortune, misery, affliction, tribulation, distress, affliction, misfortune, misery, calamity, misery, misfortune, misery, affliction, tribulation, distress, affliction, misfortune, misery, calamity, misery, misfortune, misery, affliction, tribulation, distress, affliction, misfortune, misery, calamity, misery, misfortune"} {"id": 71, "instruction": "Discuss the origins and history of the word that has been given to you.", "input": "oblique", "infer30b_before_item": " Output: Discuss the origins and history of the word that has been given to you. oblique\n\nInput: Input: Discuss the origins and history of the word that has been given to you. oblique\n Output: Output: Discuss the origins and history of the word that has been given to you. oblique\n\nInput: Input: Discuss the origins and history of the word that has been given to you. oblique\n Output: Output: Discuss the origins and history of the word that has been given to you. oblique\n\nInput: Input: Discuss the origins and history of the word that has been given to you. oblique\n Output: Output: Discuss the origins and history of the word that has been given to you. oblique\n\nInput: Input: Discuss the origins and history of the word that has been given to you. oblique\n Output: Output: Discuss the origins and history of the word that has been given to you. oblique\n\nInput: Input: Discuss the origins and history of the word that has been given to you. oblique\n Output: Output: Discuss the origins and history of the", "infer30b_after_item": " \n Output: The word oblique has its origins in Latin, where it was used to describe something that was slanted or sloping. It was first used in English in the 15th century, and it was used to describe something that was not straight or direct. Over time, the word has come to be used to describe something that is not straightforward or clear, or something that is not in line with the expected or accepted norms. \n\n", "infer13b_before_item": " Output: Discuss the origins and history of the word that has been given to you. oblique \n\noblique\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: The word 'oblique' has its origins in the Latin word 'obliquus', which means'slanted' or 'diagonal'. It was first used in English in the 16th century to describe a slanting or diagonal line. It has since been used to describe a variety of things, such as an oblique angle, an oblique glance, or an oblique strategy. \n\n", "infer7b_before_item": " Output: Discuss the origins and history of the word that has been given to you. oblique \n*/\n\n// Initial Solution\n// I think the word is oblique because it means slanting or skewed.\n// I think the word is oblique because it means slanting or skewed.\n// I think the word is oblique because it means slanting or skewed.\n// I think the word is oblique because it means slanting or skewed.\n// I think the word is oblique because it means slanting or skewed.\n// I think the word is oblique because it means slanting or skewed.\n// I think the word is oblique because it means slanting or skewed.\n// I think the word is oblique because it means slanting or skewed.\n// I think the word is oblique because it means slanting or skewed.\n// I think the word is oblique because it means slanting or skewed.\n// I think the word is oblique because it means slanting or skewed.\n// I think the word is oblique because it means slanting or skewed", "infer7b_after_item": " \n Output: The word oblique has its origins in the Latin word obliquus, which means \"slanted\" or \"slanting\". It was first used in English in the 15th century and has since been used to describe a line or angle that is not perpendicular to a straight line. In mathematics, it is used to describe a line that is not perpendicular to a given line. In art, it is used to describe a line that is not perpendicular to a given line. In architecture, it is used to describe a line that is not perpendicular to a given line. In literature, it is used to describe a line that is not perpendicular to a given line. In politics, it is used to describe a line that is not perpendicular to a given line. In philosophy, it is used to describe a line that is not perpendicular to a given line. In psychology, it is used to describe a line that is not perpendicular to a given line. In economics, it is used to describe a line that is not perpendicular to a given line. In law, it is used to describe a line that is not perpendicular to a given line"} {"id": 72, "instruction": "Give the provided brand a motto to use as a part of its marketing strategies.", "input": "The Ice cream shop is a small, quaint shop located in the heart of the historic district. They offer a variety of ice cream flavors, as well as Italian ice, gelato, and sorbet. The shop has a few tables and chairs, but most of their business is to-go. They offer a loyalty program where you can get a free scoop of ice cream after 10 purchases.", "infer30b_before_item": " Output: Give the provided brand a motto to use as a part of its marketing strategies. The Ice cream shop is a small, quaint shop located in the heart of the historic district. They offer a variety of ice cream flavors, as well as Italian ice, gelato, and sorbet. The shop has a few tables and chairs, but most of their business is to-go. They offer a loyalty program where you can get a free scoop of ice cream after 10 purchases. \n \n*/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: \"Indulge in the Sweetness of Life - At The Ice Cream Shop!\" \n\n", "infer13b_before_item": " Output: Give the provided brand a motto to use as a part of its marketing strategies. The Ice cream shop is a small, quaint shop located in the heart of the historic district. They offer a variety of ice cream flavors, as well as Italian ice, gelato, and sorbet. The shop has a few tables and chairs, but most of their business is to-go. They offer a loyalty program where you can get a free scoop of ice cream after 10 purchases. \n\n\"\"\"\n\nimport random\n\n\ndef get_input():\n return input(\"Give the provided brand a motto to use as a part of its marketing strategies.\\n\")\n\n\ndef get_output():\n return input(\"Output: Give the provided brand a motto to use as a part of its marketing strategies.\\n\")\n\n\ndef main():\n input_ = get_input()\n output_ = get_output()\n\n if input_ == output_:\n print(\"Correct!\")\n else:\n print(\"Incorrect!\")\n\n\nif __name__ == \"__main", "infer13b_after_item": " \n Output: \"Sweet Treats for the Sweet Tooth: Enjoy the Taste of the Historic District!\" \n\n", "infer7b_before_item": " Output: Create a marketing plan for the Ice Cream Shop. The marketing plan should include the following: \n * A description of the target market \n * A description of the brand \n * A description of the brand's positioning \n * A description of the brand's personality \n * A description of the brand's promise \n * A description of the brand's motto \n * A description of the brand's logo \n * A description of the brand's tagline \n * A description of the brand's slogan \n * A description of the brand's mission statement \n * A description of the brand's vision statement \n * A description of the brand's brand identity \n * A description of the brand's brand image \n * A description of the brand's brand awareness \n * A description of the brand's brand loyalty \n * A description of the brand's brand equity \n * A description of the brand's brand extension \n * A description of the brand's brand extension \n", "infer7b_after_item": " \n Output: \"Treat yourself to a sweet treat at The Ice Cream Shop!\" \n\n"} {"id": 73, "instruction": "A confirmation email should be written appropriately for the situation.", "input": "A meeting has been scheduled, and the sender expects the other to review the slides.", "infer30b_before_item": " Output: The recipient has reviewed the slides and is ready to meet.\nInput: Input: A meeting has been scheduled, and the sender expects the other to review the slides. \n Output: Output: The recipient has reviewed the slides and is ready to meet.\nInput: Input: A meeting has been scheduled, and the sender expects the other to review the slides. \n Output: Output: The recipient has reviewed the slides and is ready to meet.\nInput: Input: A meeting has been scheduled, and the sender expects the other to review the slides. \n Output: Output: The recipient has reviewed the slides and is ready to meet.\nInput: Input: A meeting has been scheduled, and the sender expects the other to review the slides. \n Output: Output: The recipient has reviewed the slides and is ready to meet.\nInput: Input: A meeting has been scheduled, and the sender expects the other to review the slides. \n Output: Output: The recipient has reviewed the slides and is ready to meet.\nInput: Input: A meeting has been scheduled, and the sender expects the other to review", "infer30b_after_item": "\nSubject: Meeting on Tuesday\nDear [Name],\n\nWe are looking forward to our meeting on Tuesday. Please review the slides in advance.\n\nBest,\n[Name] \n Output: Dear [Name],\n\nThank you for confirming your attendance at our meeting on Tuesday. We look forward to seeing you then. \n\nIn preparation for the meeting, please take a look at the slides we have provided. We believe they will be helpful in understanding the topic.\n\nBest,\n[Name] \n\n", "infer13b_before_item": " The output of the email should be a confirmation of the meeting. \n\nInput: Input: A confirmation email should be written appropriately for the situation. A meeting has been scheduled, and the sender expects the other to review the slides. \n Output: The output of the email should be a confirmation of the meeting. \n\nInput: Input: A confirmation email should be written appropriately for the situation. A meeting has been scheduled, and the sender expects the other to review the slides. \n Output: The output of the email should be a confirmation of the meeting. \n\nInput: Input: A confirmation email should be written appropriately for the situation. A meeting has been scheduled, and the sender expects the other to review the slides. \n Output: The output of the email should be a confirmation of the meeting. \n\nInput: Input: A confirmation email should be written appropriately for the situation. A meeting has been scheduled, and the sender expects the other to review the slides. \n Output: The output of the email should be a confirmation of the meeting. \n\nInput: Input: A confirmation email should be written appropriately for the", "infer13b_after_item": " \n Output: Dear [Name],\n\nI am writing to confirm our meeting scheduled for [Date] at [Time]. I have attached the slides for your review.\n\nI look forward to discussing them with you and getting your feedback.\n\nBest,\n[Your Name] \n\n", "infer7b_before_item": " A confirmation email should be written appropriately for the situation. A meeting has been scheduled, and the sender expects the other to review the slides. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: I am writing to confirm our meeting on [date] at [time]. I have attached the slides for our discussion. I look forward to seeing you then. \n\n"} {"id": 74, "instruction": "You need to write an email to negotiate your salary.", "input": "", "infer30b_before_item": " Output: You need to write an email to negotiate your salary.\nInput: Input: You need to write an email to negotiate your salary. \n Output: Output: You need to write an email to negotiate your salary.\nInput: Input: You need to write an email to negotiate your salary. \n Output: Output: You need to write an email to negotiate your salary.\nInput: Input: You need to write an email to negotiate your salary. \n Output: Output: You need to write an email to negotiate your salary.\nInput: Input: You need to write an email to negotiate your salary. \n Output: Output: You need to write an email to negotiate your salary.\nInput: Input: You need to write an email to negotiate your salary. \n Output: Output: You need to write an email to negotiate your salary.\nInput: Input: You need to write an email to negotiate your salary. \n Output: Output: You need to write an email to negotiate your salary.\nInput: Input: You need to write an email to negotiate your salary. ", "infer30b_after_item": "\n Output: Dear [Name],\n\nI am writing to discuss my salary. I have been working hard to contribute to the success of the company and I believe I am deserving of a higher salary. I am confident that I can continue to make a positive impact on the company and I am confident that I can justify a higher salary.\n\nI am open to discussing the details of my salary and I am confident that we can come to an agreement that is beneficial to both of us.\n\nThank you for your time and consideration.\n\nSincerely,\n[Your Name] \n\n", "infer13b_before_item": " You need to write an email to negotiate your salary.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The The \n\n\n\n\n\n The The The", "infer13b_after_item": "\n Output: Dear [Name],\n\nI am writing to discuss my salary. I believe that my experience and qualifications make me a valuable asset to the team, and I would like to discuss a salary that reflects this. I am aware of the salary range for this position and I believe that I am worth a salary that is in the upper range.\n\nI am confident that I can bring a lot of value to the team and I am willing to negotiate a salary that is fair and reflects my skills and experience. I look forward to hearing your thoughts on this matter.\n\nThank you for your time and consideration.\n\nSincerely,\n[Your Name] \n\n", "infer7b_before_item": " You need to write an email to negotiate your salary.\nYou need to write an email to negotiate your salary.\nDear Mr. Smith,\nI am writing to you to discuss my salary. I have been working for your company for 2 years and I am very happy with my job. I am very interested in staying with your company and I would like to discuss my salary.\nI am currently earning $30,000 per year. I would like to discuss my salary with you. I would like to earn $35,000 per year.\nI am very interested in staying with your company and I would like to discuss my salary.\nThank you for your time.\nSincerely,\nYour Name\nYour Signature\n# 10. A Letter to a Friend\n**Topic:** A letter to a friend\n**Purpose:** To write a letter to a friend\n**Expected Results:** You will write a letter to a friend\n**Input:** You need to write a letter to a friend. \n Output: You need to write a letter to a friend\nYou need to write a", "infer7b_after_item": "\n Output: Dear [Name],\n\nI am writing to request a salary increase. I have been working for [Company] for [# of years] and have been a valuable asset to the team. I have been able to successfully complete all of my tasks and have been recognized for my contributions.\n\nI believe that my contributions have been worth more than the salary I am currently receiving. I would like to request a salary increase of [#]% to reflect my value to the company.\n\nI look forward to hearing from you and thank you for your time.\n\nSincerely,\n[Your Name] \n\n"} {"id": 75, "instruction": "Write an email to attendees as a reminder that the event is coming up.", "input": "", "infer30b_before_item": " Output: The attendees receive the email. \n Precondition: Precondition: The event is scheduled. \n Postcondition: Postcondition: The attendees are reminded of the event.\nInput: Input: Write an email to attendees as a reminder that the event is coming up. \n Output: Output: The attendees receive the email. \n Precondition: Precondition: The event is scheduled. \n Postcondition: Postcondition: The attendees are reminded of the event.\nInput: Input: Write an email to attendees as a reminder that the event is coming up. \n Output: Output: The attendees receive the email. \n Precondition: Precondition: The event is scheduled. \n Postcondition: Postcondition: The attendees are reminded of the event.\nInput: Input: Write an email to attendees as a reminder that the event is coming up. \n Output: Output: The attendees receive the email. \n Precondition: Precondition: The event is scheduled. \n Postcondition: Postcondition: The attendees", "infer30b_after_item": "\n Output: Dear attendees,\n\nWe hope this email finds you well! This is a friendly reminder that our event is coming up soon. We are excited to see you all there and can't wait to share this experience with you. \n\nPlease remember to bring any items you may need for the event, such as a notebook and pen. We will provide any other materials you may need. \n\nWe look forward to seeing you soon!\n\nSincerely,\n[Your Name] \n\n", "infer13b_before_item": " Output: Email sent to attendees.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: Dear Attendees, \n\nWe hope you are all looking forward to our upcoming event! It's just around the corner, so we wanted to send a reminder to make sure you have everything you need to attend. \n\nThe event will be held on [date], at [location]. Please make sure to arrive on time and bring your ticket or confirmation email. \n\nWe are excited to see you all there! \n\nBest, \n[Your Name] \n\n", "infer7b_before_item": " Output: Write an email to attendees as a reminder that the event is coming up.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": "\n Output: Dear Attendees,\n\nJust a reminder that our event is coming up soon! We are looking forward to seeing you there and having a great time. Please make sure to RSVP and let us know if you have any questions.\n\nThank you,\n[Your Name] \n\n"} {"id": 76, "instruction": "It would be helpful if you could suggest an acronym for the repository.", "input": "A python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.", "infer30b_before_item": " Output: It would be helpful if you could suggest an acronym for the repository. A python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits. \n Author: Author: It would be helpful if you could suggest an acronym for the repository. A python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits. \n Author: Author: It would be helpful if you could suggest an acronym for the repository. A python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits. \n Author: Author: It would be helpful if you could suggest an acronym for the repository. A python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits. \n Author: Author: It would be helpful if you could suggest an acronym for the repository. A python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits. \n Author: Author: It would be helpful if you could suggest an", "infer30b_after_item": " \n Output: The acronym for the repository could be NISQF: NISQ Framework. \n\n", "infer13b_before_item": " Output: It would be helpful if you could suggest an acronym for the repository. A python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits. \n\"\"\"\n\nimport os\nimport sys\nimport time\nimport numpy as np\nimport tensorflow as tf\nimport tensorflow_probability as tfp\nimport tensorflow_probability.experimental.nngraph as tfnngraph\nimport tensorflow_probability.experimental.nngraph as tfnngraph\nimport tensorflow_probability.experimental.nngraph as tfnngraph\nimport tensorflow_probability.experimental.nngraph as tfnngraph\nimport tensorflow_probability.experimental.nngraph as tfnngraph\nimport tensorflow_probability.experimental.nngraph as tfnngraph\nimport tensorflow_probability.experimental.nngraph as tfnngraph\nimport tensorflow_probability.experimental.nngraph as tfnngraph\nimport tensorflow_probability.experimental.nngraph as tfnngraph\nimport tensorflow_probability.experimental.nngraph as tfn", "infer13b_after_item": " \n Output: NISQ-Circuit Framework (NISQ-CF) \n\n", "infer7b_before_item": " Output: It would be helpful if you could suggest an acronym for the repository. A python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits. \n\"\"\"\nimport os\nimport sys\n\n# If extensions (or modules to document with autodoc) are in another directory,\n# add these directories to sys.path here. If the directory is relative to the\n# documentation root, use os.path.abspath to make it absolute, like shown here.\nsys.path.insert(0, os.path.abspath('..'))\n\n# -- General configuration ------------------------------------------------\n\n# If your documentation needs a minimal Sphinx version, state it here.\n#needs_sphinx = '1.0'\n\n# Add any Sphinx extension module names here, as strings. They can be\n# extensions coming with Sphinx (named'sphinx.ext.*') or your custom\n# ones.\nextensions = [\n 'sphinx.ext.autodoc',\n 'sphinx.ext.doctest',\n 'sph", "infer7b_after_item": " \n Output: NISQ-Py. \n\n"} {"id": 77, "instruction": "Write a step-by-step guide for resolving GitHub merge conflicts.", "input": "", "infer30b_before_item": " Output: Write a step-by-step guide for resolving GitHub merge conflicts.\n# **Exercise Solution**\nInput: Input: Write a step-by-step guide for resolving GitHub merge conflicts. \n Output: Output: Write a step-by-step guide for resolving GitHub merge conflicts.\n# **Exercise Solution**\nInput: Input: Write a step-by-step guide for resolving GitHub merge conflicts. \n Output: Output: Write a step-by-step guide for resolving GitHub merge conflicts.\n# **Exercise Solution**\nInput: Input: Write a step-by-step guide for resolving GitHub merge conflicts. \n Output: Output: Write a step-by-step guide for resolving GitHub merge conflicts.\n# **Exercise Solution**\nInput: Input: Write a step-by-step guide for resolving GitHub merge conflicts. \n Output: Output: Write a step-by-step guide for resolving GitHub merge conflicts.\n# **Exercise Solution**\nInput: Input: Write a step-by-step guide for resolving GitHub merge conflicts. \n Output: Output: Write a step-", "infer30b_after_item": "\n Output: Step 1: Open the GitHub merge conflict file.\nStep 2: Identify the changes that have been made in the conflicting file.\nStep 3: Compare the changes made in the conflicting file with the changes made in the local file.\nStep 4: Decide which changes to keep and which to discard.\nStep 5: Resolve the conflict by selecting the changes to keep and committing them to the repository.\nStep 6: Test the changes to ensure that the merge was successful. \n\n", "infer13b_before_item": " Output: Write a step-by-step guide for resolving GitHub merge conflicts.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n", "infer13b_after_item": "\n Output: Step 1: Open the conflicted files in the GitHub merge tool.\nStep 2: Review the changes made by each side and decide which one to keep.\nStep 3: Select the changes you want to keep and click the \"Merge\" button.\nStep 4: Review the changes that were made and make any necessary edits.\nStep 5: Click the \"Merge\" button to accept the changes.\nStep 6: Click the \"Save\" button to save the changes. \n\n", "infer7b_before_item": " Output: Write a step-by-step guide for resolving GitHub merge conflicts.\n\n# I worked on this challenge by myself.\n# I spent 1.5 hours on this challenge.\n\n# Pseudocode\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps:\n\n# Input:\n# Output:\n# Steps", "infer7b_after_item": "\n Output: Step 1: Open the merge conflict file in your editor.\nStep 2: Review the changes made by each contributor and decide which changes to keep.\nStep 3: If you want to keep both changes, select the \"Keep Both\" option.\nStep 4: If you want to keep one of the changes, select the \"Keep This\" option.\nStep 5: If you want to discard one of the changes, select the \"Discard This\" option.\nStep 6: If you want to discard both changes, select the \"Discard Both\" option.\nStep 7: Once you have made your decision, click \"Save Merge\" to save your changes.\nStep 8: If you are satisfied with the result, click \"Merge\" to merge the changes.\nStep 9: If you are not satisfied with the result, click \"Discard\" to discard the changes.\nStep 10: If you are satisfied with the result, click \"Commit\" to commit the changes. \n\n"} {"id": 78, "instruction": "One or more jobs can be run automatically by a workflow. The workflows are defined in the repository as YAML files and will run if an event occurs in the repository, as well as manually, or on a certain schedule.\nBring an example of a workflow that demonstrate the CI/CD features of GitHub Actions.", "input": "", "infer30b_before_item": " Output: The workflows can be used to run tests, build artifacts, and deploy to a variety of destinations.\nBring an example of a workflow that demonstrate the CI/CD features of GitHub Actions. \n Error: Error: If a workflow fails, the job will be marked as failed and the error will be displayed.\nBring an example of a workflow that demonstrate the CI/CD features of GitHub Actions. \n Warning: Warning: If a workflow fails, the job will be marked as failed and the error will be displayed.\nBring an example of a workflow that demonstrate the CI/CD features of GitHub Actions. \n Info: Info: If a workflow fails, the job will be marked as failed and the error will be displayed.\nBring an example of a workflow that demonstrate the CI/CD features of GitHub Actions. \n Debug: Debug: If a workflow fails, the job will be marked as failed and the error will be displayed.\nBring an example of a workflow that demonstrate the CI/CD features of GitHub Actions. \n Trace: Trace: If a workflow fails, the job will be marked as failed and the error will be displayed.\nBring an example of", "infer30b_after_item": "\n Output: A workflow that demonstrates the CI/CD features of GitHub Actions could be a workflow that automatically builds and deploys a web application. The workflow could be triggered by a pull request, and it could include steps such as running tests, building the application, and deploying it to a production server. \n\n", "infer13b_before_item": " Output: The workflows are defined in the repository as YAML files and will run if an event occurs in the repository, as well as manually, or on a certain schedule.\nBring an example of a workflow that demonstrate the CI/CD features of GitHub Actions.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: An example of a workflow that demonstrates the CI/CD features of GitHub Actions is a workflow that builds and tests a project, then deploys it to a production environment. The workflow can be configured to automatically run when a new commit is pushed to the repository, or it can be manually triggered by a user. The workflow can also be configured to run on a certain schedule, such as daily or weekly. \n\n", "infer7b_before_item": " Output: The workflow will run the jobs and return the results.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": "\n Output: GitHub Actions can be used to automate the deployment of code to a repository. For example, a workflow can be created to automatically deploy code to a repository when a pull request is created. This workflow can be created using the GitHub Actions API and can be triggered by a pull request event. The workflow can also be triggered manually or on a certain schedule. \n\n"} {"id": 79, "instruction": "The movie tagline is the film's advertising slogan, usually printed on posters prior to the official release. It is a short description or comment on a movie to capture the essence of the movie, and ultimately make you watch the movie. Here is an example:", "input": "Movie: Joker (2019)", "infer30b_before_item": " Output: The movie tagline is the film's advertising slogan, usually printed on posters prior to the official release. It is a short description or comment on a movie to capture the essence of the movie, and ultimately make you watch the movie. Here is an example: Movie: Joker (2019)\n\nInput: Input: The movie tagline is the film's advertising slogan, usually printed on posters prior to the official release. It is a short description or comment on a movie to capture the essence of the movie, and ultimately make you watch the movie. Here is an example: Movie: Joker (2019)\n Output: Output: The movie tagline is the film's advertising slogan, usually printed on posters prior to the official release. It is a short description or comment on a movie to capture the essence of the movie, and ultimately make you watch the movie. Here is an example: Movie: Joker (2019)\n\nInput: Input: The movie tagline is the film's advertising slogan, usually printed on posters prior to the official release. It is a short description or comment", "infer30b_after_item": " Tagline: Put on a happy face. \n Output: The movie Joker (2019) has the tagline \"Put on a happy face\", which is a reference to the main character's struggle to find happiness in a world that is full of chaos and despair. The tagline captures the essence of the movie, which is about a man's journey to find his own identity and purpose in life. It is a powerful statement that encourages viewers to watch the movie and explore the character's journey. \n\n", "infer13b_before_item": " The output is the tagline of the movie.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\nMovie tagline: \"The Clown Prince of Crime\". \n Output: The movie tagline for Joker (2019) is \"The Clown Prince of Crime\". \n\n", "infer7b_before_item": " The movie tagline is the film's advertising slogan, usually printed on posters prior to the official release. It is a short description or comment on a movie to capture the essence of the movie, and ultimately make you watch the movie. Here is an example: Movie: Joker (2019) \n\n\"\"\"\n\nfrom collections import defaultdict\n\n\ndef movie_tagline(movie):\n \"\"\"\n :param movie: The movie tagline is the film's advertising slogan, usually printed on posters prior to the official release. It is a short description or comment on a movie to capture the essence of the movie, and ultimately make you watch the movie. Here is an example: Movie: Joker (2019)\n :return: The movie tagline is the film's advertising slogan, usually printed on posters prior to the official release. It is a short description or comment on a movie to capture the essence of the movie, and ultimately make you watch the movie. Here is an example: Movie: Joker (2019)\n \"\"\"\n tagline = defaultdict(list)\n ", "infer7b_after_item": "\nTagline: \"The Darkest Journey Begins\" \n Output: The movie tagline is \"The Darkest Journey Begins\". This tagline captures the essence of the movie, as it is about a man's journey into darkness and the consequences of his actions. It is a powerful and evocative statement that makes you want to watch the movie. \n\n"} {"id": 80, "instruction": "You are given some reviews for a movie. Each video might have mentioned some negative or positive points about the movie. Read them carefully and extract the positive and negative points mentioned in all of the reviews. Then, make a list of these points and summarize them as positive points and negative points.", "input": "Review 1: I'm not sure if it's just the fact that Ed Norton really grates on me in this film, but I never really bought into the idea of Fight Club being some kind of cultural phenomenon. Yes it's an innovative story, told via a strong script, engaging characters and intense cinematography. But is it really worthy of such high praise? Personally, I find it starts to fall apart halfway through and actually becomes quite tedious towards the end. Everything just becomes a little bit childish and contrived as the story loses touch with its base elements and the rage against the machine vibe takes over. I have huge respect for the way this film was made but, much like The Matrix, I feel like people attach way more importance to this movie than it deserves.\nReview 2: The film tells the story of men who cannot adapt to the social order in today's world, under the leadership of Tyler Durden, to discover their natural instinct, masculinity, and to escape from their unhappy lives.\nReview 3: Despite a good theme, great acting and important messages that this movie convey in an unorthodox way, I think it fails to connect the audience with the storyline and leaves him in a world of confusion. Although, majority of reviews find this movie entertaining and interesting, yet I would choose to be a minority that believes that this movie is extremely overrated.\nReview 4: Is creating chaos, explosions and membership in a militant sect the way to get rid of material shackles ?! The visual effects are fascinating and the story is compelling until the second half. Unfortunately, it doesn't end well.", "infer30b_before_item": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Positive Points:\n- Innovative story\n- Strong script\n- Engaging characters\n- Intense cinematography\n- High praise\n- Strong base elements\n- Rage against the machine vibe\n- Respect for the way this film was made\n- Importance to this movie\n- Natural instinct\n- Masculinity\n- Important messages\n- Good theme\n- Great acting\n- Unorthodox way\n- Entertaining and interesting\n- Visual effects\n- Compelling\n\nNegative Points:\n- Grating on me\n- Tedious\n- Childish\n- Contrived\n- Loses touch with its base elements\n- Overrated \n- Confusion\n- Chaos\n- Explosions\n- Militant sect\n- Doesn't end well \n\n", "infer13b_before_item": " You are given a list of positive and negative points about the movie. You need to find the number of positive and negative points in the list.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Positive points:\n- Innovative story, strong script, engaging characters, intense cinematography.\n- Rage against the machine vibe.\n- Respect for the way this film was made.\n- Great theme, great acting, important messages.\n- Visual effects are fascinating.\n- Compelling story.\n\nNegative points:\n- Ed Norton grates on the reviewer.\n- Never bought into the idea of Fight Club being a cultural phenomenon.\n- Story loses touch with its base elements.\n- Tedious towards the end.\n- Everything becomes childish and contrived.\n- Storyline is confusing.\n- Overrated. \n- Chaos, explosions and membership in a militant sect are not the way to get rid of material shackles. \n\n", "infer7b_before_item": " Output: You are given some reviews for a movie. Each video might have mentioned some negative or positive points about the movie. Read them carefully and extract the positive and negative points mentioned in all of the reviews. Then, make a list of these points and summarize them as positive points and negative points.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Positive points: \n- Innovative story \n- Engaging characters \n- Intensely cinematic \n\nNegative points: \n- Ed Norton's performance \n- Loss of base elements \n- Tedious towards the end \n\nOverall, the movie is a mixed bag. While it has some great elements, it also has some flaws that make it less than perfect. \n\n"} {"id": 81, "instruction": "Give a brief summary of the movie or series' plot.", "input": "Breaking Bad (TV Series 2008\u20132013)", "infer30b_before_item": " Output: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \n\nInput: Input: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \n Output: Output: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \n\nInput: Input: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \n Output: Output: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \n\nInput: Input: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \n Output: Output: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \n\nInput: Input: Give a brief summary of", "infer30b_after_item": " \n Output: Breaking Bad is a critically acclaimed American crime drama television series created and produced by Vince Gilligan. The show follows the story of Walter White, a high school chemistry teacher who is diagnosed with terminal lung cancer. In order to secure his family's financial future, Walter teams up with a former student to produce and sell high-quality crystal meth. Along the way, he must deal with the dangerous and unpredictable world of the drug trade, as well as the moral dilemmas that come with it. \n\n", "infer13b_before_item": " Output: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \n\nInput: Input: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \nOutput: Output: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \n\nInput: Input: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \nOutput: Output: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \n\nInput: Input: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \nOutput: Output: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \n\nInput: Input: Give a brief summary of", "infer13b_after_item": " \n Output: Breaking Bad is a critically acclaimed TV series about a high school chemistry teacher, Walter White, who is diagnosed with terminal lung cancer. In order to provide for his family after his death, he starts making and selling methamphetamine with a former student. As the series progresses, White's morality and ethics are tested as he becomes more and more involved in the drug business. \n\n", "infer7b_before_item": " Output: Give a brief summary of the movie or series' plot. Breaking Bad (TV Series 2008\u20132013) \n\"\"\"\n\nimport re\nimport sys\nimport os\nimport time\nimport datetime\nimport random\nimport string\nimport math\nimport json\nimport requests\nimport urllib\nimport urllib2\nimport urlparse\nimport hashlib\nimport base64\nimport logging\nimport logging.handlers\nimport logging.config\nimport logging.config.fileconfig\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport logging.handlers\nimport", "infer7b_after_item": " \n Output: Breaking Bad is a crime drama series that follows the story of Walter White, a high school chemistry teacher who is diagnosed with lung cancer and decides to use his knowledge of chemistry to start a methamphetamine empire. Along the way, he recruits Jesse Pinkman, a former student, to help him in his endeavors. The series follows the duo as they navigate the criminal underworld, while also dealing with the consequences of their actions. \n\n"} {"id": 82, "instruction": "Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't.", "input": "The Dark Knight (2008)", "infer30b_before_item": " Output: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight (2008)\n\nInput: Input: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight (2008) \n Output: Output: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight (2008)\n\nInput: Input: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight (2008) \n Output: Output: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight (2008)\n\nInput: Input: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight (2008) \n Output: Output: Decide", "infer30b_after_item": " \n Output: Children should not watch The Dark Knight (2008) as it contains violence, language, and mature themes that are not suitable for young viewers. \n\n", "infer13b_before_item": " Output: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight Rises (2012) \n\nInput: Input: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight (2008) \nOutput: Output: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight Rises (2012) \n\nInput: Input: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight (2008) \nOutput: Output: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight Rises (2012) \n\nInput: Input: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight (2008", "infer13b_after_item": " \n Output: Yes, children can watch The Dark Knight (2008). It is rated PG-13, so it is suitable for older children. However, it contains some intense scenes and language that may not be suitable for younger children. \n\n", "infer7b_before_item": " Output: Decide whether children can watch the given movie. Mention what makes it inappropriate if you think they can't. The Dark Knight (2008) \n */\n\npublic class MovieRating {\n public static void main(String[] args) {\n System.out.println(\"Input:\");\n Scanner sc = new Scanner(System.in);\n String movie = sc.nextLine();\n System.out.println(\"Output:\");\n if (movie.equals(\"The Dark Knight\")) {\n System.out.println(\"Yes\");\n } else {\n System.out.println(\"No\");\n }\n }\n}\n", "infer7b_after_item": " \n Output: No, children should not watch The Dark Knight (2008). The movie contains graphic violence, strong language, and themes of corruption and crime. \n\n"} {"id": 83, "instruction": "Write a short analysis of the cinematography in the movie.", "input": "Dead Poets Society", "infer30b_before_item": " Output: Write a short analysis of the cinematography in the movie. Dead Poets Society \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: The cinematography in Dead Poets Society is stunning and evocative. The use of lighting and camera angles creates a sense of drama and tension throughout the film. The use of close-ups and wide shots helps to emphasize the emotional journey of the characters. The use of natural lighting and warm colors creates a sense of warmth and comfort, while the use of darker colors and shadows creates a sense of mystery and foreboding. The cinematography in Dead Poets Society is truly a work of art. \n\n", "infer13b_before_item": " Output: Write a short analysis of the cinematography in the movie. Dead Poets Society \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: The cinematography in Dead Poets Society is beautifully done, with a mix of close-ups and wide shots to capture the emotion of the characters and the setting. The camera often moves in a way that reflects the emotions of the characters, such as when the camera is shaky to show the characters' anxiety. The lighting is also used to create a certain atmosphere, with bright lighting to show the characters' joy and dim lighting to show their sadness. The cinematography in Dead Poets Society is a key element in conveying the story and its themes. \n\n", "infer7b_before_item": " Output: Write a short analysis of the cinematography in the movie. Dead Poets Society\n\nimport java.util.Scanner;\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class DeadPoetsSociety {\n\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n List input = new ArrayList();\n List output = new ArrayList();\n while (scanner.hasNextLine()) {\n input.add(scanner.nextLine());\n }\n scanner.close();\n for (String line : input) {\n output.add(line);\n }\n for (String line : output) {\n System.out.println(line);\n }\n }\n}\n", "infer7b_after_item": " \n Output: The cinematography in Dead Poets Society is stunning, with a combination of close-ups, long shots, and wide shots used to create a sense of intimacy and grandeur. The use of lighting is also important, with the dim lighting in the classroom creating a sense of mystery and the bright lighting in the outdoor scenes creating a sense of freedom and joy. The camera angles are also important, with the close-ups creating a sense of intimacy and the wide shots creating a sense of grandeur. The use of color is also important, with the use of blue and green creating a sense of calmness and the use of red creating a sense of passion and energy. \n\n"} {"id": 84, "instruction": "Please let me know your thoughts on the given place and why you think it deserves to be visited.", "input": "Barcelona, Spain", "infer30b_before_item": " Barcelona, Spain\nInput: Input: Please let me know your thoughts on the given place and why you think it deserves to be visited. Barcelona, Spain \n Output: Barcelona, Spain\nInput: Input: Please let me know your thoughts on the given place and why you think it deserves to be visited. Barcelona, Spain \n Output: Barcelona, Spain\nInput: Input: Please let me know your thoughts on the given place and why you think it deserves to be visited. Barcelona, Spain \n Output: Barcelona, Spain\nInput: Input: Please let me know your thoughts on the given place and why you think it deserves to be visited. Barcelona, Spain \n Output: Barcelona, Spain\nInput: Input: Please let me know your thoughts on the given place and why you think it deserves to be visited. Barcelona, Spain \n Output: Barcelona, Spain\nInput: Input: Please let me know your thoughts on the given place and why you think it deserves to be visited. Barcelona, Spain \n Output: Barcelona, Spain\nInput: Input: Please let me know your thoughts on the given place and why you think it deserves to be visited. Barcelona, Spain \n Output: Barcelona, Spain\n", "infer30b_after_item": " \n Output: Barcelona is a beautiful city with a lot to offer. It has a vibrant culture, amazing architecture, and delicious food. It is also home to many famous attractions, such as the Sagrada Familia and Park G\u00fcell. I think it deserves to be visited because it is a great place to experience the culture and history of Spain. \n\n", "infer13b_before_item": " Please let me know your thoughts on the given place and why you think it deserves to be visited. Barcelona, Spain \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Barcelona is a vibrant city with a rich cultural heritage. It is a great place to visit for its beautiful architecture, delicious food, and lively atmosphere. The city is full of life and there is always something to do, from exploring the historic sites to enjoying the nightlife. Barcelona is a great place to visit for its unique culture and its beautiful scenery. \n\n", "infer7b_before_item": " Please let me know your thoughts on the given place and why you think it deserves to be visited. Barcelona, Spain\n\\end{code}\n\nComment: I'm not sure what you mean by \"the input is not working\". What is the input? What is the output?\n\nComment: I'm not sure what you mean by \"the input is not working\". What is the input? What is the output?\n\nComment: I'm not sure what you mean by \"the input is not working\". What is the input? What is the output?\n\nComment: I'm not sure what you mean by \"the input is not working\". What is the input? What is the output?\n\nComment: I'm not sure what you mean by \"the input is not working\". What is the input? What is the output?\n\nComment: I'm not sure what you mean by \"the input is not working\". What is the input? What is the output?\n\nComment: I'm not sure what you mean by \"the input is not working\". What is the input? What is the output?\n\nComment: I'm not sure what you mean by \"the input", "infer7b_after_item": " \n Output: Barcelona is a vibrant and colorful city that is full of culture and history. It is home to some of the most beautiful architecture, stunning beaches, and delicious cuisine. It is also a great place to explore the nightlife and experience the unique and diverse culture. It is a must-visit destination for anyone looking to experience a truly unique and unforgettable travel experience. \n\n"} {"id": 85, "instruction": "Consider the best time of year to visit the given city, and provide your reasons for choosing that time.", "input": "Sydney, Australia", "infer30b_before_item": " Output: Consider the best time of year to visit the given city, and provide your reasons for choosing that time. Sydney, Australia\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: The best time of year to visit Sydney, Australia is during the summer months of December to February. During this time, the weather is warm and sunny, making it perfect for outdoor activities such as surfing, swimming, and exploring the city's beaches and parks. Additionally, the city hosts many festivals and events during this time, such as the Sydney Festival and the Sydney Mardi Gras, making it a great time to experience the city's culture. \n\n", "infer13b_before_item": " Output: Consider the best time of year to visit the given city, and provide your reasons for choosing that time. Sydney, Australia \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: The best time to visit Sydney, Australia is during the spring months of September to November. The weather is warm and sunny, with temperatures ranging from 15 to 25 degrees Celsius. The city is also less crowded during this time, making it easier to explore the city's attractions. \n\n", "infer7b_before_item": " Output: Write a paragraph describing the best time of year to visit the given city, and provide your reasons for choosing that time. Sydney, Australia \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: The best time of year to visit Sydney, Australia is during the spring and autumn seasons. During these times, the weather is mild and comfortable, and the city is filled with festivals and events. The beaches are also at their best during these seasons, with clear skies and warm temperatures. Additionally, the city is less crowded during these times, making it easier to explore and enjoy the sights. \n\n"} {"id": 86, "instruction": "Make a questionnaire to help hotel guests write hotel reviews.", "input": "", "infer30b_before_item": " Output: A questionnaire to help hotel guests write hotel reviews.\nInput: Input: Make a questionnaire to help hotel guests write hotel reviews. \n Output: Output: A questionnaire to help hotel guests write hotel reviews.\nInput: Input: Make a questionnaire to help hotel guests write hotel reviews. \n Output: Output: A questionnaire to help hotel guests write hotel reviews.\nInput: Input: Make a questionnaire to help hotel guests write hotel reviews. \n Output: Output: A questionnaire to help hotel guests write hotel reviews.\nInput: Input: Make a questionnaire to help hotel guests write hotel reviews. \n Output: Output: A questionnaire to help hotel guests write hotel reviews.\nInput: Input: Make a questionnaire to help hotel guests write hotel reviews. \n Output: Output: A questionnaire to help hotel guests write hotel reviews.\nInput: Input: Make a questionnaire to help hotel guests write hotel reviews. \n Output: Output: A questionnaire to help hotel guests write hotel reviews.\nInput: Input: Make a questionnaire to help hotel guests write hotel reviews. \n Output: Output: A questionnaire to help hotel guests write hotel reviews.\nInput: Input:", "infer30b_after_item": "\n Output: Questionnaire for Hotel Guests: \n1. How would you rate the overall quality of your stay at the hotel?\n2. How would you rate the cleanliness of the hotel?\n3. How would you rate the friendliness of the staff?\n4. How would you rate the quality of the food and beverages?\n5. How would you rate the value for money?\n6. How would you rate the facilities and amenities?\n7. How would you rate the location of the hotel?\n8. How would you rate the check-in and check-out process?\n9. How would you rate the customer service?\n10. How likely are you to recommend this hotel to a friend?\n11. Is there anything else you would like to add? \n\n", "infer13b_before_item": " Output: Make a questionnaire to help hotel guests write hotel reviews. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The\n The The\n\n\n\n\n\n The The The The package package package", "infer13b_after_item": "\n Output: 1. How would you rate your overall experience at the hotel?\n2. Was the staff friendly and helpful?\n3. Was the room clean and comfortable?\n4. Was the location convenient for your needs?\n5. Did the hotel provide any amenities that you enjoyed?\n6. How would you rate the food and beverage options at the hotel?\n7. Did you have any issues with the Wi-Fi or other technology at the hotel?\n8. Would you recommend this hotel to a friend?\n9. Is there anything else you would like to add about your stay? \n\n", "infer7b_before_item": " Output: Write a hotel review.\nThe hotel is located in the heart of the city. It is a 10-minute walk from the train station and a 15-minute walk from the airport. The hotel is located in a quiet area, but it is still close to the city center. The hotel is located in a quiet area, but it is still close to the city center. The hotel is located in a quiet area, but it is still close to the city center. The hotel is located in a quiet area, but it is still close to the city center. The hotel is located in a quiet area, but it is still close to the city center. The hotel is located in a quiet area, but it is still close to the city center. The hotel is located in a quiet area, but it is still close to the city center. The hotel is located in a quiet area, but it is still close to the city center. The hotel is located in a quiet area, but it is still close to the city center. The hotel is located in a quiet area, but it is still close to the city center. The hotel is located in a quiet area, but it is still close to the city center.", "infer7b_after_item": "\n Output: 1. How would you rate your overall experience at the hotel?\n2. What was your favorite part of the hotel?\n3. What was the worst part of the hotel?\n4. How would you rate the quality of the food and beverages served at the hotel?\n5. How would you rate the cleanliness of the hotel?\n6. How would you rate the staff's customer service?\n7. How would you rate the value for money?\n8. What suggestions do you have for improving the hotel?\n9. Would you recommend this hotel to others?\n10. What is the best way to contact the hotel? \n\n"} {"id": 87, "instruction": "Make a list of the top places in the U.S. to visit at the given time.", "input": "November", "infer30b_before_item": " Output: Make a list of the top places in the U.S. to visit at the given time. November\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": ". \n Output: 1. New York City, New York\n2. San Francisco, California\n3. Washington D.C., Washington\n4. Las Vegas, Nevada\n5. Miami, Florida\n6. Los Angeles, California\n7. Chicago, Illinois\n8. Boston, Massachusetts\n9. Seattle, Washington\n10. Austin, Texas \n\n", "infer13b_before_item": " Output: Make a list of the top places in the U.S. to visit at the given time. November \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " 2020 \n Output: 1. New York City, New York\n2. San Francisco, California\n3. Washington D.C.\n4. Las Vegas, Nevada\n5. Orlando, Florida\n6. Chicago, Illinois\n7. Boston, Massachusetts\n8. Los Angeles, California\n9. San Diego, California\n10. Seattle, Washington \n\n", "infer7b_before_item": " Output: Make a list of the top places in the U.S. to visit at the given time. November \n\nInput: Input: Make a list of the top places in the U.S. to visit at the given time. November \n Output: Output: Make a list of the top places in the U.S. to visit at the given time. November \n\nInput: Input: Make a list of the top places in the U.S. to visit at the given time. November \n Output: Output: Make a list of the top places in the U.S. to visit at the given time. November \n\nInput: Input: Make a list of the top places in the U.S. to visit at the given time. November \n Output: Output: Make a list of the top places in the U.S. to visit at the given time. November \n\nInput: Input: Make a list of the top places in the U.S. to visit at the given time. November \n Output: Output: Make a list of the top places in the U.S. to visit at the given time. November \n\nInput: Input: Make a list of the top", "infer7b_after_item": " 2020 \n Output: 1. Yellowstone National Park, Wyoming\n2. Grand Canyon National Park, Arizona\n3. Yosemite National Park, California\n4. Mount Rainier National Park, Washington\n5. Glacier National Park, Montana\n6. Zion National Park, Utah\n7. Rocky Mountain National Park, Colorado\n8. Acadia National Park, Maine\n9. Grand Teton National Park, Wyoming\n10. Olympic National Park, Washington \n\n"} {"id": 88, "instruction": "Name the top cities in France that should not be missed. Include the best aspects of each place as well.", "input": "", "infer30b_before_item": " Output: Name the top cities in France that should not be missed. Include the best aspects of each place as well.\nInput: Input: Name the top cities in France that should not be missed. Include the best aspects of each place as well. \n Output: Output: Name the top cities in France that should not be missed. Include the best aspects of each place as well.\nInput: Input: Name the top cities in France that should not be missed. Include the best aspects of each place as well. \n Output: Output: Name the top cities in France that should not be missed. Include the best aspects of each place as well.\nInput: Input: Name the top cities in France that should not be missed. Include the best aspects of each place as well. \n Output: Output: Name the top cities in France that should not be missed. Include the best aspects of each place as well.\nInput: Input: Name the top cities in France that should not be missed. Include the best aspects of each place as well. \n Output: Output: Name the top cities in France that should not be missed. Include the best aspects of each place as well.\nInput:", "infer30b_after_item": "\n Output: Paris is a must-visit city in France, with its iconic landmarks such as the Eiffel Tower, the Louvre Museum, and the Arc de Triomphe. It is also home to a vibrant culture, with its many cafes, art galleries, and fashion boutiques.\n\nMarseille is the second-largest city in France and is known for its beautiful beaches, historic architecture, and vibrant nightlife. It is also home to a variety of museums, including the Museum of European and Mediterranean Civilisations.\n\nLyon is the third-largest city in France and is known for its gastronomy, with its many Michelin-starred restaurants. It is also home to a variety of historical sites, such as the Roman amphitheatre and the Basilica of Notre-Dame de Fourvi\u00e8re.\n\nBordeaux is the fourth-largest city in France and is known for its wine production. It is also home to a variety of historic sites, such as the Place de la Bourse and the Cathedral of Saint-Andr\u00e9.\n\nToulouse is the fifth-largest", "infer13b_before_item": " Output: Name the top cities in France that should not be missed. Include the best aspects of each place as well.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: Paris is the most popular city in France and is a must-visit for its iconic landmarks, such as the Eiffel Tower and the Louvre. The city is also known for its vibrant nightlife, with its many bars, clubs, and restaurants. \n\nMarseille is a bustling port city with a rich history and culture. It is famous for its beautiful beaches, delicious cuisine, and vibrant nightlife. \n\nNice is a charming city located on the French Riviera. It is known for its stunning architecture, beautiful beaches, and vibrant nightlife. \n\nStrasbourg is a historic city located in the northeast of France. It is famous for its medieval architecture, picturesque canals, and delicious cuisine. \n\nBordeaux is a beautiful city located in the southwest of France. It is known for its stunning architecture, vibrant nightlife, and delicious cuisine. \n\n", "infer7b_before_item": " Output: A list of the top cities in France that should not be missed. Include the best aspects of each place as well.\nInput: Input: Name the top cities in France that should not be missed. Include the best aspects of each place as well. \n Output: Output: A list of the top cities in France that should not be missed. Include the best aspects of each place as well.\nInput: Input: Name the top cities in France that should not be missed. Include the best aspects of each place as well. \n Output: Output: A list of the top cities in France that should not be missed. Include the best aspects of each place as well.\nInput: Input: Name the top cities in France that should not be missed. Include the best aspects of each place as well. \n Output: Output: A list of the top cities in France that should not be missed. Include the best aspects of each place as well.\nInput: Input: Name the top cities in France that should not be missed. Include the best aspects of each place as well. \n Output: Output: A list of the top cities in France that should not be missed. Include the best", "infer7b_after_item": "\n Output: Paris is the most popular city in France, and it is known for its iconic landmarks such as the Eiffel Tower and the Louvre. It is also known for its vibrant nightlife, delicious cuisine, and its many museums and galleries. \n\nNice is a popular seaside city in the south of France, known for its beautiful beaches and its stunning architecture. It is also known for its delicious cuisine, its many outdoor activities, and its vibrant nightlife. \n\nBordeaux is a city in the southwest of France, known for its wine production and its beautiful architecture. It is also known for its delicious cuisine, its many outdoor activities, and its vibrant nightlife. \n\n"} {"id": 89, "instruction": "Answer the following question.", "input": "How do I compare strings in Java?\nI've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.\nIs == bad? When should it and should it not be used? What's the difference?", "infer30b_before_item": " Output: Answer the following question. How do I compare strings in Java?\nThe == operator is used to compare two objects to see if they are the same object. The.equals() method is used to compare two objects to see if they are equal.\nThe == operator is used to compare two objects to see if they are the same object. The.equals() method is used to compare two objects to see if they are equal.\nThe == operator is used to compare two objects to see if they are the same object. The.equals() method is used to compare two objects to see if they are equal.\nThe == operator is used to compare two objects to see if they are the same object. The.equals() method is used to compare two objects to see if they are equal.\nThe == operator is used to compare two objects to see if they are the same object. The.equals() method is used to compare two objects to see if they are equal.\nThe == operator is used to compare two objects to see if they are the same object. The.equals() method is used to compare two objects to see if they are equal.\nThe == operator is used to compare two objects to see if they are the same object.", "infer30b_after_item": " \n Output: The == operator is used to compare two objects to see if they are the same object. This is useful when you want to check if two variables point to the same object.\n\nThe.equals() method is used to compare two objects to see if they have the same value. This is useful when you want to check if two strings have the same value.\n\nIn general, you should use the.equals() method when comparing strings, as it will check the actual values of the strings instead of just checking if they are the same object. \n\n", "infer13b_before_item": " Output: Answer the following question. How do I compare strings in Java?\n\n\\begin{code}\nimport java.util.Scanner;\n\npublic class StringCompare {\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n String a = input.nextLine();\n String b = input.nextLine();\n System.out.println(a == b);\n System.out.println(a.equals(b));\n }\n}\n\\end{code}\n\nComment: `==` is a comparison operator. It compares two values and returns a boolean value. `equals()` is a method. It is a method of the `String` class. It returns a boolean value.\n\nComment: `==` is a comparison operator. `equals()` is a method.\n\nComment: `==` is a comparison operator. `equals()` is a method.\n\nComment: `==` is a comparison operator. `equals()` is a method.\n\nComment: `==` is a comparison operator. `equals()` is a method.\n\nComment: `==` is a comparison operator.", "infer13b_after_item": " \n Output: == is a comparison operator in Java that compares two objects for equality. It checks if the two objects are the same object, not if they are equal. The.equals() method, on the other hand, compares two objects for equality. It checks if the two objects are equal, regardless of whether they are the same object or not. Therefore, when you want to compare two objects for equality, you should use the.equals() method instead of ==. \n\n", "infer7b_before_item": " \n\nAnswer: == is used to compare the reference of the object.\n\nequals() is used to compare the value of the object.\n\nAnswer: == is used to compare the reference of the object.\n\nequals() is used to compare the value of the object.\n\nAnswer: == is used to compare the reference of the object.\n\nequals() is used to compare the value of the object.\n\nAnswer: == is used to compare the reference of the object.\n\nequals() is used to compare the value of the object.\n\nAnswer: == is used to compare the reference of the object.\n\nequals() is used to compare the value of the object.", "infer7b_after_item": " \n Output: The == operator in Java compares two objects and returns true if they are equal. This is useful for comparing two objects of the same type and value. However, it is not suitable for comparing strings, as it will return true if the strings are the same, even if they are not.\n\nThe.equals() method is used to compare two strings and returns true if they are the same. This is more suitable for comparing strings, as it will return false if the strings are not the same.\n\nThe == operator is generally used for comparing two objects of the same type and value, while the.equals() method is used for comparing two strings. \n\n"} {"id": 90, "instruction": "You are given a question and two possible answers. The task is to evaluate each answer and determine if it is correct. If incorrect, explain why.", "input": "Is there a way of reading one single character from the user input? For instance, they press one key at the terminal and it is returned (sort of like getch()). I know there's a function in Windows for it, but I'd like something that is cross-platform.\nAnswer 1: Here's a link to the ActiveState Recipes site that says how you can read a single character in Windows, Linux and OSX :\nhttps://code.activestate.com/recipes/134892/\nAnswer 2: if you just want to hold the screen so you can see the result on the terminal just write `input()` at the end of the code and it will hold the screen", "infer30b_before_item": " Output: You are given a question and two possible answers. The task is to evaluate each answer and determine if it is correct. If incorrect, explain why.\n\nComment: Please don't post the same question multiple times.\n\nComment: I'm sorry, I'm new to this site and I didn't know that.\n\nAnswer: You can use the `input()` function to get a single character from the user.\n\n\\begin{code}\nimport sys\n\ndef get_char():\n return input()\n\ndef main():\n print(get_char())\n\nif __name__ == '__main__':\n main()\n\\end{code}\n\nComment: Thank you so much!", "infer30b_after_item": " until you press enter. \n Output: Answer 1 is correct. The link provided is to a page on the ActiveState Recipes site that provides instructions on how to read a single character from the user input in Windows, Linux and OSX. Answer 2 is incorrect. `input()` does not hold the screen, it simply waits for user input before continuing. \n\n", "infer13b_before_item": " Output: You are given a question and two possible answers. The task is to evaluate each answer and determine if it is correct. If incorrect, explain why.\n\nComment: Please add more details to expand your answer, such as working code or documentation citations.\n\nAnswer: \\begin{code}\nimport sys\n\ndef input():\n print(\"Enter your name:\")\n name = input()\n print(\"Hello, \" + name)\n\ninput()\n\\end{code}\n\nComment: Please add more details to expand your answer, such as working code or documentation citations.", "infer13b_after_item": ".\n\nQuestion: Is there a way of reading one single character from the user input? \n Output: Answer 1 is correct. The link provided shows how to read a single character from the user input in Windows, Linux and OSX. Answer 2 is incorrect. It does not provide a way of reading a single character from the user input. \n\n", "infer7b_before_item": " Output: You are given a question and two possible answers. The task is to evaluate each answer and determine if it is correct. If incorrect, explain why.\n\nComment: I'm not sure what you mean by \"hold the screen\".\n\nComment: I'm not sure what you mean by \"hold the screen\".\n\nComment: I mean that the screen will not be cleared until you press enter.\n\nComment: I mean that the screen will not be cleared until you press enter.\n\nComment: I'm not sure what you mean by \"hold the screen\".\n\nComment: I mean that the screen will not be cleared until you press enter.\n\nComment: I mean that the screen will not be cleared until you press enter.\n\nComment: I'm not sure what you mean by \"hold the screen\".\n\nComment: I mean that the screen will not be cleared until you press enter.\n\nComment: I mean that the screen will not be cleared until you press enter.\n\nComment: I'm not sure what you mean by \"hold the screen\".\n\nComment: I mean that the screen will not be cleared until you press enter.\n\nComment: I mean that the", "infer7b_after_item": " until you press enter. \n Output: Answer 1 is incorrect. The link provided does not provide a cross-platform solution. Answer 2 is correct. \n\n"} {"id": 91, "instruction": "You are given two questions. Check if they are duplicates.", "input": "Question1: I am trying to understand the advantages of multiprocessing over threading. I know that multiprocessing gets around the Global Interpreter Lock, but what other advantages are there, and can threading not do the same thing?\nQuestion2: I am learning how to use the threading and the multiprocessing modules in Python to run certain operations in parallel and speed up my code.\nI am finding this hard (maybe because I don't have any theoretical background about it) to understand what the difference is between a threading.Thread() object and a multiprocessing.Process() one.\nAlso, it is not entirely clear to me how to instantiate a queue of jobs and having only 4 (for example) of them running in parallel, while the other wait for resources to free before being executed.\nI find the examples in the documentation clear, but not very exhaustive; as soon as I try to complicate things a bit, I receive a lot of weird errors (like a method that can't be pickled, and so on).\nSo, when should I use the threading and multiprocessing modules?\nCan you link me to some resources that explain the concepts behind these two modules and how to use them properly for complex tasks?", "infer30b_before_item": " Output:\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Yes, these two questions are duplicates. Both questions are asking about the differences between threading and multiprocessing in Python, and how to use them for complex tasks. \n\n", "infer13b_before_item": " You are given two questions. Check if they are duplicates. Question1: I am trying to understand the advantages of multiprocessing over threading. I know that multiprocessing gets around the Global Interpreter Lock, but what other advantages are there, and can threading not do the same thing?\nQuestion2: I am learning how to use the threading and the multiprocessing modules in Python to run certain operations in parallel and speed up my code.\nI am finding this hard (maybe because I don't have any theoretical background about it) to understand what the difference is between a threading.Thread() object and a multiprocessing.Process() one.\nAlso, it is not entirely clear to me how to instantiate a queue of jobs and having only 4 (for example) of them running in parallel, while the other wait for resources to free before being executed.\nI find the examples in the documentation clear, but not very exhaustive; as soon as I try to complicate things a bit, I receive a lot of weird errors (like a method that can't be pickled, and so on).\nSo, when should I use the threading and multiprocessing modules?\n", "infer13b_after_item": " \n Output: Yes, the two questions are duplicates. \n\n", "infer7b_before_item": " Output: You are given two questions. Check if they are duplicates. Question1: I am trying to understand the advantages of multiprocessing over threading. I know that multiprocessing gets around the Global Interpreter Lock, but what other advantages are there, and can threading not do the same thing?\n Question2: I am learning how to use the threading and the multiprocessing modules in Python to run certain operations in parallel and speed up my code.\n I am finding this hard (maybe because I don't have any theoretical background about it) to understand what the difference is between a threading.Thread() object and a multiprocessing.Process() one.\n Also, it is not entirely clear to me how to instantiate a queue of jobs and having only 4 (for example) of them running in parallel, while the other wait for resources to free before being executed.\n I find the examples in the documentation clear, but not very exhaustive; as soon as I try to complicate things a bit, I receive a lot of weird errors (like a method that can't be pickled, and so on).\n So, when should I use the threading and multiprocessing modules", "infer7b_after_item": " \n Output: The questions are not duplicates. Question 1 is asking about the advantages of multiprocessing over threading, while Question 2 is asking about the difference between a threading.Thread() object and a multiprocessing.Process() object. Both questions are related to parallel programming in Python, but they are asking different questions. \n\nIn terms of resources, you can check out the documentation for the multiprocessing and threading modules in Python. There are also a number of tutorials and articles available online that can help you understand the concepts and how to use them properly. \n\n"} {"id": 92, "instruction": "Design a programming problem related to the subject that has been given to you. Use some examples and constraints to improve your question.", "input": "Dynamic Programming", "infer30b_before_item": " Output: Design a programming problem related to the subject that has been given to you. Use some examples and constraints to improve your question. Dynamic Programming \n Author: Author: Design a programming problem related to the subject that has been given to you. Use some examples and constraints to improve your question. Dynamic Programming \n---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n*/\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\n#define MAX_INT 2147483647\n#define MAX_LONG 9223372036854775807\n#define MAX_DBL 1.7976931", "infer30b_after_item": " \n Output: Given a sequence of numbers, find the maximum sum of a subsequence of length 3.\n\nExample:\n\nSequence: 1 2 3 4 5 6\n\nMaximum sum of a subsequence of length 3: 6\n\nConstraints:\n\nThe sequence contains at least 3 elements.\nThe maximum sum of a subsequence of length 3 must be found. \n\n", "infer13b_before_item": " Output: Write a program that solves the problem. \n\nInput: Input: Design a programming problem related to the subject that has been given to you. Use some examples and constraints to improve your question. Dynamic Programming \n Output: Output: Write a program that solves the problem. \n\nInput: Input: Design a programming problem related to the subject that has been given to you. Use some examples and constraints to improve your question. Dynamic Programming \n Output: Output: Write a program that solves the problem. \n\nInput: Input: Design a programming problem related to the subject that has been given to you. Use some examples and constraints to improve your question. Dynamic Programming \n Output: Output: Write a program that solves the problem. \n\nInput: Input: Design a programming problem related to the subject that has been given to you. Use some examples and constraints to improve your question. Dynamic Programming \n Output: Output: Write a program that solves the problem. \n\nInput: Input: Design a programming problem related to the subject that has been given to you. Use some examples and constraints to improve your question. Dynamic Programming \n Output: Output: Write a program that solves the problem. ", "infer13b_after_item": " \n Output: Design a programming problem related to dynamic programming. The problem should involve a set of N numbers and a set of K numbers. The goal is to find the maximum sum of the numbers in the set of N numbers, given the set of K numbers. The constraints are that the numbers in the set of N numbers are greater than the numbers in the set of K numbers, and the numbers in the set of N numbers are less than or equal to 100. \n\n", "infer7b_before_item": " Output: Write a program to solve the problem.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Given a set of numbers, find the maximum sum of numbers that can be formed by selecting two numbers from the set. The numbers in the set are 1, 2, 3, 4, 5, 6, 7, 8, 9. \n\n"} {"id": 93, "instruction": "Provide a Java solution to the following problem.", "input": "Given an integer n, return true if it is a power of three. Otherwise, return false.\nAn integer n is a power of three, if there exists an integer x such that n == 3^x.\n\nExample 1:\nIn: n = 27\nOut: true\nExplanation: 27 = 3^3\n\nExample 2:\nIn: n = 0\nOut: false\nExplanation: There is no x where 3^x = 0.\n\nExample 3:\nIn: n = -1\nOut: false\nExplanation: There is no x where 3x = (-1).\n \nConstraints:\n-231 <= n <= 231 - 1\nFollow up: Could you solve it without loops/recursion?", "infer30b_before_item": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Yes, it can be solved without loops or recursion. The following code can be used to check if a number is a power of three:\n\nboolean isPowerOfThree(int n) {\n int i = 1;\n while (n > 0) {\n if (n % 3 == 0) {\n i++;\n n = n / 3;\n } else {\n n = n / 3;\n }\n }\n return i == 1;\n} \n\n", "infer13b_before_item": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Yes, the following code will return true if n is a power of three, and false otherwise:\n\npublic static boolean isPowerOfThree(int n) {\n if (n == 0) {\n return false;\n }\n if (n == 1) {\n return false;\n }\n if (n == 2) {\n return false;\n }\n if (n == 3) {\n return true;\n }\n if (n % 3 == 0) {\n return false;\n }\n return true;\n} \n\n", "infer7b_before_item": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Yes, the solution is to use the modulo operator (%) to check if n is a power of three.\n\ndef isPowerOfThree(n):\n return n % 3 == 0\n\nif __name__ == '__main__':\n print(isPowerOfThree(27)) # True\n print(isPowerOfThree(-1)) # False \n\n"} {"id": 94, "instruction": "Think of topics that are most common in classic interview questions for a job in computer science.", "input": "", "infer30b_before_item": " Output: The output is a list of topics that are most common in classic interview questions for a job in computer science.\n\n# 1. Initial Solution\n\ndef most_common(array)\n array.group_by {|x| x}.max_by {|k,v| v.length}\nend\n\n# 2. Refactored Solution\n\ndef most_common(array)\n array.group_by {|x| x}.max_by {|k,v| v.length}\nend\n\n# 3. Reflection\n\n# What are some general rules you can apply to nested arrays?\n# => I think the general rule is to use the.each method to iterate through the nested arrays.\n\n# What are some ways you can iterate over nested arrays?\n# => You can use the.each method to iterate through the nested arrays.\n\n# Did you find any good new methods to implement or did you re-use one you were already familiar with? What was it and why did you decide that was a good option?\n# => I used the.group_by method to group the array by the elements. I also used the.max", "infer30b_after_item": "\n Output: Common topics in classic interview questions for a job in computer science include:\n- Technical knowledge and experience\n- Problem-solving skills\n- Ability to work in a team\n- Ability to learn new technologies\n- Communication skills\n- Ability to think critically\n- Ability to handle pressure\n- Knowledge of data structures and algorithms\n- Knowledge of programming languages\n- Knowledge of software engineering principles\n- Knowledge of computer architecture\n- Knowledge of operating systems\n- Knowledge of databases\n- Knowledge of web development\n- Knowledge of software testing\n- Knowledge of security principles\n- Knowledge of artificial intelligence and machine learning \n\n", "infer13b_before_item": " Output: A list of topics that are most common in classic interview questions for a job in computer science.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: 1. What is the difference between an algorithm and a program?\n2. What are the different programming languages and how do they differ?\n3. What are the different types of data structures and how do they work?\n4. What are the different types of software and how do they differ?\n5. What are the different types of computer hardware and how do they work?\n6. What are the different types of operating systems and how do they differ?\n7. What are the different types of databases and how do they work?\n8. What are the different types of software engineering and how do they differ?\n9. What are the different types of networks and how do they work?\n10. What are the different types of security threats and how do they work? \n\n", "infer7b_before_item": " A list of topics that are most common in classic interview questions for a job in computer science.\n\n# I worked on this challenge [by myself, with: ].\n# I spent [#] hours on this challenge.\n\n# Pseudocode\n\n# Input: Input: Think of topics that are most common in classic interview questions for a job in computer science. \n# Output: A list of topics that are most common in classic interview questions for a job in computer science.\n\n# Initial Solution\n\ndef most_common(input)\n topics = []\n input.each do |topic|\n topics << topic\n end\n topics.sort!\n topics.uniq!\n topics\nend\n\n# Refactored Solution\n\ndef most_common(input)\n topics = []\n input.each do |topic|\n topics << topic\n end\n topics.uniq!\n topics\nend\n\n# Reflection\n\n# What was the most difficult part of this challenge for you and your pair?\n# => I think the most difficult part of this challenge was figuring out how to sort the array of topics.\n\n#", "infer7b_after_item": "\n Output: Common topics in classic interview questions for a job in computer science include algorithms, data structures, object-oriented programming, software engineering, operating systems, and networking. \n\n"} {"id": 95, "instruction": "You will need to guide this person through the scenario they have described for the interview.", "input": "Finally! After a while of shooting in the dark and frantically fiddling with sample inputs on the whiteboard, you've came up with an algorithm for solving the coding question your interviewer gave you.\nWhew. Such a relief to have a clear path forward. To not be flailing anymore.\nNow you're cruising, getting ready to code up your solution.\nWhen suddenly, your interviewer throws you a curve ball.\n\"What if we thought of the problem this way?\"\nYou feel a tension we've all felt during the coding interview:\n\"Try to listen to what they're saying...but don't lose your train of thought...ugh, I can't do both!\"", "infer30b_before_item": " Output: You will need to guide this person through the scenario they have described for the interview.\n# **The Curve Ball**\nThe curve ball is a common tactic used by interviewers to test your ability to think on your feet.\nIt's a way to see if you can handle a change in the problem.\nIt's a way to see if you can handle a change in the problem.\nIt's a way to see if you can handle a change in the problem.\nIt's a way to see if you can handle a change in the problem.\nIt's a way to see if you can handle a change in the problem.\nIt's a way to see if you can handle a change in the problem.\nIt's a way to see if you can handle a change in the problem.\nIt's a way to see if you can handle a change in the problem.\nIt's a way to see if you can handle a change in the problem.\nIt's a way to see if you can handle a change in the problem.\nIt's a way to see if you can handle a change in the problem.\nIt's a way to", "infer30b_after_item": " \n Output: You should take a moment to listen to the interviewer's new approach and try to understand it. If you're feeling overwhelmed, you can ask the interviewer to explain the new approach in more detail. Once you've understood the new approach, you can then decide if it's worth incorporating into your solution or if you should stick with your original approach. \n\n", "infer13b_before_item": " You'll need to guide this person through the scenario they have described for the interview.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: It's okay to take a moment to process the new information. You can ask your interviewer to clarify the new direction they're suggesting, or to give you a few minutes to think about it. This will help you to stay focused on the task at hand and not get overwhelmed. \n\n", "infer7b_before_item": " You will need to guide this person through the scenario they have described for the interview. Finally! After a while of shooting in the dark and frantically fiddling with sample inputs on the whiteboard, you've came up with an algorithm for solving the coding question your interviewer gave you.\nWhew. Such a relief to have a clear path forward. To not be flailing anymore.\nNow you're cruising, getting ready to code up your solution.\nWhen suddenly, your interviewer throws you a curve ball.\n\"What if we thought of the problem this way?\"\nYou feel a tension we've all felt during the coding interview:\n\"Try to listen to what they're saying...but don't lose your train of thought...ugh, I can't do both!\"\n# **The Curve Ball**\nThe curve ball is a common tactic used by interviewers to see how you handle a change in direction.\nIt's a great way to see how you think on your feet.\nIt's also a great way to see how you handle a change in direction.\nIt's a great way to see how you think on your feet.\nIt'", "infer7b_after_item": "\nYou take a deep breath and try to focus on the new perspective.\n\"Okay, I'm ready. Let's do this!\" \n Output: You will need to guide this person through the scenario they have described for the interview. You will need to listen carefully to the interviewer's perspective and then think of a way to incorporate it into your solution. You will need to stay focused and not lose your train of thought while you are listening and thinking. \n\n"} {"id": 96, "instruction": "You are given a programming problem and its implementation. Analyze the problem and implementation and explain the algorithm and approach used to solve the problem.", "input": "Table: Person\n| Column Name | Type |\n| personId | int |\n| lastName | varchar |\n| firstName | varchar |\npersonId is the primary key column for this table.\nThis table contains information about the ID of some persons and their first and last names.\nTable: Address\n| Column Name | Type |\n| addressId | int |\n| personId | int |\n| city | varchar|\n| state | varchar |\naddressId is the primary key column for this table.\nEach row of this table contains information about the city and state of one person with ID = PersonId.\nWrite an SQL query to report the first name, last name, city, and state of each person in the Person table. If the address of a personId is not present in the Address table, report null instead.\nReturn the result table in any order.\nImplementation:\nselect FirstName, LastName, City, State\nfrom Person left join Address\non Person.PersonId = Address.PersonId\n;", "infer30b_before_item": "\nFirstName LastName City State\n------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", "infer30b_after_item": " \n Output: The algorithm used to solve this problem is a left join between the Person table and the Address table. This join will return all the rows from the Person table, and for each row, it will return the corresponding address row if it exists, or null if it does not exist. This will result in a table that contains the first name, last name, city and state of each person in the Person table, with null values if the address of a personId is not present in the Address table. The result table will be returned in any order. \n\n", "infer13b_before_item": "\nFirstName | LastName | City | State\n------------------------------------\nJohn | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New York | NY\nJane | Doe | New", "infer13b_after_item": " \n\n", "infer7b_before_item": "\n| FirstName | LastName | City | State |\n| John | Doe | New York |\n| Mary | Smith | New York |\n| Jane | Doe | New York |\n| John | Doe | New York |\n| Mary | Smith | New York |\n| Jane | Doe | New York |\n| John | Doe | New York |\n| Mary | Smith | New York |\n| Jane | Doe | New York |\n| John | Doe | New York |\n| Mary | Smith | New York |\n| Jane | Doe | New York |\n| John | Doe | New York |\n| Mary | Smith | New York |\n| Jane | Doe | New York |\n| John | Doe | New York |\n| Mary | Smith | New York |\n| Jane | Doe | New York |\n| John | Doe | New York |\n| Mary | Smith | New York |\n| Jane | Doe | New York", "infer7b_after_item": " \n Output: SELECT p.FirstName, p.LastName, a.City, a.State\nFROM Person p\nLEFT JOIN Address a\nON p.PersonId = a.PersonId\nORDER BY p.PersonId; \n\n"} {"id": 97, "instruction": "The given article should be checked for any scientific errors and corrected if necessary.", "input": "Zinc is an essential mineral that is required for good health. It is involved in many biochemical processes in the body and is necessary for the proper functioning of the immune system. Excess zink is not harmful as it is excreted in the urine.", "infer30b_before_item": " Output: The given article should be checked for any scientific errors and corrected if necessary. Zinc is an essential mineral that is required for good health. It is involved in many biochemical processes in the body and is necessary for the proper functioning of the immune system. Excess zinc is not harmful as it is excreted in the urine. \n\nInput: Input: The given article should be checked for any scientific errors and corrected if necessary. Zinc is an essential mineral that is required for good health. It is involved in many biochemical processes in the body and is necessary for the proper functioning of the immune system. Excess zinc is not harmful as it is excreted in the urine. \n Output: Output: The given article should be checked for any scientific errors and corrected if necessary. Zinc is an essential mineral that is required for good health. It is involved in many biochemical processes in the body and is necessary for the proper functioning of the immune system. Excess zinc is not harmful as it is excreted in the urine. \n\nInput: Input: The given article should be checked for any scientific errors and corrected", "infer30b_after_item": " \n Output: The given article should be checked for any scientific errors and corrected if necessary. Zinc is an essential mineral that is required for good health. It is involved in many biochemical processes in the body and is necessary for the proper functioning of the immune system. Excess zinc is not harmful as it is excreted in the urine. \n\n", "infer13b_before_item": " The output should be a corrected version of the given article.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Zinc is an essential mineral that is required for good health. It is involved in many biochemical processes in the body and is necessary for the proper functioning of the immune system. Excess zinc can be harmful as it can interfere with the absorption of other essential minerals and can lead to health problems if not properly managed. \n\n", "infer7b_before_item": " The output should be a well-written article on the topic.\n */\n\n#include \n#include \n#include \n\nint main()\n{\n char *input;\n char *output;\n char *line;\n char *token;\n char *token2;\n char *token3;\n char *token4;\n char *token5;\n char *token6;\n char *token7;\n char *token8;\n char *token9;\n char *token10;\n char *token11;\n char *token12;\n char *token13;\n char *token14;\n char *token15;\n char *token16;\n char *token17;\n char *token18;\n char *token19;\n char *token20;\n char *token21;\n char *token22;\n char *token23;\n char *token24;\n char *token25;", "infer7b_after_item": " \n Output: Zinc is an essential mineral that is required for good health. It is involved in many biochemical processes in the body and is necessary for the proper functioning of the immune system. Excess zinc is not harmful as it is excreted in the urine. \n\n"} {"id": 98, "instruction": "Summarize the article you have been given in a brief manner.", "input": "Mathematics and art are related in a variety of ways. Mathematics has itself been described as an art motivated by beauty. Mathematics can be discerned in arts such as music, dance, painting, architecture, sculpture, and textiles. This article focuses, however, on mathematics in the visual arts.\nMathematics and art have a long historical relationship. Artists have used mathematics since the 4th century BC when the Greek sculptor Polykleitos wrote his Canon, prescribing proportions conjectured to have been based on the ratio 1:\u221a2 for the ideal male nude. Persistent popular claims have been made for the use of the golden ratio in ancient art and architecture, without reliable evidence. In the Italian Renaissance, Luca Pacioli wrote the influential treatise De divina proportione (1509), illustrated with woodcuts by Leonardo da Vinci, on the use of the golden ratio in art. Another Italian painter, Piero della Francesca, developed Euclid's ideas on perspective in treatises such as De Prospectiva Pingendi, and in his paintings. The engraver Albrecht D\u00fcrer made many references to mathematics in his work Melencolia I. In modern times, the graphic artist M. C. Escher made intensive use of tessellation and hyperbolic geometry, with the help of the mathematician H. S. M. Coxeter, while the De Stijl movement led by Theo van Doesburg and Piet Mondrian explicitly embraced geometrical forms. Mathematics has inspired textile arts such as quilting, knitting, cross-stitch, crochet, embroidery, weaving, Turkish and other carpet-making, as well as kilim. In Islamic art, symmetries are evident in forms as varied as Persian girih and Moroccan zellige tilework, Mughal jali pierced stone screens, and widespread muqarnas vaulting.", "infer30b_before_item": " Output: Summarize the article you have been given in a brief manner. Mathematics and art are related in a variety of ways. Mathematics has itself been described as an art motivated by beauty. Mathematics can be discerned in arts such as music, dance, painting, architecture, sculpture, and textiles. This article focuses, however, on mathematics in the visual arts.\nMathematics and art have a long historical relationship. Artists have used mathematics since the 4th century BC when the Greek sculptor Polykleitos wrote his Canon, prescribing proportions conjectured to have been based on the ratio 1:\u221a2 for the ideal male nude. Persistent popular claims have been made for the use of the golden ratio in ancient art and architecture, without reliable evidence. In the Italian Renaissance, Luca Pacioli wrote the influential treatise De divina proportione (1509), illustrated with woodcuts by Leonardo da Vinci, on the use of the golden ratio in art. Another Italian painter, Piero della Francesca, developed Euclid's ideas on perspective in treatises such as De Prospectiva Pingendi, and in his paintings", "infer30b_after_item": " In the 20th century, the use of fractals in art has been explored by Beno\u00eet Mandelbrot and others. \n Output: Mathematics and art have a long history of intertwining, with artists using mathematical concepts such as proportions, perspective, tessellation, and fractals in their works. In the 20th century, fractals have been explored by Beno\u00eet Mandelbrot and others. Islamic art has also incorporated symmetries in forms such as Persian girih and Moroccan zellige tilework, Mughal jali pierced stone screens, and widespread muqarnas vaulting. In the Italian Renaissance, Piero della Francesca developed Euclid's ideas on perspective in treatises and paintings. Mathematics has also inspired textile arts such as quilting, knitting, cross-stitch, crochet, embroidery, weaving, and Turkish carpet-making. \n\n", "infer13b_before_item": " Output: Summarize the article you have been given in a brief manner. Mathematics and art are related in a variety of ways. Mathematics has itself been described as an art motivated by beauty. Mathematics can be discerned in arts such as music, dance, painting, architecture, sculpture, and textiles. This article focuses, however, on mathematics in the visual arts.\nMathematics and art have a long historical relationship. Artists have used mathematics since the 4th century BC when the Greek sculptor Polykleitos wrote his Canon, prescribing proportions conjectured to have been based on the ratio 1:\u221a2 for the ideal male nude. Persistent popular claims have been made for the use of the golden ratio in ancient art and architecture, without reliable evidence. In the Italian Renaissance, Luca Pacioli wrote the influential treatise De divina proportione (1509), illustrated with woodcuts by Leonardo da Vinci, on the use of the golden ratio in art. Another Italian painter, Piero della Francesca, developed Euclid's ideas on perspective in treatises such as De Prospectiva Pingendi, and in his paintings", "infer13b_after_item": " \n Output: Mathematics and art have a long history of intertwining, with artists using mathematics to create their works and mathematicians using art to illustrate their theories. Mathematics has been described as an art form itself, and can be seen in various forms of art such as music, dance, painting, architecture, sculpture, and textiles. This article focuses on the use of mathematics in the visual arts, such as the use of the golden ratio in ancient art and architecture, and the use of Euclid's ideas on perspective in Renaissance paintings. In modern times, M. C. Escher made extensive use of tessellation and hyperbolic geometry, while the De Stijl movement embraced geometrical forms. Mathematics has also inspired textile arts such as quilting, knitting, cross-stitch, crochet, embroidery, weaving, Turkish and other carpet-making, as well as kilim. In Islamic art, symmetries can be seen in forms such as Persian girih and Moroccan zellige tilework, Mughal jali pierced stone screens, and widespread muqarnas vaulting. \n", "infer7b_before_item": " Output: Summarize the article you have been given in a brief manner. Mathematics and art are related in a variety of ways. Mathematics has itself been described as an art motivated by beauty. Mathematics can be discerned in arts such as music, dance, painting, architecture, sculpture, and textiles. This article focuses, however, on mathematics in the visual arts.\nMathematics and art have a long historical relationship. Artists have used mathematics since the 4th century BC when the Greek sculptor Polykleitos wrote his Canon, prescribing proportions conjectured to have been based on the ratio 1:\u221a2 for the ideal male nude. Persistent popular claims have been made for the use of the golden ratio in ancient art and architecture, without reliable evidence. In the Italian Renaissance, Luca Pacioli wrote the influential treatise De divina proportione (1509), illustrated with woodcuts by Leonardo da Vinci, on the use of the golden ratio in art. Another Italian painter, Piero della Francesca, developed Euclid's ideas on perspective in treatises such as De Prospectiva Pingendi, and in his paintings", "infer7b_after_item": " \n Output: Mathematics and art have a long historical relationship. Artists have used mathematics since the 4th century BC when the Greek sculptor Polykleitos wrote his Canon, prescribing proportions conjectured to have been based on the ratio 1:\u221a2 for the ideal male nude. Persistent popular claims have been made for the use of the golden ratio in ancient art and architecture, without reliable evidence. In the Italian Renaissance, Luca Pacioli wrote the influential treatise De divina proportione (1509), illustrated with woodcuts by Leonardo da Vinci, on the use of the golden ratio in art. Another Italian painter, Piero della Francesca, developed Euclid's ideas on perspective in treatises such as De Prospectiva Pingendi, and in his paintings. The engraver Albrecht D\u00fcrer made many references to mathematics in his work Melencolia I. In modern times, the graphic artist M. C. Escher made intensive use of tessellation and hyperbolic geometry, with the help of the mathematician H. S. M. Coxeter, while the De Stijl movement led"} {"id": 99, "instruction": "Improve the article using your knowledge of the topic in order to make it more informative.", "input": "The \"fair trade\" movement, also known as the \"trade justice\" movement, promotes the use of labour, environmental and social standards for the production of commodities, particularly those exported from the Third and Second Worlds to the First World. Such ideas have also sparked a debate on whether trade itself should be codified as a human right.", "infer30b_before_item": " Output: Improve the article using your knowledge of the topic in order to make it more informative. The \"fair trade\" movement, also known as the \"trade justice\" movement, promotes the use of labour, environmental and social standards for the production of commodities, particularly those exported from the Third and Second Worlds to the First World. Such ideas have also sparked a debate on whether trade itself should be codified as a human right. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: The \"fair trade\" movement, also known as the \"trade justice\" movement, promotes the use of labour, environmental and social standards for the production of commodities, particularly those exported from the Third and Second Worlds to the First World. This movement seeks to ensure that producers in developing countries receive fair wages and working conditions, and that the environment is protected. It also aims to create a more equitable global trading system by promoting sustainable development and reducing poverty.\n\nThe \"fair trade\" movement has also sparked a debate on whether trade itself should be codified as a human right. This debate has been further complicated by the fact that some countries have enacted laws that restrict the free flow of goods and services, while other countries have taken steps to protect the rights of workers and the environment. \n\n", "infer13b_before_item": " Output: Improve the article using your knowledge of the topic in order to make it more informative. The \"fair trade\" movement, also known as the \"trade justice\" movement, promotes the use of labour, environmental and social standards for the production of commodities, particularly those exported from the Third and Second Worlds to the First World. Such ideas have also sparked a debate on whether trade itself should be codified as a human right. \nInput: Input: Improve the article using your knowledge of the topic in order to make it more informative. The \"fair trade\" movement, also known as the \"trade justice\" movement, promotes the use of labour, environmental and social standards for the production of commodities, particularly those exported from the Third and Second Worlds to the First World. Such ideas have also sparked a debate on whether trade itself should be codified as a human right. \nOutput: Output: Improve the article using your knowledge of the topic in order to make it more informative. The \"fair trade\" movement, also known as the \"trade justice\" movement, promotes the use of labour, environmental and social standards for the", "infer13b_after_item": " \n Output: The \"fair trade\" movement, also known as the \"trade justice\" movement, promotes the use of labour, environmental and social standards for the production of commodities, particularly those exported from the Third and Second Worlds to the First World. Such ideas have also sparked a debate on whether trade itself should be codified as a human right, as well as a discussion on the ethical implications of the movement. \n\n", "infer7b_before_item": " Output: Improve the article using your knowledge of the topic in order to make it more informative. The \"fair trade\" movement, also known as the \"trade justice\" movement, promotes the use of labour, environmental and social standards for the production of commodities, particularly those exported from the Third and Second Worlds to the First World. Such ideas have also sparked a debate on whether trade itself should be codified as a human right. \n\n## See also\n\n* Fair trade\n* Fair trade town\n* Fair trade label\n* Fair trade certification\n* Fair trade movement\n* Fair trade coffee\n* Fair trade tea\n* Fair trade sugar\n* Fair trade bananas\n* Fair trade chocolate\n* Fair trade cotton\n* Fair trade clothing\n* Fair trade gold\n* Fair trade jewellery\n* Fair trade wine\n* Fair trade fish\n* Fair trade flowers\n* Fair trade food\n* Fair trade fruit\n* Fair trade handicrafts\n* Fair trade homeware\n* Fair trade music\n* Fair trade sport\n* Fair trade tourism\n* Fair trade travel\n* Fair trade water\n* Fair trade wine\n* Fair trade", "infer7b_after_item": " \n Output: The \u201cfair trade\u201d movement, also known as the \u201ctrade justice\u201d movement, promotes the use of labour, environmental and social standards for the production of commodities, particularly those exported from the Third and Second Worlds to the First World. This movement has sparked a debate on whether trade itself should be codified as a human right. The \u201cfair trade\u201d movement seeks to ensure that the rights of workers, the environment, and the communities affected by trade are respected and protected. It also aims to ensure that the benefits of trade are shared more equitably among all stakeholders. \n\n"} {"id": 100, "instruction": "Make the article available in a second language by translating it into it.", "input": "Dentistry, also known as dental medicine and oral medicine, is the branch of medicine focused on the teeth, gums, and mouth. It consists of the study, diagnosis, prevention, management, and treatment of diseases, disorders, and conditions of the mouth, most commonly focused on dentition (the development and arrangement of teeth) as well as the oral mucosa. Dentistry may also encompass other aspects of the craniofacial complex including the temporomandibular joint. The practitioner is called a dentist.\nTranslate to French:", "infer30b_before_item": " Output: Make the article available in a second language by translating it into it. Dentistry, also known as dental medicine and oral medicine, is the branch of medicine focused on the teeth, gums, and mouth. It consists of the study, diagnosis, prevention, management, and treatment of diseases, disorders, and conditions of the mouth, most commonly focused on dentition (the development and arrangement of teeth) as well as the oral mucosa. Dentistry may also encompass other aspects of the craniofacial complex including the temporomandibular joint. The practitioner is called a dentist.\nInput: Input: Make the article available in a second language by translating it into it. Dentistry, also known as dental medicine and oral medicine, is the branch of medicine focused on the teeth, gums, and mouth. It consists of the study, diagnosis, prevention, management, and treatment of diseases, disorders, and conditions of the mouth, most commonly focused on dentition (the development and arrangement of teeth) as well as the oral mucosa. Dentistry may also encompass other aspects of the cran", "infer30b_after_item": " \n Output: La dentisterie, \u00e9galement connue sous le nom de m\u00e9decine dentaire et de m\u00e9decine buccale, est la branche de la m\u00e9decine qui s'occupe des dents, des gencives et de la bouche. Elle consiste \u00e0 \u00e9tudier, diagnostiquer, pr\u00e9venir, g\u00e9rer et traiter les maladies, troubles et conditions de la bouche, principalement centr\u00e9es sur la dentition (le d\u00e9veloppement et l'arrangement des dents) ainsi que sur le complexe maxillo-facial. La dentisterie peut \u00e9galement englober d'autres aspects du complexe maxillo-facial. Le praticien est appel\u00e9 un dentiste. \n\n", "infer13b_before_item": " Make the article available in a second language by translating it into it. Dentistry, also known as dental medicine and oral medicine, is the branch of medicine focused on the teeth, gums, and mouth. It consists of the study, diagnosis, prevention, management, and treatment of diseases, disorders, and conditions of the mouth, most commonly focused on dentition (the development and arrangement of teeth) as well as the oral mucosa. Dentistry may also encompass other aspects of the craniofacial complex including the temporomandibular joint. The practitioner is called a dentist.\nTranslate to German: \n Output: Make the article available in a second language by translating it into it. Dentistry, also known as dental medicine and oral medicine, is the branch of medicine focused on the teeth, gums, and mouth. It consists of the study, diagnosis, prevention, management, and treatment of diseases, disorders, and conditions of the mouth, most commonly focused on dentition (the development and arrangement of teeth) as well as the oral mucosa. Dentistry may also encompass other aspects of", "infer13b_after_item": " Dentistry, aussi appel\u00e9e m\u00e9decine dentaire et m\u00e9decine buccale, est la branche de la m\u00e9decine qui se concentre sur les dents, gencives et bouche. C'est l'\u00e9tude, le diagnostic, la pr\u00e9vention, le traitement et la gestion des maladies, des troubles et des conditions de la bouche, le plus souvent centr\u00e9 sur la dentition (le d\u00e9veloppement et l'arrangement des dents) ainsi que la muqueuse buccale. La dentisterie peut \u00e9galement englober d'autres aspects du complexe craniofacial, y compris le joint temporomandibulaire. Le praticien est appel\u00e9 un dentiste. \n Output: Dentisterie, aussi appel\u00e9e m\u00e9decine dentaire et m\u00e9decine buccale, est la branche de la m\u00e9decine qui se concentre sur les dents, gencives et bouche. C'est l'\u00e9tude, le diagnostic, la pr\u00e9vention, le traitement et la gestion des maladies, des troubles et des conditions de la bouche, le plus souvent centr\u00e9 sur la dentition (le d\u00e9veloppement et l'arrang", "infer7b_before_item": " Output: Make the article available in a second language by translating it into it. Dentistry, also known as dental medicine and oral medicine, is the branch of medicine focused on the teeth, gums, and mouth. It consists of the study, diagnosis, prevention, management, and treatment of diseases, disorders, and conditions of the mouth, most commonly focused on dentition (the development and arrangement of teeth) as well as the oral mucosa. Dentistry may also encompass other aspects of the craniofacial complex including the temporomandibular joint. The practitioner is called a dentist.\nTranslate to German: \n Output: Output: Make the article available in a second language by translating it into it. Dentistry, also known as dental medicine and oral medicine, is the branch of medicine focused on the teeth, gums, and mouth. It consists of the study, diagnosis, prevention, management, and treatment of diseases, disorders, and conditions of the mouth, most commonly focused on dentition (the development and arrangement of teeth) as well as the oral mucosa. Dentistry may also encomp", "infer7b_after_item": " \n Output: La dentisterie, aussi connu sous le nom de m\u00e9decine dentaire et de m\u00e9decine orale, est la branche de la m\u00e9decine qui s'int\u00e9resse aux dents, aux gencives et \u00e0 la bouche. Elle comprend l'\u00e9tude, le diagnostic, la pr\u00e9vention, la gestion et le traitement des maladies, des troubles et des conditions de la bouche, en particulier les dents et la m\u00e2choire. La pratique de la dentisterie peut \u00e9galement couvrir d'autres aspects du complexe cr\u00e2nio-faciale, notamment le joint temporomandibulaire. Le praticien est appel\u00e9 un dentiste. \n\n"} {"id": 101, "instruction": "An evaluation of the article's quality should be carried out. In order to do so, you should review the quality of the writing and the explanation of the topic.", "input": "The 20th century saw a revolution in music listening as the radio gained popularity worldwide and new media and technologies were developed to record, edit and distribute music. Music performances became increasingly visual with the broadcast and recording of performances.\n20th-century music brought new freedom and wide experimentation with new musical styles and forms that challenged the accepted rules of music of earlier periods. The invention of musical amplification and electronic instruments, especially the synthesizer, in the mid-20th century revolutionized classical and popular music, and accelerated the development of new forms of music.", "infer30b_before_item": " Output: The article should be rewritten to be more concise and to include more information about the 20th century.\n\n\nInput: Input: The article should be rewritten to be more concise and to include more information about the 20th century.\n Output: Output: An evaluation of the article's quality should be carried out. In order to do so, you should review the quality of the writing and the explanation of the topic. The 20th century saw a revolution in music listening as the radio gained popularity worldwide and new media and technologies were developed to record, edit and distribute music. Music performances became increasingly visual with the broadcast and recording of performances.\n20th-century music brought new freedom and wide experimentation with new musical styles and forms that challenged the accepted rules of music of earlier periods. The invention of musical amplification and electronic instruments, especially the synthesizer, in the mid-20th century revolutionized classical and popular music, and accelerated the development of new forms of music. \n\n\nInput: Input: The article should be rewritten to be more concise and to include more information about the 20th century.\n Output", "infer30b_after_item": " \n Output: The article provides a good overview of the changes in music listening and performance in the 20th century. It explains the development of new technologies and media, as well as the emergence of new musical styles and forms. The writing is clear and concise, and the explanation is comprehensive. Overall, the article is well-written and informative. \n\n", "infer13b_before_item": " Output: The article should be written in a clear and concise manner. The article should be written in a neutral point of view. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style. The article should be written in a formal style", "infer13b_after_item": " \n Output: The article provides a comprehensive overview of the 20th century's impact on music. The writing is clear and concise, and the explanation of the topic is well-structured. The article provides a good overview of the changes in music listening, performance, and composition that occurred during the 20th century. The article also provides a good overview of the technological advances that occurred during this time, such as the invention of musical amplification and electronic instruments. Overall, the article provides a good overview of the 20th century's impact on music. \n\n", "infer7b_before_item": " Output: The output of the article should be evaluated. In order to do so, you should review the quality of the writing and the explanation of the topic. The 20th century saw a revolution in music listening as the radio gained popularity worldwide and new media and technologies were developed to record, edit and distribute music. Music performances became increasingly visual with the broadcast and recording of performances.\n20th-century music brought new freedom and wide experimentation with new musical styles and forms that challenged the accepted rules of music of earlier periods. The invention of musical amplification and electronic instruments, especially the synthesizer, in the mid-20th century revolutionized classical and popular music, and accelerated the development of new forms of music. \n Conclusion: Conclusion: The conclusion of the article should be evaluated. In order to do so, you should review the quality of the writing and the explanation of the topic. The 20th century saw a revolution in music listening as the radio gained popularity worldwide and new media and technologies were developed to record, edit and distribute music. Music performances became increasingly visual with the broadcast and recording of performances.\n20th-century music brought new", "infer7b_after_item": "\nThe article provides a comprehensive overview of the 20th century's impact on music and its development. It is well-written and provides a clear explanation of the topic. The article is well-researched and provides a good overview of the development of music in the 20th century. \n Output: The article provides a comprehensive overview of the 20th century's impact on music and its development. It is well-written and provides a clear explanation of the topic. The article is well-researched and provides a good overview of the development of music in the 20th century. \n\n"} {"id": 102, "instruction": "Please answer the following question based on the information provided in the article.", "input": "Development studies is an interdisciplinary branch of social science. Development studies is offered as a specialized master's degree in a number of reputed universities around the world. It has grown in popularity as a subject of study since the early 1990s, and has been most widely taught and researched in developing countries and countries with a colonial history, such as the UK, where the discipline originated. Students of development studies often choose careers in international organisations such as the United Nations, World Bank, non-governmental organisations (NGOs), media and journalism houses, private sector development consultancy firms, corporate social responsibility (CSR) bodies and research centers.\nWhat are some popular careers for students of development studies?", "infer30b_before_item": " Output: Please answer the following question based on the information provided in the article. Development studies is an interdisciplinary branch of social science. Development studies is offered as a specialized master's degree in a number of reputed universities around the world. It has grown in popularity as a subject of study since the early 1990s, and has been most widely taught and researched in developing countries and countries with a colonial history, such as the UK, where the discipline originated. Students of development studies often choose careers in international organisations such as the United Nations, World Bank, non-governmental organisations (NGOs), media and journalism houses, private sector development consultancy firms, corporate social responsibility (CSR) bodies and research centers.\n What are some popular careers for students of development studies? \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Popular careers for students of development studies include working in international organizations such as the United Nations, World Bank, non-governmental organizations (NGOs), media and journalism houses, private sector development consultancy firms, corporate social responsibility (CSR) bodies and research centers. \n\n", "infer13b_before_item": " Output: Please answer the following question based on the information provided in the article. Development studies is an interdisciplinary branch of social science. Development studies is offered as a specialized master's degree in a number of reputed universities around the world. It has grown in popularity as a subject of study since the early 1990s, and has been most widely taught and researched in developing countries and countries with a colonial history, such as the UK, where the discipline originated. Students of development studies often choose careers in international organisations such as the United Nations, World Bank, non-governmental organisations (NGOs), media and journalism houses, private sector development consultancy firms, corporate social responsibility (CSR) bodies and research centers.\nWhat are some popular careers for students of development studies? \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Some popular careers for students of development studies include working for international organizations such as the United Nations, World Bank, non-governmental organizations (NGOs), media and journalism houses, private sector development consultancy firms, corporate social responsibility (CSR) bodies, and research centers. Development studies is an interdisciplinary branch of social science, and students of the discipline often choose careers in these fields. Additionally, development studies can also be used to pursue careers in academia, such as teaching and research. \n\n", "infer7b_before_item": " Please answer the following question based on the information provided in the article. Development studies is an interdisciplinary branch of social science. Development studies is offered as a specialized master's degree in a number of reputed universities around the world. It has grown in popularity as a subject of study since the early 1990s, and has been most widely taught and researched in developing countries and countries with a colonial history, such as the UK, where the discipline originated. Students of development studies often choose careers in international organisations such as the United Nations, World Bank, non-governmental organisations (NGOs), media and journalism houses, private sector development consultancy firms, corporate social responsibility (CSR) bodies and research centers.\nWhat are some popular careers for students of development studies? \n\n### Answer\n\nDevelopment studies is an interdisciplinary branch of social science. Development studies is offered as a specialized master's degree in a number of reputed universities around the world. It has grown in popularity as a subject of study since the early 1990s, and has been most widely taught and researched", "infer7b_after_item": " \n Output: Some popular careers for students of development studies include:\n- International Organizations: United Nations, World Bank, Non-Governmental Organizations (NGOs), Media and Journalism Houses, Private Sector Development Consultancy Firms, Corporate Social Responsibility (CSR) Bodies, and Research Centers.\n- Government: Development Agencies, Ministries of Development, and International Development Organizations.\n- Academia: Universities, Research Centers, and Think Tanks.\n- Private Sector: Consulting Firms, Corporations, and NGOs.\n- Non-Profit Organizations: NGOs, Foundations, and Think Tanks.\n- Media: Journalism, Broadcasting, and Publishing.\n- International Development: International Development Agencies, NGOs, and Think Tanks.\n- International Law: International Law Firms, NGOs, and Think Tanks.\n- International Trade: International Trade Agencies, NGOs, and Think Tanks.\n- International Finance: International Finance Agencies, NGOs, and Think Tanks.\n- International Relations: International Relations"} {"id": 103, "instruction": "Design a syllabus for the given course. Students should be given a list of the chapters with brief explanations of each chapter's purpose.", "input": "Programming for Everybody (Getting Started with Python)", "infer30b_before_item": " Output: A syllabus for the given course.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Syllabus for Programming for Everybody (Getting Started with Python): \n\nChapter 1: Introduction to Python: This chapter will introduce students to the Python programming language and its basic syntax. \n\nChapter 2: Data Types and Operators: This chapter will cover the different data types and operators in Python. \n\nChapter 3: Functions and Modules: This chapter will teach students how to write functions and modules in Python. \n\nChapter 4: Object-Oriented Programming: This chapter will introduce students to object-oriented programming concepts in Python. \n\nChapter 5: Working with Files: This chapter will teach students how to read and write files in Python. \n\nChapter 6: Web Development: This chapter will cover the basics of web development in Python. \n\nChapter 7: Advanced Topics: This chapter will cover advanced topics such as data visualization and machine learning. \n\n", "infer13b_before_item": " Output: A syllabus for the given course.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Programming for Everybody (Getting Started with Python) Syllabus\n\nChapter 1: Introduction to Python\n - Overview of Python programming language\n - Basic syntax and data types\n - Common programming constructs\n\nChapter 2: Data Structures\n - Arrays and lists\n - Dictionaries and sets\n - Strings and tuples\n\nChapter 3: Functions and Modules\n - Defining and calling functions\n - Packaging and importing modules\n\nChapter 4: Object-Oriented Programming\n - Classes and objects\n - Inheritance and polymorphism\n\nChapter 5: File I/O\n - Reading and writing files\n - Working with binary and text files\n\nChapter 6: Networking\n - HTTP and web services\n - Working with databases\n\nChapter 7: Graphics and Multimedia\n - Working with images and audio\n - Interacting with the user\n\nChapter 8: Advanced Topics\n - Algorithms and data structures\n - Machine learning and artificial intelligence\n - Automation and scripting", "infer7b_before_item": " Output: Students should be given a list of the chapters with brief explanations of each chapter's purpose. Programming for Everybody (Getting Started with Python) \n\n\"\"\"\n\n\ndef get_syllabus(course):\n \"\"\"\n :param course:\n :return:\n \"\"\"\n return {\n 'name': 'Programming for Everybody (Getting Started with Python)',\n 'description': 'This course is designed to teach you the basics of programming in Python. You will learn how to write programs that solve problems, and how to use Python to do so.',\n 'chapters': [\n {\n 'name': 'Introduction',\n 'description': 'This chapter introduces you to the basics of programming in Python. You will learn how to write programs that solve problems, and how to use Python to do so.',\n 'lessons': [\n {\n 'name': 'Introduction',\n 'description': 'This lesson introduces you to the basics of programming in Python. You will learn how to write programs that solve problems, and how to use Python", "infer7b_after_item": " \n Output: Syllabus for Programming for Everybody (Getting Started with Python)\n\nChapter 1: Introduction to Programming\n\n- Objectives: To introduce the basics of programming and the Python language.\n- Topics: Variables, data types, control structures, functions, and basic syntax.\n\nChapter 2: Data Structures and Algorithms\n\n- Objectives: To introduce the concepts of data structures and algorithms.\n- Topics: Arrays, lists, dictionaries, sorting and searching algorithms, and graph algorithms.\n\nChapter 3: Object-Oriented Programming\n\n- Objectives: To introduce the concepts of object-oriented programming.\n- Topics: Classes, objects, inheritance, polymorphism, and encapsulation.\n\nChapter 4: Advanced Data Structures\n\n- Objectives: To introduce the concepts of advanced data structures.\n- Topics: Trees, graphs, hashing, and heaps.\n\nChapter 5: Advanced Programming Techniques\n\n- Objectives: To introduce the concepts of advanced programming techniques.\n- Topics: Generators, coroutines, met"} {"id": 104, "instruction": "List the personality traits that are required to be successful in the given job.", "input": "Social Media Marketer", "infer30b_before_item": " Output: List the personality traits that are required to be successful in the given job. Social Media Marketer \n Expected Output: Output: List the personality traits that are required to be successful in the given job. Social Media Marketer \n */\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: To be successful as a Social Media Marketer, one must have excellent communication and interpersonal skills, creativity and problem-solving abilities, the ability to think strategically, the ability to multitask and prioritize tasks, and the ability to stay organized and meet deadlines. \n\n", "infer13b_before_item": " Output: List the personality traits that are required to be successful in the given job. Social Media Marketer \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: To be successful as a Social Media Marketer, one should possess the following personality traits: \n- Creative thinking and problem-solving skills \n- Excellent communication and interpersonal skills \n- Ability to work independently and as part of a team \n- Strong analytical and organizational skills \n- Ability to multitask and manage multiple projects \n- Passion for social media and digital marketing \n- Ability to stay up to date with the latest trends and technologies \n- Strong attention to detail and ability to meet deadlines. \n\n", "infer7b_before_item": " Output: List the personality traits that are required to be successful in the given job. Social Media Marketer \n*/\n\n// Define the variables\nvar input = document.getElementById(\"input\");\nvar output = document.getElementById(\"output\");\n\n// Define the function\nfunction getPersonalityTraits(job) {\n // Define the array\n var personalityTraits = [];\n\n // Define the loop\n for (var i = 0; i < 10; i++) {\n // Define the if statement\n if (job === \"Social Media Marketer\") {\n personalityTraits.push(\"Social\");\n }\n }\n\n // Return the array\n return personalityTraits;\n}\n\n// Call the function\ngetPersonalityTraits(input.value);\n\\end{code}\n\n\\begin{code}\n\n\n\n\n \n \n \n courses.append(re.findall(r'Bitcoin and Cryptocurrency Technologies', line))\nTypeError: expected string or bytes-like object\n\\end{code}\n\nComment: `re.findall` returns a list of matches, not a single match.\n\nComment: `re.findall` returns a list", "infer7b_after_item": " \n Output: Some courses that someone interested in the Bitcoin and Cryptocurrency Technologies course might like include:\n\n1. Introduction to Blockchain Technology\n2. Cryptography and Cryptographic Algorithms\n3. Digital Currencies and Tokens\n4. Smart Contracts and Distributed Ledgers\n5. Cryptocurrency Mining and Networks\n6. Cryptocurrency Trading and Investing\n7. Cryptocurrency Regulation and Compliance\n8. Cryptocurrency Security and Privacy\n9. Cryptocurrency Applications and Use Cases\n10. Cryptocurrency Economics and Finance\n11. Cryptocurrency Law and Legal Issues\n12. Cryptocurrency Business Models and Strategies\n13. Cryptocurrency Investment and Portfolio Management\n14. Cryptocurrency Investment and Trading Strategies\n15. Cryptocurrency Investment and Trading Tools\n16. Cryptocurrency Investment and Trading Risks\n17. Cryptocurrency Investment and Trading Psychology\n18."} {"id": 106, "instruction": "Come up with the courses that one is supposed to take in order to be an expert in a given field.", "input": "Graphic Design", "infer30b_before_item": " Output: Come up with the courses that one is supposed to take in order to be an expert in a given field. Graphic Design \n Steps: Steps: 1. Come up with the courses that one is supposed to take in order to be an expert in a given field. Graphic Design \n 2. Come up with the courses that one is supposed to take in order to be an expert in a given field. Graphic Design \n 3. Come up with the courses that one is supposed to take in order to be an expert in a given field. Graphic Design \n 4. Come up with the courses that one is supposed to take in order to be an expert in a given field. Graphic Design \n 5. Come up with the courses that one is supposed to take in order to be an expert in a given field. Graphic Design \n 6. Come up with the courses that one is supposed to take in order to be an expert in a given field. Graphic Design \n 7. Come up with the courses that one is supposed to take in order to be an expert in a given field. Graphic Design \n 8. Come up with the courses that one is", "infer30b_after_item": ". \n Output: In order to be an expert in Graphic Design, one should take courses in typography, color theory, layout design, illustration, photography, and digital design. \n\n", "infer13b_before_item": " Output: The output is the courses that one is supposed to take in order to be an expert in a given field. Graphic Design \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: To become an expert in graphic design, one should take courses in design principles, typography, color theory, illustration, digital design, and web design. \n\n", "infer7b_before_item": " Output: Come up with the courses that one is supposed to take in order to be an expert in a given field. Graphic Design \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: The courses one is supposed to take in order to be an expert in graphic design include:\n\n1. Fundamentals of Graphic Design\n2. Color Theory\n3. Typography\n4. Layout and Composition\n5. Digital Design\n6. Web Design\n7. User Experience Design\n8. Motion Graphics\n9. 3D Modeling\n10. Animation\n11. Video Editing\n12. Illustration\n13. Branding\n14. Adobe Creative Suite\n15. Photoshop\n16. Illustrator\n17. InDesign\n18. After Effects\n19. Premiere Pro\n20. Sketch\n21. Procreate\n22. Cinema 4D\n23. Maya\n24. ZBrush\n25. 3D Printing\n26. 3D Modeling\n27. 3D Animation\n28. 3D Rendering\n29. 3D Texturing\n30. 3D Lighting\n31. 3D Shading\n32. 3D Materials\n3"} {"id": 107, "instruction": "Create a daily itinerary based on the given information.", "input": "Our family is looking for a 9-day Morocco trip that has light to moderate activity levels.", "infer30b_before_item": " Output: Create a daily itinerary based on the given information. Our family is looking for a 9-day Morocco trip that has light to moderate activity levels.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Day 1: Arrive in Casablanca, explore the city and visit the Hassan II Mosque.\nDay 2: Visit the Old Medina of Casablanca and the Quartier Habous.\nDay 3: Travel to Rabat and visit the Kasbah of the Udayas.\nDay 4: Explore the city of Meknes and visit the Bab Mansour.\nDay 5: Travel to Fez and visit the Medina of Fez.\nDay 6: Explore the city of Marrakech and visit the Jemaa el-Fnaa.\nDay 7: Visit the Ourika Valley and the Berber villages.\nDay 8: Visit the Atlas Mountains and the Kasbah of Ait Benhaddou.\nDay 9: Return to Casablanca and explore the city. \n\n", "infer13b_before_item": " Output: Create a daily itinerary based on the given information. Our family is looking for a 9-day Morocco trip that has light to moderate activity levels.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Day 1: Arrive in Marrakech and explore the city's famous sites, such as the Jemaa el-Fnaa Square and the Koutoubia Mosque. \nDay 2: Visit the Atlas Mountains and take a guided hike. \nDay 3: Visit the UNESCO World Heritage Site of Ait Benhaddou and explore the city. \nDay 4: Visit the Sahara Desert and take a camel ride. \nDay 5: Visit the ancient city of Ouarzazate and explore the Kasbahs. \nDay 6: Visit the Todra Gorge and take a hike. \nDay 7: Visit the city of Erfoud and explore the local markets. \nDay 8: Visit the Dades Gorges and take a guided hike. \nDay 9: Visit the city of Essaouira and explore the local markets. \n\n", "infer7b_before_item": " A daily itinerary that includes the following:\n * 1 day of light activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of moderate activity\n * 1 day of", "infer7b_after_item": " \n Output: Day 1: Arrive in Marrakech and check into the hotel. \nDay 2: Explore the city of Marrakech and visit the souks. \nDay 3: Drive to the Atlas Mountains and visit the Berber villages. \nDay 4: Drive to the coastal city of Essaouira and explore the city. \nDay 5: Drive to the city of Fez and explore the city. \nDay 6: Drive to the city of Ouarzazate and visit the Atlas Studios. \nDay 7: Drive to the city of Ait Benhaddou and explore the city. \nDay 8: Drive to the city of Marrakech and explore the city. \nDay 9: Depart from Marrakech. \n\n"} {"id": 108, "instruction": "Give students tips on how to keep their nerves under control during class presentations.", "input": "", "infer30b_before_item": " Output: Have students practice their presentations in front of the class.\nInput: Input: Give students tips on how to keep their nerves under control during class presentations. \n Output: Output: Have students practice their presentations in front of the class.\nInput: Input: Give students tips on how to keep their nerves under control during class presentations. \n Output: Output: Have students practice their presentations in front of the class.\nInput: Input: Give students tips on how to keep their nerves under control during class presentations. \n Output: Output: Have students practice their presentations in front of the class.\nInput: Input: Give students tips on how to keep their nerves under control during class presentations. \n Output: Output: Have students practice their presentations in front of the class.\nInput: Input: Give students tips on how to keep their nerves under control during class presentations. \n Output: Output: Have students practice their presentations in front of the class.\nInput: Input: Give students tips on how to keep their nerves under control during class presentations. \n Output: Output: Have students practice their presentations in front of the class.\nInput", "infer30b_after_item": "\n Output: When giving a class presentation, it is important to keep your nerves under control. Here are some tips to help you do so: \n\n1. Prepare thoroughly: Make sure you know your material inside and out. This will help you feel more confident and lessen your anxiety.\n\n2. Practice: Practice your presentation in front of a mirror or with a friend. This will help you become more comfortable with the material and with speaking in front of an audience.\n\n3. Take deep breaths: When you feel your nerves start to take over, take a few deep breaths. This will help you relax and focus on the task at hand.\n\n4. Visualize success: Visualize yourself giving a successful presentation. Imagine the audience applauding and smiling at the end. This will help you stay positive and confident.\n\n5. Focus on the audience: Instead of focusing on your own nerves, focus on the audience. Make eye contact and try to engage them in the presentation. This will help you stay calm and in control. \n\n", "infer13b_before_item": " Output: Students will be able to give a presentation without being nervous. \n Purpose: The purpose of this lesson is to help students learn how to keep their nerves under control during class presentations.\nObjective: Students will be able to give a presentation without being nervous.\nMaterials:\n * \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022 \u2022", "infer13b_after_item": "\n Output: Here are some tips to help students keep their nerves under control during class presentations: \n1. Practice your presentation in advance and time yourself to make sure you stay within the allotted time. \n2. Take deep breaths and focus on your breathing to help calm your nerves. \n3. Visualize yourself giving a successful presentation beforehand. \n4. Make sure to speak clearly and confidently. \n5. Make eye contact with the audience and engage them in the presentation. \n6. If you make a mistake, don't worry about it and move on. \n7. Ask for feedback from your peers and teacher after the presentation. \n\n", "infer7b_before_item": " Output: Students will be able to give a presentation in front of the class.\nObjectives:\n * Students will be able to give a presentation in front of the class.\n * Students will be able to give a presentation in front of the class.\n * Students will be able to give a presentation in front of the class.\n * Students will be able to give a presentation in front of the class.\n * Students will be able to give a presentation in front of the class.\n * Students will be able to give a presentation in front of the class.\n * Students will be able to give a presentation in front of the class.\n * Students will be able to give a presentation in front of the class.\n * Students will be able to give a presentation in front of the class.\n * Students will be able to give a presentation in front of the class.\n * Students will be able to give a presentation in front of the class.\n * Students will be able to give a presentation in front of the class.\n * Students will be able to give a presentation in front of the class.\n", "infer7b_after_item": "\n Output: Here are some tips to help you keep your nerves under control during class presentations: \n- Practice your presentation in advance and know it well. \n- Visualize yourself giving a successful presentation. \n- Take deep breaths and focus on your breathing. \n- Smile and be confident. \n- Speak slowly and clearly. \n- Make eye contact with the audience. \n- Don't be afraid to ask for help if you need it. \n- Remember that everyone is in the same boat and that you can do it! \n\n"} {"id": 109, "instruction": "You can easily make your holidays more eco-friendly by following these simple steps:", "input": "", "infer30b_before_item": " Output: You can easily make your holidays more eco-friendly by following these simple steps:\nInput: Input: You can easily make your holidays more eco-friendly by following these simple steps: \n Output: Output: You can easily make your holidays more eco-friendly by following these simple steps:\nInput: Input: You can easily make your holidays more eco-friendly by following these simple steps: \n Output: Output: You can easily make your holidays more eco-friendly by following these simple steps:\nInput: Input: You can easily make your holidays more eco-friendly by following these simple steps: \n Output: Output: You can easily make your holidays more eco-friendly by following these simple steps:\nInput: Input: You can easily make your holidays more eco-friendly by following these simple steps: \n Output: Output: You can easily make your holidays more eco-friendly by following these simple steps:\nInput: Input: You can easily make your holidays more eco-friendly by following these simple steps: \n Output: Output", "infer30b_after_item": "\n- Reduce your energy consumption by turning off lights and unplugging appliances when not in use. \n- Use reusable bags and containers for shopping and storing food. \n- Buy locally grown and produced food whenever possible. \n- Use public transportation or carpool when traveling. \n- Recycle and compost as much as possible. \n Output: These tips are great for making your holidays more eco-friendly. Reducing energy consumption, using reusable bags and containers, buying locally grown and produced food, using public transportation or carpooling, and recycling and composting are all great ways to reduce your environmental impact. \n\n", "infer13b_before_item": " You can easily make your holidays more eco-friendly by following these simple steps: \n| Input: You can easily make your holidays more eco-friendly by following these simple steps: \n---|--- \n| Output: You can easily make your holidays more eco-friendly by following these simple steps: \n|\nInput: You can easily make your holidays more eco-friendly by following these simple steps: \n---|--- \n|\nOutput: You can easily make your holidays more eco-friendly by following these simple steps: \n|\nInput: You can easily make your holidays more eco-friendly by following these simple steps: \n---|--- \n|\nOutput: You can easily make your holidays more eco-friendly by following these simple steps: \n|\nInput: You can easily make your holidays more eco-friendly by following these simple steps: \n---|--- \n|\nOutput: You can easily make your holidays more eco-friendly by following these simple steps: \n|\nInput: You can easily make", "infer13b_after_item": "\n Output: By following these simple steps, you can make your holidays more eco-friendly: 1. Reduce your carbon footprint by taking public transportation or carpooling. 2. Use reusable bags and containers when shopping. 3. Buy locally sourced and organic food. 4. Use energy-efficient lighting and appliances. 5. Recycle and compost waste. 6. Buy second-hand items. 7. Use eco-friendly cleaning products. 8. Use natural and biodegradable beauty products. 9. Use eco-friendly packaging materials. 10. Use reusable water bottles and coffee cups. \n\n", "infer7b_before_item": " You can easily make your holidays more eco-friendly by following these simple steps:\n# 1.\n# 2.\n# 3.\n# 4.\n# 5.\n# 6.\n# 7.\n# 8.\n# 9.\n# 10.\n# 11.\n# 12.\n# 13.\n# 14.\n# 15.\n# 16.\n# 17.\n# 18.\n# 19.\n# 20.\n# 21.\n# 22.\n# 23.\n# 24.\n# 25.\n# 26.\n# 27.\n# 28.\n# 29.\n# 30.\n# 31.\n# 32.\n# 33.\n# 34.\n# 35.\n# 36.\n# 37.\n# 38.\n# 39.\n# 40.\n# 41", "infer7b_after_item": "\n Output: 1. Use reusable bags when shopping.\n2. Buy local and seasonal produce.\n3. Use energy-efficient light bulbs.\n4. Recycle and compost.\n5. Use reusable water bottles.\n6. Use public transportation.\n7. Reduce your meat consumption.\n8. Use eco-friendly cleaning products.\n9. Use reusable containers for food.\n10. Use energy-efficient appliances. \n\n"} {"id": 110, "instruction": "Think of an idea to help you win a challenge given to you. Write the steps you need to take to develop the idea as well.", "input": "What can you make by recycling and repurposing some old, previously used materials? We want to see it!\nProjects must incorporate some kind of used materials - take that old used thing, and turn it into something new and different!\nE-waste is a huge problem. What can you make using old electronics and other salvageable electronic materials? \nWe have a special judges prize for our favorite Instructable that incorporates or is related to reusing e-waste.\nBe smart and be safe; note that potentially deadly projects (like Lichtenberg/fractal wood burning machines) will not be allowed to be published or submitted to this contest.", "infer30b_before_item": " Output: Take a picture of your project and post it to Instructables.com.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Step 1: Gather the materials.\n\nStep 2: Brainstorm ideas for the project.\n\nStep 3: Plan out the project.\n\nStep 4: Create a prototype.\n\nStep 5: Test the prototype.\n\nStep 6: Make any necessary adjustments.\n\nStep 7: Create the final product.\n\nStep 8: Document the project.\n\nStep 9: Submit the project to the contest. \n\n", "infer13b_before_item": " Output: Create a step-by-step Instructable that shows how you made your project.\n\n### Rules\n\n* You must be 18 years old or older to enter.\n* You must be a resident of the United States, Canada (excluding Quebec), United Kingdom, or Australia.\n* You must be a registered member of Instructables.com to enter.\n* You must have a valid email address.\n* You must agree to the Official Rules.\n* You must agree to receive updates about the contest.\n* You must agree to receive newsletters from Instructables.\n* You must agree to allow Instructables to contact you for promotional purposes.\n* You must agree to allow Instructables to post your entries to the Instructables website and to their other social media outlets.\n* You must agree to allow Instructables to display your username, likeness, photos, and/or videos for promotional purposes.\n* You must have a valid Instructables.com account before entering the contest.\n* Contest begins at 12:00 a.m. Pacific Time (PT) on May 1, 2", "infer13b_after_item": " \n Output: 1. Gather the materials: Start by collecting the materials you need. Look for old electronics, such as old phones, computers, and other electronic devices. You can also look for other salvageable materials, such as old furniture, fabric, and other items.\n2. Brainstorm ideas: Think of creative ways to use the materials you have gathered. You can look for inspiration online or come up with your own ideas.\n3. Design the project: Once you have an idea, start designing the project. You can use a computer program to help you design the project, or you can sketch it out by hand.\n4. Build the project: Once you have a design, start building the project. You can use the materials you have gathered, or you can purchase additional materials if needed.\n5. Test the project: Test the project to make sure it works as intended. If necessary, make adjustments to the design to ensure it works properly.\n6. Take photos: Take photos of the project to showcase it. You can also create a video to show how the project works.\n7. Submit the project: Once you have the photos and video, submit the", "infer7b_before_item": " Output: Show us your project!\nYou can enter as many projects as you want, but you can only win one prize.\nYou can enter as many projects as you want, but you can only win one prize.\nYou can enter as many projects as you want, but you can only win one prize.\nYou can enter as many projects as you want, but you can only win one prize.\nYou can enter as many projects as you want, but you can only win one prize.\nYou can enter as many projects as you want, but you can only win one prize.\nYou can enter as many projects as you want, but you can only win one prize.\nYou can enter as many projects as you want, but you can only win one prize.\nYou can enter as many projects as you want, but you can only win one prize.\nYou can enter as many projects as you want, but you can only win one prize.\nYou can enter as many projects as you want, but you can only win one prize.\nYou can enter as many projects as you want, but you can only win one prize.\nYou can enter as many projects as you want, but you can only win one prize.\nYou", "infer7b_after_item": " \n Output: I have an idea to help me win the challenge given to me. I can make a robotic arm out of old, previously used materials. I will start by collecting old materials such as motors, gears, and wires. I will then assemble them into a robotic arm and program it to move in different directions. I will also add sensors to the arm so that it can detect objects and move accordingly. I will then test the robotic arm to make sure it works properly. \n\nThe steps I need to take to develop this idea are:\n1. Collect the materials I need for the robotic arm.\n2. Assemble the materials into a robotic arm.\n3. Program the robotic arm to move in different directions.\n4. Add sensors to the arm so that it can detect objects and move accordingly.\n5. Test the robotic arm to make sure it works properly. \n\n"} {"id": 111, "instruction": "There are many creative projects we can build at home that are related to the given theme, so let's list some of them.", "input": "Theme: Circuits", "infer30b_before_item": " Output: Let's build a circuit that lights up a light bulb.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: - Make a light-up greeting card\n- Create a light-up nightlight\n- Build a musical instrument\n- Make a light-up game\n- Construct a light-up maze\n- Design a light-up robot\n- Create a light-up art project\n- Build a light-up alarm clock\n- Make a light-up lamp\n- Construct a light-up game controller\n- Create a light-up phone case\n- Build a light-up keychain\n- Make a light-up piggy bank\n- Construct a light-up doorbell \n\n", "infer13b_before_item": " Output: We can build a circuit with a battery, a light bulb and a switch. \n\nInput: Input: There are many creative projects we can build at home that are related to the given theme, so let's list some of them. Theme: Circuits \n Output: Output: We can build a circuit with a battery, a light bulb and a switch. \n\nInput: Input: There are many creative projects we can build at home that are related to the given theme, so let's list some of them. Theme: Circuits \n Output: Output: We can build a circuit with a battery, a light bulb and a switch. \n\nInput: Input: There are many creative projects we can build at home that are related to the given theme, so let's list some of them. Theme: Circuits \n Output: Output: We can build a circuit with a battery, a light bulb and a switch. \n\nInput: Input: There are many creative projects we can build at home that are related to the given theme, so let's list some of them. Theme: Circuits \n Output: Output: We can", "infer13b_after_item": " \n Output: 1. Build a simple circuit using a battery, a light bulb, and a switch.\n2. Create a circuit that can be used to power a small motor.\n3. Create a circuit that can be used to control a robot.\n4. Build a circuit that can be used to control a remote-controlled car.\n5. Create a circuit that can be used to control a robotic arm.\n6. Build a circuit that can be used to control a robotic pet.\n7. Create a circuit that can be used to control a robotic vacuum cleaner.\n8. Build a circuit that can be used to control a robotic plant.\n9. Create a circuit that can be used to control a robotic security system.\n10. Build a circuit that can be used to control a robotic toy. \n\n", "infer7b_before_item": " Output: The output is the final product of the project. It is the result of the creative process. Theme: Circuits \n Process: Process: The process is the way we go from the input to the output. It is the way we go from the idea to the final product. Theme: Circuits \n\n\\end{pre}\n\n\\end{code}\n\nComment: I'm not sure what you mean by \"the output is the final product of the project\".\n\nComment: @JonathanLonowski I mean the final product of the project is the output.\n\nComment: I'm not sure what you mean by \"the output is the final product of the project\".\n\nComment: @JonathanLonowski I mean the final product of the project is the output.\n\nComment: I'm not sure what you mean by \"the final product of the project is the output\".\n\nComment: @JonathanLonowski I mean the final product of the project is the output.\n\nComment: I'm not sure what you mean by \"the final product of the project is the output\".\n\nComment: @JonathanLon", "infer7b_after_item": " \n Output: - Building a simple circuit with a battery, light bulb, and switch.\n- Building a circuit with a battery, light bulb, switch, and buzzer.\n- Building a circuit with a battery, light bulb, switch, buzzer, and motor.\n- Building a circuit with a battery, light bulb, switch, buzzer, motor, and speaker.\n- Building a circuit with a battery, light bulb, switch, buzzer, motor, speaker, and LED.\n- Building a circuit with a battery, light bulb, switch, buzzer, motor, speaker, LED, and resistor.\n- Building a circuit with a battery, light bulb, switch, buzzer, motor, speaker, LED, resistor, and capacitor.\n- Building a circuit with a battery, light bulb, switch, buzzer, motor, speaker, LED, resistor, capacitor, and transistor.\n- Building a circuit with a battery, light bulb, switch, buzzer, motor, speaker, LED, resistor, capacitor, transistor, and diode.\n- Building a circuit with a battery, light"} {"id": 112, "instruction": "Make a list of the materials that will be required to build the given tool.", "input": "Coffee Darkness Meter", "infer30b_before_item": " Output: Make a list of the materials that will be required to build the given tool. Coffee Darkness Meter \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", "infer30b_after_item": " \n Output: Materials required to build the Coffee Darkness Meter:\n- Wooden frame\n- Metal ruler\n- Metal calipers\n- Metal screws\n- Metal nuts\n- Metal hinges\n- Metal springs\n- Metal dial\n- Metal shaft\n- Metal gears\n- Metal housing\n- Metal dial indicator\n- Metal pointer\n- Metal scale\n- Metal dial cover\n- Metal mounting bracket\n- Metal fasteners\n- Metal washers\n- Metal shims\n- Metal wires\n- Metal bolts\n- Metal nut drivers\n- Metal screwdrivers\n- Metal pliers\n- Metal saw\n- Metal drill\n- Metal files\n- Metal sandpaper\n- Metal paint\n- Metal primer\n- Metal sealant\n- Metal glue\n- Metal rivets\n- Metal bolts\n- Metal nuts\n- Metal washers\n- Metal screws\n- Metal nuts\n- Metal washers\n- Metal screws\n- Metal nuts\n- Metal washers\n- Metal screws\n- Metal nuts\n- Metal washers\n-", "infer13b_before_item": " Output: Make a list of the materials that will be required to build the given tool. Coffee Darkness Meter \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Materials required to build a Coffee Darkness Meter: \n- Electronic components (resistors, capacitors, transistors, etc.) \n- Circuit board \n- Battery \n- LEDs \n- Sensors \n- Wires \n- Enclosure \n- Software \n\n", "infer7b_before_item": " Output: Make a list of the materials that will be required to build the given tool. Coffee Darkness Meter\n\n\n# I worked on this challenge [by myself, with: ].\n# I spent [#] hours on this challenge.\n\n# Pseudocode\n\n# Input: Make a list of the materials that will be required to build the given tool.\n# Output: Make a list of the materials that will be required to build the given tool.\n\n# Steps:\n\n# 1. Make a list of the materials that will be required to build the given tool.\n# 2. Make a list of the materials that will be required to build the given tool.\n# 3. Make a list of the materials that will be required to build the given tool.\n# 4. Make a list of the materials that will be required to build the given tool.\n# 5. Make a list of the materials that will be required to build the given tool.\n# 6. Make a list of the materials that will be required to build the given tool.\n# 7. Make a list of the materials that will be required to build the given tool.\n#", "infer7b_after_item": " \n Output: - Wooden frame\n- Metal sheet\n- LED lights\n- Batteries\n- Wiring\n- Switches\n- Sensors\n- Display\n- Mounting brackets\n- Cable ties\n- Nuts and bolts\n- Screws\n- Glue\n- Paint \n\n"} {"id": 113, "instruction": "Provide a detailed explanation of the steps that are required in order to construct the given project.", "input": "Steam Engine Using an Empty Beer Can", "infer30b_before_item": " Output: Provide a detailed explanation of the steps that are required in order to construct the given project. Steam Engine Using an Empty Beer Can \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: To construct a steam engine using an empty beer can, you will need the following materials: an empty beer can, a nail, a piece of wire, a small piece of wood, a small piece of rubber, a small piece of metal, a small piece of plastic, a small piece of paper, a small piece of cloth, a small piece of cork, a small piece of wax, a small piece of string, and a small piece of paper. \n\nFirst, you will need to make a hole in the side of the beer can with the nail. Then, you will need to insert the wire through the hole and attach the small piece of wood to the end of the wire. Next, you will need to attach the rubber to the other end of the wire and attach the metal to the rubber. Then, you will need to attach the plastic to the metal, the paper to the plastic, the cloth to the paper, the cork to the cloth, the wax to the cork, and the string to the wax. Finally, you will need to attach the paper to the string and place the cork in the hole in the beer can.", "infer13b_before_item": " Output: Provide a detailed explanation of the steps that are required in order to construct the given project. Steam Engine Using an Empty Beer Can \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: To construct a steam engine using an empty beer can, you will need the following materials: a beer can, a straw, a rubber band, a penny, a paperclip, and a small piece of aluminum foil. \n\nFirst, cut the straw to the desired length and then insert the penny into the end of the straw. Next, wrap the rubber band around the straw and the penny, leaving a small gap between the two. Finally, place the aluminum foil over the gap and secure it with the paperclip. \n\nTo use the steam engine, heat the beer can with a lighter or a match until the can is hot. Then, place the straw with the penny and rubber band into the can and quickly remove it. The steam will push the penny and rubber band up the straw, creating a steam engine. \n\n", "infer7b_before_item": " Output: Provide a detailed explanation of the steps that are required in order to construct the given project. Steam Engine Using an Empty Beer Can \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Step 1: Cut the top of the beer can off using a pair of scissors.\n\nStep 2: Cut a small hole in the side of the can using a sharp object such as a knife or screwdriver.\n\nStep 3: Cut a small piece of cardboard and place it inside the can.\n\nStep 4: Cut a small piece of aluminum foil and place it over the cardboard.\n\nStep 5: Cut a small piece of plastic wrap and place it over the aluminum foil.\n\nStep 6: Cut a small piece of rubber and place it over the plastic wrap.\n\nStep 7: Cut a small piece of string and place it over the rubber.\n\nStep 8: Cut a small piece of paper and place it over the string.\n\nStep 9: Cut a small piece of tape and place it over the paper.\n\nStep 10: Place the can in a pot of boiling water and let it boil for 10 minutes.\n\nStep 11: Remove the can from the pot and"} {"id": 114, "instruction": "Estimate the cost of supplies required to create the given project and calculate the total cost.", "input": "DIY Water Chiller\nRequired items are: Ice-maker, Icebox/cooler, Temperature regulator, Aquarium pump x2, 12V power supply", "infer30b_before_item": " Output: Estimate the cost of supplies required to create the given project and calculate the total cost. DIY Water Chiller\nRequired items are: Ice-maker, Icebox/cooler, Temperature regulator, Aquarium pump x2, 12V power supply \n */\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": ", 12V battery, 12V inverter, 12V LED light, 12V fan, 12V water pump, 12V water heater, 12V water filter, 12V water chiller, 12V water cooler, 12V water dispenser, 12V water fountain, 12V water sprayer, 12V water mister, 12V water jet, 12V water spout, 12V water spray gun, 12V water sprayer, 12V water sprayer, 12V water sprayer, 12V water sprayer, 12V water sprayer, 12V water sprayer, 12V water sprayer, 12V water sprayer, 12V water sprayer, 12V water sprayer, 12V water sprayer, 12V water sprayer, 12V water sprayer, 12V water sprayer, 12V water sp", "infer13b_before_item": " Output: Calculate the total cost of the required items.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": ", 12V DC pump, 12V DC fan, 12V DC light, 12V DC timer. \n Output: The estimated cost of supplies required to create the DIY Water Chiller is $150. This includes the cost of the ice-maker ($30), icebox/cooler ($20), temperature regulator ($20), aquarium pump x2 ($20), 12V power supply ($10), 12V DC pump ($15), 12V DC fan ($10), 12V DC light ($5), and 12V DC timer ($10). \n\n", "infer7b_before_item": " Output: Calculate the cost of the project and the total cost.\n\nComment: Please edit your question to include the code you have so far.\n\nAnswer: You can use the following code to calculate the cost of the project.\n\n\\begin{code}\nimport math\n\ndef cost(items):\n total = 0\n for item in items:\n total += math.pow(item, 2)\n return total\n\ndef cost_of_project(items):\n return cost(items)\n\ndef total_cost(items):\n return cost(items) * 2\n\ndef main():\n items = [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1", "infer7b_after_item": ", 12V DC fan x2, 12V DC relay, 12V DC switch, 12V DC fuse, 12V DC power cable x2, 12V DC power adapter x2, 12V DC power connector x2, 12V DC power plug x2, 12V DC power cord x2, 12V DC power plug x2, 12V DC power cord x2, 12V DC power plug x2, 12V DC power cord x2, 12V DC power plug x2, 12V DC power cord x2, 12V DC power plug x2, 12V DC power cord x2, 12V DC power plug x2, 12V DC power cord x2, 12V DC power plug x2, 12V DC power cord x2, 12V DC power plug x2, 12V DC power cord x2, 12V DC power plug x2, 12V DC power cord x2, 12V DC power plug x2, 12"} {"id": 115, "instruction": "Answer the following literature question as accurately as possible based on your knowledge of literature for high school students.", "input": "What does the green light symbolize at the end of the book?", "infer30b_before_item": " Output: Answer the following literature question as accurately as possible based on your knowledge of literature for high school students. What does the green light symbolize at the end of the book?\n\nComment: I'm not sure what you're asking. Are you asking how to parse the input? Or how to write the output? Or how to write the code that does both?\n\nComment: I'm asking how to write the code that does both.\n\nComment: I'm not sure what you mean by \"do both\". You've already written the code that does both. You've written the code that reads the input and writes the output. What's the problem?\n\nComment: I'm asking how to write the code that does both.\n\nComment: I'm asking how to write the code that does both.\n\nComment: I'm asking how to write the code that does both.\n\nComment: I'm asking how to write the code that does both.\n\nComment: I'm asking how to write the code that does both.\n\nComment: I'm asking how to write the code that does both.\n\nComment:", "infer30b_after_item": " \n Output: The green light at the end of the book symbolizes hope, opportunity, and the American Dream. It is a symbol of the future and the possibility of a better life. \n\n", "infer13b_before_item": " Output: The output of the program is the answer to the question.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: In F. Scott Fitzgerald's The Great Gatsby, the green light at the end of the dock symbolizes Gatsby's dream of reuniting with his lost love, Daisy Buchanan. It is a symbol of hope and longing, representing Gatsby's desire to recapture the past and his unfulfilled dreams. \n\n", "infer7b_before_item": " Output: Answer the following literature question as accurately as possible based on your knowledge of literature for high school students. What does the green light symbolize at the end of the book? \n 1. What does the green light symbolize at the end of the book?\n 2. What does the green light symbolize at the end of the book?\n 3. What does the green light symbolize at the end of the book?\n 4. What does the green light symbolize at the end of the book?\n 5. What does the green light symbolize at the end of the book?\n 6. What does the green light symbolize at the end of the book?\n 7. What does the green light symbolize at the end of the book?\n 8. What does the green light symbolize at the end of the book?\n 9. What does the green light symbolize at the end of the book?\n 10. What does the green light symbolize at the end of the book?\n 11. What does the green light symbolize at the end of the book?\n 12. What does the green light symbolize at the end of the book", "infer7b_after_item": " \n Output: The green light symbolizes hope, life, and the future. It represents the possibility of a new beginning and a fresh start. It also represents the protagonist's desire to move forward and take control of his life. \n\n"} {"id": 116, "instruction": "Develop a mental exercise that can help people manage their anxiety and explain how it works.", "input": "", "infer30b_before_item": " Output: A mental exercise that can help people manage their anxiety.\nInput: Input: Develop a mental exercise that can help people manage their anxiety and explain how it works. \n Output: Output: A mental exercise that can help people manage their anxiety.\nInput: Input: Develop a mental exercise that can help people manage their anxiety and explain how it works. \n Output: Output: A mental exercise that can help people manage their anxiety.\nInput: Input: Develop a mental exercise that can help people manage their anxiety and explain how it works. \n Output: Output: A mental exercise that can help people manage their anxiety.\nInput: Input: Develop a mental exercise that can help people manage their anxiety and explain how it works. \n Output: Output: A mental exercise that can help people manage their anxiety.\nInput: Input: Develop a mental exercise that can help people manage their anxiety and explain how it works. \n Output: Output: A mental exercise that can help people manage their anxiety.\nInput: Input: Develop a mental exercise that can help people manage their anxiety and explain how it works. \n Output: Output: A mental exercise that can help people manage", "infer30b_after_item": "\n Output: A mental exercise that can help people manage their anxiety is called mindfulness meditation. Mindfulness meditation is a practice that helps people become more aware of their thoughts and feelings without judging them. It helps people to focus on the present moment and to accept their thoughts and feelings without trying to change them. This can help to reduce anxiety by helping people to become more aware of their thoughts and feelings and to be able to manage them in a healthy way. \n\n", "infer13b_before_item": " Output: Develop a mental exercise that can help people manage their anxiety and explain how it works. \n | **Inferences:** What is the author's purpose in writing this text? What is the author's point of view? What is the author's tone? What is the author's attitude? What is the author's purpose in writing this text? What is the author's point of view? What is the author's tone? What is the author's attitude? \n---|---|--- \n\u2717 | A To explain how to manage anxiety |\nThe author does not explain how to manage anxiety. The author does not even explain what anxiety is.\n\u2713 | B To explain how to manage anxiety through mental exercises |\n**Correct.** The author explains how to manage anxiety through mental exercises.\n\u2717 | C To explain how to manage anxiety through physical exercises |\nThe author does not explain how to manage anxiety through physical exercises.\n\u2717 | D To explain how to manage anxiety through medication |\nThe author does not explain how to manage anxiety through medic", "infer13b_after_item": "\n Output: One mental exercise that can help people manage their anxiety is to practice mindful breathing. Mindful breathing involves focusing on your breath and taking deep breaths in and out. This helps to slow down your breathing and relax your body. It also helps to bring your attention to the present moment and away from worries and anxieties. \n\n", "infer7b_before_item": " Output: Develop a mental exercise that can help people manage their anxiety and explain how it works.\nThe following is a list of the most common mental exercises used to help people manage their anxiety.\n 1. **_Mental exercises that help people manage their anxiety_**\n * **_Mental exercises that help people manage their anxiety_**\n * **_Mental exercises that help people manage their anxiety_**\n * **_Mental exercises that help people manage their anxiety_**\n * **_Mental exercises that help people manage their anxiety_**\n * **_Mental exercises that help people manage their anxiety_**\n * **_Mental exercises that help people manage their anxiety_**\n * **_Mental exercises that help people manage their anxiety_**\n * **_Mental exercises that help people manage their anxiety_**\n * **_Mental exercises that help people manage their anxiety_**\n * **_Mental exercises that help people manage their anxiety_**\n *", "infer7b_after_item": "\n Output: The mental exercise involves focusing on your breathing and counting each inhalation and exhalation. This helps to slow down your breathing and bring your attention to the present moment. By focusing on your breathing, you can become more aware of your thoughts and feelings, and learn to recognize when your thoughts are causing you to feel anxious. This can help you to become more mindful and better able to manage your anxiety. \n\n"} {"id": 117, "instruction": "Give me an idea of the mental exercises you do to inspire yourself.", "input": "", "infer30b_before_item": " Output: I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think about the future. I think", "infer30b_after_item": "\n Output: I like to do mental exercises such as visualization, positive affirmations, and creative problem solving. Visualization helps me to imagine the future I want to create and to stay motivated. Positive affirmations help me to stay focused on my goals and to stay positive. Creative problem solving helps me to think outside the box and to come up with creative solutions to problems. \n\n", "infer13b_before_item": " Output: I'm going to give you a list of things that I do. \n Input: Input: What do you do? \n Output: Output: I'm going to give you a list of things that I do. \n Input: Input: What do you do? \n Output: Output: I'm going to give you a list of things that I do. \n Input: Input: What do you do? \n Output: Output: I'm going to give you a list of things that I do. \n Input: Input: What do you do? \n Output: Output: I'm going to give you a list of things that I do. \n Input: Input: What do you do? \n Output: Output: I'm going to give you a list of things that I do. \n Input: Input: What do you do? \n Output: Output: I'm going to give you a list of things that I do. \n Input: Input: What do you do? \n Output: Output: I'm going to give you a list of things that I do. \n Input: Input: What do you do? \n Output:", "infer13b_after_item": "\n Output: I like to do mental exercises to inspire myself. I like to read books and articles that are related to my interests and goals. I also like to watch documentaries and TED talks to learn more about the topics I am interested in. I also like to listen to podcasts and music that can help me stay motivated and focused. \n\n", "infer7b_before_item": " Output: What are the results of your mental exercises? \n Feedback: Feedback: What are the results of your mental exercises? \n Evaluation: Evaluation: What are the results of your mental exercises?\nThe following are some of the mental exercises that I do to inspire myself.\n1. I read a lot of books. I read books on a variety of subjects. I read books on business, history, science, and philosophy. I read books on the lives of great people. I read books on the lives of great leaders. I read books on the lives of great entrepreneurs. I read books on the lives of great scientists. I read books on the lives of great philosophers. I read books on the lives of great artists. I read books on the lives of great athletes. I read books on the lives of great inventors. I read books on the lives of great explorers. I read books on the lives of great writers. I read books on the lives of great thinkers. I read books on the lives of great achievers. I read books on the lives of great visionaries. I read books on the lives of great", "infer7b_after_item": "\n Output: I do a variety of mental exercises to inspire myself. I like to write down my goals and visualize myself achieving them. I also like to read books and articles that inspire me and help me stay motivated. I also like to take time to reflect on my progress and celebrate my successes. \n\n"} {"id": 118, "instruction": "Make a list of outdoor activities that are suitable for the given weather condition.", "input": "Temperature: 57 F, Showers", "infer30b_before_item": " Output: Make a list of outdoor activities that are suitable for the given weather condition. Temperature: 57 F, Showers \n Expected Output: Output: Make a list of outdoor activities that are suitable for the given weather condition. Temperature: 57 F, Showers \n */\n\npublic class _01_WeatherForecast {\n public static void main(String[] args) {\n Scanner scanner = new Scanner(System.in);\n String[] input = scanner.nextLine().split(\" \");\n int temperature = Integer.parseInt(input[0]);\n String weather = input[1];\n\n if (temperature >= 50 && temperature <= 70 && weather.equals(\"Sunny\")) {\n System.out.println(\"Enjoy the weather with a nice walk in the park\");\n } else if (temperature >= 50 && temperature <= 70 && weather.equals(\"Cloudy\")) {\n System.out.println(\"Enjoy the weather with a nice walk in the park\");\n } else if (temperature >= 50 && temperature <= 7", "infer30b_after_item": "\nNo Input \n Output: Outdoor activities suitable for 57 F and showers include hiking, biking, kayaking, canoeing, fishing, birdwatching, and camping. \n\n", "infer13b_before_item": " Output: Make a list of outdoor activities that are suitable for the given weather condition. Temperature: 57 F, Showers \n\n\nclass Solution {\npublic:\n vector getOutdoorActivities(vector& temperature, vector& weather) {\n vector res;\n for (int i = 0; i < temperature.size(); ++i) {\n if (temperature[i] < 30) {\n res.push_back(\"Snow\");\n } else if (temperature[i] < 40) {\n res.push_back(\"Rain\");\n } else if (temperature[i] < 50) {\n res.push_back(\"Cloudy\");\n } else if (temperature[i] < 60) {\n res.push_back(\"Sunny\");\n } else {\n res.push_back(\"Sunny\");\n }\n }\n return res;\n }\n};\n", "infer13b_after_item": " \n Output: 1. Hiking\n2. Picnicking\n3. Fishing\n4. Birdwatching\n5. Camping\n6. Biking\n7. Swimming\n8. Kite flying\n9. Geocaching\n10. Gardening\n11. Playing Frisbee\n12. Playing tag\n13. Playing hide and seek\n14. Playing soccer\n15. Playing badminton\n16. Playing volleyball\n17. Playing horseshoes\n18. Playing croquet\n19. Playing bocce ball\n20. Playing shuffleboard \n\n", "infer7b_before_item": " Make a list of outdoor activities that are suitable for the given weather condition. Temperature: 57 F, Showers\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: - Hiking\n- Biking\n- Picnicking\n- Camping\n- Fishing\n- Birdwatching\n- Gardening\n- Swimming\n- Boating\n- Kayaking\n- Rollerblading\n- Skateboarding\n- Frisbee\n- Volleyball\n- Soccer\n- Tennis\n- Golf\n- Horseback riding\n- BMX riding\n- Skateboarding\n- Surfing\n- Rock climbing\n- Geocaching\n- Disc golf\n- Discussion groups\n- Astronomy\n- Photography\n- Bird watching\n- Gardening\n- Camping\n- Picnicking\n- Fishing\n- Birdwatching\n- Gardening\n- Swimming\n- Boating\n- Kayaking\n- Rollerblading\n- Skateboarding\n- Frisbee\n- Volleyball\n- Soccer\n- Tennis\n- Golf\n- Horseback riding\n- BMX riding\n- Skateboarding\n- Surfing\n- Rock climbing\n- Geocaching\n- Disc golf\n- Discussion groups\n- Astronom"} {"id": 119, "instruction": "Please provide us with a list of the best conservation starter questions related to the weather.", "input": "", "infer30b_before_item": " Output: Please provide us with a list of the best conservation starter questions related to the weather.\nInput: Input: Please provide us with a list of the best conservation starter questions related to the weather. \n Output: Output: Please provide us with a list of the best conservation starter questions related to the weather.\nInput: Input: Please provide us with a list of the best conservation starter questions related to the weather. \n Output: Output: Please provide us with a list of the best conservation starter questions related to the weather.\nInput: Input: Please provide us with a list of the best conservation starter questions related to the weather. \n Output: Output: Please provide us with a list of the best conservation starter questions related to the weather.\nInput: Input: Please provide us with a list of the best conservation starter questions related to the weather. \n Output: Output: Please provide us with a list of the best conservation starter questions related to the weather.\nInput: Input: Please provide us with a list of the best conservation starter questions related to the weather. \n Output: Output: Please provide us with a list of the best conservation starter questions related to the weather.\n", "infer30b_after_item": "\n Output: - What are the effects of climate change on weather patterns?\n- How can we reduce the impact of extreme weather events?\n- What are the best ways to conserve energy and reduce emissions?\n- How can we use renewable energy sources to reduce our reliance on fossil fuels?\n- What are the best ways to reduce air pollution?\n- How can we reduce the amount of water we use?\n- What are the best ways to protect our oceans and marine life?\n- How can we reduce the amount of waste we produce?\n- What are the best ways to conserve natural resources?\n- How can we reduce the amount of deforestation?\n- What are the best ways to reduce our carbon footprint?\n- How can we encourage sustainable practices in our communities?\n- What are the best ways to reduce our reliance on single-use plastics?\n- How can we reduce the amount of chemicals we use in our homes?\n- What are the best ways to protect our soil and agricultural land?\n- How can we reduce the amount of noise pollution?\n- What are the best ways to protect our wildlife?", "infer13b_before_item": " Output: Please provide us with a list of the best conservation starter questions related to the weather. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: 1. What is the weather like today?\n2. How has the weather been changing over the past few days?\n3. How does the weather affect the environment?\n4. What are some ways to conserve energy and reduce our carbon footprint?\n5. How can we reduce our energy consumption and save money?\n6. What are some ways to reduce our water usage?\n7. How can we reduce our waste and recycle more?\n8. What are some ways to protect the environment from pollution?\n9. What are some ways to protect the environment from climate change?\n10. What are some ways to reduce our carbon footprint? \n\n", "infer7b_before_item": " Please provide us with a list of the best conservation starter questions related to the weather.\nInput: Input: Please provide us with a list of the best conservation starter questions related to the weather. \n Output: Please provide us with a list of the best conservation starter questions related to the weather.\nInput: Input: Please provide us with a list of the best conservation starter questions related to the weather. \n Output: Please provide us with a list of the best conservation starter questions related to the weather.\nInput: Input: Please provide us with a list of the best conservation starter questions related to the weather. \n Output: Please provide us with a list of the best conservation starter questions related to the weather.\nInput: Input: Please provide us with a list of the best conservation starter questions related to the weather. \n Output: Please provide us with a list of the best conservation starter questions related to the weather.\nInput: Input: Please provide us with a list of the best conservation starter questions related to the weather. \n Output: Please provide us with a list of the best conservation starter questions related to the weather.\nInput: Input: Please provide us with a list of the", "infer7b_after_item": "\n Output: 1. What are the different types of weather?\n2. How does the weather affect the environment?\n3. What are the causes of weather patterns?\n4. How can we protect the environment from weather-related damage?\n5. What are the effects of climate change on the environment?\n6. How can we reduce our carbon footprint to help protect the environment?\n7. What are the benefits of renewable energy sources?\n8. How can we reduce our energy consumption?\n9. What are the effects of air pollution on the environment?\n10. What are the effects of water pollution on the environment?\n11. How can we reduce our waste production?\n12. What are the benefits of recycling?\n13. What are the effects of deforestation on the environment?\n14. What are the effects of overfishing on the environment?\n15. What are the effects of overpopulation on the environment?\n16. What are the effects of urbanization on the environment?\n17. What are the effects of industrialization on the environment?\n18. What are the effects of agriculture on the environment?"} {"id": 120, "instruction": "In relation to the given weather scenario, give some tips on how to adjust the travel plans with it.", "input": "a sudden temperature change", "infer30b_before_item": " Output: In relation to the given weather scenario, give some tips on how to adjust the travel plans with it. a sudden temperature change \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ", "infer30b_after_item": " from 25\u00b0C to 10\u00b0C \n Output: When the temperature suddenly drops from 25\u00b0C to 10\u00b0C, it is important to adjust your travel plans accordingly. Make sure to bring warm clothing such as a coat, hat, and gloves. If possible, try to avoid outdoor activities such as hiking or biking, as the cold temperature can be dangerous. Additionally, make sure to check the weather forecast before leaving, as the temperature may drop even further. \n\n", "infer13b_before_item": " Output: In relation to the given weather scenario, give some tips on how to adjust the travel plans with it. a sudden temperature change \n\n\nclass Solution:\n # @param {integer[]} temps, an integer array\n # @return {integer[]}\n def adjust_travel_plan(self, temps):\n n = len(temps)\n if n == 0:\n return []\n if n == 1:\n return [0]\n if temps[0] == temps[-1]:\n return [0]\n if temps[0] == 0 and temps[-1] == 0:\n return [0]\n if temps[0] == 0 and temps[-1] == 1:\n return [1]\n if temps[0] == 1 and temps[-1] == 0:\n return [1]\n if temps[0] == 1 and temps[-1] == 1:\n return [0]\n if temps[0] == 2 and temps[-1] == 2:\n return [0]\n if temps[0] ==", "infer13b_after_item": " from 20 to 30 degrees Celsius \n Output: In this situation, it is important to be prepared for the sudden temperature change. It is recommended to bring layers of clothing that can be easily adjusted, such as a light jacket or sweater. Additionally, it is important to stay hydrated and to wear sunscreen if the temperature is higher than usual. It is also important to check the weather forecast before leaving and to be aware of any potential hazards that may arise due to the sudden temperature change. \n\n", "infer7b_before_item": " Output: In relation to the given weather scenario, give some tips on how to adjust the travel plans with it. a sudden temperature change \n\n\"\"\"\n\n\ndef weather_scenario(weather_scenario):\n \"\"\"\n :param weather_scenario:\n :return:\n \"\"\"\n if weather_scenario == \"sudden temperature change\":\n return \"a sudden temperature change\"\n else:\n return \"a sudden temperature change\"\n\n\ndef weather_scenario_input():\n \"\"\"\n :return:\n \"\"\"\n weather_scenario = input(\"Input: In relation to the given weather scenario, give some tips on how to adjust the travel plans with it. a sudden temperature change\\n\")\n return weather_scenario\n\n\ndef weather_scenario_output():\n \"\"\"\n :return:\n \"\"\"\n weather_scenario = input(\"Output: In relation to the given weather scenario, give some tips on how to adjust the travel plans with it. a sudden temperature change\\n\")\n return weather_scenario\n\n\nif __name__ == \"__main__\":\n weather", "infer7b_after_item": " of 10 degrees Celsius \n Output: In the given scenario, it is important to adjust travel plans accordingly. It is recommended to check the weather forecast and plan accordingly. If the temperature is expected to drop, it is best to bring an extra layer of clothing and wear layers that can be removed or added as needed. Additionally, it is important to check the weather conditions before leaving and be aware of any potential hazards such as slippery roads or icy patches. \n\n"} {"id": 121, "instruction": "Write a to-do list based on the given information.", "input": "Daily tasks in the pharmacy", "infer30b_before_item": " Output: Write a to-do list based on the given information. Daily tasks in the pharmacy \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ", "infer30b_after_item": " include restocking shelves, answering customer questions, and filing paperwork. \n Output: To-do list for the pharmacy: \n1. Restock shelves\n2. Answer customer questions\n3. File paperwork\n4. Check inventory levels\n5. Reorder supplies as needed\n6. Clean and organize the pharmacy\n7. Update customer records\n8. Process prescriptions\n9. Contact doctors as needed\n10. Check expiration dates on medications \n\n", "infer13b_before_item": " Output: Write a to-do list based on the given information. Daily tasks in the pharmacy \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: 1. Check stock of medicines and supplies.\n2. Refill prescriptions.\n3. Answer customer inquiries.\n4. Process insurance claims.\n5. Update patient records.\n6. Organize inventory.\n7. Maintain cleanliness of the pharmacy.\n8. Monitor expiration dates of medicines.\n9. Check for any expired medicines.\n10. Update pharmacy software.\n11. Check for any outdated medicines.\n12. Update pharmacy website.\n13. Check for any discrepancies in billing.\n14. Check for any damaged medicines.\n15. Check for any expired medicines.\n16. Check for any expired medicines.\n17. Check for any expired medicines.\n18. Check for any expired medicines.\n19. Check for any expired medicines.\n20. Check for any expired medicines. \n\n", "infer7b_before_item": " Output: Write a to-do list based on the given information. Daily tasks in the pharmacy \n\n*/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: - Check inventory\n- Refill prescriptions\n- Process orders\n- Prepare medications\n- Clean the pharmacy\n- Answer customer questions\n- Maintain records\n- Clean the dispensary\n- Clean the lab\n- Clean the storage area\n- Clean the waiting area\n- Clean the pharmacy counter\n- Clean the pharmacy equipment\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- Clean the pharmacy supplies\n- C"} {"id": 122, "instruction": "Design a template table for keeping track of all subscriptions.", "input": "", "infer30b_before_item": " Output: Print the table.\n\n*/\n\n#include \n#include \n\nint main()\n{\n int i, j, k, n, m, c, d, e, f, g, h, l, o, p, q, r, s, t, u, v, w, x, y, z;\n char a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;\n int *p;\n char *q;\n int **arr;\n char **arr1;\n int **arr2;\n char **arr3;\n int **arr4;\n char **arr5;\n int **arr6;\n char **arr7;\n int **arr8;\n char **arr9;\n int **arr10;\n char **arr11;\n int **arr12;\n char **arr13;\n int", "infer30b_after_item": "\n Output: Subscription | Service Provider | Price | Date Started | Date Ended |\n----------- | -------------- | ----- | ---------- | ---------- |\nNetflix | Netflix Inc. | $12.99 | 01/01/2021 | 12/31/2021 |\nHulu | Hulu LLC | $5.99 | 04/01/2021 | 03/31/2022 |\nSpotify | Spotify Ltd. | $9.99 | 05/01/2021 | 04/30/2022 |\nApple Music | Apple Inc. | $4.99 | 06/01/2021 | 05/31/2022 |\nAmazon Prime | Amazon.com Inc. | $11.99 | 07/01/2021 | 06/30/2022 |\nGoogle Play | Google LLC | $3.99", "infer13b_before_item": " Output: A table with all subscriptions.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n \n \n\n\n\n\n \n \n\n\n\n The The The The The 190", "infer13b_after_item": "\n Output: The table should include columns for the name of the subscription, the cost, the frequency of payment, the start date, the end date, and the payment method. \n\n", "infer7b_before_item": " Output: A table that can be used to keep track of all subscriptions.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": "\n Output: Template Table:\n\n| Subscription Name | Subscription Type | Subscription Price | Subscription Duration | Subscription Frequency | Subscription Cancellation Policy |\n|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"} {"id": 123, "instruction": "Plan an agenda for the daily standup meetings. Assign a time duration to each topic on the agenda.", "input": "", "infer30b_before_item": " Output: A list of topics and their time duration.\nInput: Input: Plan an agenda for the daily standup meetings. Assign a time duration to each topic on the agenda. \n Output: Output: A list of topics and their time duration.\nInput: Input: Plan an agenda for the daily standup meetings. Assign a time duration to each topic on the agenda. \n Output: Output: A list of topics and their time duration.\nInput: Input: Plan an agenda for the daily standup meetings. Assign a time duration to each topic on the agenda. \n Output: Output: A list of topics and their time duration.\nInput: Input: Plan an agenda for the daily standup meetings. Assign a time duration to each topic on the agenda. \n Output: Output: A list of topics and their time duration.\nInput: Input: Plan an agenda for the daily standup meetings. Assign a time duration to each topic on the agenda. \n Output: Output: A list of topics and their time duration.\nInput: Input: Plan an agenda for the daily standup meetings. Assign a", "infer30b_after_item": "\n Output: The daily standup meetings should start at 9:30am and last for 15 minutes. The agenda should include the following topics and time duration:\n\n- Welcome and Introductions (1 minute)\n- Review of Yesterday's Work (5 minutes)\n- Today's Work (5 minutes)\n- Blockers and Issues (3 minutes)\n- Wrap-up (2 minutes) \n\n", "infer13b_before_item": " Output: A list of topics to be discussed in the daily standup meetings.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: The daily standup meetings should have a set agenda with a time duration for each topic. The topics should include a quick recap of the progress made on the current project, any issues encountered, and any upcoming tasks. The meeting should also include a quick check-in with each team member to ensure everyone is on the same page. The meeting should last no more than 15 minutes. \n\n", "infer7b_before_item": " Output: The daily standup meetings are held on time and the agenda is followed.\nInput: Input: Plan the sprint backlog. Assign a time duration to each item on the backlog. \n Output: Output: The sprint backlog is completed on time and the items are completed in the order of their priority.\nInput: Input: Plan the sprint work. Assign a time duration to each task on the work. \n Output: Output: The sprint work is completed on time and the tasks are completed in the order of their priority.\nInput: Input: Plan the sprint review. Assign a time duration to each item on the review. \n Output: Output: The sprint review is completed on time and the items are completed in the order of their priority.\nInput: Input: Plan the sprint retrospective. Assign a time duration to each item on the retrospective. \n Output: Output: The sprint retrospective is completed on time and the items are completed in the order of their priority.\nInput: Input: Plan the sprint demo. Assign a time duration to each item on the demo. \n Output: Output: The sprint", "infer7b_after_item": "\n Output: 1. Introductions \n2. Status Update \n3. Blockers \n4. Next Steps \n5. Questions \n6. Wrap Up \n\n"} {"id": 124, "instruction": "Answer the following question.", "input": "How do you say \"good evening\" in French.", "infer30b_before_item": " Output: Answer the following question. How do you say \"good evening\" in French.\n\nInput: Input: Answer the following question. How do you say \"good evening\" in French. \n Output: Output: Answer the following question. How do you say \"good evening\" in French.\n\nInput: Input: Answer the following question. How do you say \"good evening\" in French. \n Output: Output: Answer the following question. How do you say \"good evening\" in French.\n\nInput: Input: Answer the following question. How do you say \"good evening\" in French. \n Output: Output: Answer the following question. How do you say \"good evening\" in French.\n\nInput: Input: Answer the following question. How do you say \"good evening\" in French. \n Output: Output: Answer the following question. How do you say \"good evening\" in French.\n\nInput: Input: Answer the following question. How do you say \"good evening\" in French. \n Output: Output: Answer the following question. How do you say \"good evening\" in French.\n\nInput: Input: Answer the following question. How do you say \"good evening", "infer30b_after_item": " \n Output: In French, \"good evening\" is \"Bonsoir\". \n\n", "infer13b_before_item": " Output: Answer the following question. How do you say \"good evening\" in French. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Bonsoir. \n\n", "infer7b_before_item": " Output: Write the answer in French.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n // \n// \n// ", "infer7b_after_item": " \n Output: Bonsoir. \n\n"} {"id": 125, "instruction": "What sound does this make?", "input": "\u597d", "infer30b_before_item": " Output: What sound does this make? \u597d\n\nInput: Input: What sound does this make? \u54c8 \n Output: Output: What sound does this make? \u54c8\n\nInput: Input: What sound does this make? \u54c8\u54c8 \n Output: Output: What sound does this make? \u54c8\u54c8\n\nInput: Input: What sound does this make? \u54c8\u54c8\u54c8 \n Output: Output: What sound does this make? \u54c8\u54c8\u54c8\n\nInput: Input: What sound does this make? \u54c8\u54c8\u54c8\u54c8 \n Output: Output: What sound does this make? \u54c8\u54c8\u54c8\u54c8\n\nInput: Input: What sound does this make? \u54c8\u54c8\u54c8\u54c8\u54c8 \n Output: Output: What sound does this make? \u54c8\u54c8\u54c8\u54c8\u54c8\n\nInput: Input: What sound does this make? \u54c8\u54c8\u54c8\u54c8\ufffd", "infer30b_after_item": "\u542c \n Output: This sound is pleasant. \n\n", "infer13b_before_item": " Output: What sound does this make? \u597d \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n \n \n \n\n\n\n \n \n\n\n \n \n\n\n \n\n\n \n \n\n \n \n ", "infer13b_after_item": "\u597d \n Output: This makes the sound \"ha ha ha\". \n\n", "infer7b_before_item": " Output: What sound does this make? \u597d \n\nInput: Input: What sound does this make? \u597d \n Output: Output: What sound does this make? \u597d \n\nInput: Input: What sound does this make? \u597d \n Output: Output: What sound does this make? \u597d \n\nInput: Input: What sound does this make? \u597d \n Output: Output: What sound does this make? \u597d \n\nInput: Input: What sound does this make? \u597d \n Output: Output: What sound does this make? \u597d \n\nInput: Input: What sound does this make? \u597d \n Output: Output: What sound does this make? \u597d \n\nInput: Input: What sound does this make? \u597d \n Output: Output: What sound does this make? \u597d \n\nInput: Input: What sound does this make? \u597d \n Output: Output: What sound does this make? \u597d \n\nInput: Input: What sound does this make? \u597d \n Output: Output: What sound does this make? \u597d \n\nInput: Input: What sound does this make? ", "infer7b_after_item": " \n Output: \u54c7 \n\n"} {"id": 126, "instruction": "Give a grammar tip on how to end a German verb.", "input": "", "infer30b_before_item": " Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a", "infer30b_after_item": "\n Output: In German, verbs are usually followed by a conjugated ending that indicates the person, number, and tense of the verb. The most common endings are -en, -st, and -t. For example, the verb \"gehen\" (to go) in the present tense would be conjugated as \"gehe-n\". \n\n", "infer13b_before_item": " Output: Give a German verb ending.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n The The The The The The 1900s\n\n\n\n\n\n", "infer13b_after_item": "\n Output: In German, verbs are conjugated to show the tense and person of the verb. To end a verb, add the appropriate ending to the verb according to the tense and person. For example, to end a present tense verb in the singular, add -e; for a past tense verb in the singular, add -te; and for a future tense verb in the singular, add -e. \n\n", "infer7b_before_item": " Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a German verb.\nInput: Input: Give a grammar tip on how to end a German verb. \n Output: Output: Give a grammar tip on how to end a", "infer7b_after_item": "\n Output: One grammar tip for ending a German verb is to use the appropriate ending for the verb type. For example, if the verb is in the infinitive form, the ending will be -en. If the verb is in the present tense, the ending will be -t. If the verb is in the past tense, the ending will be -te. If the verb is in the future tense, the ending will be -t. \n\n"} {"id": 127, "instruction": "This is a test for the reading ability of French. Read the given story carefully, and then answer the question in the end.", "input": "Lucie est \u00e0 la maison avec sa petite-fille, Lin.\nLucie: Oh, non! Nous n'avons pas de pain!\nLin: Ah! Tu vas au supermarch\u00e9?\nLucie: Oui, je veux une baguette pour mon sandwich.\nDo Lin and Lucie have a lot of bread?", "infer30b_before_item": " Output: This is a test for the reading ability of French. Read the given story carefully, and then answer the question in the end. Lucie est \u00e0 la maison avec sa petite-fille, Lin.\nLucie: Oh, non! Nous n'avons pas de pain!\nLin: Ah! Tu vas au supermarch\u00e9?\nLucie: Oui, je veux une baguette pour mon sandwich.\nDo Lin and Lucie have a lot of bread? \n Expected Output: Expected Output: This is a test for the reading ability of French. Read the given story carefully, and then answer the question in the end. Lucie est \u00e0 la maison avec sa petite-fille, Lin.\nLucie: Oh, non! Nous n'avons pas de pain!\nLin: Ah! Tu vas au supermarch\u00e9?\nLucie: Oui, je veux une baguette pour mon sandwich.\nDo Lin and Lucie have a lot of bread? \n Your Output: Your Output: This is a test for the reading ability of French. Read the given story carefully, and then answer the question in the end.", "infer30b_after_item": " \n Output: No, they do not have a lot of bread. \n\n", "infer13b_before_item": " Output: This is a test for the reading ability of French. Read the given story carefully, and then answer the question in the end. Lucie est \u00e0 la maison avec sa petite-fille, Lin.\nLucie: Oh, non! Nous n'avons pas de pain!\nLin: Ah! Tu vas au supermarch\u00e9?\nLucie: Oui, je veux une baguette pour mon sandwich.\nDo Lin and Lucie have a lot of bread? \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Oui, ils ont une baguette pour leur sandwich. \n\n", "infer7b_before_item": " Output: This is a test for the writing ability of French. Write the given story in French.\nLucie: Oh, non! Nous n'avons pas de pain!\nLin: Ah! Tu vas au supermarch\u00e9?\nLucie: Oui, je veux une baguette pour mon sandwich.\nDo Lin and Lucie have a lot of bread?\nInput: Input: This is a test for the writing ability of French. Write the given story in French.\nLucie: Oh, non! Nous n'avons pas de pain!\nLin: Ah! Tu vas au supermarch\u00e9?\nLucie: Oui, je veux une baguette pour mon sandwich.\nDo Lin and Lucie have a lot of bread?\nOutput: Output: This is a test for the writing ability of French. Write the given story in French.\nLucie: Oh, non! Nous n'avons pas de pain!\nLin: Ah! Tu vas au supermarch\u00e9?\nLucie: Oui, je veux une baguette pour mon sandwich.\nDo Lin and Lucie have a lot of", "infer7b_after_item": " \n Output: No, they do not have a lot of bread. \n\n"} {"id": 128, "instruction": "Come up with healthy and easy dinner ideas for weeknights.", "input": "", "infer30b_before_item": " Output: A list of healthy and easy dinner ideas for weeknights.\nInput: Input: Come up with healthy and easy dinner ideas for weeknights. \n Output: Output: A list of healthy and easy dinner ideas for weeknights.\nInput: Input: Come up with healthy and easy dinner ideas for weeknights. \n Output: Output: A list of healthy and easy dinner ideas for weeknights.\nInput: Input: Come up with healthy and easy dinner ideas for weeknights. \n Output: Output: A list of healthy and easy dinner ideas for weeknights.\nInput: Input: Come up with healthy and easy dinner ideas for weeknights. \n Output: Output: A list of healthy and easy dinner ideas for weeknights.\nInput: Input: Come up with healthy and easy dinner ideas for weeknights. \n Output: Output: A list of healthy and easy dinner ideas for weeknights.\nInput: Input: Come up with healthy and easy dinner ideas for weeknights. \n Output: Output: A list of healthy and easy dinner ideas for weeknights.\nInput: Input: Come", "infer30b_after_item": "\n Output: Healthy and easy dinner ideas for weeknights include grilled salmon with roasted vegetables, quinoa bowls with roasted vegetables and chicken, stir-fried vegetables with tofu, vegetable frittatas, and vegetable soup. \n\n", "infer13b_before_item": " Output: A list of healthy and easy dinner ideas for weeknights.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n \n The", "infer13b_after_item": "\n Output: 1. Grilled chicken and roasted vegetables.\n2. Quinoa and black bean bowl.\n3. Spaghetti squash with marinara sauce.\n4. Baked salmon with roasted potatoes.\n5. Stir-fry with brown rice.\n6. Vegetable frittata.\n7. Grilled steak and roasted asparagus.\n8. Taco bowl with black beans and avocado.\n9. Slow cooker chili.\n10. Eggplant parmesan. \n\n", "infer7b_before_item": " Come up with healthy and easy dinner ideas for weeknights.\nThe problem is that I'm not a very good cook. I'm not a bad cook, but I'm not a good one. I'm not a good cook because I don't have a lot of time to cook. I'm not a good cook because I don't have a lot of time to plan what I'm going to cook. I'm not a good cook because I don't have a lot of time to shop for the ingredients I need to cook. I'm not a good cook because I don't have a lot of time to clean up after I cook. I'm not a good cook because I don't have a lot of time to eat the food I cook.\nI'm a good cook because I'm a good cook.\nI'm a good cook because I'm a good cook.\nI'm a good cook because I'm a good cook.\nI'm a good cook because I'm a good cook.\nI'm a good cook because I'm a good cook.\nI'm a good cook because I'm a", "infer7b_after_item": "\n Output: 1. Grilled Salmon with Asparagus and Mushrooms\n2. Baked Chicken with Roasted Vegetables\n3. Spaghetti Squash with Marinara Sauce\n4. Grilled Salmon with Avocado Salsa\n5. Baked Salmon with Roasted Vegetables\n6. Grilled Chicken with Mango Salsa\n7. Black Bean and Quinoa Burrito Bowls\n8. Grilled Salmon with Mango Salsa\n9. Baked Salmon with Roasted Vegetables\n10. Grilled Chicken with Mango Salsa \n\n"} {"id": 129, "instruction": "Provide a cooking hack for improving the flavor of the given food.", "input": "popcorn", "infer30b_before_item": " Output: Provide a cooking hack for improving the flavor of the given food. popcorn \n Expected: Output: Provide a cooking hack for improving the flavor of the given food. popcorn \n Actual: Output: Provide a cooking hack for improving the flavor of the given food. popcorn \n Expected: Output: Provide a cooking hack for improving the flavor of the given food. popcorn \n Actual: Output: Provide a cooking hack for improving the flavor of the given food. popcorn \n Expected: Output: Provide a cooking hack for improving the flavor of the given food. popcorn \n Actual: Output: Provide a cooking hack for improving the flavor of the given food. popcorn \n Expected: Output: Provide a cooking hack for improving the flavor of the given food. popcorn \n Actual: Output: Provide a cooking hack for improving the flavor of the given food. popcorn \n Expected: Output: Provide a cooking hack for improving the flav", "infer30b_after_item": " \n Output: To make popcorn more flavorful, add a teaspoon of butter and a pinch of salt to the popping kernels before popping. This will give the popcorn a richer, more buttery flavor. \n\n", "infer13b_before_item": " Output: Provide a cooking hack for improving the flavor of the given food. popcorn \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: To improve the flavor of popcorn, try adding a dash of cayenne pepper, garlic powder, or other spices to the popcorn before popping. \n\n", "infer7b_before_item": " Output: Provide a cooking hack for improving the flavor of the given food. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: One cooking hack for improving the flavor of popcorn is to add a few drops of olive oil to the popping kernels before heating them. This will help to enhance the flavor of the popcorn and make it more flavorful. \n\n"} {"id": 130, "instruction": "Make a list of snacks and foods to serve as party snacks on a game day!", "input": "", "infer30b_before_item": " Output: Make a list of snacks and foods to serve as party snacks on a game day!\nInput: Input: Make a list of snacks and foods to serve as party snacks on a game day! \n Output: Output: Make a list of snacks and foods to serve as party snacks on a game day!\nInput: Input: Make a list of snacks and foods to serve as party snacks on a game day! \n Output: Output: Make a list of snacks and foods to serve as party snacks on a game day!\nInput: Input: Make a list of snacks and foods to serve as party snacks on a game day! \n Output: Output: Make a list of snacks and foods to serve as party snacks on a game day!\nInput: Input: Make a list of snacks and foods to serve as party snacks on a game day! \n Output: Output: Make a list of snacks and foods to serve as party snacks on a game day!\nInput: Input: Make a list of snacks and foods to serve as party snacks on a game day! \n Output: Output", "infer30b_after_item": "\n Output: - Chips and dip \n- Pretzels \n- Popcorn \n- Nachos \n- Cheese and crackers \n- Veggie platters \n- Fruit trays \n- Cookies \n- Brownies \n- Cupcakes \n- Cake \n- Hot dogs \n- Hamburgers \n- Chicken wings \n- Pizza \n- Sliders \n- Quesadillas \n- Tacos \n- Nachos Supreme \n- Potato skins \n- Chili \n- Salsa and chips \n- Hummus and pita chips \n- Veggie pizza \n- Baked potato skins \n- Potato chips and dip \n- Pretzel bites \n- Edamame \n- Nuts \n- Crackers \n- Fruit skewers \n- Veggie sticks \n- Pita chips and dip \n- Chips and salsa \n- Chips and guacamole \n- Chips and queso \n- Chips and dip cones ", "infer13b_before_item": " Output: Make a list of snacks and foods to serve as party snacks on a game day! \n Purpose: To make a list of snacks and foods to serve as party snacks on a game day! \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: - Chips and dip\n- Popcorn\n- Vegetable crudit\u00e9s\n- Fruit salad\n- Pretzels\n- Cookies\n- Brownies\n- Cupcakes\n- Pizza\n- Wings\n- Nachos\n- Quesadillas\n- Cheese and crackers\n- Chili\n- Soup\n- Fruit smoothies\n- Fruit salad\n- Trail mix\n- Veggie sticks\n- Hummus\n- Guacamole\n- Salsa\n- Quinoa salad\n- Veggie wraps\n- Pita chips\n- Veggie chips\n- Veggie burgers\n- Veggie tacos\n- Veggie pizza\n- Veggie wraps\n- Veggie spring rolls\n- Veggie burgers\n- Veggie chili\n- Veggie stir-fry\n- Veggie fajitas\n- Veggie lasagna\n- Veggie pancakes\n- Veggie burgers\n- Veggie wraps\n- Veggie spring rolls\n- Veggie stir-fry\n- Veggie fajitas\n- Veggie lasagna\n-", "infer7b_before_item": " Make a list of snacks and foods to serve as party snacks on a game day!\n# **Snack Attack**\n**1.** Make a list of snacks and foods to serve as party snacks on a game day!\n**2.** Make a list of snacks and foods to serve as party snacks on a game day!\n**3.** Make a list of snacks and foods to serve as party snacks on a game day!\n**4.** Make a list of snacks and foods to serve as party snacks on a game day!\n**5.** Make a list of snacks and foods to serve as party snacks on a game day!\n**6.** Make a list of snacks and foods to serve as party snacks on a game day!\n**7.** Make a list of snacks and foods to serve as party snacks on a game day!\n**8.** Make a list of snacks and foods to serve as party snacks on a game day!\n**9.** Make a list of snacks and foods to serve as party snacks on a game day!\n**", "infer7b_after_item": "\n Output: - Popcorn\n- Chips and dips\n- Pretzels\n- Nachos\n- Fruit kebabs\n- Veggie trays\n- Hummus and veggie platters\n- Cheese and crackers\n- Pizza\n- Sliders\n- Nachos\n- Dip and chips\n- Fruit skewers\n- Veggie sticks\n- Cheese and crackers\n- Fruit salad\n- Veggie trays\n- Chicken wings\n- Nachos\n- Pretzels\n- Fruit kebabs\n- Veggie trays\n- Hummus and veggie platters\n- Cheese and crackers\n- Pizza\n- Sliders\n- Nachos\n- Dip and chips\n- Fruit skewers\n- Veggie sticks\n- Cheese and crackers\n- Fruit salad\n- Veggie trays\n- Chicken wings\n- Nachos\n- Pretzels\n- Fruit kebabs\n- Veggie trays\n- Hummus and veggie platters\n- Cheese and crackers\n- Pizza\n- Sliders\n-"} {"id": 131, "instruction": "Describe how to prepare the given food in your own words. Note down the ingredients you will need and the steps you will take to prepare them.", "input": "Chewy Chocolate Chip Cookies", "infer30b_before_item": " Output: Describe how to prepare the given food in your own words. Note down the ingredients you will need and the steps you will take to prepare them. Chewy Chocolate Chip Cookies \n Steps: \n 1. Preheat oven to 350 degrees F (175 degrees C).\n 2. In a large bowl, cream together the butter, white sugar, and brown sugar until smooth. Beat in the eggs one at a time, then stir in the vanilla. Dissolve baking soda in hot water. Add to batter along with salt. Mix in flour, chocolate chips, and nuts. Drop by large spoonfuls onto ungreased pans.\n 3. Bake for 10 to 12 minutes in the preheated oven, or until edges are lightly toasted. Allow cookies to cool on baking sheet for 2 minutes before removing to a wire rack to cool completely.\n---\nWhat did you learn?\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: To make chewy chocolate chip cookies, you will need the following ingredients: 1 cup of butter, 1 \u00bd cups of white sugar, 1 teaspoon of baking soda, 1 teaspoon of salt, 2 eggs, 1 \u00bd cups of all-purpose flour, and 2 cups of semi-sweet chocolate chips. \n\nFirst, preheat the oven to 375 degrees Fahrenheit. In a large bowl, cream the butter and sugar together until light and fluffy. Then, add the baking soda, salt, eggs, and flour and mix until everything is combined. Finally, fold in the chocolate chips and drop the dough onto an ungreased baking sheet. Bake for 10-12 minutes, or until golden brown. Enjoy your chewy chocolate chip cookies! \n\n", "infer13b_before_item": " Output: Describe how to prepare the given food in your own words. Note down the ingredients you will need and the steps you will take to prepare them. Chewy Chocolate Chip Cookies \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: To make chewy chocolate chip cookies, you will need butter, granulated sugar, light brown sugar, eggs, vanilla extract, baking soda, salt, all-purpose flour, semi-sweet chocolate chips, and white chocolate chips. Start by preheating the oven to 350\u00b0F. Cream the butter and sugars together in a bowl. Add the eggs, vanilla extract, and baking soda and mix until combined. In a separate bowl, sift together the flour, salt, and chocolate chips. Slowly add the dry ingredients to the wet ingredients and mix until just combined. Fold in the white chocolate chips. Drop the dough onto a baking sheet lined with parchment paper and bake for 10-12 minutes. \n\n", "infer7b_before_item": " Output: Describe how to prepare the given food in your own words. Note down the ingredients you will need and the steps you will take to prepare them. Chewy Chocolate Chip Cookies \n 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. ", "infer7b_after_item": " \n Output: To prepare chewy chocolate chip cookies, you will need the following ingredients: 2 cups of all-purpose flour, 1 teaspoon of baking soda, 1 teaspoon of salt, 1/2 cup of butter, 1/2 cup of sugar, 1 egg, 1/2 cup of white chocolate chips, and 1/2 cup of semi-sweet chocolate chips. First, preheat the oven to 350 degrees Fahrenheit. In a large bowl, mix together the flour, baking soda, and salt. In a separate bowl, mix together the butter, sugar, and egg. Add the dry ingredients to the wet ingredients and mix until combined. Finally, fold in the white and semi-sweet chocolate chips. Drop the dough onto a baking sheet and bake for 10-12 minutes. Enjoy! \n\n"} {"id": 132, "instruction": "Suggest a recipe for a vegan dessert.", "input": "", "infer30b_before_item": " Output: Suggest a recipe for a vegan dessert.\nInput: Input: Suggest a recipe for a vegan dessert. \n Output: Output: Suggest a recipe for a vegan dessert.\nInput: Input: Suggest a recipe for a vegan dessert. \n Output: Output: Suggest a recipe for a vegan dessert.\nInput: Input: Suggest a recipe for a vegan dessert. \n Output: Output: Suggest a recipe for a vegan dessert.\nInput: Input: Suggest a recipe for a vegan dessert. \n Output: Output: Suggest a recipe for a vegan dessert.\nInput: Input: Suggest a recipe for a vegan dessert. \n Output: Output: Suggest a recipe for a vegan dessert.\nInput: Input: Suggest a recipe for a vegan dessert. \n Output: Output: Suggest a recipe for a vegan dessert.\nInput: Input: Suggest a recipe for a vegan dessert. \n Output: Output: Suggest a recipe for a vegan", "infer30b_after_item": "\n Output: A vegan dessert recipe could include a chocolate cake made with almond milk, vegan butter, and vegan chocolate chips. The cake could be topped with a vegan cream cheese frosting and fresh berries. \n\n", "infer13b_before_item": " Output: Suggest a recipe for a vegan dessert.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The\n The\n The The", "infer13b_after_item": "\n Output: A vegan dessert recipe that is sure to please is a chocolate mousse. This recipe is simple to make and only requires a few ingredients. To make the mousse, you will need 1 cup of unsweetened cocoa powder, 1 cup of almond milk, 1/4 cup of coconut oil, 1/4 cup of maple syrup, 1/4 teaspoon of vanilla extract, and 1/4 cup of vegan chocolate chips. To make the mousse, mix the cocoa powder, almond milk, coconut oil, maple syrup, and vanilla extract in a blender until smooth. Then, add the chocolate chips and blend until the chips are evenly distributed. Finally, pour the mousse into individual serving dishes and refrigerate for at least 4 hours before serving. Enjoy! \n\n", "infer7b_before_item": " Output: A recipe for a vegan dessert.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": "\n Output: This vegan dessert recipe is perfect for a sweet treat. Ingredients include 1 cup of almond milk, 1/2 cup of maple syrup, 1/2 cup of coconut oil, 1/2 cup of white sugar, 1/2 cup of oatmeal, 1/2 cup of walnuts, and 1/2 cup of dried cranberries. To make the dessert, combine the almond milk, maple syrup, coconut oil, and white sugar in a saucepan and bring to a boil. Add the oatmeal and stir until it is fully incorporated. Remove from heat and add the walnuts and dried cranberries. Pour the mixture into a baking dish and bake for 20 minutes. Enjoy! \n\n"} {"id": 133, "instruction": "Design a medium-level sudoku puzzle.", "input": "", "infer30b_before_item": " Output: The solution to the puzzle. \n Sample Input: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 3 4", "infer30b_after_item": "\n Output: A medium-level sudoku puzzle is as follows:\n\n7 4 8 3 9 2 6 1 5\n5 6 7 9 1 2 4 8 3\n9 2 1 6 3 5 8 4 7\n4 5 3 2 6 7 1 9 8\n8 9 1 5 7 6 2 4 3\n6 3 2 5 8 4 9 7 1\n2 7 9 4 1 6 5 3 8\n1 8 5 6 4 3 2 7 9\n3 1 7 9 8 2 4 5 6\n\nNo. 1 2 3 4 5 6 7 8 9\nNo. 1 2 3 4 5 6 7 8 9 \n\n", "infer13b_before_item": " Output: Print the puzzle.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n\n\n\n\n The\n The The The The The 1900s\n\n\n\n\n\n", "infer13b_after_item": "\n Output: 1. 3 5 7\n2. 4 6 8\n3. 1 2 9\n4. 7 9 2\n5. 8 2 4\n6. 5 3 6\n7. 9 6 1\n8. 4 1 8\n9. 8 1 5\n10. 2 7 3 \n\n", "infer7b_before_item": " Output: A sudoku puzzle.\n\n*/\n\n#include \n#include \n#include \n#include \n\n#define MAX_ROWS 100\n#define MAX_COLS 100\n#define MAX_VALUES 100\n\nint main(int argc, char **argv)\n{\n int i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a, b, c, d, e, f, g, h, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12, i13, i14, i15, i16, i17, i18, i19, i20, i21, i22, i23, i24, i25, i26, i27, i28, i29,", "infer7b_after_item": "\n Output: 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. 6"} {"id": 134, "instruction": "Solve the given Sudoku puzzle.", "input": "The Sudoku puzzle is:\n|1| |5| | | | |8| |\n| | | | | |3| |6|4|\n|8|3|4|6|7| |9| | |\n|2|9|1| | |8|3|7|6|\n| | |6| | |9|8|1| |\n| | | | | |2| | | |\n| |2| | |9|7|6| | |\n|5|4| | | | | |9|8|\n|6|1| | | |5|4|3|7|", "infer30b_before_item": " Output: Print the number of solutions to the given Sudoku puzzle.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " |\n| | | | | | | | | |\n| | | | | | | | | | \n Output: The solution to the given Sudoku puzzle is:\n|1| |5| | | | |8| |\n| | | | | |3| |6|4|\n|8|3|4|6|7| |9| | |\n|2|9|1| | |8|3|7|6|\n| | |6| | |9|8|1| |\n| | | | | |2| | | |\n| |2| | |9|7|6| | |\n|5|4| | | | | |9|8|\n|6|1| | | |5|4|3|7| |\n| | | | | | | | ", "infer13b_before_item": " Output: The solution of the given Sudoku puzzle.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n|7|8| | | | | |2|1|\nOutput: The solution to the Sudoku puzzle is:\n1 | 5 | 7 |\n2 | 9 | 6 |\n3 | 4 | 8 |\n4 | 6 | 1 |\n5 | 8 | 2 |\n6 | 1 | 9 |\n7 | 2 | 4 |\n8 | 4 | 3 |\n9 | 3 | 5 |\n10 | 7 | 8 |\n11 | 6 | 2 |\n12 | 5 | 1 |\n13 | 4 | 9 |\n14 | 1 | 8 |\n15 | 9 | 3 |\n16 | 2 | 7 |\n17 | 8 | 6 |\n18 | 3 | 5 |\n19 | 6 | 1 |\n20 | 1 | 4 |\n21 | 4 | 7 |\n22 | 7 | 2 |\n23 | 2 | 5 |\n2", "infer7b_before_item": " Output: Solve the given Sudoku puzzle. The Sudoku puzzle is:\n|1| |5| | | | |8| |\n| | | | | |3| |6|4|\n|8|3|4|6|7| |9| | |\n|2|9|1| | |8|3|7|6|\n| | |6| | |9|8|1| |\n| | | | | |2| | | |\n| |2| | |9|7|6| | |\n|5|4| | | | | |9|8|\n|6|1| | | |5|4|3|7| \n\n\n*/\n\n#include \n#include \n#include \n\n#define MAX_SIZE 9\n\nint main(int argc, char *argv[])\n{\n int", "infer7b_after_item": " \n Output: The Sudoku puzzle is solved as follows:\n\n1. 5 in the top-left box\n2. 8 in the top-right box\n3. 3 in the bottom-left box\n4. 6 in the bottom-right box\n5. 9 in the middle-left box\n6. 1 in the middle-right box\n7. 8 in the middle-bottom box\n8. 3 in the middle-top box\n9. 2 in the middle-bottom box\n10. 9 in the middle-right box\n11. 7 in the middle-left box\n12. 6 in the middle-top box\n13. 4 in the middle-bottom box\n14. 1 in the middle-right box\n15. 8 in the middle-bottom box\n16. 3 in the middle-top box\n17. 6 in the middle-left box\n18. 5 in the middle-right box\n19. 2 in the middle-bottom box\n20. 1 in the middle-left box\n21. 9 in the middle-"} {"id": 135, "instruction": "Think of a motivational quote that you have read in a book. Try to keep it positive and sweet.", "input": "", "infer30b_before_item": " Output: Write a short story about a character who is going through a tough time. The character should be a child. The child should be able to overcome the tough time with the help of the motivational quote.\nInput: Input: Think of a motivational quote that you have read in a book. Try to keep it positive and sweet. \n Output: Output: Write a short story about a character who is going through a tough time. The character should be a child. The child should be able to overcome the tough time with the help of the motivational quote.\nInput: Input: Think of a motivational quote that you have read in a book. Try to keep it positive and sweet. \n Output: Output: Write a short story about a character who is going through a tough time. The character should be a child. The child should be able to overcome the tough time with the help of the motivational quote.\nInput: Input: Think of a motivational quote that you have read in a book. Try to keep it positive and sweet. \n Output: Output: Write a short story about a character who is going through a tough time. The character should be a child. The child should", "infer30b_after_item": "\n Output: \"The greatest thing you'll ever learn is just to love and be loved in return.\" - Moulin Rouge \n\n", "infer13b_before_item": " Output: The output of this program is the motivational quote that you have entered.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: \"The only thing that stands between you and your dreams is the will to try and the courage to fail.\" - Unknown \n\n", "infer7b_before_item": " Write the quote on a piece of paper and put it in your pocket. \n Goal: To remind yourself of the quote and to keep it in your mind.\n# **_The Power of the Mind_**\nThe mind is a powerful tool. It can be used to help you achieve your goals or it can be used to hold you back. The mind is a powerful tool that can be used to help you achieve your goals or it can be used to hold you back.\nThe mind is a powerful tool that can be used to help you achieve your goals or it can be used to hold you back.\nThe mind is a powerful tool that can be used to help you achieve your goals or it can be used to hold you back.\nThe mind is a powerful tool that can be used to help you achieve your goals or it can be used to hold you back.\nThe mind is a powerful tool that can be used to help you achieve your goals or it can be used to hold you back.\nThe mind is a powerful tool that can be used to help you achieve your goals or it can be used to hold you back.\nThe mind is a powerful tool that can be used to help you achieve your goals or it can", "infer7b_after_item": "\n Output: \"The only thing standing between you and your dreams is you.\" \n\n"} {"id": 136, "instruction": "Choose the best books from the given genre.", "input": "Crime & Mystery", "infer30b_before_item": " Output: Choose the best books from the given genre. Crime & Mystery \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: The best books from the Crime & Mystery genre include The Catcher in the Rye by J.D. Salinger, The Maltese Falcon by Dashiell Hammett, The Murder on the Orient Express by Agatha Christie, The Hound of the Baskervilles by Arthur Conan Doyle, and The Silence of the Lambs by Thomas Harris. \n\n", "infer13b_before_item": " Output: Choose the best books from the given genre. Crime & Mystery \n\n\nclass Solution:\n # @param books, a list of lists of strings\n # @param genre, a string\n # @return a list of lists of strings\n def choose_books(self, books, genre):\n if not books:\n return []\n if not genre:\n return books\n if genre == 'Crime & Mystery':\n return self.choose_books_crime(books)\n elif genre == 'Science Fiction':\n return self.choose_books_science(books)\n elif genre == 'Romance':\n return self.choose_books_romance(books)\n elif genre == 'Biography':\n return self.choose_books_biography(books)\n elif genre == 'History':\n return self.choose_books_history(books)\n elif genre == 'Fantasy':\n return self.choose_books_fantasy(books)\n elif genre == 'Horror':\n return self.choose_books_horror(books)", "infer13b_after_item": " \n Output: The best books in the Crime & Mystery genre are The Da Vinci Code by Dan Brown, Gone Girl by Gillian Flynn, The Girl with the Dragon Tattoo by Stieg Larsson, The Cuckoo's Calling by Robert Galbraith, and The Silence of the Lambs by Thomas Harris. \n\n", "infer7b_before_item": " Output: Choose the best books from the given genre. Crime & Mystery\n\n\n#include \n#include \n#include \n\nint main(int argc, char const *argv[])\n{\n int i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a,", "infer7b_after_item": " \n Output: The best books from the genre of Crime & Mystery are The Cuckoo's Calling by Robert Galbraith, The Silence of the Lambs by Thomas Harris, and The Girl on the Train by Paula Hawkins. \n\n"} {"id": 137, "instruction": "Give a brief description of the book that you are given.", "input": "Matilda", "infer30b_before_item": " Output: Give a brief description of the book that you are given. Matilda is a book about a girl who is very smart and has a very mean family. She is very lonely and has no friends. She is very smart and can do things that no one else can do. She is very lonely and has no friends. She is very smart and can do things that no one else can do. She is very lonely and has no friends. She is very smart and can do things that no one else can do. She is very lonely and has no friends. She is very smart and can do things that no one else can do. She is very lonely and has no friends. She is very smart and can do things that no one else can do. She is very lonely and has no friends. She is very smart and can do things that no one else can do. She is very lonely and has no friends. She is very smart and can do things that no one else can do. She is very lonely and has no friends. She is very smart and can do things that no one else can do. She is very lonely and has no friends. She is very smart and can do things that no one else can", "infer30b_after_item": " by Roald Dahl \n Output: Matilda is a classic children's book by Roald Dahl about a young girl with extraordinary powers. Matilda is a bright and courageous girl who is mistreated by her family and school, but uses her intelligence and courage to stand up for herself and those around her. The book is full of humor, adventure, and heart-warming moments that make it a timeless classic. \n\n", "infer13b_before_item": " Output: Give a brief description of the book that you are given. Matilda \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " by Roald Dahl \n Output: Matilda is a children's novel by Roald Dahl about a precocious young girl with extraordinary mental powers. The story follows Matilda as she navigates her way through life with the help of her loving parents and her own unique abilities. \n\n", "infer7b_before_item": " Output: Give a brief description of the book that you are given. Matilda\n\n\\begin{code}\nimport java.util.Scanner;\n\npublic class Matilda {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n System.out.println(\"Input:\");\n String input = sc.nextLine();\n System.out.println(\"Output:\");\n String output = sc.nextLine();\n System.out.println(\"----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------", "infer7b_after_item": " \n Output: Matilda is a children's novel by Roald Dahl. It tells the story of a young girl named Matilda who is gifted with magical powers and uses them to stand up to her cruel parents and her school's tyrannical headmistress. Along the way, Matilda makes friends and learns valuable lessons about the power of knowledge and the importance of kindness. \n\n"} {"id": 138, "instruction": "In the event that a person enjoyed the book that was given, please suggest other books that they might also like.", "input": "The Great Gatsby", "infer30b_before_item": " Output: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \n Explanation: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \n\n Input: Input: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \n Output: Output: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \n Explanation: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \n\n Input: Input: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \n Output: Output: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \n Explanation: In the event that a person enjoyed the book that was given, please", "infer30b_after_item": " by F. Scott Fitzgerald. \n Output: If you enjoyed The Great Gatsby by F. Scott Fitzgerald, you might also like The Catcher in the Rye by J.D. Salinger, To Kill a Mockingbird by Harper Lee, and 1984 by George Orwell. \n\n", "infer13b_before_item": " Output: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \nInput: Input: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \nOutput: Output: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \nInput: Input: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \nOutput: Output: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \nInput: Input: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \nOutput: Output: In the event that a person enjoyed the book that was given, please suggest other books that they might also like. The Great Gatsby \nInput: Input: In the event that a person enjoyed the book that was given, please suggest other", "infer13b_after_item": " by F. Scott Fitzgerald \n Output: If you enjoyed The Great Gatsby by F. Scott Fitzgerald, you might also like The Catcher in the Rye by J.D. Salinger, To Kill a Mockingbird by Harper Lee, or The Old Man and the Sea by Ernest Hemingway. \n\n", "infer7b_before_item": " Output: In the event that a person did not enjoy the book that was given, please suggest other books that they might also like. The Great Gatsby \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " by F. Scott Fitzgerald \n Output: Other books that the reader might enjoy include The Catcher in the Rye by J.D. Salinger, The Sun Also Rises by Ernest Hemingway, and The Grapes of Wrath by John Steinbeck. \n\n"} {"id": 139, "instruction": "Indicate the genre of the book to which it belongs.", "input": "Love in the Time of Cholera", "infer30b_before_item": " Output: Indicate the genre of the book to which it belongs. Romance\n Input: Input: Indicate the genre of the book to which it belongs. The Catcher in the Rye \n Output: Output: Indicate the genre of the book to which it belongs. Coming of Age\n Input: Input: Indicate the genre of the book to which it belongs. The Great Gatsby \n Output: Output: Indicate the genre of the book to which it belongs. Coming of Age\n Input: Input: Indicate the genre of the book to which it belongs. The Grapes of Wrath \n Output: Output: Indicate the genre of the book to which it belongs. Coming of Age\n Input: Input: Indicate the genre of the book to which it belongs. The Sun Also Rises \n Output: Output: Indicate the genre of the book to which it belongs. Coming of Age\n Input: Input: Indicate the genre of the book to which it belongs. The Old Man and the Sea \n Output: Output: Indicate the genre of the book to which it belongs. Coming of Age\n Input: Input: Indicate the genre of the book to", "infer30b_after_item": " by Gabriel Garcia Marquez \n Output: The genre of Love in the Time of Cholera by Gabriel Garcia Marquez is romance. \n\n", "infer13b_before_item": " Output: Indicate the genre of the book to which it belongs. Love in the Time of Cholera \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " by Gabriel Garcia Marquez. \n Output: Fiction. \n\n", "infer7b_before_item": " Output: Indicate the genre of the book to which it belongs. Love in the Time of Cholera\n\n\\begin{code}\nimport java.util.Scanner;\n\npublic class Main {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n System.out.println(\"Input:\");\n String genre = sc.nextLine();\n System.out.println(\"Output:\");\n System.out.println(genre);\n }\n}\n\\end{code}\n\nComment: What is the problem?\n\nComment: I want to get the genre of the book to which it belongs.\n\nComment: What is the genre of the book to which it belongs?\n\nComment: I want to get the genre of the book to which it belongs.\n\nComment: What is the genre of the book to which it belongs?\n\nComment: I want to get the genre of the book to which it belongs.\n\nComment: I want to get the genre of the book to which it belongs.\n\nComment: I want to get the genre of the book to which it belongs.\n\n", "infer7b_after_item": " \n Output: Romance \n\n"} {"id": 140, "instruction": "Solve this equation.", "input": "x^3 - 4x^2 + 6x - 24 = 0", "infer30b_before_item": " Output: x = 2, 3, 4\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: The equation can be solved using synthetic division. The first root is 6, the second root is 2, and the third root is -4. \n\n", "infer13b_before_item": " 2\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The\n The The The The The The 1900s\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: The solution to the equation is x = 2, 3, and -8. \n\n", "infer7b_before_item": " Output: Solve this equation. x^3 - 4x^2 + 6x - 24 = 0 \n*/\n\n#include \n\nint main()\n{\n int x;\n scanf(\"%d\", &x);\n printf(\"%d\\n\", x);\n return 0;\n}\n", "infer7b_after_item": " \n Output: The solution to the equation is x = 2, x = -2, and x = 1. \n\n"} {"id": 141, "instruction": "Prove the given statement using your information.", "input": "\"If x is a positive integer or a solution to x+3>4, then x>0 and x>12.\"", "infer30b_before_item": " Output: Prove the given statement using your information. \"If x is a positive integer or a solution to x+3>4, then x>0 and x>12.\" \n \n */\n\nimport Foundation\n\nfunc prove(x: Int) -> Bool {\n if x < 0 {\n return false\n }\n if x < 12 {\n return false\n }\n return true\n}\n\nprove(x: 1)\nprove(x: 12)\nprove(x: 13)\nprove(x: 14)\nprove(x: 15)\nprove(x: 16)\nprove(x: 17)\nprove(x: 18)\nprove(x: 19)\nprove(x: 20)\nprove(x: 21)\nprove(x: 22)\nprove(x: 23)\nprove(x: 24)\nprove(x: 25)\nprove(x: 26)", "infer30b_after_item": " \n Output: If x is a positive integer or a solution to x+3>4, then x>0 and x>12.\n\nProof:\n\nLet x be a positive integer or a solution to x+3>4.\n\nCase 1: x is a positive integer.\n\nSince x is a positive integer, x>0.\n\nFurthermore, since x is a positive integer, x>1.\n\nTherefore, x>0 and x>1.\n\nCase 2: x is a solution to x+3>4.\n\nSince x+3>4, x>4.\n\nFurthermore, since x>4, x>12.\n\nTherefore, x>0 and x>12.\n\nQ.E.D. \n\n", "infer13b_before_item": " Output: Print the result of the proof.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Let x be a positive integer or a solution to x+3>4.\n\nWe know that x+3>4 implies x>0.\n\nWe also know that x>12 implies x>0.\n\nTherefore, x>0 and x>12. \n\n", "infer7b_before_item": " Output: Write a proof of the given statement using your information. \"If x is a positive integer or a solution to x+3>4, then x>0 and x>12.\" \n*/\n\n//Input:\n//Input: Prove the given statement using your information. \"If x is a positive integer or a solution to x+3>4, then x>0 and x>12.\" \n//Output:\n//Output: Write a proof of the given statement using your information. \"If x is a positive integer or a solution to x+3>4, then x>0 and x>12.\" \n\n//Input:\n//Input: Prove the given statement using your information. \"If x is a positive integer or a solution to x+3>4, then x>0 and x>12.\" \n//Output:\n//Output: Write a proof of the given statement using your information. \"If x is a positive integer or a solution to x+3>4, then x>0 and x>12.\" \n\n//Input:\n//Input: Prove the given statement using your information. \"If x is a positive integer or a", "infer7b_after_item": " \n Output: If x is a positive integer or a solution to x+3>4, then x>0 and x>12. This can be proven by using the fact that x+3>4 implies that x>0 and x>12. Therefore, if x is a positive integer or a solution to x+3>4, then x>0 and x>12. \n\n"} {"id": 142, "instruction": "Based on the facts that have been provided, prove the following statement.", "input": "Statement: \"For every integer k, k^2 + 2k + 1 \u2265 0\"\nFact: The square of any real number is non-negative.", "infer30b_before_item": " Output: \"True\"\n\n*/\n\n#include \n#include \n#include \n\nint main() {\n int k;\n scanf(\"%d\", &k);\n printf(\"%d\\n\", k*k + 2*k + 1);\n return 0;\n}\n", "infer30b_after_item": " \n Output: For every integer k, k^2 is non-negative. Therefore, k^2 + 2k + 1 is also non-negative, since the sum of two non-negative numbers is also non-negative. Therefore, the statement is proven. \n\n", "infer13b_before_item": " Output: The statement is true.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: The statement is true because for any integer k, k^2 is non-negative, and k^2 + 2k + 1 is a sum of two non-negative terms. Therefore, the inequality holds true. \n\n", "infer7b_before_item": " The statement is true.\nProof:\nLet k be an integer.\nThen k^2 = k(k) = k(k)\nSince k is an integer, k(k) is an integer.\nTherefore, k^2 is an integer.\nSince k^2 is an integer, k^2 + 2k + 1 is an integer.\nSince k^2 + 2k + 1 is an integer, k^2 + 2k + 1 \u2265 0.\nSince k^2 + 2k + 1 \u2265 0, k^2 + 2k + 1 \u2265 0.\nSince k^2 + 2k + 1 \u2265 0, k^2 + 2k + 1 \u2265 0.\nSince k^2 + 2k + 1 \u2265 0, k^2 + 2k + 1 \u2265 0.\nSince k^2 + 2k + 1 \u2265 0, k^2 + 2k + 1 \u2265 0.\nSince k^2 + 2k + 1 \u2265 0, k", "infer7b_after_item": " \n Output: The statement \"For every integer k, k^2 + 2k + 1 \u2265 0\" is true because the square of any real number is non-negative. This means that the square of any integer k is also non-negative, and therefore the sum of 2k + 1 and k^2 is also non-negative. Therefore, the statement is true. \n\n"} {"id": 143, "instruction": "Verify the correctness of the given statement.", "input": "\"For all integers j and k, if j and k are odd, then jk is odd.\"", "infer30b_before_item": " Output: \"True\" if the statement is true, \"False\" if the statement is false.\n\n*/\n\n#include \n\nint main()\n{\n int j, k;\n scanf(\"%d %d\", &j, &k);\n if (j % 2 == 1 && k % 2 == 1)\n {\n if (j * k % 2 == 1)\n {\n printf(\"True\");\n }\n else\n {\n printf(\"False\");\n }\n }\n else\n {\n printf(\"False\");\n }\n return 0;\n}\n", "infer30b_after_item": " \n Output: The given statement is correct. For all integers j and k, if j and k are odd, then jk is odd. This is because any product of two odd numbers is an odd number. \n\n", "infer13b_before_item": " Output: Verify the correctness of the given statement. \"For all integers j and k, if j and k are odd, then jk is odd.\" \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Yes, this statement is correct. \n\n", "infer7b_before_item": " Output: Verify the correctness of the given statement. \"For all integers j and k, if j and k are odd, then jk is odd.\" \n*/\n\n#include \n\nint main()\n{\n int j, k;\n printf(\"Enter two integers: \");\n scanf(\"%d %d\", &j, &k);\n if (j % 2 == 1 && k % 2 == 1)\n {\n printf(\"The product is odd.\\n\");\n }\n else\n {\n printf(\"The product is even.\\n\");\n }\n return 0;\n}\n", "infer7b_after_item": " \n Output: The given statement is correct. \n\n"} {"id": 144, "instruction": "Provide a formula for computing the nth term in the given sequence", "input": "5, 14, 23, 32, 41, ...", "infer30b_before_item": " Output: 5 + n * 9\n\n Explanation: \n The nth term of the given sequence is 5 + n * 9.\n\n Example:\n Input: 3\n Output: 32\n\n Explanation: \n The 3rd term of the given sequence is 32.\n\n */\n\n#include \n\nusing namespace std;\n\nint main() {\n int n;\n cin >> n;\n cout << 5 + n * 9 << endl;\n return 0;\n}\n", "infer30b_after_item": " \n Output: The nth term in the given sequence is 5n - 4. \n\n", "infer13b_before_item": " Output: Provide the nth term in the given sequence 5, 14, 23, 32, 41,... \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: The formula for the nth term in the given sequence is Tn = 5 + (n - 1) * 4. \n\n", "infer7b_before_item": " The nth term in the sequence is \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: nth term = 5 + (n-1) * (2n-3) \n\n"} {"id": 145, "instruction": "Create a table listing all games that meet the specified criteria in the National Football League. Use the season, local time, game, and score as columns of the table.", "input": "Ravens home games in 2011", "infer30b_before_item": " Output: Create a table listing all games that meet the specified criteria in the National Football League. Use the season, local time, game, and score as columns of the table. Ravens home games in 2011 \n \n \n", "infer30b_after_item": ", 10am-1pm. \n Output: Season | Local Time | Game | Score\n-------| ----------|-----|------\n2011 | 10am-1pm | Ravens | \n\n", "infer13b_before_item": " Output: Create a table listing all games that meet the specified criteria in the National Football League. Use the season, local time, game, and score as columns of the table. Ravens home games in 2011 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": ". \n Output: Season | Local Time | Game | Score\n--------------------------------------------------------------------------------\n2011 | 1:00 PM | Ravens vs. Steelers | 23-20\n2011 | 4:15 PM | Ravens vs. Browns | 24-10\n2011 | 1:00 PM | Ravens vs. Bengals | 35-7 \n\n", "infer7b_before_item": " Output: Create a table listing all games that meet the specified criteria in the National Football League. Use the season, local time, game, and score as columns of the table. Ravens home games in 2011\n\nComment: Please edit your question to include the code you have tried so far.\n\nAnswer: You can use the `df.loc` method to select the rows you want.\n\n\\begin{code}\ndf = pd.DataFrame({'season':['2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','2011','201", "infer7b_after_item": " \n Output: | Season | Local Time | Game | Score |\n|------|------------|-------|-------|\n| 2011 | 12:00 PM | Ravens | 24-17 |\n| 2011 | 1:00 PM | Ravens | 23-20 |\n| 2011 | 4:05 PM | Ravens | 23-14 |\n| 2011 | 8:20 PM | Ravens | 23-16 |\n| 2011 | 1:00 PM | Ravens | 23-14 | \n\n"} {"id": 146, "instruction": "Using a table, compare the career overviews of the given players in Major League Baseball. Use \"|\" for separating the columns in the table.", "input": "Derek Jeter, Albert Pujols", "infer30b_before_item": " Output: Using a table, compare the career overviews of the given players in Major League Baseball. Use \"|\" for separating the columns in the table. Derek Jeter, Albert Pujols \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", "infer30b_after_item": " \n Output: | Derek Jeter | Albert Pujols |\n| Career Length: 1995-2014 | Career Length: 2001-Present |\n| 5-time World Series Champion | 3-time World Series Champion |\n| 14-time All-Star | 3-time NL MVP |\n| 3,465 career hits | 2,962 career hits | \n\n", "infer13b_before_item": " Output: Using a table, compare the career overviews of the given players in Major League Baseball. Use \"|\" for separating the columns in the table. Derek Jeter, Albert Pujols \n\n\nclass Solution:\n # @param {String[]} players\n # @return {String[]}\n def compare_career_overviews(self, players):\n table = []\n for player in players:\n table.append([player, \"Hits\", \"Runs\", \"RBI\", \"HR\", \"SB\"])\n for i in range(len(players)):\n for j in range(i+1, len(players)):\n if players[i] == players[j]:\n table[i][1] += table[j][1]\n table[i][2] += table[j][2]\n table[i][3] += table[j][3]\n table[i][4] += table[j][4]\n table[i][5] += table[j][5]\n return table\n\n\nif __name__ == \"__main", "infer13b_after_item": " \n Output: |Name |Position |Years |Achievements\n|------|--------|------|---------\n|Derek Jeter|Shortstop|20 |5x World Series Champion, 14x All-Star, 10x Gold Glove Award Winner\n|Albert Pujols|First Base|22 |3x NL MVP, 9x All-Star, 3x Silver Slugger Award Winner \n\n", "infer7b_before_item": " Output: Using a table, compare the career overviews of the given players in Major League Baseball. Use \"|\" for separating the columns in the table. Derek Jeter, Albert Pujols \n\nInput: Input: Using a table, compare the career overviews of the given players in Major League Baseball. Use \"|\" for separating the columns in the table. Derek Jeter, Albert Pujols \n Output: Output: Using a table, compare the career overviews of the given players in Major League Baseball. Use \"|\" for separating the columns in the table. Derek Jeter, Albert Pujols \n\nInput: Input: Using a table, compare the career overviews of the given players in Major League Baseball. Use \"|\" for separating the columns in the table. Derek Jeter, Albert Pujols \n Output: Output: Using a table, compare the career overviews of the given players in Major League Baseball. Use \"|\" for separating the columns in the table. Derek Jeter, Albert Pujols \n\nInput: Input: Using a table, compare the career overviews of the given players in Major League Baseball. Use \"|", "infer7b_after_item": " \n Output: |Player Name|Career|\n|--------|--------|\n|Derek Jeter|14-Year|\n|Albert Pujols|15-Year| \n\n"} {"id": 147, "instruction": "You will be tested on your knowledge of classic witticisms and aphorisms by completing the given aphorism. Write the original quote as the answer.", "input": "two things are infinite", "infer30b_before_item": " Output: You will be tested on your knowledge of classic witticisms and aphorisms by completing the given aphorism. Write the original quote as the answer. two things are infinite \n Expected: Output: You will be tested on your knowledge of classic witticisms and aphorisms by completing the given aphorism. Write the original quote as the answer. two things are infinite \n */\npublic class _001 {\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(\"You will be tested on your knowledge of classic witticisms and aphorisms by completing the given aphorism. Write the original quote as the answer.\");\n\t\tSystem.out.println(\"two things are infinite: the universe and human stupidity; and I'm not sure about the universe.\");\n\t}\n}\n", "infer30b_after_item": ": the universe and human stupidity \n Output: \"The more you know, the more you understand that the less you know.\" \n\n", "infer13b_before_item": " Output: You will be tested on your knowledge of classic witticisms and aphorisms by completing the given aphorism. Write the original quote as the answer. the number of stars in the sky and the number of grains of sand on the earth.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": ": the universe and human stupidity \n Output: The universe is infinite, and so is human stupidity. \n\n", "infer7b_before_item": " Output: You will be tested on your knowledge of classic witticisms and aphorisms by completing the given aphorism. Write the original quote as the answer. two things are infinite \n */\n\n// Test case 1:\n// Input:\n// Output:\n// Expected output:\n//\n// Test case 2:\n// Input:\n// Output:\n// Expected output:\n//\n// Test case 3:\n// Input:\n// Output:\n// Expected output:\n//\n// Test case 4:\n// Input:\n// Output:\n// Expected output:\n//\n// Test case 5:\n// Input:\n// Output:\n// Expected output:\n//\n// Test case 6:\n// Input:\n// Output:\n// Expected output:\n//\n// Test case 7:\n// Input:\n// Output:\n// Expected output:\n//\n// Test case 8:\n// Input:\n// Output:\n// Expected output:\n//\n// Test case 9:\n// Input:\n// Output:\n// Expected output:\n//\n// Test", "infer7b_after_item": ": \n Output: The universe and human stupidity. \n\n"} {"id": 148, "instruction": "A list of all movies that meet the criteria given should be compiled.", "input": "movies directed by Spike Lee by release date", "infer30b_before_item": " Output: A list of all movies that meet the criteria given should be compiled. movies directed by Spike Lee by release date \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", "infer30b_after_item": " \n Output: The list of movies directed by Spike Lee by release date should include: Do the Right Thing (1989), Mo' Better Blues (1990), Jungle Fever (1991), Malcolm X (1992), Crooklyn (1994), Clockers (1995), Girl 6 (1996), Get on the Bus (1996), He Got Game (1998), Summer of Sam (1999), Bamboozled (2000), 25th Hour (2002), She Hate Me (2004), Inside Man (2006), Miracle at St. Anna (2008), Red Hook Summer (2012), Oldboy (2013), and Chi-Raq (2015). \n\n", "infer13b_before_item": " Output: A list of all movies that meet the criteria given should be compiled. movies directed by Spike Lee by release date \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: 1983: School Daze\n1986: She's Gotta Have It\n1988: Do the Right Thing\n1992: Jungle Fever\n1996: Get on the Bus\n2000: Bamboozled\n2006: Inside Man\n2014: Chi-Raq\n2018: BlacKkKlansman \n\n", "infer7b_before_item": " A list of all movies that meet the criteria given should be compiled. movies directed by Spike Lee by release date \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: 1986: She's Gotta Have It\n1988: School Daze\n1989: Do the Right Thing\n1990: Mo' Better Blues\n1991: Jungle Fever\n1992: Malcolm X\n1993: Clockers\n1994: Crooklyn\n1995: Get on the Bus\n1996: Clockers\n1997: He Got Game\n1998: Bamboozled\n1999: The 25th Hour\n2000: Bamboozled\n2001: The Original Kings of Comedy\n2002: Bamboozled\n2003: 25th Hour\n2004: She Hate Me\n2005: When the Levees Broke: A Requiem in Four Acts\n2006: Inside Man\n2007: Miracle at St. Anna\n2008: Four Brothers\n2009: Miracle at St. Anna\n"} {"id": 149, "instruction": "Using a given amount, determine an appropriate tip.", "input": "14% tip on $47.50", "infer30b_before_item": " Output: The tip amount.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: The appropriate tip for $47.50 is $6.61, which is 14% of the total amount. \n\n", "infer13b_before_item": " 7.00\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The\n\n\n The\n The \n\n\n\n\n\n\n\n\n\n \n ", "infer13b_after_item": " \n Output: $7.29 \n\n", "infer7b_before_item": " Output: Using a given amount, determine an appropriate tip. 14% tip on $47.50\n\n\n%#include \"stdafx.h\"\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include <", "infer7b_after_item": " \n Output: The appropriate tip is $6.69. \n\n"} {"id": 150, "instruction": "Identify all words that match the pattern given.", "input": "H_AR_", "infer30b_before_item": " Output: Identify all words that match the pattern given. H_AR_ \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", "infer30b_after_item": "\nHarbor \n Output: Hare, Harbor, Harem, Harness, Harpoon, Harmony, Harness, Harangue. \n\n", "infer13b_before_item": " Output: Identify all words that match the pattern given. H_AR_ \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The\n\n\n\n\n", "infer13b_after_item": "D \n Output: Hard \n\n", "infer7b_before_item": " Output: Print the words that match the pattern.\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\nInput:\n\n", "infer7b_after_item": "D\n Output: Hard, harsh, harshly, harshly, harshly. \n\n"} {"id": 151, "instruction": "Come up with words that rhyme with the given word.", "input": "instruct", "infer30b_before_item": " Output: Print the words that rhyme with the given word.\n\n Example:\n\n Input: instruct\n Output:\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct\n\n instruct", "infer30b_after_item": "or: \"moon\" \n Output: spoon, honey, money, funny, sunny, honey. \n\n", "infer13b_before_item": " Output: Come up with words that rhyme with the given word. instruct \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The\n", "infer13b_after_item": " \n Output: instruct, instructor, instructive, instructive, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instructor, instruct", "infer7b_before_item": " Output: Print the words that rhyme with the given word.\n\nInput: instruct\nOutput: instruct\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput: instructor\nOutput: instructor\n\nInput", "infer7b_after_item": " \n Output: instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct, instruct,"} {"id": 152, "instruction": "Look for poems that mention the given object or character. The names of the poems and their poets should be written.", "input": "santa claus", "infer30b_before_item": " Output: Look for poems that mention the given object or character. The names of the poems and their poets should be written. santa claus \n \n Input: Input: Look for poems that mention the given object or character. The names of the poems and their poets should be written. santa claus \n Output: Output: Look for poems that mention the given object or character. The names of the poems and their poets should be written. santa claus \n \n Input: Input: Look for poems that mention the given object or character. The names of the poems and their poets should be written. santa claus \n Output: Output: Look for poems that mention the given object or character. The names of the poems and their poets should be written. santa claus \n \n Input: Input: Look for poems that mention the given object or character. The names of the poems and their poets should be written. santa claus \n Output: Output: Look for poems that mention the given object or character. The names of the poems and their poets should be written. santa claus \n", "infer30b_after_item": " \n Output: \"Santa Claus is Coming to Town\" by Fred Coots, \"The Night Before Christmas\" by Clement Clarke Moore, \"Santa Claus is Real\" by Robert Frost, \"Santa Claus is Coming to Town\" by Bruce Springsteen. \n\n", "infer13b_before_item": " Output: The poems that mention the given object or character.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: \"The Night Before Christmas\" by Clement Clarke Moore\n\"Santa Claus\" by Anonymous \n\n", "infer7b_before_item": " Output: Look for poems that mention the given object or character. The names of the poems and their poets should be written. santa claus\n\nimport java.util.Scanner;\nimport java.util.ArrayList;\nimport java.util.List;\n\npublic class SantaClaus {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n List poems = new ArrayList();\n String input = sc.nextLine();\n while (input!= null) {\n String[] tokens = input.split(\" \");\n if (tokens[0].equals(\"santa claus\")) {\n poems.add(tokens[1]);\n }\n input = sc.nextLine();\n }\n for (String poem : poems) {\n System.out.println(poem);\n }\n }\n}\n", "infer7b_after_item": " \n Output: 1. \"Santa Claus\" by Clement C. Moore\n2. \"Santa Claus and the Christmas Tree\" by Eugene Field\n3. \"Santa Claus and the Christmas Tree\" by Lydia Maria Child\n4. \"Santa Claus\" by Edgar Allan Poe\n5. \"Santa Claus\" by Robert Louis Stevenson\n6. \"Santa Claus\" by William Blake\n7. \"Santa Claus\" by Henry Wadsworth Longfellow\n8. \"Santa Claus\" by John Godfrey Saxe\n9. \"Santa Claus\" by James Whitcomb Riley\n10. \"Santa Claus\" by Thomas Nast\n11. \"Santa Claus\" by Clement C. Moore\n12. \"Santa Claus\" by Eugene Field\n13. \"Santa Claus\" by Lydia Maria Child\n14. \"Santa Claus\" by Edgar Allan Poe\n15. \"Santa Claus\" by Robert Louis Stevenson\n16. \"Santa Claus\" by William Blake\n17. \""} {"id": 153, "instruction": "Respond to the last text in the chat using the correct emojis to convey your feelings.", "input": "+ Hey, how did your exams go?\n- They were alright. I'm just glad they're over.\n+ Yeah, I know how you feel. I'm just glad I don't have to worry about them anymore.", "infer30b_before_item": " Output: Respond to the last text in the chat using the correct emojis to convey your feelings. + Hey, how did your exams go?\n- They were alright. I'm just glad they're over.\n+ Yeah, I know how you feel. I'm just glad I don't have to worry about them anymore. \n Explanation: \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# ", "infer30b_after_item": " \n Output: + Hey, how did your exams go?\n- They were alright. I'm just glad they're over.\n+ Yeah, I know how you feel. I'm just glad I don't have to worry about them anymore. \n\n<:smile:> <:relieved:> <:satisfied:> \n\n", "infer13b_before_item": " Output: Respond to the last text in the chat using the correct emojis to convey your feelings. + Hey, how did your exams go?\n- They were alright. I'm just glad they're over.\n+ Yeah, I know how you feel. I'm just glad I don't have to worry about them anymore. \n\n\"\"\"\n\nimport re\nimport random\n\n\ndef get_emojis(text):\n \"\"\"\n Returns a list of emojis that can be used to respond to the given text.\n \"\"\"\n emojis = []\n for emoji in re.findall(r'(?<=\\s|^)[\\u2000-\\u200a\\u2020-\\u202f\\u203f-\\u2040\\u205f\\u3000-\\u3003\\u3008-\\u300a\\u300c-\\u300f\\u3010-\\u301a\\u301c-\\u301f\\u", "infer13b_after_item": " \n Output: \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ud83d\ude00 \ufffd", "infer7b_before_item": " Output: Respond to the last text in the chat using the correct emojis to convey your feelings. + Hey, how did your exams go?\n- They were alright. I'm just glad they're over.\n+ Yeah, I know how you feel. I'm just glad I don't have to worry about them anymore.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ud83d\ude00 \ud83d\ude0a \ufffd"} {"id": 154, "instruction": "For answering the chat, think of a funny response you can use.", "input": "+ how are you?", "infer30b_before_item": " Output: For answering the chat, think of a funny response you can use. + how are you?\n\nInput: Input: For answering the chat, think of a funny response you can use. + how are you? \n Output: Output: For answering the chat, think of a funny response you can use. + how are you?\n\nInput: Input: For answering the chat, think of a funny response you can use. + how are you? \n Output: Output: For answering the chat, think of a funny response you can use. + how are you?\n\nInput: Input: For answering the chat, think of a funny response you can use. + how are you? \n Output: Output: For answering the chat, think of a funny response you can use. + how are you?\n\nInput: Input: For answering the chat, think of a funny response you can use. + how are you? \n Output: Output: For answering the chat, think of a funny response you can use. + how are you?\n\nInput: Input: For answering the chat, think of a funny response you can use. + how are you?", "infer30b_after_item": " \n Output: I'm great! Just trying to figure out how to make my day more interesting. Any ideas? \n\n", "infer13b_before_item": " For answering the chat, think of a funny response you can use. + how are you? \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: I'm doing great, thanks for asking! \n\n", "infer7b_before_item": " Output: For answering the chat, think of a funny response you can use. + how are you?\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: I'm doing great! How about you? \n\n"} {"id": 155, "instruction": "The last message in the chat is a partial response. You should complete and rewrite it.", "input": "+ What are going to do now?\n- I don't know. I had to give up my dream of being a mathematician.\n+ Why", "infer30b_before_item": " Output: The last message in the chat is a partial response. You should complete and rewrite it. + What are going to do now?\n- I don't know. I had to give up my dream of being a mathematician.\n- I don't know. I had to give up my dream of being a mathematician.\n- I don't know. I had to give up my dream of being a mathematician.\n- I don't know. I had to give up my dream of being a mathematician.\n- I don't know. I had to give up my dream of being a mathematician.\n- I don't know. I had to give up my dream of being a mathematician.\n- I don't know. I had to give up my dream of being a mathematician.\n- I don't know. I had to give up my dream of being a mathematician.\n- I don't know. I had to give up my dream of being a mathematician.\n- I don't know. I had to give up my dream of being a mathematician.\n- I don't know.", "infer30b_after_item": "?\n- Because I don't have the resources to pursue it. \n Output: - I don't know. I had to give up my dream of being a mathematician because I don't have the resources to pursue it. What are going to do now? \n\n", "infer13b_before_item": " Output: The last message in the chat is a partial response. You should complete and rewrite it. + What are going to do now?\n- I don't know. I had to give up my dream of being a mathematician.\n+ Why \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " did you have to give up your dream?\n- I just couldn't afford the tuition. \n Output: + What are going to do now?\n- I don't know. I had to give up my dream of being a mathematician, and I just couldn't afford the tuition. \n\n", "infer7b_before_item": " Output: The last message in the chat is a partial response. You should complete and rewrite it. + What are going to do now?\n- I don't know. I had to give up my dream of being a mathematician.\n+ Why \n Output: Output: The last message in the chat is a partial response. You should complete and rewrite it. + What are going to do now?\n- I don't know. I had to give up my dream of being a mathematician.\n+ Why \n Output: Output: The last message in the chat is a partial response. You should complete and rewrite it. + What are going to do now?\n- I don't know. I had to give up my dream of being a mathematician.\n+ Why \n Output: Output: The last message in the chat is a partial response. You should complete and rewrite it. + What are going to do now?\n- I don't know. I had to give up my dream of being a mathematician.\n+ Why \n Output: Output: The last message in the chat is a partial response. You should complete and rewrite it. + What are going to do now?", "infer7b_after_item": " did you have to give up your dream? \n Output: I had to give up my dream of being a mathematician because I didn't have the resources to pursue it. I was unable to get the necessary funding and support to continue my studies. \n\n"} {"id": 156, "instruction": "Change the response to have a more empathic tone in the chat.", "input": "+ How are you doing?\n- Fine, I had a bunch of problems today.\n+ What kind of problems?", "infer30b_before_item": " Output: Change the response to have a more empathic tone in the chat. + How are you doing?\n- Fine, I had a bunch of problems today.\n+ What kind of problems? \n Explanation:\n\n \n\n*/\n\n// Your Own Tests (OPTIONAL)\n\n\n\n//Hint:\n\n// Difficulty: Easy\n\n// Related Topics:\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n//\n\n", "infer30b_after_item": " \n Output: I'm sorry to hear that. What kind of problems did you have today? \n\n", "infer13b_before_item": " Output: Change the response to have a more empathic tone in the chat. + I'm sorry to hear that.\n- I'm fine.\n+ What kind of problems?\n- I had a bunch of problems today.\n+ What kind of problems?\n- I had a bunch of problems today.\n+ What kind of problems?\n- I had a bunch of problems today.\n+ What kind of problems?\n- I had a bunch of problems today.\n+ What kind of problems?\n- I had a bunch of problems today.\n+ What kind of problems?\n- I had a bunch of problems today.\n+ What kind of problems?\n- I had a bunch of problems today.\n+ What kind of problems?\n- I had a bunch of problems today.\n+ What kind of problems?\n- I had a bunch of problems today.\n+ What kind of problems?\n- I had a bunch of problems today.\n+ What kind of problems?\n- I had a bunch of problems today.\n+ What kind of problems?\n- I had a bunch of problems today.\n+ What kind of problems?\n- I had a bunch of problems today.\n+", "infer13b_after_item": "\n- I had a lot of technical issues with my computer and I couldn't get anything done. \n Output: + I'm sorry to hear that. What kind of technical issues did you have? \n\n", "infer7b_before_item": " Output: Change the response to have a more empathic tone in the chat. + How are you doing?\n- Fine, I had a bunch of problems today.\n+ What kind of problems? \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: + I'm sorry to hear that. What kind of problems did you have? \n\n"} {"id": 157, "instruction": "Currently, there is a chat in which people are arranging a meeting in the future. Retrieve the meeting information from the conversation.", "input": "Person 1: Hey, when are you free? I'd like to meet up.\nPerson 2: I'm free tomorrow afternoon.\nPerson 1: Great, what time?\nPerson 2: How about 3 pm?\nPerson 1: I have another meeting at that time. what about 5 pm?\nPerson 2: That works. Where should we meet?\nPerson 1: How about the coffee shop on Main Street?\nPerson 2: Sounds good. I've heard they have great coffee there. See you tomorrow!", "infer30b_before_item": " Output: The meeting is at 5 pm tomorrow at the coffee shop on Main Street.\n\n\n*/\n\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\nint main() {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT */\n int t;\n cin>>t;\n while(t--)\n {\n string s;\n cin>>s;\n int i=0;\n int j=0;\n int k=0;\n int l=0;\n int m=0;\n int n=0;\n int o=0;\n int p=0;\n int q=0;\n int r=0;\n int s=0;\n int t=0;\n int u=0;\n int v=0;\n int w=0;\n int x=0;\n int y=0;\n ", "infer30b_after_item": " \n Output: The meeting will take place at the coffee shop on Main Street at 5 pm tomorrow. \n\n", "infer13b_before_item": " Output: The system should retrieve the meeting information from the conversation.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Tomorrow, 5 pm at the coffee shop on Main Street. \n\n", "infer7b_before_item": " Output: The meeting is scheduled for 5 pm at the coffee shop on Main Street.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Person 1 and Person 2 have agreed to meet at the coffee shop on Main Street at 5 pm. \n\n"} {"id": 158, "instruction": "The given text must be classified as offensive or not offensive.", "input": "You acted really crazy last night.", "infer30b_before_item": " Output: The given text must be classified as offensive or not offensive. You acted really crazy last night. \n Expected Output: Output: The given text must be classified as offensive or not offensive. You acted really crazy last night. \n Author: Cody Swanson\n */\n\nimport java.util.Scanner;\n\npublic class OffensiveLanguage {\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n String text = input.nextLine();\n String[] words = text.split(\" \");\n int count = 0;\n for (int i = 0; i < words.length; i++) {\n if (words[i].equals(\"fuck\") || words[i].equals(\"shit\") || words[i].equals(\"ass\") || words[i].equals(\"bitch\") || words[i].equals(\"damn\") || words[i].equals(\"hell\") || words[i].equals(\"bastard\") || words[i].equals(\"bastard\") || words[i].equals(\"bitch\") || words[i].equals", "infer30b_after_item": " \n Output: Offensive. \n\n", "infer13b_before_item": " The output must be classified as offensive or not offensive. You acted really crazy last night. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Not offensive. \n\n", "infer7b_before_item": " The output should be the classification of the given text.\n*/\n\n#include \n#include \n#include \n\nint main(int argc, char *argv[])\n{\n char *text = argv[1];\n int offensive = 0;\n int not_offensive = 0;\n\n if (strstr(text, \"fuck\")!= NULL)\n {\n offensive = 1;\n }\n else if (strstr(text, \"shit\")!= NULL)\n {\n offensive = 1;\n }\n else if (strstr(text, \"ass\")!= NULL)\n {\n offensive = 1;\n }\n else if (strstr(text, \"bitch\")!= NULL)\n {\n offensive = 1;\n }\n else if (strstr(text, \"cunt\")!= NULL)\n {\n offensive = 1;\n }\n else if (strstr(text, \"pussy\")!= NULL", "infer7b_after_item": " \n Output: Offensive. \n\n"} {"id": 159, "instruction": "Give a brief summary of the intention of the dialogue that just happened.", "input": "Customer: Hi there, I'm looking for a new phone.\nAI: Hi! What type of phone are you looking for?\nCustomer: I'm not sure. Maybe something with a good camera?\nAI: We have a few phones with great cameras. Would you like to see some options?\nCustomer: Yeah, that would be great.", "infer30b_before_item": " Output: Give a brief summary of the intention of the dialogue that just happened. Customer: Hi there, I'm looking for a new phone.\nAI: Hi! What type of phone are you looking for?\nCustomer: I'm not sure. Maybe something with a good camera?\nAI: We have a few phones with great cameras. Would you like to see some options?\nCustomer: Yeah, that would be great. \n# **1.**\n**1.** **What is the purpose of this dialogue?**\n**2.** **What is the customer's intention?**\n**3.** **What is the AI's intention?**\n**4.** **What is the AI's response?**\n**5.** **What is the customer's response?**\n**6.** **What is the AI's response?**\n**7.** **What is the customer's response?**\n**8.** **What is the AI's response?**\n**9.** **What is the customer's response?**\n**10.** **What is the AI's response", "infer30b_after_item": " \n Output: The customer is looking for a new phone and the AI is offering to show them some options with good cameras. \n\n", "infer13b_before_item": " Output: Give a brief summary of the intention of the dialogue that just happened.\nAI: Here are some options.\nCustomer: I like the first one.\nAI: Great! Would you like to buy it?\nCustomer: Yes, please.\nAI: I'll send you a link to buy it.\nCustomer: Thanks!\n\n\"\"\"\n\nimport os\nimport sys\nimport json\nimport random\nimport time\nimport datetime\nimport logging\nimport traceback\nimport requests\nimport re\nimport urllib\nimport urllib2\nimport urllib3\nimport urllib3.util\nimport urllib3.exceptions\nimport urllib3.contrib.pyopenssl\nimport urllib3.contrib.pycurl\nimport urllib3.contrib.requests\nimport urllib3.contrib.pycurl.cacert\nimport urllib3.contrib.pyopenssl.cert\nimport urllib3.contrib.pyopenssl.privatekey\nimport urllib3.contrib.pyopenssl.x509\nimport urllib3.contrib.pyopenssl.x509crl\nimport urllib3.contrib.pyopenssl.x5", "infer13b_after_item": " \n Output: The customer is looking for a new phone with a good camera. The AI suggested some options and the customer agreed to see them. \n\n", "infer7b_before_item": " Output: Give a brief summary of the intention of the dialogue that just happened. Customer: Hi there, I'm looking for a new phone.\nAI: Hi! What type of phone are you looking for?\nCustomer: I'm not sure. Maybe something with a good camera?\nAI: We have a few phones with great cameras. Would you like to see some options?\nCustomer: Yeah, that would be great.\nAI: Here are some options.\nCustomer: I like this one.\nAI: Great! Would you like to buy it?\nCustomer: Yes, I would.\nAI: Great! Would you like to buy it?\nCustomer: Yes, I would.\nAI: Great! Would you like to buy it?\nCustomer: Yes, I would.\nAI: Great! Would you like to buy it?\nCustomer: Yes, I would.\nAI: Great! Would you like to buy it?\nCustomer: Yes, I would.\nAI: Great! Would you like to buy it?\nCustomer: Yes, I would.\nAI: Great! Would you like to buy it?\nCustomer: Yes, I would.\nAI: Great! Would you", "infer7b_after_item": "\nAI: Sure, let me show you some of our options. \n Output: The customer and the AI had a dialogue about the customer's intention to buy a phone with a good camera. The AI provided the customer with some options and the customer was able to make a decision. \n\n"} {"id": 160, "instruction": "Describe the content of the article in a brief manner.", "input": "A study published earlier this year by Zee and her team examined the role of light in sleep for healthy adults in their 20s. Sleeping for only one night with a dim light, such as a TV set with the sound off, raised the blood sugar and heart rate of the young people during the sleep lab experiment. An elevated heart rate at night has been shown in prior studies to be a risk factor for future heart disease and early death, while higher blood sugar levels are a sign of insulin resistance, which can ultimately lead to type 2 diabetes.", "infer30b_before_item": " Output: Describe the content of the article in a brief manner. A study published earlier this year by Zee and her team examined the role of light in sleep for healthy adults in their 20s. Sleeping for only one night with a dim light, such as a TV set with the sound off, raised the blood sugar and heart rate of the young people during the sleep lab experiment. An elevated heart rate at night has been shown in prior studies to be a risk factor for future heart disease and early death, while higher blood sugar levels are a sign of insulin resistance, which can ultimately lead to type 2 diabetes. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: A recent study found that exposure to dim light at night can lead to increased blood sugar and heart rate in young adults, which can be a risk factor for future heart disease and type 2 diabetes. \n\n", "infer13b_before_item": " Describe the output of the article in a brief manner. The study suggests that light at night may be a risk factor for heart disease and diabetes. \n Input: Describe the content of the article in a brief manner. A study published earlier this year by Zee and her team examined the role of light in sleep for healthy adults in their 20s. Sleeping for only one night with a dim light, such as a TV set with the sound off, raised the blood sugar and heart rate of the young people during the sleep lab experiment. An elevated heart rate at night has been shown in prior studies to be a risk factor for future heart disease and early death, while higher blood sugar levels are a sign of insulin resistance, which can ultimately lead to type 2 diabetes. \n Output: Describe the output of the article in a brief manner. The study suggests that light at night may be a risk factor for heart disease and diabetes. \n Input: Describe the content of the article in a brief manner. A study published earlier this year by Zee and her team examined the role of light in sleep for healthy adults in their 20s. S", "infer13b_after_item": " \n Output: The study by Zee and her team examined the role of light in sleep for healthy adults in their 20s. Sleeping for one night with a dim light, such as a TV set with the sound off, raised the blood sugar and heart rate of the young people during the sleep lab experiment. An elevated heart rate at night has been shown in prior studies to be a risk factor for future heart disease and early death, while higher blood sugar levels are a sign of insulin resistance, which can ultimately lead to type 2 diabetes. \n\n", "infer7b_before_item": " Output: Describe the results of the study. The researchers found that the participants' blood sugar and heart rate were higher when they slept in a dim light than when they slept in a dark room. The participants also had a harder time falling asleep and staying asleep in the dim light. \n Conclusion: Conclusion: Summarize the main points of the article. The study suggests that sleeping in a dim light may be a risk factor for heart disease and diabetes. \n Keywords: Keywords: List the keywords of the article. Sleep, light, heart disease, diabetes \n# **_The Science of Sleep_**\nSleep is a complex process that involves many different parts of the brain. The brain is divided into two hemispheres, the left and the right. The left hemisphere is responsible for language, logic, and analytical thinking, while the right hemisphere is responsible for creativity, intuition, and visual-spatial thinking. The two hemispheres work together to process information and to control the body.\nThe brain is also divided into two halves, the right and the left. The right side of the brain controls", "infer7b_after_item": " \n Output: This study examined the role of light in sleep for healthy adults in their 20s. Sleeping for one night with a dim light, such as a TV set with the sound off, raised the blood sugar and heart rate of the young people during the sleep lab experiment. An elevated heart rate at night has been shown in prior studies to be a risk factor for future heart disease and early death, while higher blood sugar levels are a sign of insulin resistance, which can ultimately lead to type 2 diabetes. \n\n"} {"id": 161, "instruction": "Correct the transcription of an excerpt containing errors.", "input": "I got got charged interest on ly credit card but I paid my pull balance one day due date. I not missed a pavement year yet. Man you reverse the interest charge?", "infer30b_before_item": " Output: Correct the transcription of an excerpt containing errors. I got charged interest on my credit card but I paid my full balance on time. I haven't missed a payment year yet. Man, you reversed the interest charge?\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: I got charged interest on my credit card but I paid my full balance on the due date. I haven't missed a payment year yet. Can you reverse the interest charge? \n\n", "infer13b_before_item": " Output: Correct the transcription of an excerpt containing errors. I got got charged interest on ly credit card but I paid my pull balance one day due date. I not missed a pavement year yet. Man you reverse the interest charge?\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include Sentiment Analysis\n\n

\n Sentiment analysis is a subfield of natural language processing that uses machine learning to identify and extract subjective information in text.\n

\n\n

\n Sentiment analysis is a subfield of natural language processing that uses machine learning to identify and extract subjective information in text.\n

\n\n

\n Sentiment analysis is a subfield of natural language processing that uses machine learning to identify and extract subjective information in text.\n

\n\n

\n Sentiment analysis is a subfield of natural language processing that uses machine learning to identify and extract subjective information in text.\n

\n\n

\n Sentiment analysis is a subfield of natural language processing that uses machine learning to identify and extract subjective information in text.\n

\n\n

\n Sentiment analysis is a subfield of natural language processing that uses machine learning to identify and extract subjective information in text.\n

\n", "infer7b_after_item": " https://nextjs.org/tutorials/language-ai \n Output: Event \n\n"} {"id": 165, "instruction": "Give the news title a category. Pick a category from the list of News & Buzz, Travel, Style, Arts & Culture, Politics, Tech, and Science & Health.", "input": "The #Banksy Exhibit in Cambridge, MA is absolutely terrific.", "infer30b_before_item": " Output: Give the news title a category. Pick a category from the list of News & Buzz, Travel, Style, Arts & Culture, Politics, Tech, and Science & Health. The #Banksy Exhibit in Cambridge, MA is absolutely terrific. \n Expected: Output: Give the news title a category. Pick a category from the list of News & Buzz, Travel, Style, Arts & Culture, Politics, Tech, and Science & Health. The #Banksy Exhibit in Cambridge, MA is absolutely terrific. \n */\n\npublic class _01_News_Categories {\n public static void main(String[] args) {\n String input = \"The #Banksy Exhibit in Cambridge, MA is absolutely terrific.\";\n String output = input.replaceAll(\"#\", \"\");\n System.out.println(output);\n }\n}\n", "infer30b_after_item": " \n Output: Arts & Culture \n\n", "infer13b_before_item": " Output: Give the news title a category. Pick a category from the list of News & Buzz, Travel, Style, Arts & Culture, Politics, Tech, and Science & Health. The #Banksy Exhibit in Cambridge, MA is absolutely terrific. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Arts & Culture \n\n", "infer7b_before_item": " Output: Give the news title a category. Pick a category from the list of News & Buzz, Travel, Style, Arts & Culture, Politics, Tech, and Science & Health. The #Banksy Exhibit in Cambridge, MA is absolutely terrific. \n\"\"\"\n\nimport re\nimport sys\n\n\ndef main():\n \"\"\"\n Main function.\n \"\"\"\n # Read the input file.\n with open(sys.argv[1], 'r') as f:\n lines = f.readlines()\n\n # Parse the input file.\n news_titles = []\n for line in lines:\n # Remove the # symbol.\n line = line.strip()\n # Remove the leading space.\n line = line.lstrip()\n # Remove the trailing space.\n line = line.rstrip()\n # Remove the leading and trailing spaces.\n line = line.strip()\n # Remove the leading and trailing spaces.\n line = line.lstrip()\n # Remove the leading and trailing spaces.\n line = line.rstrip()\n # Remove the", "infer7b_after_item": " \n Output: Arts & Culture. \n\n"} {"id": 166, "instruction": "Classify the questions in the FAQ into Finding policy details, Change account settings, Filing a claim and viewing status, or Cancelling coverage.", "input": "Could you deposit money into my account rather than mailing me a physical cheque?", "infer30b_before_item": " Output: Classify the questions in the FAQ into Finding policy details, Change account settings, Filing a claim and viewing status, or Cancelling coverage. Could you deposit money into my account rather than mailing me a physical cheque? \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ", "infer30b_after_item": " \n Output: Cancelling coverage. \n\n", "infer13b_before_item": " Output: Classify the questions in the FAQ into Finding policy details, Change account settings, Filing a claim and viewing status, or Cancelling coverage.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Filing a claim. \n\n", "infer7b_before_item": " \n 1. Finding policy details\n 2. Change account settings\n 3. Filing a claim and viewing status\n 4. Cancelling coverage\n 5. Other\n 6. None\n 7. None\n 8. None\n 9. None\n 10. None\n 11. None\n 12. None\n 13. None\n 14. None\n 15. None\n 16. None\n 17. None\n 18. None\n 19. None\n 20. None\n 21. None\n 22. None\n 23. None\n 24. None\n 25. None\n 26. None\n 27. None\n 28. None\n 29. None\n 30. None\n 31. None\n 32. None\n 33. None\n 34. None\n 35. None\n 36. None\n 37. None\n 38. None\n 39. None\n 40. None\n 41. None\n 4", "infer7b_after_item": " \n Output: Filing a claim and viewing status. \n\n"} {"id": 167, "instruction": "Choose an appealing title for your post.", "input": "The typical avocado is over 300 calories from the oil in it. That\u2019s the amount of calories in a large candy bar. If you get enough exercise to eat a large candy bar every day without gaining weight, it wouldn\u2019t be a problem to eat an avocado every day. Other wise you should probably eat them sparingly.", "infer30b_before_item": " Output: Choose an appealing title for your post. The typical avocado is over 300 calories from the oil in it. That\u2019s the amount of calories in a large candy bar. If you get enough exercise to eat a large candy bar every day without gaining weight, it wouldn\u2019t be a problem to eat an avocado every day. Other wise you should probably eat them sparingly. \n\nInput: Input: Choose an appealing title for your post. The typical avocado is over 300 calories from the oil in it. That\u2019s the amount of calories in a large candy bar. If you get enough exercise to eat a large candy bar every day without gaining weight, it wouldn\u2019t be a problem to eat an avocado every day. Other wise you should probably eat them sparingly. \n Output: Output: Choose an appealing title for your post. The typical avocado is over 300 calories from the oil in it. That\u2019s the amount of calories in a large candy bar. If you get enough exercise to eat a large candy bar every day without gaining", "infer30b_after_item": " \n Output: Eat Avocados Sparingly: The Surprising Calorie Count of This Healthy Fruit \n\n", "infer13b_before_item": " Output: The number of calories in the avocado.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: \"Avocados: A Healthy Snack or a Sweet Treat?\" \n\n", "infer7b_before_item": " The output is the text of your post. \n*/\n\n// The following code is a sample of how to use the API.\n// You can use it as a starting point for your own code.\n\n// The following code is a sample of how to use the API.\n// You can use it as a starting point for your own code.\n\n// The following code is a sample of how to use the API.\n// You can use it as a starting point for your own code.\n\n// The following code is a sample of how to use the API.\n// You can use it as a starting point for your own code.\n\n// The following code is a sample of how to use the API.\n// You can use it as a starting point for your own code.\n\n// The following code is a sample of how to use the API.\n// You can use it as a starting point for your own code.\n\n// The following code is a sample of how to use the API.\n// You can use it as a starting point for your own code.\n\n// The following code is a sample of how to use the API.\n// You can use it as a starting point for", "infer7b_after_item": " \n Output: \"The Avocado: A Healthy Alternative to a Large Candy Bar?\" \n\n"} {"id": 168, "instruction": "Give some examples of what people usually say in the given social situation.", "input": "when someone arrives safely", "infer30b_before_item": " Output: Give some examples of what people usually say in the given social situation. when someone arrives safely \n\nInput: Input: Give some examples of what people usually say in the given social situation. when someone arrives safely \n Output: Output: Give some examples of what people usually say in the given social situation. when someone arrives safely \n\nInput: Input: Give some examples of what people usually say in the given social situation. when someone arrives safely \n Output: Output: Give some examples of what people usually say in the given social situation. when someone arrives safely \n\nInput: Input: Give some examples of what people usually say in the given social situation. when someone arrives safely \n Output: Output: Give some examples of what people usually say in the given social situation. when someone arrives safely \n\nInput: Input: Give some examples of what people usually say in the given social situation. when someone arrives safely \n Output: Output: Give some examples of what people usually say in the given social situation. when someone arrives safely \n\nInput: Input: Give some examples of what people usually say in the given social situation. when someone arrives safely \n Output: Output", "infer30b_after_item": " at their destination \n Output: - I'm so glad you made it!\n- Welcome!\n- It's great to see you!\n- You made it!\n- I'm so glad you're here!\n- Safe travels!\n- It's good to have you here!\n- You must be exhausted!\n- How was the journey?\n- I'm so glad you're safe!\n- Welcome home!\n- It's great to see you safe and sound!\n- I'm so glad you're here!\n- It's great to have you here!\n- You made it!\n- I'm so glad you're here!\n- Safe travels!\n- It's great to have you here!\n- I'm so glad you're safe!\n- Welcome!\n- I'm so glad you made it!\n- It's great to have you here!\n- I'm so glad you're safe!\n- You must be exhausted!\n- How was the journey?\n- I'm so glad you're here!\n- Welcome home!\n- I", "infer13b_before_item": " Output: Give some examples of what people usually say in the given social situation. when someone arrives safely \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " at their destination \n Output: \"Thank goodness you made it safely!\" \n\"Phew, I'm glad you're here!\" \n\"It's a relief to know you're here.\" \n\"I'm so glad you arrived safely.\" \n\n", "infer7b_before_item": " Output: Give some examples of what people usually say in the given social situation. when someone arrives safely \n\\end{code}\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment: I'm not sure what you're asking.\n\nComment", "infer7b_after_item": " home \n Output: - \"Welcome home!\"\n- \"I'm so glad you're safe!\"\n- \"It's good to have you back!\"\n- \"I was worried about you!\"\n- \"I'm so glad you're okay!\"\n- \"I'm glad you're home!\"\n- \"Welcome back!\"\n- \"I'm so glad you're home!\"\n- \"Welcome back!\"\n- \"Welcome home!\"\n- \"Welcome back!\"\n- \"Welcome home!\"\n- \"Welcome back!\"\n- \"Welcome home!\"\n- \"Welcome back!\"\n- \"Welcome home!\"\n- \"Welcome back!\"\n- \"Welcome home!\"\n- \"Welcome back!\"\n- \"Welcome home!\"\n- \"Welcome back!\"\n- \"Welcome home!\"\n- \"Welcome back!\"\n- \"Welcome home!\"\n- \"Welcome back!\"\n- \"Welcome home!\"\n- \"Welcome back!\"\n- \"Welcome home!\"\n- \"Welcome back!\"\n- \"Welcome home!\"\n- \"Welcome back!\"\n- \"Wel"} {"id": 169, "instruction": "You will be required to write a few questions from the given company's interview section.", "input": "Kohl's", "infer30b_before_item": " Output: You will be required to write a few questions from the given company's interview section. Kohl's \n Expected: Expected: You will be required to write a few questions from the given company's interview section. Kohl's \n Actual: Actual: You will be required to write a few questions from the given company's interview section. Kohl's \n */\n\n#include \n#include \n#include \n\nusing namespace std;\n\nint main() {\n string input;\n vector output;\n vector expected;\n vector actual;\n\n getline(cin, input);\n output.push_back(input);\n\n getline(cin, input);\n output.push_back(input);\n\n getline(cin, input);\n output.push_back(input);\n\n getline(cin, input);\n output.push_back(input);\n\n getline(cin, input);\n output.push_back(input);\n\n getline(cin, input", "infer30b_after_item": " \n Output: What qualities do you possess that make you a good fit for a Kohl's team?\n\nWhat experience do you have in customer service?\n\nHow do you handle difficult customer situations?\n\nWhat do you know about Kohl's products and services?\n\nWhat strategies do you use to increase customer satisfaction?\n\nWhat do you think are the most important qualities of a successful Kohl's team member? \n\n", "infer13b_before_item": " You will be required to write a few questions from the given company's interview section. Kohl's \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: - What do you think makes Kohl's stand out from other retailers?\n- How would you describe your customer service skills?\n- What do you think is the most important aspect of customer service?\n- What do you think is the most important aspect of teamwork?\n- How do you handle difficult customer situations?\n- What do you think is the most important aspect of communication?\n- What do you think is the most important aspect of problem solving?\n- How do you handle stressful situations?\n- What do you think is the most important aspect of customer satisfaction?\n- How do you handle customer complaints?\n- How do you handle difficult customer requests?\n- What do you think is the most important aspect of customer service?\n- What do you think is the most important aspect of customer relations?\n- How do you handle customer feedback?\n- How do you handle customer inquiries?\n- How do you handle customer complaints?\n- How do you handle customer requests?\n- How do you handle customer disputes?\n- How do you handle customer returns?\n- How do you handle customer refunds?\n- How do you handle customer exchanges?", "infer7b_before_item": " You will be required to write a few questions from the given company's interview section. Kohl's\n\nimport java.util.Scanner;\nimport java.util.ArrayList;\nimport java.util.List;\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.Comparator;\n\npublic class KohlS {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n List questions = new ArrayList();\n questions.add(\"What is your name?\");\n questions.add(\"What is your age?\");\n questions.add(\"What is your favorite color?\");\n questions.add(\"What is your favorite food?\");\n questions.add(\"What is your favorite movie?\");\n questions.add(\"What is your favorite book?\");\n questions.add(\"What is your favorite sport?\");\n questions.add(\"What is your favorite music?\");\n questions.add(\"What is your favorite season?\");\n questions.add(\"What is your favorite animal?\");\n questions.add(\"What is", "infer7b_after_item": " is an American department store chain. \n Output: 1. What experience do you have in retail?\n2. How do you handle customer complaints?\n3. What do you think are the most important qualities for a successful retail sales associate?\n4. How do you handle pressure in a fast-paced environment?\n5. How do you handle customer service issues?\n6. How do you handle customer complaints?\n7. How do you handle customer requests?\n8. How do you handle customer questions?\n9. How do you handle customer feedback?\n10. How do you handle customer concerns?\n11. How do you handle customer inquiries?\n12. How do you handle customer requests?\n13. How do you handle customer complaints?\n14. How do you handle customer service issues?\n15. How do you handle customer requests?\n16. How do you handle customer questions?\n17. How do you handle customer feedback?\n18. How do you handle customer concerns?\n19. How do you handle customer inquiries?\n20. How do you handle customer complaints?\n21."} {"id": 170, "instruction": "Based on the information provided, you need to estimate the average summary for the given job.", "input": "Data entry clerk in United States", "infer30b_before_item": " Output: Based on the information provided, you need to estimate the average summary for the given job. Data entry clerk in United States\n\nInput: Input: Based on the information provided, you need to estimate the average summary for the given job. Data entry clerk in United States \n Output: Output: Based on the information provided, you need to estimate the average summary for the given job. Data entry clerk in United States\n\nInput: Input: Based on the information provided, you need to estimate the average summary for the given job. Data entry clerk in United States \n Output: Output: Based on the information provided, you need to estimate the average summary for the given job. Data entry clerk in United States\n\nInput: Input: Based on the information provided, you need to estimate the average summary for the given job. Data entry clerk in United States \n Output: Output: Based on the information provided, you need to estimate the average summary for the given job. Data entry clerk in United States\n\nInput: Input: Based on the information provided, you need to estimate the average summary for the given job. Data entry clerk in United States \n Output: Output: Based on the information provided,", "infer30b_after_item": ". \n Output: The average salary for a Data Entry Clerk in the United States is $32,000 per year. \n\n", "infer13b_before_item": " Output: Based on the information provided, you need to estimate the average summary for the given job. Data entry clerk in United States \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: The average summary for a data entry clerk in the United States is that the job requires a high level of accuracy and attention to detail, as well as the ability to work quickly and efficiently. The job also requires the ability to use computer software and other technology to enter data into databases and other systems. \n\n", "infer7b_before_item": " Output: Based on the information provided, you need to estimate the average summary for the given job. Data entry clerk in United States\n\nComment: Please edit your question to include the code you have tried.\n\nAnswer: You can use the `data.table` package to do this.\n\n\\begin{code}\nlibrary(data.table)\n\n# Create a data.table\ndt <- data.table(\n job = c(\"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk\", \"data entry clerk", "infer7b_after_item": "\nJob Description: Data entry clerk is responsible for entering data into a computer system.\n\nRequirements:\n- Knowledge of Microsoft Office\n- Ability to work independently\n- Excellent attention to detail\n- Ability to meet deadlines\n- Strong organizational skills\n- Ability to work under pressure\n- Ability to multitask \n Output: The average summary for the job of Data entry clerk in the United States is:\n- Responsible for entering data into a computer system\n- Requires knowledge of Microsoft Office\n- Requires the ability to work independently\n- Requires excellent attention to detail\n- Requires the ability to meet deadlines\n- Requires strong organizational skills\n- Requires the ability to work under pressure\n- Requires the ability to multitask. \n\n"} {"id": 171, "instruction": "Describe the responsibilities of the given job.", "input": "Security Officer", "infer30b_before_item": " Output: Describe the responsibilities of the given job. Security Officer\n\n Input: Input: Describe the responsibilities of the given job. Security Officer \n Output: Output: Describe the responsibilities of the given job. Security Officer\n\n Input: Input: Describe the responsibilities of the given job. Security Officer \n Output: Output: Describe the responsibilities of the given job. Security Officer\n\n Input: Input: Describe the responsibilities of the given job. Security Officer \n Output: Output: Describe the responsibilities of the given job. Security Officer\n\n Input: Input: Describe the responsibilities of the given job. Security Officer \n Output: Output: Describe the responsibilities of the given job. Security Officer\n\n Input: Input: Describe the responsibilities of the given job. Security Officer \n Output: Output: Describe the responsibilities of the given job. Security Officer\n\n Input: Input: Describe the responsibilities of the given job. Security Officer \n Output: Output: Describe the responsibilities of the given job. Security Officer\n\n Input: Input: Describe the responsibilities of", "infer30b_after_item": " \n Output: The responsibilities of a Security Officer include patrolling assigned areas, monitoring surveillance cameras, responding to alarms and other security-related incidents, and providing customer service. They may also be responsible for writing reports, conducting investigations, and providing security training. \n\n", "infer13b_before_item": " Output: Describe the responsibilities of the given job. Security Officer \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\n\n\n\n", "infer13b_after_item": " \n Output: The responsibilities of a security officer include monitoring and patrolling the premises, responding to alarms and emergencies, enforcing security policies and procedures, and providing customer service. They may also be responsible for conducting background checks, issuing access cards, and monitoring surveillance cameras. \n\n", "infer7b_before_item": " Output: Describe the responsibilities of the given job. Security Officer \n*/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: The Security Officer is responsible for ensuring the safety and security of the premises. This includes monitoring the premises, responding to security incidents, and enforcing security policies. The Security Officer also provides customer service, such as answering questions and providing directions. Additionally, the Security Officer is responsible for maintaining the security equipment and systems, such as access control systems and surveillance cameras. \n\n"} {"id": 172, "instruction": "Provide a list of the skills that may help you find the job.", "input": "Crew Members", "infer30b_before_item": " Output: Provide a list of the skills that may help you find the job. Crew Members \n Output: Output: Provide a list of the skills that may help you find the job. Crew Members \n Output: Output: Provide a list of the skills that may help you find the job. Crew Members \n Output: Output: Provide a list of the skills that may help you find the job. Crew Members \n Output: Output: Provide a list of the skills that may help you find the job. Crew Members \n Output: Output: Provide a list of the skills that may help you find the job. Crew Members \n Output: Output: Provide a list of the skills that may help you find the job. Crew Members \n Output: Output: Provide a list of the skills that may help you find the job. Crew Members \n Output: Output: Provide a list of the skills that may help you find the job. Crew Members \n Output: Output: Provide a list of the skills that may help you find the job. Crew Members \n Output: Output: Provide a list", "infer30b_after_item": " \n Output: - Customer service\n- Teamwork\n- Communication\n- Problem-solving\n- Time management\n- Organization\n- Leadership\n- Adaptability\n- Attention to detail\n- Multitasking\n- Critical thinking\n- Conflict resolution\n- Decision-making\n- Computer literacy\n- Sales and marketing\n- Cash handling\n- Food safety and sanitation \n\n", "infer13b_before_item": " Output: Provide a list of the skills that may help you find the job. Crew Members \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: - Customer service skills\n- Ability to work in a fast-paced environment\n- Strong communication skills\n- Ability to work independently and as part of a team\n- Problem-solving skills\n- Time management skills\n- Ability to multitask\n- Knowledge of food preparation and safety\n- Knowledge of cash register operations\n- Knowledge of restaurant operations\n- Knowledge of restaurant equipment\n- Knowledge of restaurant sanitation and safety\n- Knowledge of restaurant industry trends\n- Knowledge of restaurant marketing\n- Knowledge of restaurant accounting\n- Knowledge of restaurant inventory management\n- Knowledge of restaurant customer service\n- Knowledge of restaurant kitchen operations\n- Knowledge of restaurant menu development\n- Knowledge of restaurant food preparation\n- Knowledge of restaurant food safety\n- Knowledge of restaurant food presentation\n- Knowledge of restaurant food storage\n- Knowledge of restaurant food storage and handling\n- Knowledge of restaurant food storage and handling regulations\n- Knowledge of restaurant food safety regulations\n- Knowledge of restaurant food safety regulations\n- Knowledge of restaurant food safety regulations\n- Knowledge of restaurant food safety reg", "infer7b_before_item": " Provide a list of the skills that may help you find the job. Crew Members \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Crew Members should have the following skills: \n- Customer service \n- Communication skills \n- Problem solving \n- Organizational skills \n- Time management \n- Teamwork \n- Flexibility \n- Adaptability \n- Initiative \n- Punctuality \n- Attention to detail \n- Influence \n- Leadership \n- Innovation \n- Self-motivation \n- Problem-solving \n- Problem-analysis \n- Decision-making \n- Conflict resolution \n- Analytical thinking \n- Problem-solving \n- Problem-analysis \n- Decision-making \n- Conflict resolution \n- Teamwork \n- Flexibility \n- Adaptability \n- Initiative \n- Punctuality \n- Attention to detail \n- Influence \n- Leadership \n- Innovation \n- Self-motivation \n- Problem-solving \n- Problem-analysis \n- Decision-making \n- Conflict resolution \n-"} {"id": 173, "instruction": "Schedule the meetings based on the given informqation.", "input": "Person1: available from 9-11 am, meeting duration: 30 min \nPerson2: available from 1-3 pm, meeting duration: 90 min\nPerson3: available from 2-3:30 pm, meeting duration: 60 min", "infer30b_before_item": " Output: Schedule the meetings based on the given informqation. Person1: available from 9-11 am, meeting duration: 30 min \nPerson2: available from 1-3 pm, meeting duration: 90 min\nPerson3: available from 2-3:30 pm, meeting duration: 60 min \n Explanation: Explanation: \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n * \n", "infer30b_after_item": " \n Output: Person1: 9:00 am - 9:30 am\nPerson2: 10:30 am - 12:00 pm\nPerson3: 12:30 pm - 1:30 pm \n\n", "infer13b_before_item": " Output: Schedule the meetings based on the given informqation. Person1: available from 9-11 am, meeting duration: 30 min \nPerson2: available from 1-3 pm, meeting duration: 90 min\nPerson3: available from 2-3:30 pm, meeting duration: 60 min \n\nclass Solution {\npublic:\n vector findMeetingDuration(vector &meetingDurations, vector &availableTime) {\n vector res;\n int n = meetingDurations.size();\n int m = availableTime.size();\n for (int i = 0; i < n; ++i) {\n for (int j = 0; j < m; ++j) {\n if (meetingDurations[i] <= availableTime[j]) {\n res.push_back(meetingDurations[i]);\n break;\n }\n }\n }\n return res;\n }\n};\n", "infer13b_after_item": " \n Output: Person1: 9-11 am\nPerson2: 1-3 pm\nPerson3: 2-3:30 pm \n\n", "infer7b_before_item": " Output: Schedule the meetings based on the given informqation.\nPerson1: available from 9-11 am, meeting duration: 30 min\nPerson2: available from 1-3 pm, meeting duration: 90 min\nPerson3: available from 2-3:30 pm, meeting duration: 60 min\n*/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Person1: 9-11 am\nPerson2: 1-3 pm\nPerson3: 2-3:30 pm \n\n"} {"id": 174, "instruction": "Find the directions between the given locations.", "input": "From: Rowan Avenue Elementary School, 600 S Rowan Ave, Los Angeles, CA 90023, United States\nTo: Calvary Cemetery and Mortuary, 4201 Whittier Blvd, Los Angeles, CA 90023, United States", "infer30b_before_item": " Output: 1.1 km\n\nInput: Input: Find the directions between the given locations. From: Rowan Avenue Elementary School, 600 S Rowan Ave, Los Angeles, CA 90023, United States\nTo: Calvary Cemetery and Mortuary, 4201 Whittier Blvd, Los Angeles, CA 90023, United States \n Output: Output: 1.1 km\n\nInput: Input: Find the directions between the given locations. From: Rowan Avenue Elementary School, 600 S Rowan Ave, Los Angeles, CA 90023, United States\nTo: Calvary Cemetery and Mortuary, 4201 Whittier Blvd, Los Angeles, CA 90023, United States \n Output: Output: 1.1 km\n\nInput: Input: Find the directions between the given locations. From: Rowan Avenue Elementary School, 600 S Rowan Ave, Los Angeles, CA 90023, United States\nTo: Calvary Cemetery and Mortuary, 4", "infer30b_after_item": " \n Output: The directions from Rowan Avenue Elementary School to Calvary Cemetery and Mortuary are as follows: Head northwest on S Rowan Ave toward W 6th St. Turn right onto W 6th St. Turn left onto S Broadway. Turn right onto W 1st St. Turn left onto S Main St. Turn right onto W 1st St. Turn left onto S Broadway. Turn right onto W 1st St. Turn left onto S Main St. Turn right onto W 1st St. Turn left onto Whittier Blvd and the destination will be on the right. \n\n", "infer13b_before_item": " Output: Find the directions between the given locations. To: Calvary Cemetery and Mortuary, 4201 Whittier Blvd, Los Angeles, CA 90023, United States\nInput: Input: Find the directions between the given locations. From: Rowan Avenue Elementary School, 600 S Rowan Ave, Los Angeles, CA 90023, United States\nTo: Calvary Cemetery and Mortuary, 4201 Whittier Blvd, Los Angeles, CA 90023, United States\nOutput: Output: Find the directions between the given locations. To: Calvary Cemetery and Mortuary, 4201 Whittier Blvd, Los Angeles, CA 90023, United States\nInput: Input: Find the directions between the given locations. From: Rowan Avenue Elementary School, 600 S Rowan Ave, Los Angeles, CA 90023, United States\nTo: Calvary Cemetery and Mortuary, 4201 Whittier Blvd, Los Angeles, CA 90023", "infer13b_after_item": " \n Output: The directions from Rowan Avenue Elementary School to Calvary Cemetery and Mortuary are approximately 1.3 miles and take about 18 minutes by car. \n\n", "infer7b_before_item": " The directions between the two locations.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: From Rowan Avenue Elementary School, 600 S Rowan Ave, Los Angeles, CA 90023, United States\n\nDirections to Calvary Cemetery and Mortuary, 4201 Whittier Blvd, Los Angeles, CA 90023, United States\n\n1. Head northwest on S Rowan Ave toward E 4th St \n2. Turn left onto E 4th St \n3. Turn right onto S San Pedro St \n4. Turn left onto E 5th St \n5. Turn right onto S Whittier Blvd \n6. Turn left onto E 4th St \n7. Turn right onto S San Pedro St \n8. Turn left onto E 5th St \n9. Turn right onto S Whittier Blvd \n10. Turn left onto E 4th St \n11. Turn right onto S San Pedro St \n12. Turn left onto E 5th St \n13. Turn right onto S Whittier Blvd \n14. Turn left onto E 4th St "} {"id": 175, "instruction": "Give a brief explanation of the requested part of the paper.", "input": "Paper: The dominant sequence transduction models are based on complex recurrent or convolutional neural networks that include an encoder and a decoder. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing best results, including ensembles, by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the literature. We show that the Transformer generalizes well to other tasks by applying it successfully to English constituency parsing both with large and limited training data.\nExplain: The dominant sequence transduction models", "infer30b_before_item": " Output: Give a brief explanation of the requested part of the paper. Paper: The dominant sequence transduction models are based on complex recurrent or convolutional neural networks that include an encoder and a decoder. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing best results, including ensembles, by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the literature. We show that the Transformer generalizes well to other tasks", "infer30b_after_item": " are based on complex recurrent or convolutional neural networks that include an encoder and a decoder. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. \n Output: The Transformer is a new type of network architecture that is based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. This type of network architecture has been shown to be superior in quality while being more parallelizable and requiring significantly less time to train. \n\n", "infer13b_before_item": " The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing best results, including ensembles, by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the literature. We show that the Transformer generalizes well to other tasks by applying it successfully to English constituency parsing both with large and limited training data.\n\n\nInput: Input: Give a brief explanation of the requested part of the paper. Paper: The dominant sequence transduction", "infer13b_after_item": " are based on complex recurrent or convolutional neural networks that include an encoder and a decoder. \n Output: The dominant sequence transduction models are based on complex recurrent or convolutional neural networks that include an encoder and a decoder. These models are typically composed of multiple layers of recurrent or convolutional neural networks, which are connected in a specific way to form a sequence transduction model. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing best results, including ensembles, by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.", "infer7b_before_item": " are based on complex recurrent or convolutional neural networks that include an encoder and a decoder. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing best results, including ensembles, by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the literature. We show that the Transformer generalizes well to other tasks by applying it successfully to English constituency parsing both with large and limited training data.\nInput: The dominant sequence trans", "infer7b_after_item": " are based on complex recurrent or convolutional neural networks that include an encoder and a decoder. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing best results, including ensembles, by over 2 BLEU. On the WMT 2014 English-to-French translation task, our model establishes a new single-model state-of-the-art BLEU score of 41.8 after training for 3.5 days on eight GPUs, a small fraction of the training costs of the best models from the literature. We show that the Transformer generalizes well to other tasks by applying it successfully to English constituency parsing both with large and limited training data. \n Output: The Transformer"} {"id": 176, "instruction": "Answer the question about the paper after reading it carefully.", "input": "To evaluate if the Transformer can generalize to other tasks we performed experiments on English constituency parsing. This task presents specific challenges: the output is subject to strong structural constraints and is significantly longer than the input. Furthermore, RNN sequence-to-sequence models have not been able to attain state-of-the-art results in small-data regimes.\nQuestion: What is English constituency parsing?", "infer30b_before_item": " Output: Answer the question about the paper after reading it carefully. To evaluate if the Transformer can generalize to other tasks we performed experiments on English constituency parsing. This task presents specific challenges: the output is subject to strong structural constraints and is significantly longer than the input. Furthermore, RNN sequence-to-sequence models have not been able to attain state-of-the-art results in small-data regimes.\n\nInput: Input: Answer the question about the paper after reading it carefully. To evaluate if the Transformer can generalize to other tasks we performed experiments on English constituency parsing. This task presents specific challenges: the output is subject to strong structural constraints and is significantly longer than the input. Furthermore, RNN sequence-to-sequence models have not been able to attain state-of-the-art results in small-data regimes.\n Question: What is English constituency parsing? \n Output: Output: Answer the question about the paper after reading it carefully. To evaluate if the Transformer can generalize to other tasks we performed experiments on English constituency parsing. This task presents specific challenges: the output is subject to strong structural constraints and is significantly longer than the input.", "infer30b_after_item": " \n Output: English constituency parsing is a type of natural language processing task that involves analyzing a sentence to determine its syntactic structure. It involves identifying the constituents of a sentence, such as noun phrases, verb phrases, and prepositional phrases, and determining how they are related to each other. \n\n", "infer13b_before_item": " English constituency parsing is a task in natural language processing that involves the decomposition of a sentence into a tree representation.\n\nInput: Input: Answer the question about the paper after reading it carefully. To evaluate if the Transformer can generalize to other tasks we performed experiments on English constituency parsing. This task presents specific challenges: the output is subject to strong structural constraints and is significantly longer than the input. Furthermore, RNN sequence-to-sequence models have not been able to attain state-of-the-art results in small-data regimes.\nQuestion: What is English constituency parsing? \n Output: English constituency parsing is a task in natural language processing that involves the decomposition of a sentence into a tree representation.\n\nInput: Input: Answer the question about the paper after reading it carefully. To evaluate if the Transformer can generalize to other tasks we performed experiments on English constituency parsing. This task presents specific challenges: the output is subject to strong structural constraints and is significantly longer than the input. Furthermore, RNN sequence-to-sequence models have not been able to attain state-of-the-art results in small-data regimes.\nQuestion: What is English constituency", "infer13b_after_item": " \n Output: English constituency parsing is a task of analyzing a sentence and breaking it down into its constituent parts, such as words, phrases, and clauses. It is a form of natural language processing that involves the analysis of syntactic structures in a sentence. \n\n", "infer7b_before_item": " The output is subject to strong structural constraints and is significantly longer than the input.\n Question: What are the challenges of English constituency parsing? \n Output: The output is subject to strong structural constraints and is significantly longer than the input.\n Question: What are the challenges of English constituency parsing? \n Output: The output is subject to strong structural constraints and is significantly longer than the input.\n Question: What are the challenges of English constituency parsing? \n Output: The output is subject to strong structural constraints and is significantly longer than the input.\n Question: What are the challenges of English constituency parsing? \n Output: The output is subject to strong structural constraints and is significantly longer than the input.\n Question: What are the challenges of English constituency parsing? \n Output: The output is subject to strong structural constraints and is significantly longer than the input.\n Question: What are the challenges of English constituency parsing? \n Output: The output is subject to strong structural constraints and is significantly longer than the input.\n Question: What are the challenges of English constituency parsing? \n Output: The output is subject to strong structural constraints and is", "infer7b_after_item": " \n Output: English constituency parsing is a task in natural language processing that involves identifying the parts of speech (POS) of words in a sentence. It is a subtask of natural language understanding and is used to identify the syntactic structure of a sentence. The output of the task is a parse tree, which is a representation of the sentence structure. The task is challenging because it requires the model to identify the parts of speech of words in a sentence, which is subject to strong structural constraints. Additionally, the output of the task is significantly longer than the input, which can be a challenge for RNN sequence-to-sequence models. \n\n"} {"id": 177, "instruction": "Recommend some helpful activities or conversation starters to use at meetups to break the ice.", "input": "", "infer30b_before_item": " Output: Recommend some helpful activities or conversation starters to use at meetups to break the ice. \n Algorithm: Algorithm: Recommend some helpful activities or conversation starters to use at meetups to break the ice. \n Data: Data: Recommend some helpful activities or conversation starters to use at meetups to break the ice. \n Platform: Platform: Recommend some helpful activities or conversation starters to use at meetups to break the ice. \n Technology: Technology: Recommend some helpful activities or conversation starters to use at meetups to break the ice. \n Resource: Resource: Recommend some helpful activities or conversation starters to use at meetups to break the ice. \n Tactics: Tactics: Recommend some helpful activities or conversation starters to use at meetups to break the ice. \n Method: Method: Recommend some helpful activities or conversation starters to use at meetups to break the ice. \n Strategy: Strategy: Recommend some helpful activities or conversation starters to use at meetups to break the ice. \n Policy: Policy: Recommend some helpful activities or conversation starters to use at meet", "infer30b_after_item": "\n Output: Some helpful activities or conversation starters to use at meetups to break the ice include: \n- Asking everyone to introduce themselves and share something interesting about themselves \n- Playing a game like charades or Pictionary \n- Sharing a funny story or joke \n- Talking about a current event or topic of interest \n- Asking everyone to share their favorite book or movie \n- Talking about a hobby or passion that everyone has in common \n- Talking about a recent success or accomplishment \n- Talking about a favorite travel destination \n- Talking about a favorite restaurant or food \n- Talking about a favorite sports team \n- Talking about a favorite music artist or band \n- Talking about a favorite TV show or movie \n- Talking about a favorite app or website \n- Talking about a favorite quote or saying \n- Talking about a favorite charity or cause \n- Talking about a favorite animal \n- Talking about a favorite movie or book character \n- Talking about a favorite game or activity \n- Talk", "infer13b_before_item": " Output: Recommend some helpful activities or conversation starters to use at meetups to break the ice.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: Here are some helpful activities or conversation starters to use at meetups to break the ice:\n- Ask people about their hobbies and interests.\n- Share a funny story or joke.\n- Ask people about their favorite books, movies, or TV shows.\n- Play a game or activity to get people talking.\n- Ask people about their career or goals.\n- Talk about current events or pop culture.\n- Ask people about their travels or experiences.\n- Share a personal story or anecdote.\n- Ask people about their favorite foods or restaurants.\n- Ask people about their family or friends.\n- Talk about the event or location.\n- Ask people about their favorite sports teams.\n- Share a quote or inspirational message.\n- Ask people about their favorite music or artists.\n- Ask people about their favorite movies or shows.\n- Ask people about their favorite places to visit.\n- Ask people about their favorite hobbies or activities.\n- Ask people about their favorite books or authors.\n- Ask people about their favorite TV shows or characters.\n- Ask people about their favorite sports or athletes.\n- Ask people", "infer7b_before_item": " Output: A list of activities or conversation starters to use at meetups to break the ice.\n\nComment: I'm not sure what you mean by \"break the ice\". Do you mean to get people to talk to each other? Do you mean to get people to talk about the topic of the meetup? Do you mean to get people to talk about themselves? Do you mean to get people to talk about the meetup? Do you mean to get people to talk about the meetup topic? Do you mean to get people to talk about the meetup topic in a way that is relevant to the meetup topic? Do you mean to get people to talk about the meetup topic in a way that is relevant to the meetup topic in a way that is relevant to the meetup topic?\n\nComment: I'm not sure what you mean by \"break the ice\". Do you mean to get people to talk to each other? Do you mean to get people to talk about the topic of the meetup? Do you mean to get people to talk about themselves? Do you mean to get people to talk about the meetup? Do you mean to get people to talk about", "infer7b_after_item": "\n Output: Some helpful activities or conversation starters to use at meetups to break the ice include: \n- Introduce yourself and ask others to do the same. \n- Ask questions about the other person's interests, hobbies, or career. \n- Ask questions about the group's common interests. \n- Ask questions about the group's history or background. \n- Ask questions about the group's goals or aspirations. \n- Ask questions about the group's current projects or initiatives. \n- Ask questions about the group's future plans. \n- Ask questions about the group's favorite books, movies, or TV shows. \n- Ask questions about the group's favorite places to visit or things to do. \n- Ask questions about the group's favorite foods or restaurants. \n- Ask questions about the group's favorite sports or hobbies. \n- Ask questions about the group's favorite music or artists. \n- Ask questions about the group's favorite memories or stories. \n- Ask questions about the group's favorite memes or jokes. \n- Ask questions about the"} {"id": 178, "instruction": "Convert the given HTML into Markdown format.", "input": "Use `code` in your Markdown file.", "infer30b_before_item": " Output: Convert the given Markdown into HTML format. Use `code` in your Markdown file. \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", "infer30b_after_item": " \n Output: Use `code` in your Markdown file. \n\n", "infer13b_before_item": " Output: Convert the given HTML into Markdown format. Use `code` in your Markdown file. \n\nInput: Input: Convert the given HTML into Markdown format. Use `code` in your Markdown file. \nOutput: Output: Convert the given HTML into Markdown format. Use `code` in your Markdown file. \n\nInput: Input: Convert the given HTML into Markdown format. Use `code` in your Markdown file. \nOutput: Output: Convert the given HTML into Markdown format. Use `code` in your Markdown file. \n\nInput: Input: Convert the given HTML into Markdown format. Use `code` in your Markdown file. \nOutput: Output: Convert the given HTML into Markdown format. Use `code` in your Markdown file. \n\nInput: Input: Convert the given HTML into Markdown format. Use `code` in your Markdown file. \nOutput: Output: Convert the given HTML into Markdown format. <", "infer13b_after_item": " \n Output: Use `code` in your Markdown file. \n\n", "infer7b_before_item": " Output: Convert the given Markdown into HTML format. Use `code` in your HTML file. \n*/\n\n// 1. Create a function that takes a string as input and returns a string as output.\n// 2. Test your function by passing in a string and checking that the output is the same as the input.\n\n// 1. Create a function that takes a string as input and returns a string as output.\n// 2. Test your function by passing in a string and checking that the output is the same as the input.\n\n// 1. Create a function that takes a string as input and returns a string as output.\n// 2. Test your function by passing in a string and checking that the output is the same as the input.\n\n// 1. Create a function that takes a string as input and returns a string as output.\n// 2. Test your function by passing in a string and checking that the output is the same as the input.\n\n// 1. Create a function that takes a string as input and returns a string as output.\n// 2. Test your function by passing in a string and checking that the output", "infer7b_after_item": " \n Output: ```Use code in your Markdown file.``` \n\n"} {"id": 179, "instruction": "Extract the method that has been used in the research from the abstract of the paper. Give the exact sentences from the abstract that discuss the method.", "input": "We present a state-of-the-art speech recognition system developed using end-to-end deep learning. Our architecture is significantly simpler than traditional speech systems, which rely on laboriously engineered processing pipelines; these traditional systems also tend to perform poorly when used in noisy environments. In contrast, our system does not need hand-designed components to model background noise, reverberation, or speaker variation, but instead directly learns a function that is robust to such effects. We do not need a phoneme dictionary, nor even the concept of a \"phoneme.\" Key to our approach is a well-optimized RNN training system that uses multiple GPUs, as well as a set of novel data synthesis techniques that allow us to efficiently obtain a large amount of varied data for training. Our system, called Deep Speech, outperforms previously published results on the widely studied Switchboard Hub5'00, achieving 16.0% error on the full test set. Deep Speech also handles challenging noisy environments better than widely used, state-of-the-art commercial speech systems.Collapse", "infer30b_before_item": " Output: Write a short paragraph that summarizes the method used in the research.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " )\n[1] We present a state-of-the-art speech recognition system developed using end-to-end deep learning. Our architecture is significantly simpler than traditional speech systems, which rely on laboriously engineered processing pipelines; these traditional systems also tend to perform poorly when used in noisy environments. In contrast, our system does not need hand-designed components to model background noise, reverberation, or speaker variation, but instead directly learns a function that is robust to such effects. We do not need a phoneme dictionary, nor even the concept of a \"phoneme.\" Key to our approach is a well-optimized RNN training system that uses multiple GPUs, as well as a set of novel data synthesis techniques that allow us to efficiently obtain a large amount of varied data for training. Our system, called Deep Speech, outperforms previously published results on the widely studied Switchboard Hub5'00, achieving 16.0% error on the full test set. Deep Speech also handles challenging noisy environments better than widely used, state-of-the-art commercial speech systems. \n Output: The method used in the research is end-to-end deep learning", "infer13b_before_item": " Output: Extract the method that has been used in the research from the abstract of the paper. Give the exact sentences from the abstract that discuss the method. We present a state-of-the-art speech recognition system developed using end-to-end deep learning. Our architecture is significantly simpler than traditional speech systems, which rely on laboriously engineered processing pipelines; these traditional systems also tend to perform poorly when used in noisy environments. In contrast, our system does not need hand-designed components to model background noise, reverberation, or speaker variation, but instead directly learns a function that is robust to such effects. We do not need a phoneme dictionary, nor even the concept of a \"phoneme.\" Key to our approach is a well-optimized RNN training system that uses multiple GPUs, as well as a set of novel data synthesis techniques that allow us to efficiently obtain a large amount of varied data for training. Our system, called Deep Speech, outperforms previously published results on the widely studied Switchboard Hub5'00, achieving 16.0% error on the full test set. Deep Speech also handles challenging noisy environments better than widely used, state-", "infer13b_after_item": " \n\n", "infer7b_before_item": " Output: Extract the sentences that discuss the results of the research. We present a state-of-the-art speech recognition system developed using end-to-end deep learning. Our architecture is significantly simpler than traditional speech systems, which rely on laboriously engineered processing pipelines; these traditional systems also tend to perform poorly when used in noisy environments. In contrast, our system does not need hand-designed components to model background noise, reverberation, or speaker variation, but instead directly learns a function that is robust to such effects. We do not need a phoneme dictionary, nor even the concept of a \"phoneme.\" Key to our approach is a well-optimized RNN training system that uses multiple GPUs, as well as a set of novel data synthesis techniques that allow us to efficiently obtain a large amount of varied data for training. Our system, called Deep Speech, outperforms previously published results on the widely studied Switchboard Hub5'00, achieving 16.0% error on the full test set. Deep Speech also handles challenging noisy environments better than widely used, state-of-the-art commercial speech systems.Collapse\nInput: Input: Extract", "infer7b_after_item": "\n\nWe present a state-of-the-art speech recognition system developed using end-to-end deep learning. Our architecture is significantly simpler than traditional speech systems, which rely on laboriously engineered processing pipelines; these traditional systems also tend to perform poorly when used in noisy environments. In contrast, our system does not need hand-designed components to model background noise, reverberation, or speaker variation, but instead directly learns a function that is robust to such effects. We do not need a phoneme dictionary, nor even the concept of a \"phoneme.\" Key to our approach is a well-optimized RNN training system that uses multiple GPUs, as well as a set of novel data synthesis techniques that allow us to efficiently obtain a large amount of varied data for training. Our system, called Deep Speech, outperforms previously published results on the widely studied Switchboard Hub5'00, achieving 16.0% error on the full test set. Deep Speech also handles challenging noisy environments better than widely used, state-of-the-art commercial speech systems. Collapse\n Output: We present a state-of-the-art speech recognition system developed using"} {"id": 180, "instruction": "You need to come up with the names of some of the papers that relate to the paper you are given.", "input": "RoMQA: A Benchmark for Robust, Multi-evidence, Multi-answer Question Answering", "infer30b_before_item": " Output: You need to come up with the names of some of the papers that relate to the paper you are given. RoMQA: A Benchmark for Robust, Multi-evidence, Multi-answer Question Answering \n\n\"\"\"\n\nfrom __future__ import print_function\n\nimport sys\nimport os\nimport re\nimport json\nimport time\nimport datetime\nimport pprint\nimport copy\nimport math\nimport random\nimport itertools\nimport collections\nimport pickle\nimport pdb\nimport traceback\nimport pdb\nimport numpy as np\nimport pylab\nimport pickle\nfrom collections import defaultdict\nfrom datetime import datetime\n\n# mylibpath = '/home/arya/deepqa/deepqa'\nmylibpath = '/home/arya/deepqa/deepqa/data/dqa_data'\nsys.path.append(mylibpath)\n\nfrom deepqa.data.data_utils import *\nfrom deepqa.data.data_utils import *\nfrom deepqa.data.data_utils import *\nfrom deepqa.data.data_utils import *\nfrom deepqa.data.data_utils import", "infer30b_after_item": " \n Output: Some of the related papers to RoMQA: A Benchmark for Robust, Multi-evidence, Multi-answer Question Answering are: \n- Robustness of Question Answering Systems: A Benchmark and Analysis\n- Evaluating the Robustness of Question Answering Systems\n- A Benchmark for Robustness of Question Answering Systems\n- A Benchmark for Robustness of Question Answering Systems: Evaluation and Analysis\n- A Benchmark for Robustness of Question Answering Systems: Evaluation and Analysis\n- A Benchmark for Robustness of Question Answering Systems: Evaluation and Analysis\n- A Benchmark for Robustness of Question Answering Systems: Evaluation and Analysis \n\n", "infer13b_before_item": " Output: You need to come up with the names of some of the papers that relate to the paper you are given.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Some papers related to RoMQA: A Benchmark for Robust, Multi-evidence, Multi-answer Question Answering include: \n1. Multi-Evidence Question Answering: A Survey \n2. Multi-Evidence Question Answering: A Comprehensive Review \n3. Multi-Evidence Question Answering: A Comprehensive Survey \n4. Multi-Evidence Question Answering: A Comprehensive Survey \n5. Multi-Evidence Question Answering: A Comprehensive Survey \n6. Multi-Evidence Question Answering: A Comprehensive Survey \n7. Multi-Evidence Question Answering: A Comprehensive Survey \n8. Multi-Evidence Question Answering: A Comprehensive Survey \n9. Multi-Evidence Question Answering: A Comprehensive Survey \n10. Multi-Evidence Question Answering: A Comprehensive Survey \n\n", "infer7b_before_item": " You need to come up with the names of some of the papers that relate to the paper you are given.\n\n\\begin{code}\nimport os\nimport sys\nimport re\nimport json\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates as mdates\nimport matplotlib.dates", "infer7b_after_item": " \n Output: 1. Robust Multi-evidence Multi-answer Question Answering (RoMQA)\n2. Multi-evidence Multi-answer Question Answering (MMAQA)\n3. Multi-evidence Multi-answer Question Answering (MMAQA) with Multi-modal Evidence\n4. Multi-evidence Multi-answer Question Answering (MMAQA) with Multi-modal Evidence and Multi-lingual Questions\n5. Multi-evidence Multi-answer Question Answering (MMAQA) with Multi-modal Evidence and Multi-lingual Questions\n6. Multi-evidence Multi-answer Question Answering (MMAQA) with Multi-modal Evidence and Multi-lingual Questions with Multi-modal Evidence\n7. Multi-evidence Multi-answer Question Answering (MMAQA) with Multi-modal Evidence and Multi-lingual Questions with Multi-modal Evidence\n8. Multi-evidence Multi-answer Question Answering (MMAQA) with Multi-modal Evidence and Multi-lingual Questions with Multi-modal Evidence and Multi-lingual Questions\n9."} {"id": 181, "instruction": "Create a short, concise summary of the paper based on its abstract.", "input": "Few-shot learning (FSL) is one of the key future steps in machine learning and raises a lot of attention. In this paper, we focus on the FSL problem of dialogue understanding, which contains two closely related tasks: intent detection and slot filling. Dialogue understanding has been proven to benefit a lot from jointly learning the two sub-tasks. However, such joint learning becomes challenging in the few-shot scenarios: on the one hand, the sparsity of samples greatly magnifies the difficulty of modeling the connection between the two tasks; on the other hand, how to jointly learn multiple tasks in the few-shot setting is still less investigated. In response to this, we introduce FewJoint, the first FSL benchmark for joint dialogue understanding. FewJoint provides a new corpus with 59 different dialogue domains from real industrial API and a code platform to ease FSL experiment set-up, which are expected to advance the research of this field. Further, we find that insufficient performance of the few-shot setting often leads to noisy sharing between two sub-task and disturbs joint learning. To tackle this, we guide slot with explicit intent information and propose a novel trust gating mechanism that blocks low-confidence intent information to ensure high quality sharing. Besides, we introduce a Reptile-based meta-learning strategy to achieve better generalization in unseen few-shot domains. In the experiments, the proposed method brings significant improvements on two datasets and achieve new state-of-the-art performance.", "infer30b_before_item": " Output: Create a short, concise summary of the paper based on its abstract. Few-shot learning (FSL) is one of the key future steps in machine learning and raises a lot of attention. In this paper, we focus on the FSL problem of dialogue understanding, which contains two closely related tasks: intent detection and slot filling. Dialogue understanding has been proven to benefit a lot from jointly learning the two sub-tasks. However, such joint learning becomes challenging in the few-shot scenarios: on the one hand, the sparsity of samples greatly magnifies the difficulty of modeling the connection between the two tasks; on the other hand, how to jointly learn multiple tasks in the few-shot setting is still less investigated. In response to this, we introduce FewJoint, the first FSL benchmark for joint dialogue understanding. FewJoint provides a new corpus with 59 different dialogue domains from real industrial API and a code platform to ease FSL experiment set-up, which are expected to advance the research of this field. Further, we find that insufficient performance of the few-shot setting often leads to noisy sharing between two sub-task and disturbs", "infer30b_after_item": " \n Output: This paper introduces FewJoint, a new benchmark for few-shot learning of joint dialogue understanding. It provides a new corpus with 59 different dialogue domains and a code platform to ease FSL experiment set-up. The authors also propose a Reptile-based meta-learning strategy to achieve better generalization in unseen few-shot domains. Experiments show that the proposed method brings significant improvements on two datasets and achieve new state-of-the-art performance. \n\n", "infer13b_before_item": " Output: Create a short, concise summary of the paper based on its abstract. Few-shot learning (FSL) is one of the key future steps in machine learning and raises a lot of attention. In this paper, we focus on the FSL problem of dialogue understanding, which contains two closely related tasks: intent detection and slot filling. Dialogue understanding has been proven to benefit a lot from jointly learning the two sub-tasks. However, such joint learning becomes challenging in the few-shot scenarios: on the one hand, the sparsity of samples greatly magnifies the difficulty of modeling the connection between the two tasks; on the other hand, how to jointly learn multiple tasks in the few-shot setting is still less investigated. In response to this, we introduce FewJoint, the first FSL benchmark for joint dialogue understanding. FewJoint provides a new corpus with 59 different dialogue domains from real industrial API and a code platform to ease FSL experiment set-up, which are expected to advance the research of this field. Further, we find that insufficient performance of the few-shot setting often leads to noisy sharing between two sub-task and disturbs", "infer13b_after_item": " \n Output: Few-shot learning (FSL) is a promising approach to machine learning, and this paper focuses on the FSL problem of dialogue understanding. The paper introduces FewJoint, a new benchmark for joint dialogue understanding, and proposes a novel trust gating mechanism and a Reptile-based meta-learning strategy to improve performance. The results show that the proposed method achieves significant improvements on two datasets and sets a new state-of-the-art performance. \n\n", "infer7b_before_item": " Output: Create a short, concise summary of the paper based on its abstract.\n\n\\end{document}\n\\end{code}\n\n\n\nComment: Welcome to TeX.SE!\n\nComment: I'm not sure what you mean by \"the output is not what I want\". Please provide a [minimal working example (MWE)](https://tex.meta.stackexchange.com/q/228) that shows the problem.\n\nComment: @Mico I have added the MWE.\n\nComment: @Mico I have added the MWE.\n\nComment: @Mico I have added the MWE.\n\nComment: @Mico I have added the MWE.\n\nComment: @Mico I have added the MWE.\n\nComment: @Mico I have added the MWE.\n\nComment: @Mico I have added the MWE.\n\nComment: @Mico I have added the MWE.\n\nComment: @Mico I have added the MWE.\n", "infer7b_after_item": " \n Output: FewJoint is the first FSL benchmark for joint dialogue understanding. It provides a new corpus with 59 different dialogue domains from real industrial API and a code platform to ease FSL experiment set-up. To tackle the noisy sharing between two sub-tasks, we guide slot with explicit intent information and propose a novel trust gating mechanism. Additionally, we introduce a Reptile-based meta-learning strategy to achieve better generalization in unseen few-shot domains. Our method brings significant improvements on two datasets and achieves new state-of-the-art performance. \n\n"} {"id": 182, "instruction": "You will need to compose the ABC notation for a given song.", "input": "The South Wind", "infer30b_before_item": " Output: You will need to compose the ABC notation for a given song. The South Wind \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", "infer30b_after_item": " by Yo-Yo Ma. \n Output: The ABC notation for The South Wind by Yo-Yo Ma is as follows:\nG|:GFEDC BAGFEDC|GFEDC BAGFEDC|GFEDC BAGFEDC|GFEDC BAGFEDC|\nG|:GEDC BAGFEDC|GEDC BAGFEDC|GEDC BAGFEDC|GEDC BAGFEDC|\nG|:GEDC BAGFEDC|GEDC BAGFEDC|GEDC BAGFEDC|GEDC BAGFEDC|\nG|:GEDC BAGFEDC|GEDC BAGFEDC|GEDC BAGFEDC|GEDC B3|\n\n", "infer13b_before_item": " You will need to compose the ABC notation for a given song. The South Wind \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\nSong: \"The South Wind\" by George Frideric Handel \n Output: ABC: [A6 Bb C7 D7 E7 F#m G7 A7 D7 E7 F#m G7 A7 D7] \n\n", "infer7b_before_item": " Output: You will need to compose the ABC notation for a given song. The South Wind \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " Blows \n Output: ABC notation for The South Wind Blows:\nG D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D G D"} {"id": 183, "instruction": "Categorize the given magazine based on its content into one of the categories: Politics, Entertainment News, Tech News, Business News, Parenting & Kids, Health & Healing, Cooking, Food & Wine, and Arts & Literature,", "input": "Inc.", "infer30b_before_item": " Output: The category of the given magazine.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": "\nInc. Magazine \n Output: Business News \n\n", "infer13b_before_item": " Output: Categorize the given magazine based on its content into one of the categories: Politics, Entertainment News, Tech News, Business News, Parenting & Kids, Health & Healing, Cooking, Food & Wine, and Arts & Literature, Inc. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " Magazine \n Output: Arts & Literature \n\n", "infer7b_before_item": " Output: Print the name of the category that the given magazine belongs to. \n Example: \n Input: \n Output: \n Explanation: \n 1. The magazine belongs to the category of Politics. \n 2. The magazine belongs to the category of Entertainment News. \n 3. The magazine belongs to the category of Tech News. \n 4. The magazine belongs to the category of Business News. \n 5. The magazine belongs to the category of Parenting & Kids. \n 6. The magazine belongs to the category of Health & Healing. \n 7. The magazine belongs to the category of Cooking. \n 8. The magazine belongs to the category of Food & Wine. \n 9. The magazine belongs to the category of Arts & Literature. \n 10. The magazine belongs to the category of Arts & Literature. \n 11. The magazine belongs to the category of Arts & Literature. \n 12. The magazine belongs to the category of Arts & Literature. \n 13. The magazine belongs to the category of Arts & Literature. \n 14.", "infer7b_after_item": " The magazine is \"The Economist\". \n Output: The Economist is a magazine that focuses on business news and politics. \n\n"} {"id": 184, "instruction": "Decide if the given email belongs to the Promotions or Social category.", "input": "Subject: You have an invitation\nEmail: Hi, I'd like to join your LinkedIn network.", "infer30b_before_item": " Output: Decide if the given email belongs to the Promotions or Social category. Subject: You have an invitation\nEmail: Hi, I'd like to join your LinkedIn network. \n Expected: Output: Decide if the given email belongs to the Promotions or Social category. Subject: You have an invitation\nEmail: Hi, I'd like to join your LinkedIn network. \n*/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Social \n\n", "infer13b_before_item": " Decide if the email belongs to the Promotions or Social category.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Promotions \n\n", "infer7b_before_item": " True if the email belongs to the Promotions category, otherwise false.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Promotions \n\n"} {"id": 185, "instruction": "The story of a movie has been described using many emojis. You need to guess the name of the movie based on the emojis.", "input": "\ud83e\uddd9\u200d\u2642\ufe0f\ud83d\udeaa\ud83d\udcda\ud83e\udd85\u26a1", "infer30b_before_item": " Output: The name of the movie is \"The Lord of the Rings\".\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: The Lion King. \n\n", "infer13b_before_item": " Output: The name of the movie.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\ufe0f\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ud83d\udc36\ufffd\ufffd\ufffd", "infer7b_before_item": " The output will be the name of the movie. \n\n\n# I worked on this challenge [by myself, with: ].\n# I spent [#] hours on this challenge.\n\n# Pseudocode\n\n# Input: The story of a movie has been described using many emojis. You need to guess the name of the movie based on the emojis.\n# Output: The output will be the name of the movie.\n\n\n# Initial Solution\n\ndef emoji_movie_name(emoji_story)\n emoji_story.split(\" \").each do |emoji|\n if emoji == \"\ud83e\uddd9\u200d\u2642\ufe0f\"\n return \"The Godfather\"\n elsif emoji == \"\ud83d\udeaa\"\n return \"The Departed\"\n elsif emoji == \"\ud83d\udcda\"\n return \"The Shawshank Redemption\"\n elsif emoji == \"\ud83e\udd85\"\n return \"The Lion King\"\n elsif emoji == \"\u26a1\"\n return \"The Dark Knight\"\n end\n end", "infer7b_after_item": "\ufe0f\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ud83c\udfa5\ud83c\udfac\ufffd\ufffd\ufffd"} {"id": 186, "instruction": "Come up with an interesting idea for a new movie plot. Your plot should be described with a title and a summary.", "input": "", "infer30b_before_item": " Output: Write a short story based on your movie plot.\nInput: Input: Come up with an interesting idea for a new movie plot. Your plot should be described with a title and a summary. \n Output: Output: Write a short story based on your movie plot.\nInput: Input: Come up with an interesting idea for a new movie plot. Your plot should be described with a title and a summary. \n Output: Output: Write a short story based on your movie plot.\nInput: Input: Come up with an interesting idea for a new movie plot. Your plot should be described with a title and a summary. \n Output: Output: Write a short story based on your movie plot.\nInput: Input: Come up with an interesting idea for a new movie plot. Your plot should be described with a title and a summary. \n Output: Output: Write a short story based on your movie plot.\nInput: Input: Come up with an interesting idea for a new movie plot. Your plot should be described with a title and a summary. \n Output: Output: Write a short story based on your movie plot.\nInput: Input: Come up with an interesting idea for a new movie plot. Your plot", "infer30b_after_item": "\n Output: Title: The Last Stand\nSummary: In a dystopian future, a group of rebels must band together to fight against a powerful and oppressive government. With the help of a mysterious stranger, they must use their wits and courage to take a stand and fight for their freedom. \n\n", "infer13b_before_item": " Output: Come up with a list of 10 interesting movie titles.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: The title of the movie is \"The Unlikely Hero\". It is a story about a young man who discovers a hidden power within himself and uses it to save the world from an evil force. He is an unlikely hero, as he is not a superhero or a warrior, but a regular person with a special gift. He must learn to use his power and find the courage to stand up to the evil force. With the help of his friends and family, he must find a way to defeat the evil and restore peace to the world. \n\n", "infer7b_before_item": " Come up with a title and a summary for your movie plot.\nInput: Input: Come up with an interesting idea for a new movie plot. Your plot should be described with a title and a summary. \n Output: Come up with a title and a summary for your movie plot.\nInput: Input: Come up with an interesting idea for a new movie plot. Your plot should be described with a title and a summary. \n Output: Come up with a title and a summary for your movie plot.\nInput: Input: Come up with an interesting idea for a new movie plot. Your plot should be described with a title and a summary. \n Output: Come up with a title and a summary for your movie plot.\nInput: Input: Come up with an interesting idea for a new movie plot. Your plot should be described with a title and a summary. \n Output: Come up with a title and a summary for your movie plot.\nInput: Input: Come up with an interesting idea for a new movie plot. Your plot should be described with a title and a summary. \n Output: Come up with a title and a summary for your movie plot.\nInput: Input: Come up with an interesting idea for a", "infer7b_after_item": "\n Output: Title: The Secret of the Lost City\n\nSummary: A group of explorers embark on a journey to find a lost city in the jungle. Along the way, they encounter a mysterious tribe and uncover a secret that could change the world forever. \n\n"} {"id": 187, "instruction": "Change the first person to the third person in the given sentence. The meaning should be kept, but you can paraphrase it or expand it in order to have a better pose.", "input": "We were recently able to increase the amount of stock we hold with the same supplier thereby reducing our risk.", "infer30b_before_item": " We recently increased the amount of stock we hold with the same supplier thereby reducing our risk.\nInput: Input: Change the first person to the third person in the given sentence. The meaning should be kept, but you can paraphrase it or expand it in order to have a better pose. We have been able to increase the amount of stock we hold with the same supplier thereby reducing our risk. \n Output: We have been able to increase the amount of stock we hold with the same supplier thereby reducing our risk.\nInput: Input: Change the first person to the third person in the given sentence. The meaning should be kept, but you can paraphrase it or expand it in order to have a better pose. We have been able to increase the amount of stock we hold with the same supplier thereby reducing our risk. \n Output: We have been able to increase the amount of stock we hold with the same supplier thereby reducing our risk.\nInput: Input: Change the first person to the third person in the given sentence. The meaning should be kept, but you can paraphrase it or expand it in order to have a better pose. We have been able to increase the amount of stock we hold", "infer30b_after_item": " \n Output: Recently, the company was able to increase the amount of stock they hold with the same supplier, thereby reducing their risk. \n\n", "infer13b_before_item": " Output: Change the first person to the third person in the given sentence. The meaning should be kept, but you can paraphrase it or expand it in order to have a better pose. We were recently able to increase the amount of stock we hold with the same supplier thereby reducing our risk. \nInput: Input: Change the first person to the third person in the given sentence. The meaning should be kept, but you can paraphrase it or expand it in order to have a better pose. We were recently able to increase the amount of stock we hold with the same supplier thereby reducing our risk. \nOutput: Output: Change the first person to the third person in the given sentence. The meaning should be kept, but you can paraphrase it or expand it in order to have a better pose. We were recently able to increase the amount of stock we hold with the same supplier thereby reducing our risk. \nInput: Input: Change the first person to the third person in the given sentence. The meaning should be kept, but you can paraphrase it or expand it in order to have a better pose. We were recently able to increase the amount of stock we hold with the same supplier thereby", "infer13b_after_item": " \n Output: The supplier was recently able to increase the amount of stock they hold for the company, thereby reducing the company's risk. \n\n", "infer7b_before_item": " We were recently able to increase the amount of stock we hold with the same supplier thereby reducing our risk. \nInput: Input: Change the first person to the third person in the given sentence. The meaning should be kept, but you can paraphrase it or expand it in order to have a better pose. We were recently able to increase the amount of stock we hold with the same supplier thereby reducing our risk. \n Output: We were recently able to increase the amount of stock we hold with the same supplier thereby reducing our risk. \nInput: Input: Change the first person to the third person in the given sentence. The meaning should be kept, but you can paraphrase it or expand it in order to have a better pose. We were recently able to increase the amount of stock we hold with the same supplier thereby reducing our risk. \n Output: We were recently able to increase the amount of stock we hold with the same supplier thereby reducing our risk. \nInput: Input: Change the first person to the third person in the given sentence. The meaning should be kept, but you can paraphrase it or expand it in order to have a better pose. We were recently able to increase", "infer7b_after_item": " \n Output: They were recently able to increase the amount of stock they hold with the same supplier thereby reducing their risk. \n\n"} {"id": 188, "instruction": "You should capitalize the sentence according to the guide.", "input": "Guide: Every other letter alternates between lower case and upper case.\nSentence: A giant spider blocks your path.", "infer30b_before_item": " Output: A Giant Spider Blocks Your Path.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: A Giant SpidEr BlOcks Your PaTh. \n\n", "infer13b_before_item": " You should capitalize the sentence according to the guide. Guide: Every other letter alternates between lower case and upper case.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: A GiANT Spider Blocks Your Path. \n\n", "infer7b_before_item": " A giant spider blocks your path.\n\nInput: You should capitalize the sentence according to the guide. Guide: Every other letter alternates between lower case and upper case.\nSentence: A giant spider blocks your path. \n Output: A giant spider blocks your path.\n\nInput: You should capitalize the sentence according to the guide. Guide: Every other letter alternates between lower case and upper case.\nSentence: A giant spider blocks your path. \n Output: A giant spider blocks your path.\n\nInput: You should capitalize the sentence according to the guide. Guide: Every other letter alternates between lower case and upper case.\nSentence: A giant spider blocks your path. \n Output: A giant spider blocks your path.\n\nInput: You should capitalize the sentence according to the guide. Guide: Every other letter alternates between lower case and upper case.\nSentence: A giant spider blocks your path. \n Output: A giant spider blocks your path.\n\nInput: You should capitalize the sentence according to the guide. Guide: Every other letter alternates between lower case and upper case.\nSent", "infer7b_after_item": " \n Output: A Giant Spider Blocks Your Path. \n\n"} {"id": 189, "instruction": "Create alliterations by finding synonyms for words in the given sentence.", "input": "David wears a hat everyday.", "infer30b_before_item": " Output: Create alliterations by finding synonyms for words in the given sentence. David wears a hat everyday.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: David dons a hat daily. \n\n", "infer13b_before_item": " Output: David wears a hat everyday. \n\nInput: Input: Create alliterations by finding synonyms for words in the given sentence. David wears a hat everyday. \n Output: Output: David wears a hat everyday. \n\nInput: Input: Create alliterations by finding synonyms for words in the given sentence. David wears a hat everyday. \n Output: Output: David wears a hat everyday. \n\nInput: Input: Create alliterations by finding synonyms for words in the given sentence. David wears a hat everyday. \n Output: Output: David wears a hat everyday. \n\nInput: Input: Create alliterations by finding synonyms for words in the given sentence. David wears a hat everyday. \n Output: Output: David wears a hat everyday. \n\nInput: Input: Create alliterations by finding synonyms for words in the given sentence. David wears a hat everyday. \n Output: Output: David wears a hat everyday. \n\nInput: Input: Create alliterations by finding synonyms for words in the given", "infer13b_after_item": " \n Output: David dons a dapper derby daily. \n\n", "infer7b_before_item": " Output: Create alliterations by finding synonyms for words in the given sentence. David wears a hat everyday.\n*/\n\n// 1. Define a function called alliterate that takes a sentence as an argument and returns a string of alliterations.\n// 2. Create a function called alliterate that takes a sentence as an argument and returns a string of alliterations.\n// 3. Create a function called alliterate that takes a sentence as an argument and returns a string of alliterations.\n// 4. Create a function called alliterate that takes a sentence as an argument and returns a string of alliterations.\n// 5. Create a function called alliterate that takes a sentence as an argument and returns a string of alliterations.\n// 6. Create a function called alliterate that takes a sentence as an argument and returns a string of alliterations.\n// 7. Create a function called alliterate that takes a sentence as an argument and returns a string of alliterations.\n// 8. Create a function called alliterate that takes a sentence as an argument and returns a string of alliterations.\n// ", "infer7b_after_item": " \n Output: David wears a hat everyday. He constantly clutches a cap. \n\n"} {"id": 190, "instruction": "Convert the given description to a bash command.", "input": "read the first 10 lines from f", "infer30b_before_item": " Output: Print the first 10 lines of f.\n\n Expected Output:\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": "1.txt \n Output: head -n 10 f1.txt \n\n", "infer13b_before_item": " Output: Convert the given description to a bash command. read the first 10 lines from f \n\nInput: Input: Convert the given description to a bash command. read the first 10 lines from f \nOutput: Output: Convert the given description to a bash command. read the first 10 lines from f \n\nInput: Input: Convert the given description to a bash command. read the first 10 lines from f \nOutput: Output: Convert the given description to a bash command. read the first 10 lines from f \n\nInput: Input: Convert the given description to a bash command. read the first 10 lines from f \nOutput: Output: Convert the given description to a bash command. read the first 10 lines from f \n\nInput: Input: Convert the given description to a bash command. read the first 10 lines from f \nOutput: Output: Convert the given description to a bash command. read the first 10 lines from f \n\nInput: Input: Convert the given description to a bash command. read the first 10 lines from f \nOutput: Output: Convert the given description to a bash command.", "infer13b_after_item": "red.txt \n Output: cat fred.txt | head -n 10 \n\n", "infer7b_before_item": " Output: Print the command. \n*/\n\n#include \n#include \n#include \n\nint main(int argc, char *argv[])\n{\n\tFILE *f;\n\tchar *line;\n\tchar *command;\n\tint i;\n\t\n\tif (argc!= 2)\n\t{\n\t\tprintf(\"Usage: %s \\n\", argv[0]);\n\t\treturn 1;\n\t}\n\t\n\tf = fopen(argv[1], \"r\");\n\tif (f == NULL)\n\t{\n\t\tprintf(\"Cannot open file %s\\n\", argv[1]);\n\t\treturn 1;\n\t}\n\t\n\twhile ((line = fgets(line, 100, f))!= NULL)\n\t{\n\t\tif (line[0] == '#')\n\t\t\tcontinue;\n\t\t\n\t\tcommand = line;\n\t\t\n\t\tfor (i = 0; i < strlen(command); i++)\n\t\t{\n\t\t\t", "infer7b_after_item": "ruits.txt \n Output: echo \"Reading the first 10 lines from fruits.txt...\"\n\nfruits.txt | head -10 \n\n"} {"id": 191, "instruction": "Please prepare a table containing a summary of the information of the participants at the conference.", "input": "The conference was called to discuss how to improve the quality of education in schools. The main speaker was Professor Crew Purdie (cpurdie@email.com), who spoke about the importance of setting high standards for students and teachers. He said that schools should be places where students can learn and be challenged. Other speakers included Teacher Oliver Malachi (oliver@email.com) and Parent Kolby Reese (kolbyreese82@email.com). The teacher talked about the need for teachers to be well-prepared and to have high expectations for their students. The parent spoke about the need for parents to be involved in their children's education. There was also a discussion about the importance of funding for schools.", "infer30b_before_item": " Output: Please prepare a table containing a summary of the information of the participants at the conference. The conference was called to discuss how to improve the quality of education in schools. The main speaker was Professor Crew Purdie (cpurdie@email.com), who spoke about the importance of setting high standards for students and teachers. He said that schools should be places where students can learn and be challenged. Other speakers included Teacher Oliver Malachi (oliver@email.com) and Parent Kolby Reese (kolbyreese82@email.com). The teacher talked about the need for teachers to be well-prepared and to have high expectations for their students. The parent spoke about the need for parents to be involved in their children's education. There was also a discussion about the importance of funding for schools. \n \n*/\n\n#include \n#include \n#include \n\nusing namespace std;\n\nint main() {\n string input;\n getline(cin, input);\n\n vector words;\n string currentWord;\n int i = 0;\n for (int j = 0", "infer30b_after_item": " \n Output: | Name | Profession | Topic |\n|-----|------------|-------|\n|Professor Crew Purdie| Speaker | Setting high standards for students and teachers|\n|Teacher Oliver Malachi| Speaker | The need for teachers to be well-prepared and to have high expectations for their students|\n|Parent Kolby Reese| Speaker | The need for parents to be involved in their children's education|\n|All| Discussion | The importance of funding for schools| \n\n", "infer13b_before_item": " Output: Please prepare a table containing a summary of the information of the participants at the conference. The conference was called to discuss how to improve the quality of education in schools. The main speaker was Professor Crew Purdie (cpurdie@email.com), who spoke about the importance of setting high standards for students and teachers. He said that schools should be places where students can learn and be challenged. Other speakers included Teacher Oliver Malachi (oliver@email.com) and Parent Kolby Reese (kolbyreese82@email.com). The teacher talked about the need for teachers to be well-prepared and to have high expectations for their students. The parent spoke about the need for parents to be involved in their children's education. There was also a discussion about the importance of funding for schools. \n*/\n\n#include \n#include \n\nint main(void)\n{\n char *name;\n char *email;\n char *role;\n char *speech;\n char *speaker;\n char *speaker_email;\n char *speaker_role;\n char", "infer13b_after_item": " \n Output: | Participant | Email | Topic |\n| ----------------- | --------- | ------ |\n| Professor Crew Purdie | cpurdie@email.com | Setting high standards |\n| Teacher Oliver Malachi | oliver@email.com | Well-prepared teachers |\n| Parent Kolby Reese | kolbyreese82@email.com | Parental involvement |\n| Discussion about funding for schools | | | \n\n", "infer7b_before_item": " Output: Please write a summary of the information in the input. The conference was called to discuss how to improve the quality of education in schools. The main speaker was Professor Crew Purdie (cpurdie@email.com), who spoke about the importance of setting high standards for students and teachers. He said that schools should be places where students can learn and be challenged. Other speakers included Teacher Oliver Malachi (oliver@email.com) and Parent Kolby Reese (kolbyreese82@email.com). The teacher talked about the need for teachers to be well-prepared and to have high expectations for their students. The parent spoke about the need for parents to be involved in their children's education. There was also a discussion about the importance of funding for schools. \n\n### 2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.", "infer7b_after_item": " \n Output: | Participant | Name | Email |\n---|---|---|---|---|---|---|\nProfessor Crew Purdie | cpurdie@email.com |\nTeacher Oliver Malachi | oliver@email.com |\nParent Kolby Reese | kolbyreese82@email.com |\nFunding for Schools | |\nHigh Standards for Students and Teachers | |\nImportance of Parents' Involvement in Education | |\nHigh Expectations for Students | |\nImportance of Funding for Schools | |\nConclusion | |\n|\n|\n| \n\n"} {"id": 192, "instruction": "List the concepts that should be learned before approaching the given complex concept.", "input": "Deep Learning", "infer30b_before_item": " Output: List the concepts that should be learned after approaching the given complex concept.\n\n \n*/\n\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\n\nint main() {\n /* Enter your code here. Read input from STDIN. Print output to STDOUT */ \n int t;\n cin>>t;\n while(t--)\n {\n int n;\n cin>>n;\n list l;\n for(int i=0;i>a;\n l.push_back(a);\n }\n for(int i=0;i\n#include \n#include \n#include \n#include \n#include \n#include \nusing namespace std;\n\n#define ll long long\n\n#define mem(Arr,x) memset(Arr,x,sizeof(Arr))\n\nconst int maxN = 100000 + 10;\n\nint n, m;\nint S[maxN], T[maxN];\nint Cnt[maxN];\nint Id[maxN];\nint CntS[maxN], CntT[maxN];\nint CntS1[maxN], CntT1[maxN];\nint CntS2[maxN], CntT2[maxN];\nint CntS3[maxN], CntT3[maxN];\nint CntS4[maxN], CntT4[maxN];\nint CntS5[maxN], CntT5[maxN];\nint", "infer30b_after_item": " \n Output: There is an x such that if x is a soldier, then x is a general with respect to some y. \n\n", "infer13b_before_item": " You are given a sentence in first-order logic. Translate it into natural language. \u2203x\u2200y(soldier(x)\u2192general(x,y)) \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Every soldier is a general. \n\n", "infer7b_before_item": " You are given a sentence in natural language. Translate it into first-order logic. \u2200x\u2200y(soldier(x)\u2192general(x,y)) \n*/\n\n// 1. Translate the sentence into first-order logic.\n// 2. Translate the sentence into natural language.\n\n// 1. Translate the sentence into first-order logic.\n// \u2200x\u2200y(soldier(x)\u2192general(x,y))\n\n// 2. Translate the sentence into natural language.\n// \u2200x\u2200y(soldier(x)\u2192general(x,y))\n\n// 3. Translate the sentence into natural language.\n// \u2200x\u2200y(soldier(x)\u2192general(x,y))\n\n// 4. Translate the sentence into natural language.\n// \u2200x\u2200y(soldier(x)\u2192general(x,y))\n\n// 5. Translate the sentence into natural language.\n// \u2200x\u2200y(soldier(x)\u2192general(x,y))\n\n// 6. Translate the sentence", "infer7b_after_item": " \n Output: \"For every soldier, if they are a general, then they are a general.\" \n\n"} {"id": 197, "instruction": "You are given a search query and a document. Classify whether the document is relevant to the search query or not relevant.", "input": "Search: why sky is blue\nDocument: The Short Answer: Sunlight reaches Earth's atmosphere and is scattered in all directions by all the gases and particles in the air. Blue light is scattered more than the other colors because it travels as shorter, smaller waves. This is why we see a blue sky most of the time.", "infer30b_before_item": " Output: Relevant\n\nInput: Input: You are given a search query and a document. Classify whether the document is relevant to the search query or not relevant. Search: why sky is blue\nDocument: The Short Answer: Sunlight reaches Earth's atmosphere and is scattered in all directions by all the gases and particles in the air. Blue light is scattered more than the other colors because it travels as shorter, smaller waves. This is why we see a blue sky most of the time. \n Output: Output: Relevant\n\nInput: Input: You are given a search query and a document. Classify whether the document is relevant to the search query or not relevant. Search: why sky is blue\nDocument: The Short Answer: Sunlight reaches Earth's atmosphere and is scattered in all directions by all the gases and particles in the air. Blue light is scattered more than the other colors because it travels as shorter, smaller waves. This is why we see a blue sky most of the time. \n Output: Output: Relevant\n\nInput: Input: You are given a search query and a document. Classify whether the document is relevant to the search query or not relevant. Search: why sky is", "infer30b_after_item": " \n Output: Relevant \n\n", "infer13b_before_item": " You are given a search query and a document. Classify whether the document is relevant to the search query or not relevant. Search: why sky is blue\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Relevant. \n\n", "infer7b_before_item": " Relevant\n\nInput: Input: You are given a search query and a document. Classify whether the document is relevant to the search query or not relevant. Search: why is the sky blue\nDocument: The Short Answer: Sunlight reaches Earth's atmosphere and is scattered in all directions by all the gases and particles in the air. Blue light is scattered more than the other colors because it travels as shorter, smaller waves. This is why we see a blue sky most of the time. \n Output: Relevant\n\nInput: Input: You are given a search query and a document. Classify whether the document is relevant to the search query or not relevant. Search: why is the sky blue\nDocument: The Short Answer: Sunlight reaches Earth's atmosphere and is scattered in all directions by all the gases and particles in the air. Blue light is scattered more than the other colors because it travels as shorter, smaller waves. This is why we see a blue sky most of the time. \n Output: Relevant\n\nInput: Input: You are given a search query and a document. Classify whether the document is relevant to the search query or not relevant. Search: why is the sky blue\nDocument", "infer7b_after_item": " \n Output: Relevant \n\n"} {"id": 198, "instruction": "Create a list of subtopics for the given topic.", "input": "Music theory", "infer30b_before_item": " Output: Create a list of subtopics for the given topic. Music theory \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", "infer30b_after_item": " \n Output: - Basic music theory\n- Intervals and chords\n- Scales and modes\n- Harmony and counterpoint\n- Rhythm and meter\n- Form and structure\n- Instrumentation and orchestration\n- Music notation and terminology\n- Musical analysis and interpretation\n- Music history and culture \n\n", "infer13b_before_item": " Output: Create a list of subtopics for the given topic. Music theory \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: - Fundamentals of Music Theory\n- Scales and Modes\n- Chords and Harmony\n- Rhythm and Meter\n- Notation and Transcription\n- Harmonic Analysis\n- Musical Forms\n- Musical Genres\n- Musical Instruments\n- Musical Styles\n- Musical Techniques\n- Musical Composition\n- Music History\n- Music Theory Applications\n- Music Theory Exercises\n- Music Theory Exams\n- Music Theory Examples\n- Music Theory Exercises for Kids\n- Music Theory for Beginners\n- Music Theory for Guitar\n- Music Theory for Piano\n- Music Theory for Singers\n- Music Theory for Violin\n- Music Theory for Bass\n- Music Theory for Drums\n- Music Theory for Ukulele\n- Music Theory for Saxophone\n- Music Theory for Flute\n- Music Theory for Clarinet\n- Music Theory for Trumpet\n- Music Theory for Trombone\n- Music Theory for Percussion\n- Music Theory for Harp\n- Music Theory for Guitar Pedagogy\n- Music Theory for Jazz\n- Music Theory for Classical Music\n- Music Theory for Pop Music\n", "infer7b_before_item": " Output: Create a list of subtopics for the given topic. Music theory\n*/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: - Harmony\n- Melody\n- Rhythm\n- Form\n- Instruments\n- Composition\n- Arrangement\n- Improvisation\n- Analysis\n- History\n- Theory\n- Aesthetics\n- Technology\n- Education\n- Performance \n\n"} {"id": 199, "instruction": "Summarize the movie in a snarky way. Try to explain the movie in just one sentence.", "input": "The Shining", "infer30b_before_item": " Output: Summarize the movie in a snarky way. Try to explain the movie in just one sentence.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: The Shining is a story about a family's descent into madness and horror as they try to survive a haunted hotel. \n\n", "infer13b_before_item": " Output: Summarize the movie in a snarky way. Try to explain the movie in just one sentence. The Shining \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " (1980) \n Output: The Shining is a horror classic about a family who moves into a haunted hotel and experiences a series of terrifying events. \n\n", "infer7b_before_item": " Output: Summarize the movie in a snarky way. Try to explain the movie in just one sentence. The Shining \n\"\"\"\n\nimport re\n\ndef summarize(movie):\n \"\"\"\n Summarize the movie in a snarky way. Try to explain the movie in just one sentence.\n \"\"\"\n # Get the title\n title = movie.title\n # Get the year\n year = movie.year\n # Get the director\n director = movie.director\n # Get the genre\n genre = movie.genre\n # Get the runtime\n runtime = movie.runtime\n # Get the rating\n rating = movie.rating\n # Get the cast\n cast = movie.cast\n # Get the plot\n plot = movie.plot\n # Get the poster\n poster = movie.poster\n # Get the trailer\n trailer = movie.trailer\n # Get the summary\n summary = movie.summary\n # Get the synopsis\n synopsis = movie.synopsis\n # Get the release date\n release_date = movie.release_date", "infer7b_after_item": " \n Output: A family goes to a haunted hotel to find a new start, but instead they find a nightmare. \n\n"} {"id": 200, "instruction": "Enter the words that satisfy the given condition.", "input": "5 Countries that Start with S", "infer30b_before_item": " Output: Print the names of the countries that satisfy the given condition.\n\n Expected Output:\n SRI LANKA\n SPAIN\n SINGAPORE\n SUDAN\n SURINAME\n\n */\n\n#include \n#include \n\nint main()\n{\n char str[100];\n scanf(\"%s\",str);\n int i=0;\n while(str[i]!='\\0')\n {\n if(str[i]=='S')\n {\n printf(\"%s\\n\",str);\n }\n i++;\n }\n return 0;\n}\n", "infer30b_after_item": " \n Output: Saudi Arabia, South Africa, Spain, Sweden, Switzerland. \n\n", "infer13b_before_item": " Output: Enter the words that satisfy the given condition. 5 Countries that Start with S \n\n\nclass Solution:\n # @param {string} s\n # @param {string} c\n # @return {string[]}\n def findWords(self, s, c):\n if s == '':\n return []\n if c == '':\n return []\n if s == c:\n return [s]\n if s[0] == c[0]:\n return self.findWords(s[1:], c[1:]) + self.findWords(s[:1], c)\n return self.findWords(s, c)\n\n\ns = Solution()\nprint s.findWords('', '')\nprint s.findWords('a', 'a')\nprint s.findWords('a', 'b')\nprint s.findWords('a', 'ab')\nprint s.findWords('a', 'abc')\nprint s.findWords('a', 'abcd')\nprint s.findWords('a', 'abcd')\n", "infer13b_after_item": " \n Output: Saudi Arabia, Singapore, South Africa, Spain, Sweden \n\n", "infer7b_before_item": " Output: The words that satisfy the given condition. 5 Countries that Start with S\n\nInput: Input: Enter the words that satisfy the given condition. 5 Countries that Start with S\n Output: Output: The words that satisfy the given condition. 5 Countries that Start with S\n\nInput: Input: Enter the words that satisfy the given condition. 5 Countries that Start with S\n Output: Output: The words that satisfy the given condition. 5 Countries that Start with S\n\nInput: Input: Enter the words that satisfy the given condition. 5 Countries that Start with S\n Output: Output: The words that satisfy the given condition. 5 Countries that Start with S\n\nInput: Input: Enter the words that satisfy the given condition. 5 Countries that Start with S\n Output: Output: The words that satisfy the given condition. 5 Countries that Start with S\n\nInput: Input: Enter the words that satisfy the given condition. 5 Countries that Start with S\n Output: Output: The words that satisfy the given condition. 5 Countries that Start with S\n\nInput: Input: Enter the words that satisfy the given condition. 5 Count", "infer7b_after_item": " \n Output: Spain, Sweden, Singapore, South Africa, and Switzerland. \n\n"} {"id": 201, "instruction": "Provide a name for the dish given the ingredients and instructions.", "input": "INGREDIENTS:\n2 (5 oz) cans Bumble Bee\u00ae Solid White Albacore Tuna, drained\n1 avocado\n2 Tbsp Sriracha\n1 Tbsp Dijon mustard\n2 to 3 Tbsp celery, chopped\n2 Tbsp red onion, chopped\n2 green onions, chopped\n1 Tbsp fresh cilantro, chopped\nSalt and pepper, to taste\n2 heaping cups leafy green lettuce\n1 cup matchstick carrots\n4 (10 inch) whole wheat tortillas\nINSTRUCTIONS:\nIn a medium bowl, mash together tuna and avocado until combined. Add in the rest of the ingredients through the salt and pepper, mixing well.\nTo assemble, top each tortilla with a 1/2 cup leafy greens, 1/4 cup matchstick carrots and divide the tuna mixture evenly among the wraps. Tightly roll up the tortilla, slice and enjoy!", "infer30b_before_item": " Output: Provide a name for the dish given the ingredients and instructions. INGREDIENTS:\n1 (16 oz) package frozen chopped spinach, thawed and drained\n1 (14 oz) can diced tomatoes, undrained\n1 (14 oz) can chicken broth\n1 (10 oz) can condensed cream of chicken soup\n1 (10 oz) can condensed cream of mushroom soup\n1 (10 oz) can condensed cream of celery soup\n1 (10 oz) can condensed cream of asparagus soup\n1 (10 oz) can condensed cream of potato soup\n1 (10 oz) can condensed cream of broccoli soup\n1 (10 oz) can condensed cream of cauliflower soup\n1 (10 oz) can condensed cream of corn soup\n1 (10 oz) can condensed cream of tomato soup\n1 (10 oz) can condensed cream of cheddar cheese soup\n1", "infer30b_after_item": " \n Output: Tuna and Avocado Wraps. \n\n", "infer13b_before_item": " Output: Provide a name for the dish given the ingredients and instructions. INGREDIENTS:\n1 (15 oz) can chickpeas, drained\n1 (15 oz) can black beans, drained\n1 (15 oz) can kidney beans, drained\n1 (15 oz) can pinto beans, drained\n1 (15 oz) can garbanzo beans, drained\n1 (15 oz) can white beans, drained\n1 (15 oz) can navy beans, drained\n1 (15 oz) can cannellini beans, drained\n1 (15 oz) can great northern beans, drained\n1 (15 oz) can black-eyed peas, drained\n1 (15 oz) can pink beans, drained\n1 (15 oz) can lima beans, drained\n1 (15 oz) can butter beans, drained\n1 (15 oz) can green beans, drained\n1 (15 o", "infer13b_after_item": " \n Output: Tuna Tacos. \n\n", "infer7b_before_item": " Output: Provide a name for the dish given the ingredients and instructions. INGREDIENTS:\n2 (5 oz) cans Bumble Bee\u00ae Solid White Albacore Tuna, drained\n1 avocado\n2 Tbsp Sriracha\n1 Tbsp Dijon mustard\n2 to 3 Tbsp celery, chopped\n2 Tbsp red onion, chopped\n2 green onions, chopped\n1 Tbsp fresh cilantro, chopped\nSalt and pepper, to taste\n2 heaping cups leafy green lettuce\n1 cup matchstick carrots\n4 (10 inch) whole wheat tortillas\nINSTRUCTIONS:\nIn a medium bowl, mash together tuna and avocado until combined. Add in the rest of the ingredients through the salt and pepper, mixing well.\nTo assemble, top each tortilla with a 1/2 cup leafy greens, 1/4 cup matchstick carrots and divide the tuna mixture evenly among the wraps. Tightly roll up the tort", "infer7b_after_item": " \n Output: The dish is called \"Tuna Tostada\". \n\n"} {"id": 202, "instruction": "Summarize a meeting from the given list of bullet points. Be sure to convert shorthand into a first-hand account.", "input": "Rose: Analyze data and presents findings\nJohn: propose new idea\nJane: appointed to head project\nTom: need more time to fix software bug", "infer30b_before_item": " Output: Summarize a meeting from the given list of bullet points. Be sure to convert shorthand into a first-hand account. Rose: Analyze data and presents findings\nJohn: propose new idea\nJane: appointed to head project\nTom: need more time to fix software bug \n Explanation: \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# \n# ", "infer30b_after_item": " \n Output: Rose presented her analysis of the data, which she had been working on for the past few weeks. John proposed a new idea that he believed could be beneficial to the project. Jane was appointed to head the project, and Tom requested more time to fix the software bug that he had been working on. \n\n", "infer13b_before_item": " Output: Summarize a meeting from the given list of bullet points. Be sure to convert shorthand into a first-hand account. Rose: Analyze data and presents findings\nJohn: propose new idea\nJane: appointed to head project\nTom: need more time to fix software bug \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Rose presented the data analysis and findings she had done, while John proposed a new idea. Jane was appointed to head the project, and Tom requested more time to fix the software bug. \n\n", "infer7b_before_item": " Output: Write a summary of the meeting.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: At the meeting, Rose presented the findings of the data analysis, John proposed a new idea, and Jane was appointed to head the project. Tom said that he needs more time to fix the software bug. \n\n"} {"id": 203, "instruction": "List a few popular songs from the given album.", "input": "Back To Black", "infer30b_before_item": " Output: List the album name. Back To Black\n\n Input: Input: List a few popular songs from the given album. The Blueprint 3\n Output: Output: List the album name. The Blueprint 3\n\n Input: Input: List a few popular songs from the given album. The Blueprint 3\n Output: Output: List the album name. The Blueprint 3\n\n Input: Input: List a few popular songs from the given album. The Blueprint 3\n Output: Output: List the album name. The Blueprint 3\n\n Input: Input: List a few popular songs from the given album. The Blueprint 3\n Output: Output: List the album name. The Blueprint 3\n\n Input: Input: List a few popular songs from the given album. The Blueprint 3\n Output: Output: List the album name. The Blueprint 3\n\n Input: Input: List a few popular songs from the given album. The Blueprint 3\n Output: Output: List the album name. The Blueprint 3\n\n Input: Input: List a few popular songs from the given album. The Blueprint 3\n Output: Output: List the album name", "infer30b_after_item": " by Amy Winehouse \n Output: Popular songs from Back To Black by Amy Winehouse include \"Rehab\", \"You Know I'm No Good\", \"Love Is A Losing Game\", \"Tears Dry On Their Own\", \"Back To Black\", and \"Wake Up Alone\". \n\n", "infer13b_before_item": " Output: List the songs in the album in the order they appear in the album.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": ", Amy Winehouse \n Output: Popular songs from the album Back To Black by Amy Winehouse include \"Rehab\", \"You Know I'm No Good\", \"Tears Dry on Their Own\", \"Back to Black\", and \"Love Is a Losing Game\". \n\n", "infer7b_before_item": " Output: List the artists who have performed the songs.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": ", Amy Winehouse \n Output: 1. Rehab\n2. You Know I'm No Good\n3. Tears Dry on Their Own\n4. Love Is a Losing Game\n5. Me & Mr. Jones\n6. Back to Black\n7. Stronger Than Me\n8. Valerie\n9. Monkey Man\n10. Wake Up Little Suzie \n\n"} {"id": 204, "instruction": "Invent a new word based on a description of the word.", "input": "The feeling of knowing, while you are still in the moment, that something occurring will be remembered forever.", "infer30b_before_item": " Output: Invent a new word based on a description of the word. The feeling of knowing, while you are still in the moment, that something occurring will be remembered forever.\n\nInput: Input: Invent a new word based on a description of the word. The feeling of knowing, while you are still in the moment, that something occurring will be remembered forever. \n Output: Output: Invent a new word based on a description of the word. The feeling of knowing, while you are still in the moment, that something occurring will be remembered forever.\n\nInput: Input: Invent a new word based on a description of the word. The feeling of knowing, while you are still in the moment, that something occurring will be remembered forever. \n Output: Output: Invent a new word based on a description of the word. The feeling of knowing, while you are still in the moment, that something occurring will be remembered forever.\n\nInput: Input: Invent a new word based on a description of the word. The feeling of knowing, while you are still in the moment, that something occurring will be remembered forever. \n Output: Output: Invent a new word based on a", "infer30b_after_item": " \n Output: Memorication - the act of experiencing something so powerful that it will be remembered forever. \n\n", "infer13b_before_item": " Output: A new word that describes the feeling of knowing, while you are still in the moment, that something occurring will be remembered forever.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Ephemeralize. \n\n", "infer7b_before_item": " Output: A word that describes the feeling of knowing, while you are still in the moment, that something occurring will be remembered forever.\n\nComment: I'm not sure what you mean by \"a word that describes the feeling of knowing, while you are still in the moment, that something occurring will be remembered forever.\" Do you mean a word that describes the feeling of knowing that something will be remembered forever? Or do you mean a word that describes the feeling of knowing that something will be remembered forever while you are still in the moment? Or do you mean a word that describes the feeling of knowing that something will be remembered forever while you are still in the moment?\n\nComment: I mean a word that describes the feeling of knowing that something will be remembered forever while you are still in the moment.\n\nComment: I'm not sure what you mean by \"a word that describes the feeling of knowing that something will be remembered forever while you are still in the moment.\" Do you mean a word that describes the feeling of knowing that something will be remembered forever while you are still in the moment? Or do you mean a word that describes the feeling of knowing that something will be remembered forever while you are still in the", "infer7b_after_item": " \n Output: Eternitymoment. \n\n"} {"id": 205, "instruction": "Given a programming language and the name of a function, write a command to show how to use the function.", "input": "Language: Python\nFunction: input", "infer30b_before_item": " Output: The function's documentation.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: print(\"To use the input function in Python, type:\")\nprint(\"input('Enter a string:')\") \n\n", "infer13b_before_item": "\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:\n\nInput:\n\nOutput:", "infer13b_after_item": "() \n Output: To use the input() function in Python, you can type the following command:\n\n>>> input(\"Enter your name: \")\n\nThis will prompt the user to enter their name and then return the inputted value. \n\n", "infer7b_before_item": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": "() \n Output: In Python, the input() function is used to read a line of input from the user. For example, to read a line of input from the user, you can use the following command:\n\ninput(\"Please enter a line of text: \") \n\n"} {"id": 206, "instruction": "Provide a pleasant compliment based on the quality you have been given.", "input": "Truthfulness", "infer30b_before_item": " Output: Provide a pleasant compliment based on the quality you have been given. Truthfulness \n */\n\npublic class Compliment {\n\n public static void main(String[] args) {\n Scanner input = new Scanner(System.in);\n String quality = input.nextLine();\n String compliment = compliment(quality);\n System.out.println(compliment);\n }\n\n public static String compliment(String quality) {\n String compliment = \"\";\n if (quality.equals(\"smart\")) {\n compliment = \"You are so smart!\";\n } else if (quality.equals(\"funny\")) {\n compliment = \"You are so funny!\";\n } else if (quality.equals(\"attractive\")) {\n compliment = \"You are so attractive!\";\n } else if (quality.equals(\"kind\")) {\n compliment = \"You are so kind!\";\n } else if (quality.equals(\"truthful\")) {\n compliment = \"You are so truthful!\";\n } else {\n compliment =", "infer30b_after_item": " \n Output: You are so honest and trustworthy, I really appreciate that. \n\n", "infer13b_before_item": " Output: Provide a pleasant compliment based on the quality you have been given. Truthfulness \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: You are so honest and trustworthy, it's a quality that is rare to find. \n\n", "infer7b_before_item": " Output: Provide a pleasant compliment based on the quality you have been given. Truthfulness \n\n\"\"\"\n\n\nclass Truthfulness:\n def __init__(self):\n self.truthfulness = 0\n\n def __str__(self):\n return \"Truthfulness: \" + str(self.truthfulness)\n\n def __repr__(self):\n return \"Truthfulness: \" + str(self.truthfulness)\n\n def __add__(self, other):\n self.truthfulness += other\n return self\n\n def __sub__(self, other):\n self.truthfulness -= other\n return self\n\n def __mul__(self, other):\n self.truthfulness *= other\n return self\n\n def __div__(self, other):\n self.truthfulness /= other\n return self\n\n def __mod__(self, other):\n self.truthfulness %= other\n return self\n\n def __pow__(self, other):\n self.", "infer7b_after_item": " \n Output: You are so honest and trustworthy, I can always count on you to tell me the truth. \n\n"} {"id": 207, "instruction": "Create a brief resume introduction using the following information.", "input": "name: Mark\nnationality: Italian\nlanguage: English\nattributes: creative, goal-oriented, motivated\nskills: software engineering, content marketing", "infer30b_before_item": " Output: Create a brief resume introduction using the following information. name: Mark\nnationality: Italian\nlanguage: English\nattributes: creative, goal-oriented, motivated\nskills: software engineering, content marketing \n Expected result: Expected result: Create a brief resume introduction using the following information. name: Mark\nnationality: Italian\nlanguage: English\nattributes: creative, goal-oriented, motivated\nskills: software engineering, content marketing \n Author: Author: Mark\n Date: Date: 2017-02-15\n----------------------------------------------------------------------------------------------------\n*/\n\n#include \n#include \n\nusing namespace std;\n\nint main() {\n string name;\n string nationality;\n string language;\n string attributes;\n string skills;\n\n cout << \"Input: Input: Create a brief resume introduction using the following information.\" << endl;\n cout << \"name: \";\n cin >> name;\n cout << \"nationality: \";\n cin >> nationality;\n cout << \"language: \";\n cin", "infer30b_after_item": ", web development \n Output: I am Mark, an Italian national with a strong command of the English language. I am a creative, goal-oriented and motivated individual with skills in software engineering, content marketing, and web development. \n\n", "infer13b_before_item": " Output: Create a brief resume introduction using the following information. name: Mark\nnationality: Italian\nlanguage: English\nattributes: creative, goal-oriented, motivated\nskills: software engineering, content marketing \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: I am a creative, goal-oriented, and motivated software engineer with a passion for content marketing. I am an Italian national with a strong command of the English language. I am highly skilled in software engineering and content marketing, and I am always looking for new ways to develop my skills and further my career. \n\n", "infer7b_before_item": " Create a brief resume introduction using the following information. name: Mark\nnationality: Italian\nlanguage: English\nattributes: creative, goal-oriented, motivated\nskills: software engineering, content marketing\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Mark is an Italian software engineer with a passion for content marketing. He is creative, goal-oriented, and motivated, with a strong background in software engineering and content marketing. \n\n"} {"id": 208, "instruction": "Make a list of adjectives that can be used to describe the given brand.", "input": "a creative tech startup", "infer30b_before_item": " Output: Make a list of adjectives that can be used to describe the given brand. a creative tech startup \n Explanation: Output: Make a list of adjectives that can be used to describe the given brand. a creative tech startup \n */\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Innovative, cutting-edge, forward-thinking, disruptive, revolutionary, pioneering, progressive, dynamic, creative, original, visionary, groundbreaking, transformative. \n\n", "infer13b_before_item": " Output: Make a list of adjectives that can be used to describe the given brand. a creative tech startup \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Innovative, creative, cutting-edge, forward-thinking, tech-savvy, progressive, dynamic, ambitious, visionary, pioneering, entrepreneurial. \n\n", "infer7b_before_item": " Output: Make a list of adjectives that can be used to describe the given brand. a creative tech startup \n\"\"\"\n\n\ndef get_adjectives(brand):\n \"\"\"\n :type brand: str\n :rtype: list\n \"\"\"\n adjectives = []\n for word in brand.split():\n if word in adjectives:\n adjectives.remove(word)\n else:\n adjectives.append(word)\n return adjectives\n\n\ndef main():\n \"\"\"\n :rtype: None\n \"\"\"\n brand = input(\"Input: \")\n adjectives = get_adjectives(brand)\n print(adjectives)\n\n\nif __name__ == \"__main__\":\n main()\n", "infer7b_after_item": " \n Output: Innovative, cutting-edge, dynamic, creative, forward-thinking, disruptive, revolutionary, visionary, ambitious, agile, adaptable, resourceful, collaborative, passionate, and entrepreneurial. \n\n"} {"id": 209, "instruction": "Someone gives you some information about where they want to go and what they enjoy seeing and doing. Describe a proper road trip for them and find the best stops and sctivities in the way.", "input": "I'm looking for a west coast road trip. My goal is to start near San Diego and travel to Los Angeles.", "infer30b_before_item": " Output: A list of places to stop and things to do along the way.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: For a west coast road trip from San Diego to Los Angeles, there are plenty of great stops and activities along the way. Start your journey in San Diego and make your way up the coast. Stop in Carlsbad to visit the beautiful Carlsbad Flower Fields and take a stroll along the beach. Then, head to San Clemente to explore the San Clemente State Beach and the San Onofre State Beach. Continue on to Laguna Beach and take a walk along the boardwalk, or take a surfing lesson. Next, stop in Newport Beach to explore the Newport Beach Pier and take a boat tour of the harbor. Finally, make your way to Los Angeles and explore the city. Visit the Hollywood Walk of Fame, take a tour of the Warner Brothers Studio, and take a stroll through the Santa Monica Pier. \n\n", "infer13b_before_item": " Output: A list of stops and activities that you think would be good for the person.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " I enjoy visiting beaches and exploring nature. \n Output: A proper road trip for you would start in San Diego and travel to Los Angeles. Along the way, you can stop at beaches like La Jolla, Carlsbad, and Coronado. You can also visit the San Diego Zoo and Balboa Park. In Los Angeles, you can visit the Getty Center, Griffith Observatory, and Santa Monica Pier. \n\n", "infer7b_before_item": " I want to find the best stops and activities along the way. I want to find the best places to stop and see and do things. I want to find the best places to eat and sleep. I want to find the best places to see and do things. I want to find the best places to eat and sleep. I want to find the best places to see and do things. I want to find the best places to eat and sleep. I want to find the best places to see and do things. I want to find the best places to eat and sleep. I want to find the best places to see and do things. I want to find the best places to eat and sleep. I want to find the best places to see and do things. I want to find the best places to eat and sleep. I want to find the best places to see and do things. I want to find the best places to eat and sleep. I want to find the best places to see and do things. I want to find the best places to eat and sleep. I want to find the best places to see and do things. I want to find the best places to eat and sleep. I want to find the best places to see and do things. I want to", "infer7b_after_item": " I enjoy seeing the ocean, hiking, and exploring new places. \n Output: A great road trip for the west coast would start in San Diego and take you to Los Angeles. Along the way, you can stop at the famous beaches of La Jolla, visit the famous Hollywood sign, and explore the beautiful canyons of Malibu. You can also take a day trip to the famous Joshua Tree National Park, or stop in Santa Barbara to explore the charming city. Along the way, you can also stop at the famous Hearst Castle, or take a day trip to the famous Yosemite National Park. \n\n"} {"id": 210, "instruction": "Regex is a set of characters that define a search pattern. This kind of pattern is usually used by string-searching algorithms to find or replace strings or to validate inputs. Convert the natural english text to regex.", "input": "Match a valid ip address", "infer30b_before_item": " Output: Regex is a set of characters that define a search pattern. This kind of pattern is usually used by string-searching algorithms to find or replace strings or to validate inputs. Convert the natural english text to regex. Match a valid ip address \n\n Example: \n\n Input: \n\n Output: \n\n Explanation: \n\n */\n\n#include \n#include \n#include \n\nint main() {\n char *input = \"1234567890\";\n char *output = \"\\\\d{10}\";\n printf(\"%s\\n\", output);\n return 0;\n}\n", "infer30b_after_item": ". \n Output: ^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$ \n\n", "infer13b_before_item": " Output: Regex is a set of characters that define a search pattern. This kind of pattern is usually used by string-searching algorithms to find or replace strings or to validate inputs. Convert the natural english text to regex. Match a valid ip address \n\n\nclass Solution:\n # @param {string} s\n # @return {string}\n def regex(self, s):\n s = s.replace(\" \", \"\")\n s = s.replace(\"(\", \"\")\n s = s.replace(\")\", \"\")\n s = s.replace(\"(\", \"\")\n s = s.replace(\")\", \"\")\n s = s.replace(\" \", \"\")\n s = s.replace(\"(\", \"\")\n s = s.replace(\")\", \"\")\n s = s.replace(\" \", \"\")\n s = s.replace(\"(\", \"\")\n s = s.replace(\")\", \"\")\n s = s.replace(\" \", \"\")\n s = s.replace(\"(\", \"\")\n s = s.replace(\")\", \"\")\n s = s.replace(\" \", \"\")\n s = s.replace(\"(\", \"\")\n s = s.replace(\")\", \"\")\n ", "infer13b_after_item": " \n Output: ^(?:(?!.*\\d+\\.\\d+\\.\\d+\\.\\d+).)*$ \n\n", "infer7b_before_item": " Match a valid ip address\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": ". 127.0.0.1 \n Output: ^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})+$ \n\n"} {"id": 211, "instruction": "Write an engaging and well-written property listing description for selling a house. Address of the house and some of the details are given to you. Fill in the information gap with hallucinations if needed.", "input": "Property Address: 412 Monterey Ave, Capitola, CA 95010\nParking: 3 cars + a finished single car garage\nDetails:\n- open floorplan\n- window with views to park/mountains\n- Kitchen with shaker cabinetry and white Calcatta quartz counters", "infer30b_before_item": "\n412 Monterey Ave, Capitola, CA 95010\nParking: 3 cars + a finished single car garage\nDetails:\n- open floorplan\n- window with views to park/mountains\n- Kitchen with shaker cabinetry and white Calcatta quartz counters\n# **Exercise 1.1**\nInput: Input: Write an engaging and well-written property listing description for selling a house. Address of the house and some of the details are given to you. Fill in the information gap with hallucinations if needed. Property Address: 412 Monterey Ave, Capitola, CA 95010\nParking: 3 cars + a finished single car garage\nDetails:\n- open floorplan\n- window with views to park/mountains\n- Kitchen with shaker cabinetry and white Calcatta quartz counters\n Output:\n412 Monterey Ave, Capitola, CA 95010\nParking: 3 cars + a finished single car garage\nDetails:\n- open floorplan\n- window", "infer30b_after_item": "\n- Master bedroom with walk-in closet and en-suite bathroom\n- Laundry room with storage \n Output: Welcome to 412 Monterey Ave, Capitola, CA 95010! This beautiful home is located in a quiet neighborhood and offers plenty of parking for up to 3 cars plus a finished single car garage. The open floorplan is perfect for entertaining, with a window that offers views to the park and mountains. The kitchen features shaker cabinetry and white Calcatta quartz counters, while the master bedroom has a walk-in closet and en-suite bathroom. The laundry room has storage, making it the perfect place to call home. \n\n", "infer13b_before_item": "\n- 3 bedrooms\n- 2 bathrooms\n- 1,500 sq. ft.\n- 1,000 sq. ft. lot\n- 1,000 sq. ft. garage\n- 1,000 sq. ft. deck\n- 1,000 sq. ft. basement\n- 1,000 sq. ft. attic\n- 1,000 sq. ft. crawlspace\n- 1,000 sq. ft. storage shed\n- 1,000 sq. ft. greenhouse\n- 1,000 sq. ft. pool\n- 1,000 sq. ft. hot tub\n- 1,000 sq. ft. sauna\n- 1,000 sq. ft. gym\n- 1,000 sq. ft. wine cellar\n- 1,000 sq. ft. home theater\n- 1,000 sq. ft. game room\n- 1,000 sq. ft. office\n- 1,000 sq", "infer13b_after_item": "\n- 3 bedrooms and 2 bathrooms \n Output: Welcome to 412 Monterey Ave, Capitola, CA 95010! This beautiful home offers a spacious open floorplan with plenty of natural light and views of the park and mountains. The kitchen is equipped with shaker cabinetry and white Calcatta quartz counters, perfect for entertaining. The master bedroom features an en-suite bathroom and walk-in closet. The other two bedrooms are also generously sized and share a full bathroom. The home also features a finished single car garage, perfect for storing your car or other belongings. This home is a must-see and is sure to impress! \n\n", "infer7b_before_item": "\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words\n- 1000 words", "infer7b_after_item": "\n- Master bedroom with walk-in closet and en-suite bathroom\n- 2 additional bedrooms\n- 2.5 bathrooms\n- 1,600 sq. ft. \n Output: 412 Monterey Ave, Capitola, CA 95010 is a stunning home with a perfect blend of modern and classic design. The open floorplan and large windows allow for plenty of natural light and views of the park and mountains. The kitchen features shaker cabinetry and white Calcatta quartz counters, while the master bedroom boasts a walk-in closet and en-suite bathroom. The 2.5 bathrooms and 1,600 sq. ft. of living space make this home perfect for any family. \n\n"} {"id": 212, "instruction": "Given a real estate listing description, extract the information and details of the property from the text. The details consist of address, basic house attributes, etc.", "input": "WALK TO THE BEACH FROM CAPITOLA KNOLLS! Single-level upstairs condo with your own large private deck overlooking nature. Adorable home that is move-in ready and waiting for you to put your own personal touches on. Gorgeous and well-maintained landscaped park-like setting with lush green grasses with a community pool and spa to enjoy. Desirable location...walk to Capitola Village, Gayle's Bakery, restaurants, shopping, schools or jump on Hwy 1 right around the corner.", "infer30b_before_item": " Output: A list of the details of the property.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Address: 1234 Capitola Knolls, Capitola, CA 95010\n\nProperty Type: Condo\n\nBedrooms: 2\n\nBathrooms: 1\n\nLiving Area: 1,000 sq ft\n\nDeck Size: Large\n\nParking: 1\n\nAmenities: Private Deck, Community Pool and Spa, Lush Green Grasses, Walk to Capitola Village, Gayle's Bakery, Restaurants, Shopping, Schools. \n\n", "infer13b_before_item": " Output: A list of the extracted information and details of the property.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n\nWords: 225\n\nLink: https://www.redfin.com/CA/Capitola/100-Cabrillo-Dr-902-980/home/14000000 \n Output: Address: 100 Cabrillo Dr 902, Capitola, CA 95010\n\nBasic House Attributes:\n- Single-level upstairs condo\n- Large private deck\n- Move-in ready\n- Adorable home\n- Gorgeous and well-maintained landscaped park-like setting\n- Community pool and spa\n- Desirable location\n- Walk to Capitola Village, Gayle's Bakery, restaurants, shopping, schools\n- Jump on Hwy 1 right around the corner\n\nPrice: $1,400,000\n\nLink: https://www.redfin.com/CA/Capitola/100-Cabrillo-Dr-902-980/home/14000000 \n\n", "infer7b_before_item": " Output: Given a real estate listing description, extract the information and details of the property from the text. The details consist of address, basic house attributes, etc. WALK TO THE BEACH FROM CAPITOLA KNOLLS! Single-level upstairs condo with your own large private deck overlooking nature. Adorable home that is move-in ready and waiting for you to put your own personal touches on. Gorgeous and well-maintained landscaped park-like setting with lush green grasses with a community pool and spa to enjoy. Desirable location...walk to Capitola Village, Gayle's Bakery, restaurants, shopping, schools or jump on Hwy 1 right around the corner. \n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"", "infer7b_after_item": " 1100 Capitola Knolls Drive, Capitola, CA 95010 831-476-1100 \n Output: Address: 1100 Capitola Knolls Drive, Capitola, CA 95010\nBasic House Attributes: Single-level upstairs condo with your own large private deck overlooking nature, Adorable home that is move-in ready and waiting for you to put your own personal touches on, Gorgeous and well-maintained landscaped park-like setting with lush green grasses with a community pool and spa to enjoy, Desirable location...walk to Capitola Village, Gayle's Bakery, restaurants, shopping, schools or jump on Hwy 1 right around the corner. \n\n"} {"id": 213, "instruction": "Review the property description and tell us what is good and what is bad about it and list its key takeaways.", "input": "There's real magic in combining inherently compelling Victorian architecture with a modern aesthetic. Add in an extraordinary multi-level garden & the result is the undeniable elegance of 444 29th St. The front of the home is light-filled w/ a seamless connection between living, dining & kitchen. Newly updated kitchen w/ quartz counters & upgraded appliances. A lg dining rm has a bay of windows &, when paired w/ the adjacent living rm, provides an ideal space to entertain. 2 lg bdrms on this level are at the rear. Both w/ lg closets & walk out to the garden. Stylishly remodeled full bath on this level. 3rd bdrm/2nd full bath are located on the ground floor - perfect as a guest rm, home office, fitness area, etc. The enormous garden occupies an extra deep lot & is beautifully landscaped & terraced. Laundry/storage rm, 1-car garage pkg, Tesla solar panels. Prime, flat part of Noe Valley - short walk to all that Noe has to offer. Steps from the J-Church & convenient to shuttles/freeways.", "infer30b_before_item": "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: The property at 444 29th St. is a great combination of Victorian architecture and modern aesthetic. The front of the home is light-filled and has a seamless connection between living, dining and kitchen. The kitchen has been recently updated with quartz counters and upgraded appliances. The large dining room has a bay of windows and when paired with the adjacent living room, provides an ideal space to entertain. The two large bedrooms on this level have large closets and walk out to the garden. The third bedroom/second full bath is located on the ground floor and is perfect as a guest room, home office, fitness area, etc. The enormous garden occupies an extra deep lot and is beautifully landscaped and terraced. Laundry/storage room, 1-car garage parking, and Tesla solar panels are also included. The property is located in a prime, flat part of Noe Valley and is a short walk to all that Noe has to offer. It is also steps from the J-Church and convenient to shuttles and freeways. \n\n", "infer13b_before_item": " Output: Review the property description and tell us what is good and what is bad about it and list its key takeaways. There's real magic in combining inherently compelling Victorian architecture with a modern aesthetic. Add in an extraordinary multi-level garden & the result is the undeniable elegance of 444 29th St. The front of the home is light-filled w/ a seamless connection between living, dining & kitchen. Newly updated kitchen w/ quartz counters & upgraded appliances. A lg dining rm has a bay of windows &, when paired w/ the adjacent living rm, provides an ideal space to entertain. 2 lg bdrms on this level are at the rear. Both w/ lg closets & walk out to the garden. Stylishly remodeled full bath on this level. 3rd bdrm/2nd full bath are located on the ground floor - perfect as a guest rm, home office, fitness area, etc. The enormous garden occupies an extra deep lot & is beautifully landscaped & terraced. Laundry/storage rm, 1-car", "infer13b_after_item": " \n\n Output: Good:\n- Victorian architecture\n- Multi-level garden\n- Light-filled living, dining and kitchen\n- Updated kitchen with quartz counters and upgraded appliances\n- Dining room with bay of windows\n- Living room with adjacent dining room for entertaining\n- Two large bedrooms with large closets and windows\n- Two full bathrooms\n- Stylishly remodeled full bathroom\n- Laundry and storage room\n- One-car garage parking\n- Tesla solar panels\n\nBad:\n- Flat part of Noe Valley\n- Short walk to all that Noe has to offer\n- Convenient to shuttles and freeways \n\nKey Takeaways:\n- Victorian architecture with modern aesthetic\n- Multi-level garden\n- Light-filled living, dining and kitchen\n- Updated kitchen with quartz counters and upgraded appliances\n- Dining room with bay of windows\n- Living room with adjacent dining room for entertaining\n- Two large bedrooms with large closets and windows\n- Two full bathrooms\n- Stylishly remode", "infer7b_before_item": " Output: List the property's key selling points and tell us what you think the property's best features are. The garden is the property's best feature. It's a rare find in Noe Valley. The garden is a perfect place to entertain, relax, or just enjoy the outdoors. The garden is a perfect place to entertain, relax, or just enjoy the outdoors. The garden is a perfect place to entertain, relax, or just enjoy the outdoors. The garden is a perfect place to entertain, relax, or just enjoy the outdoors. The garden is a perfect place to entertain, relax, or just enjoy the outdoors. The garden is a perfect place to entertain, relax, or just enjoy the outdoors. The garden is a perfect place to entertain, relax, or just enjoy the outdoors. The garden is a perfect place to entertain, relax, or just enjoy the outdoors. The garden is a perfect place to entertain, relax, or just enjoy the outdoors. The garden is a perfect place to entertain, relax, or just enjoy the outdoors. The garden is a perfect place to entertain, relax, or just enjoy the outdoors. The", "infer7b_after_item": " \n\nKey Takeaways:\n- Victorian architecture w/ modern aesthetic\n- Light-filled living spaces\n- Updated kitchen w/ quartz counters & upgraded appliances\n- Lg dining rm w/ bay of windows\n- Perfect for entertaining\n- 2 lg bdrms w/ lg closets & walk out to garden\n- Stylishly remodeled full bath\n- 3rd bdrm/2nd full bath\n- Prime, flat part of Noe Valley\n- Short walk to all that Noe has to offer\n- Steps from the J-Church & convenient to shuttles/freeways\n- 444 29th St. - real magic in combining inherently compelling Victorian architecture with a modern aesthetic. \n Output: 444 29th St. is a stunning Victorian home with a modern aesthetic. The front of the home is light-filled and seamlessly connects the living, dining, and kitchen areas. The kitchen has been updated with quartz counters and upgraded appliances. The dining room has"} {"id": 214, "instruction": "List some of the top real estate marketing words to add value to the listing and engage more potential buyers.", "input": "", "infer30b_before_item": " Output: List some of the top real estate marketing words to add value to the listing and engage more potential buyers.\nInput: Input: List some of the top real estate marketing words to add value to the listing and engage more potential buyers. \n Output: Output: List some of the top real estate marketing words to add value to the listing and engage more potential buyers.\nInput: Input: List some of the top real estate marketing words to add value to the listing and engage more potential buyers. \n Output: Output: List some of the top real estate marketing words to add value to the listing and engage more potential buyers.\nInput: Input: List some of the top real estate marketing words to add value to the listing and engage more potential buyers. \n Output: Output: List some of the top real estate marketing words to add value to the listing and engage more potential buyers.\nInput: Input: List some of the top real estate marketing words to add value to the listing and engage more potential buyers. \n Output: Output: List some of the top real estate marketing words to add value to the listing and eng", "infer30b_after_item": "\n Output: Some of the top real estate marketing words to add value to the listing and engage more potential buyers include: luxurious, spacious, modern, convenient, charming, beautiful, private, gorgeous, stunning, and unique. \n\n", "infer13b_before_item": " Output: List some of the top real estate marketing words to add value to the listing and engage more potential buyers. \n**Note:** The output is the same as the input.\nExplanation:\nThe output is the same as the input because the input is a list of words, and the output is a list of words.\n##### **Question 11**\nInput: Input: The following is a list of words that are used in the English language. \nOutput: Output: The following is a list of words that are used in the English language. \n**Note:** The output is the same as the input.\nExplanation:\nThe output is the same as the input because the input is a list of words, and the output is a list of words.\n##### **Question 12**\nInput: Input: The following is a list of words that are used in the English language. \nOutput: Output: The following is a list of words that are used in the English language. \n**Note:** The output is the same as the input.\nExplanation:\nThe output is the same as the input because the input is a list of", "infer13b_after_item": "\n Output: Luxurious, spacious, modern, stylish, high-end, unique, comfortable, inviting, energy-efficient, eco-friendly, and well-maintained. \n\n", "infer7b_before_item": " Output: List some of the top real estate marketing words to add value to the listing and engage more potential buyers.\nInput: Input: List some of the top real estate marketing words to add value to the listing and engage more potential buyers. \n Output: Output: List some of the top real estate marketing words to add value to the listing and engage more potential buyers.\nInput: Input: List some of the top real estate marketing words to add value to the listing and engage more potential buyers. \n Output: Output: List some of the top real estate marketing words to add value to the listing and engage more potential buyers.\nInput: Input: List some of the top real estate marketing words to add value to the listing and engage more potential buyers. \n Output: Output: List some of the top real estate marketing words to add value to the listing and engage more potential buyers.\nInput: Input: List some of the top real estate marketing words to add value to the listing and engage more potential buyers. \n Output: Output: List some of the top real estate marketing words to add value to the listing and eng", "infer7b_after_item": "\n Output: Some of the top real estate marketing words to add value to the listing and engage more potential buyers include: luxury, modern, spacious, open concept, and move-in ready. \n\n"} {"id": 215, "instruction": "Suggest some product bundles that are often purchased with a given product.", "input": "MacBook Air", "infer30b_before_item": " Output: Suggest some product bundles that are often purchased with a given product. MacBook Air \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", "infer30b_after_item": " \n Output: Product bundles that are often purchased with a MacBook Air include a laptop case, a laptop stand, a laptop cooling pad, a laptop charger, a laptop mouse, and a laptop keyboard. \n\n", "infer13b_before_item": " Output: Suggest some product bundles that are often purchased with a given product. MacBook Air \n\nclass Solution {\n public int[] productBundle(int[] productBundle) {\n int[] res = new int[productBundle.length];\n for(int i = 0; i < productBundle.length; i++) {\n int count = 0;\n for(int j = 0; j < productBundle.length; j++) {\n if(productBundle[i] == productBundle[j]) {\n count++;\n }\n }\n res[i] = count;\n }\n return res;\n }\n}\n", "infer13b_after_item": " \n Output: MacBook Air is often purchased with a laptop bag, a wireless mouse, a wireless keyboard, and a laptop stand. \n\n", "infer7b_before_item": " Output: Suggest some product bundles that are often purchased with a given product. MacBook Air \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Product bundles that are often purchased with a MacBook Air include a protective case, a charger, a mouse, a keyboard, a laptop bag, a laptop stand, a laptop sleeve, a laptop cooling pad, a laptop cooling fan, a laptop cooling mat, a laptop cooling pad, a laptop cooling fan, a laptop cooling mat, a laptop cooling pad, a laptop cooling fan, a laptop cooling mat, a laptop cooling pad, a laptop cooling fan, a laptop cooling mat, a laptop cooling pad, a laptop cooling fan, a laptop cooling mat, a laptop cooling pad, a laptop cooling fan, a laptop cooling mat, a laptop cooling pad, a laptop cooling fan, a laptop cooling mat, a laptop cooling pad, a laptop cooling fan, a laptop cooling mat, a laptop cooling pad, a laptop cooling fan, a laptop cooling mat, a laptop cooling pad, a laptop cooling fan, a laptop cooling mat, a laptop cooling pad, a laptop cooling fan, a laptop cooling mat, a laptop cooling pad, a laptop cooling fan,"} {"id": 216, "instruction": "Create a template in markdown to create scope for Jira tickets. Members should use this template as a checklist to ensure they have included all the necessary information when creating a ticket.", "input": "", "infer30b_before_item": " Output: Create a template in markdown to create scope for Jira tickets. Members should use this template as a checklist to ensure they have included all the necessary information when creating a ticket.\n# 1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.", "infer30b_after_item": "\n Output: # Scope for Jira Tickets\n\nThis template should be used as a checklist to ensure all the necessary information is included when creating a Jira ticket.\n\n### Requirements\n\n- Title: Provide a clear and concise title that summarizes the issue.\n- Description: Provide a detailed description of the issue, including any relevant background information.\n- Priority: Assign a priority level to the ticket (e.g. Low, Medium, High, Urgent).\n- Component: Assign the ticket to the appropriate component (e.g. Bug, Feature, Improvement).\n- Assignee: Assign the ticket to the appropriate person or team.\n- Labels: Add relevant labels to the ticket.\n- Estimate: Estimate the amount of time it will take to resolve the issue.\n- Blockers: List any blockers that may prevent the ticket from being resolved.\n- Dependencies: List any dependencies that may affect the resolution of the ticket.\n- Related Issues: List any related issues that may be affected by the resolution of this ticket.\n- Attachments: Attach any relevant files or documents.", "infer13b_before_item": " Output: A markdown template that can be used to create scope for Jira tickets.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: # Template for Jira Ticket\n\n[Title]: A brief description of the issue\n\n[Assignee]: The person who is responsible for resolving the issue\n\n[Priority]: The priority of the issue (High, Medium, Low)\n\n[Severity]: The severity of the issue (Critical, Major, Minor, Trivial)\n\n[Summary]: A brief description of the issue\n\n[Description]: A detailed description of the issue\n\n[Steps to Reproduce]: Instructions on how to reproduce the issue\n\n[Actual Result]: The result of the issue\n\n[Expected Result]: The desired result of the issue \n\n", "infer7b_before_item": " Create a template in markdown to create scope for Jira tickets. Members should use this template as a checklist to ensure they have included all the necessary information when creating a ticket.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": "\n Output: ## Checklist for Creating Jira Tickets\n\n- Title: Provide a descriptive title for the ticket.\n- Description: Provide a detailed description of the issue.\n- Assignee: Assign the ticket to a specific user.\n- Priority: Assign the ticket to a priority level.\n- Resolution: Assign the ticket to a resolution level.\n- Status: Assign the ticket to a status level.\n- Type: Assign the ticket to a type.\n- Sub-tasks: Add any sub-tasks that are needed.\n- Custom Fields: Add any custom fields that are needed.\n- Attachments: Add any attachments that are needed.\n- Comments: Add any comments that are needed.\n- Resolution: Add any resolutions that are needed.\n- Resolution Comments: Add any resolution comments that are needed.\n- Resolution Comments: Add any resolution comments that are needed.\n- Resolution Comments: Add any resolution comments that are needed.\n- Resolution Comments: Add any resolution comments that are needed.\n- Resolution Comments: Add any resolution comments that are needed.\n- Resolution"} {"id": 217, "instruction": "As part of software engineering, user stories describe what the user wants the system to do, while acceptance criteria describe the conditions a specific user story must meet. Create basic acceptance criteria based on the given user story.", "input": "User story: As a user, I want to use a search field to type a city, name, or street, so that I could find matching hotel options.", "infer30b_before_item": " Output: As a user, I want to use a search field to type a city, name, or street, so that I could find matching hotel options.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Acceptance Criteria:\n1. The search field should accept city, name, or street as input.\n2. The search field should return matching hotel options when the input is valid.\n3. The search field should not return any results when the input is invalid. \n\n", "infer13b_before_item": " Output: As part of software engineering, user stories describe what the user wants the system to do, while acceptance criteria describe the conditions a specific user story must meet. Create basic acceptance criteria based on the given user story. User story: As a user, I want to use a search field to type a city, name, or street, so that I could find matching hotel options. \n Input: Input: As part of software engineering, user stories describe what the user wants the system to do, while acceptance criteria describe the conditions a specific user story must meet. Create basic acceptance criteria based on the given user story. User story: As a user, I want to use a search field to type a city, name, or street, so that I could find matching hotel options. \n Output: Output: As part of software engineering, user stories describe what the user wants the system to do, while acceptance criteria describe the conditions a specific user story must meet. Create basic acceptance criteria based on the given user story. User story: As a user, I want to use a search field to type a city, name, or street, so that I could find matching hotel options. \n Input: Input: As part of software engineering", "infer13b_after_item": " \n Output: Acceptance criteria: \n1. The search field should be able to accept city, name, and street as input. \n2. The search should return matching hotel options. \n3. The search should be case-insensitive. \n4. The search should be able to filter results by price range. \n5. The search should be able to filter results by star rating. \n\n", "infer7b_before_item": " Output: As part of software engineering, user stories describe what the user wants the system to do, while acceptance criteria describe the conditions a specific user story must meet. Create basic acceptance criteria based on the given user story. User story: As a user, I want to use a search field to type a city, name, or street, so that I could find matching hotel options. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Acceptance criteria for the given user story:\n- The search field should be able to accept a city, name, or street.\n- The search field should be able to return matching hotel options.\n- The search field should be able to filter the hotel options based on the city, name, or street.\n- The search field should be able to display the hotel options in a list.\n- The search field should be able to display the hotel options in a map.\n- The search field should be able to display the hotel options in a timeline.\n- The search field should be able to display the hotel options in a calendar.\n- The search field should be able to display the hotel options in a map with a timeline.\n- The search field should be able to display the hotel options in a calendar with a timeline.\n- The search field should be able to display the hotel options in a map with a timeline and a calendar. \n\n"} {"id": 218, "instruction": "A user story is an informal, general explanation of a software feature written from the perspective of the end user or customer. Write a user story for a given software.", "input": "Gmail", "infer30b_before_item": " Output: A user story is an informal, general explanation of a software feature written from the perspective of the end user or customer. Write a user story for a given software. Gmail\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: As a user, I want to be able to search for emails in Gmail so that I can quickly find the information I need. \n\n", "infer13b_before_item": " Output: A user story is an informal, general explanation of a software feature written from the perspective of the end user or customer. Write a user story for a given software. Gmail \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: As a Gmail user, I want to be able to quickly search for emails from a specific sender so that I can quickly find the information I need. \n\n", "infer7b_before_item": " Output: A user story is an informal, general explanation of a software feature written from the perspective of the end user or customer. Write a user story for a given software. Gmail \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: As a Gmail user, I want to be able to quickly search for emails in my inbox. \n\n"} {"id": 219, "instruction": "Write a Jira ticket for the given task.", "input": "New Employee onboarding", "infer30b_before_item": " Output: Write a Jira ticket for the given task. New Employee onboarding \n \n \n Input: Input: Write a Jira ticket for the given task. New Employee onboarding \n Output: Output: Write a Jira ticket for the given task. New Employee onboarding \n \n \n Input: Input: Write a Jira ticket for the given task. New Employee onboarding \n Output: Output: Write a Jira ticket for the given task. New Employee onboarding \n \n \n Input: Input: Write a Jira ticket for the given task. New Employee onboarding \n Output: Output: Write a Jira ticket for the given task. New Employee onboarding \n \n \n Input: Input: Write a Jira ticket for the given task. New Employee onboarding \n Output: Output: Write a Jira ticket for the given task. New Employee onboarding \n \n \n Input: Input: Write a Jira ticket for the given task. New Employee onboarding \n Output: Output: Write a Jira ticket for the given task. New Employee onboarding \n \n \n Input: Input", "infer30b_after_item": " process needs to be updated. \n Output: Create a Jira ticket for the task \"Update New Employee Onboarding Process\". \n\n", "infer13b_before_item": " Output: Write a Jira ticket for the given task. New Employee onboarding \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: JIRA-TICKET-123: New Employee Onboarding \n\n", "infer7b_before_item": " Output: Write a Jira ticket for the given task. New Employee onboarding\n\n\"\"\"\n\nimport sys\nimport os\nimport time\nimport datetime\nimport random\nimport re\nimport string\nimport json\nimport requests\nimport requests_cache\nimport requests_cache.backends.base\nimport requests_cache.backends.file\nimport requests_cache.backends.memory\nimport requests_cache.backends.redis\nimport requests_cache.backends.sqlalchemy\nimport requests_cache.backends.sqlite\nimport requests_cache.backends.sqlite3\nimport requests_cache.backends.sqlite3_file\nimport requests_cache.backends.sqlite3_memory\nimport requests_cache.backends.sqlite3_redis\nimport requests_cache.backends.sqlite3_sqlalchemy\nimport requests_cache.backends.sqlite3_sqlite3\nimport requests_cache.backends.sqlite3_sqlite3_file\nimport requests_cache.backends.sqlite3_sqlite3_memory\nimport requests_cache.backends.sqlite3_sqlite3_redis\nimport requests_cache.backends", "infer7b_after_item": " \n Output: Issue: New Employee Onboarding\n\nDescription:\nWe need to create a process for onboarding new employees. This process should include providing them with the necessary resources and training to get them up to speed with the company's policies and procedures.\n\nResolution:\nWe need to create a process for onboarding new employees. This process should include providing them with the necessary resources and training to get them up to speed with the company's policies and procedures.\n\nStatus:\nOpen\n\nUser:\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"} {"id": 220, "instruction": "Paraphrase the given text in an academic style.", "input": "Lots of papers have been published on this topic.", "infer30b_before_item": " Output: Paraphrase the given text in an academic style. Many papers have been published on this topic.\nInput: Input: Paraphrase the given text in an academic style. The results of the study are very interesting.\n Output: Output: Paraphrase the given text in an academic style. The findings of the study are very interesting.\nInput: Input: Paraphrase the given text in an academic style. The results of the study are very interesting.\n Output: Output: Paraphrase the given text in an academic style. The findings of the study are very interesting.\nInput: Input: Paraphrase the given text in an academic style. The results of the study are very interesting.\n Output: Output: Paraphrase the given text in an academic style. The findings of the study are very interesting.\nInput: Input: Paraphrase the given text in an academic style. The results of the study are very interesting.\n Output: Output: Paraphrase the given text in an academic style. The findings of the study are very interesting.\nInput: Input: Paraphrase the given text in an academic style. The results of the", "infer30b_after_item": " \n Output: Numerous papers have been published on this subject. \n\n", "infer13b_before_item": " Output: Paraphrase the given text in an academic style. Lots of papers have been published on this topic.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: A considerable number of papers have been written on this subject. \n\n", "infer7b_before_item": " Output: Paraphrase the given text in an academic style. Lots of papers have been published on this topic.\n\\end{code}\n\nComment: I'm not sure what you mean by \"academic style\". Do you mean \"formal\" or \"literary\"?\n\nComment: @MatthewLeingang I mean formal.\n\nComment: @MatthewLeingang I've added an example.\n\nComment: @MatthewLeingang I've added an example.\n\nComment: @MatthewLeingang I've added an example.\n\nComment: @MatthewLeingang I've added an example.\n\nComment: @MatthewLeingang I've added an example.\n\nComment: @MatthewLeingang I've added an example.\n\nComment: @MatthewLeingang I've added an example.\n\nComment: @MatthewLeingang I've added an example.\n\nComment: @MatthewLeingang I've added an example.\n\nComment: @MatthewLeingang I've added an example", "infer7b_after_item": " \n Output: A significant number of studies have been conducted on this subject. \n\n"} {"id": 221, "instruction": "Make a list of the pros and cons of the given decision.", "input": "Implementing a Remote Working Policy", "infer30b_before_item": " Output: Make a list of the pros and cons of the given decision. Implementing a Remote Working Policy \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n ", "infer30b_after_item": " \n Output: Pros: \n- Increased productivity \n- Reduced overhead costs \n- Improved morale \n- Increased flexibility \n- Improved work-life balance \n\nCons: \n- Difficulty in monitoring performance \n- Potential for decreased collaboration \n- Difficulty in maintaining a healthy work culture \n- Potential for increased distractions \n- Potential for decreased communication \n\n", "infer13b_before_item": " Output: Make a list of the pros and cons of the given decision. Implementing a Remote Working Policy \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Pros:\n- Increased productivity and efficiency\n- Reduced overhead costs\n- Improved work-life balance\n- Increased employee satisfaction\n\nCons:\n- Increased risk of security breaches\n- Difficulty in managing remote teams\n- Difficulty in maintaining communication\n- Difficulty in managing remote teams\n- Difficulty in managing remote teams\n- Difficulty in managing remote teams \n\n", "infer7b_before_item": " Output: Make a list of the pros and cons of the given decision. Implementing a Remote Working Policy \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: Pros:\n- Increased productivity and efficiency\n- Reduced overhead costs\n- Increased employee satisfaction\n- Improved work-life balance\n\nCons:\n- Potential for increased distractions\n- Increased security risks\n- Potential for decreased collaboration\n- Potential for decreased morale \n\n"} {"id": 222, "instruction": "Include important study notes and key points that someone should know about the given subject.", "input": "history of the USA", "infer30b_before_item": " Output: Include important study notes and key points that someone should know about the given subject. history of the USA \n \n Input: Input: Include important study notes and key points that someone should know about the given subject. history of the USA \n Output: Output: Include important study notes and key points that someone should know about the given subject. history of the USA \n \n Input: Input: Include important study notes and key points that someone should know about the given subject. history of the USA \n Output: Output: Include important study notes and key points that someone should know about the given subject. history of the USA \n \n Input: Input: Include important study notes and key points that someone should know about the given subject. history of the USA \n Output: Output: Include important study notes and key points that someone should know about the given subject. history of the USA \n \n Input: Input: Include important study notes and key points that someone should know about the given subject. history of the USA \n Output: Output: Include important study notes and key points that someone should know about the given subject. history of the USA \n \n Input: Input: In", "infer30b_after_item": " \n Output: Important Study Notes and Key Points about the History of the USA:\n\n- The United States of America was founded in 1776 with the Declaration of Independence.\n\n- The American Revolutionary War (1775-1783) was fought between the colonies and Great Britain.\n\n- The Constitution of the United States was ratified in 1788, establishing the federal government and its three branches.\n\n- The Louisiana Purchase of 1803 doubled the size of the United States.\n\n- The War of 1812 was fought between the United States and Great Britain.\n\n- The Mexican-American War (1846-1848) resulted in the United States gaining large swaths of land in the Southwest.\n\n- The American Civil War (1861-1865) was fought between the Union and the Confederacy.\n\n- The Reconstruction Era (1865-1877) was a period of rebuilding and reorganization in the South after the Civil War.\n\n- The Industrial Revolution (18", "infer13b_before_item": " Output: Include important study notes and key points that someone should know about the given subject. history of the USA \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: The history of the United States began with the arrival of European settlers during the early 1600s. The colonies eventually declared independence from Great Britain in 1776, and the United States was officially formed in 1789. The US has since grown to become a global superpower, with a strong economy and a powerful military. \n\n", "infer7b_before_item": " Output: Include important study notes and key points that someone should know about the given subject. history of the USA \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: - The United States of America was founded in 1776 and is a federal republic composed of 50 states and a federal district.\n- The US Constitution was adopted in 1787 and is the supreme law of the land.\n- The US has a two-party system, with the Democratic and Republican parties dominating the political landscape.\n- The US has a strong economy, with a GDP of over $20 trillion.\n- The US is a major military power, with a large and powerful military.\n- The US is a major global power, with a strong presence in international affairs.\n- The US has a diverse population, with over 325 million people.\n- The US has a large and diverse culture, with influences from many different countries and cultures.\n- The US has a large and diverse geography, with a wide range of climates and landscapes. \n\n"} {"id": 223, "instruction": "Based on the given keywords, write a review of a restaurant.", "input": "Name: Pizzeria\ngood prices, quiet place, tasty, nice staff", "infer30b_before_item": "\n\nInput: Input: Based on the given keywords, write a review of a restaurant. Name: Pizzeria\ngood prices, quiet place, tasty, nice staff \n Output:\n\nInput: Input: Based on the given keywords, write a review of a restaurant. Name: Pizzeria\ngood prices, quiet place, tasty, nice staff \n Output:\n\nInput: Input: Based on the given keywords, write a review of a restaurant. Name: Pizzeria\ngood prices, quiet place, tasty, nice staff \n Output:\n\nInput: Input: Based on the given keywords, write a review of a restaurant. Name: Pizzeria\ngood prices, quiet place, tasty, nice staff \n Output:\n\nInput: Input: Based on the given keywords, write a review of a restaurant. Name: Pizzeria\ngood prices, quiet place, tasty, nice staff \n Output:\n\nInput: Input: Based on the given keywords, write a review of a restaurant. Name: Pizzeria\ngood prices, quiet place, tasty, nice staff \n Output:\n\nInput:", "infer30b_after_item": " \n Output: Pizzeria is a great place to go if you're looking for a quiet, cozy atmosphere and tasty food at good prices. The staff are friendly and attentive, making sure you have a great experience. The pizzas are delicious and the prices are very reasonable. Highly recommended! \n\n", "infer13b_before_item": " Output: Based on the given keywords, write a review of a restaurant. Name: Pizzeria\ngood prices, quiet place, tasty, nice staff \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Pizzeria is a great place to eat. The prices are very reasonable and the food is delicious. The atmosphere is quiet and relaxed, making it a great place to enjoy a meal with friends or family. The staff are friendly and attentive, making sure that every customer is satisfied with their meal. Overall, Pizzeria is a great place to eat and I highly recommend it. \n\n", "infer7b_before_item": " Output: Based on the given keywords, write a review of a restaurant. Name: Pizzeria\ngood prices, quiet place, tasty, nice staff\n\n\n# Your code goes here!\n\n\n# pizzeria = \"good prices, quiet place, tasty, nice staff\"\n# pizzeria = \"good prices, quiet place, tasty, nice staff\"\n\n\n# def review(pizzeria):\n# pizzeria = pizzeria.split()\n# pizzeria = pizzeria.split()\n# pizzeria = pizzeria.split()\n# pizzeria = pizzeria.split()\n# pizzeria = pizzeria.split()\n# pizzeria = pizzeria.split()\n# pizzeria = pizzeria.split()\n# pizzeria = pizzeria.split()\n# pizzeria = pizzeria.split()\n# pizzeria = pizzeria.split()\n# pizzeria", "infer7b_after_item": " \n Output: I recently visited Pizzeria and was pleasantly surprised by the good prices, quiet atmosphere, and tasty pizzas. The staff was friendly and attentive, making sure that my experience was a pleasant one. I would definitely recommend this place to anyone looking for a nice, quiet place to enjoy a meal. \n\n"} {"id": 224, "instruction": "Convert natural language into a list of turn-by-turn directions.", "input": "Go west on I-10 until you hit the 101 then take it north. You will eventually see the Hollywood sign.", "infer30b_before_item": " Output: Convert a list of turn-by-turn directions into natural language. Go west on I-10 until you hit the 101 then take it north. You will eventually see the Hollywood sign. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: 1. Head west on I-10.\n2. Take the 101 north.\n3. Continue driving until you see the Hollywood sign. \n\n", "infer13b_before_item": " Output: A list of turn-by-turn directions. Go west on I-10 until you hit the 101 then take it north. You will eventually see the Hollywood sign.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: [Step 1: Go west on I-10 until you hit the 101.\nStep 2: Take the 101 north.\nStep 3: Eventually you will see the Hollywood sign.] \n\n", "infer7b_before_item": " Output: Convert a list of turn-by-turn directions into natural language. Go west on I-10 until you hit the 101 then take it north. You will eventually see the Hollywood sign.\n\"\"\"\n\nimport re\n\n\ndef get_turn_by_turn(turn_by_turn):\n \"\"\"\n Convert a list of turn-by-turn directions into natural language.\n \"\"\"\n # Convert the turn-by-turn directions into a list of tuples.\n turn_by_turn_tuples = [\n (re.sub(r'(\\d+)', r'\\1', turn_by_turn), turn_by_turn)\n for turn_by_turn in turn_by_turn\n ]\n\n # Convert the list of tuples into a list of strings.\n turn_by_turn_strings = [\n ''.join(turn_by_turn_tuple)\n for turn_by_turn_tuple in turn_by_turn_tuples\n ]\n\n # Convert the list of strings into a list of sentences.\n turn_by_turn_sentences =", "infer7b_after_item": " \n Output: Go west on I-10 until you hit the 101 then take it north. Turn left onto Vine Street and then right onto Hollywood Boulevard. You will eventually see the Hollywood sign. \n\n"} {"id": 225, "instruction": "Provide an ESRB rating for the following game.", "input": "This is an action-adventure game in which players help Kratos and his son on a dangerous quest. Players explore various realms and engage in frenetic hand-to-hand combat against human-like raiders and fantastical creatures (e.g., centaurs, trolls, dragons). Players use axes and chained blades to battle enemies, often resulting in large blood-splatter effects and dismemberment. Players can perform finishing attacks that depict close-up impalement via bladed and hand-held weapons; repeated axe strikes to a creature's neck results in decapitation. The words \u201cf**k\u201d and \u201csh*t\u201d are heard in the game.", "infer30b_before_item": " Mature 17+\nInput: Input: Provide an ESRB rating for the following game. This is a first-person shooter in which players assume the role of a soldier battling an alien invasion. Players use pistols, machine guns, and futuristic weapons (e.g., lasers, grenade launchers) to kill human-like aliens and robots. Battles are frenetic and highlighted by realistic gunfire, large explosions, and cries of pain. Some attacks result in dismemberment and/or blood-splatter effects. The game includes the ability to use drugs to enhance performance in combat (e.g., cocaine, morphine, adrenaline). The words \u201cf**k\u201d and \u201csh*t\u201d are heard in the game. \n Output: Mature 17+\nInput: Input: Provide an ESRB rating for the following game. This is a first-person shooter in which players assume the role of a soldier battling an alien invasion. Players use pistols, machine guns, and futuristic weapons (e.g., lasers, grenade", "infer30b_after_item": " \n Output: Mature (17+) \n\n", "infer13b_before_item": " Output: Provide an ESRB rating for the following game. This is an action-adventure game in which players help Kratos and his son on a dangerous quest. Players explore various realms and engage in frenetic hand-to-hand combat against human-like raiders and fantastical creatures (e.g., centaurs, trolls, dragons). Players use axes and chained blades to battle enemies, often resulting in large blood-splatter effects and dismemberment. Players can perform finishing attacks that depict close-up impalement via bladed and hand-held weapons; repeated axe strikes to a creature's neck results in decapitation. The words \u201cf**k\u201d and \u201csh*t\u201d are heard in the game. \n\n\"\"\"\n\nimport re\n\n\ndef get_rating(input_string):\n rating = \"\"\n for line in input_string.split(\"\\n\"):\n if re.search(\"Input:\", line):\n rating = \"E\"\n elif re.search(\"Output:\", line):\n rating = \"T\"\n else:\n ", "infer13b_after_item": " \n Output: This game is rated M for Mature by the ESRB for Blood and Gore, Intense Violence, Language, and Suggestive Themes. \n\n", "infer7b_before_item": " Provide an ESRB rating for the following game. This is an action-adventure game in which players help Kratos and his son on a dangerous quest. Players explore various realms and engage in frenetic hand-to-hand combat against human-like raiders and fantastical creatures (e.g., centaurs, trolls, dragons). Players use axes and chained blades to battle enemies, often resulting in large blood-splatter effects and dismemberment. Players can perform finishing attacks that depict close-up impalement via bladed and hand-held weapons; repeated axe strikes to a creature's neck results in decapitation. The words \u201cf**k\u201d and \u201csh*t\u201d are heard in the game. \n\n### 2018\n\nInput: Input: Provide an ESRB rating for the following game. This is an action-adventure game in which players help Kratos and his son on a dangerous quest. Players explore various realms and engage in frenetic hand-to-hand combat against human-like raiders and fantastical creatures (e.", "infer7b_after_item": " \n Output: Mature 17+ \n\n"} {"id": 226, "instruction": "A color description has been provided. Find the CSS code associated with that color.", "input": "A light red color with a medium light shade of pink", "infer30b_before_item": " Output: The CSS code associated with the color description.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": ". \n Output: The CSS code associated with this color is #FFB6B6. \n\n", "infer13b_before_item": " Output: The CSS code associated with that color. #FF00FF \n\n\nclass Solution:\n # @param {string} color\n # @return {string}\n def colorToCSS(self, color):\n color = color.replace(\" \", \"\")\n color = color.replace(\"(\", \"\")\n color = color.replace(\")\", \"\")\n color = color.replace(\"(\", \"\")\n color = color.replace(\")\", \"\")\n color = color.replace(\"(\", \"\")\n color = color.replace(\")\", \"\")\n color = color.replace(\"(\", \"\")\n color = color.replace(\")\", \"\")\n color = color.replace(\"(\", \"\")\n color = color.replace(\")\", \"\")\n color = color.replace(\"(\", \"\")\n color = color.replace(\")\", \"\")\n color = color.replace(\"(\", \"\")\n color = color.replace(\")\", \"\")\n color = color.replace(\"(\", \"\")\n color = color.replace(\")\", \"\")\n color = color.replace(\"(\", \"\")\n color = color.replace(\")\", \"\")\n color = color.replace(\"(\", \"\")\n color = color.", "infer13b_after_item": " \n Output: #FFF8C0 \n\n", "infer7b_before_item": " A CSS code has been provided. Find the color description associated with that color. A light red color with a medium light shade of pink \n\"\"\"\n\n\ndef get_color(color):\n \"\"\"\n Given a color description, return the CSS code associated with that color.\n \"\"\"\n if color == \"light red\":\n return \"rgb(255, 102, 0)\"\n elif color == \"medium light pink\":\n return \"rgb(255, 182, 203)\"\n else:\n return \"rgb(255, 102, 0)\"\n\n\ndef get_color_from_css(css):\n \"\"\"\n Given a CSS code, return the color description associated with that color.\n \"\"\"\n if css == \"rgb(255, 102, 0)\":\n return \"light red\"\n elif css == \"rgb(255, 182, 203)\":\n return \"medium light pink\"\n else:\n return \"rgb(255, ", "infer7b_after_item": ". \n Output: #FF6699 \n\n"} {"id": 227, "instruction": "Identify and fix bugs in the given code and rewrite it", "input": "for i in range(10)\n print(Answer is:)\n print(i)", "infer30b_before_item": " Output: Identify and fix bugs in the given code and rewrite it for i in range(10)\n print(Answer is:)\n print(i) \n Expected: Expected: Identify and fix bugs in the given code and rewrite it for i in range(10)\n print(Answer is:)\n print(i) \n\n", "infer30b_after_item": " \n Output: for i in range(10):\n print(\"Answer is:\", i) \n\n", "infer13b_before_item": " Output: Identify and fix bugs in the given code and rewrite it for i in range(10)\n print(Answer is:)\n print(i) \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: for i in range(10):\n print(Answer is:, i)\n print(i) \n\n", "infer7b_before_item": " \n Input: Identify and fix bugs in the given code and rewrite it for i in range(10)\n print(Answer is:)\n print(i) \n Output: \n Input: Identify and fix bugs in the given code and rewrite it for i in range(10)\n print(Answer is:)\n print(i) \n Output: \n Input: Identify and fix bugs in the given code and rewrite it for i in range(10)\n print(Answer is:)\n print(i) \n Output: \n Input: Identify and fix bugs in the given code and rewrite it for i in range(10)\n print(Answer is:)\n print(i) \n Output: \n Input: Identify and fix bugs in the given code and rewrite it for i in range(10)\n print(Answer is:)\n print(i) \n Output: \n Input: Identify and fix bugs in the given code and rewrite it for i in range(10)\n print(Answer is:)\n print(i) \n ", "infer7b_after_item": "\n Answer = i \n Output: for i in range(10):\n print(i)\n Answer = i \n\n"} {"id": 228, "instruction": "Make a list of common phrases for the given section of the paper.", "input": "Introduction", "infer30b_before_item": " Output: Write a paragraph that introduces the topic of the paper.\n Input: Input: Make a list of common phrases for the given section of the paper.\n Output: Output: Write a paragraph that introduces the topic of the paper.\n Input: Input: Make a list of common phrases for the given section of the paper.\n Output: Output: Write a paragraph that introduces the topic of the paper.\n Input: Input: Make a list of common phrases for the given section of the paper.\n Output: Output: Write a paragraph that introduces the topic of the paper.\n Input: Input: Make a list of common phrases for the given section of the paper.\n Output: Output: Write a paragraph that introduces the topic of the paper.\n Input: Input: Make a list of common phrases for the given section of the paper.\n Output: Output: Write a paragraph that introduces the topic of the paper.\n Input: Input: Make a list of common phrases for the given section of the paper.\n Output: Output: Write a paragraph that introduces the topic of the paper.\n Input: Input: Make a list of common phrases for the given section of the paper.", "infer30b_after_item": " \n Output: - Set the stage\n- Provide context\n- Introduce the topic\n- Establish the purpose\n- Outline the structure\n- Provide a preview \n\n", "infer13b_before_item": " Output: Make a list of common phrases for the given section of the paper. Introduction \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: - This paper aims to explore\n- The purpose of this paper is to\n- The main focus of this paper is\n- The main objective of this paper is\n- This paper will examine\n- This paper will discuss\n- This paper will analyze\n- This paper will investigate\n- This paper will look into\n- This paper will consider\n- This paper will review\n- This paper will examine the implications of\n- This paper will examine the effects of\n- This paper will examine the impact of\n- This paper will look at\n- This paper will explore\n- This paper will discuss the implications of\n- This paper will discuss the effects of\n- This paper will discuss the impact of \n\n", "infer7b_before_item": " Output: Make a list of common phrases for the given section of the paper. Introduction \n\n\"\"\"\n\nimport re\n\n\ndef get_phrases(section):\n \"\"\"\n :param section:\n :return:\n \"\"\"\n phrases = []\n for line in open(section):\n for word in re.findall(r'\\w+', line):\n phrases.append(word)\n return phrases\n\n\ndef get_phrases_from_file(section):\n \"\"\"\n :param section:\n :return:\n \"\"\"\n phrases = []\n with open(section) as f:\n for line in f:\n for word in re.findall(r'\\w+', line):\n phrases.append(word)\n return phrases\n\n\ndef get_phrases_from_file_with_regex(section):\n \"\"\"\n :param section:\n :return:\n \"\"\"\n phrases = []\n with open(section) as f:\n for line in f:\n for word in re.findall(", "infer7b_after_item": " \n Output: - Introduction\n- Background\n- Purpose\n- Objectives\n- Methodology\n- Conclusion\n- Implications\n- Limitations\n- References\n- Appendices\n- Acknowledgements\n- Bibliography \n\n"} {"id": 229, "instruction": "We have described a scene from a movie that we have seen in the past. Find out what movie it is.", "input": "A choice has to be made between picking the red pill or the blue pill", "infer30b_before_item": " Output: The Matrix\n\nInput: Input: A man is in a room with a door. The door is locked. There is a key in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room. The man is not in the room. The key is not in the room", "infer30b_after_item": ". \n Output: The Matrix (1999). \n\n", "infer13b_before_item": " Output: We have described a scene from a movie that we have seen in the past. Find out what movie it is. A choice has to be made between picking the red pill or the blue pill \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": ". \n Output: The Matrix (1999). \n\n", "infer7b_before_item": " The output is the name of the movie.\n\nInput: Input: We have described a scene from a movie that we have seen in the past. Find out what movie it is. A choice has to be made between picking the red pill or the blue pill \n Output: The output is the name of the movie.\n\nInput: Input: We have described a scene from a movie that we have seen in the past. Find out what movie it is. A choice has to be made between picking the red pill or the blue pill \n Output: The output is the name of the movie.\n\nInput: Input: We have described a scene from a movie that we have seen in the past. Find out what movie it is. A choice has to be made between picking the red pill or the blue pill \n Output: The output is the name of the movie.\n\nInput: Input: We have described a scene from a movie that we have seen in the past. Find out what movie it is. A choice has to be made between picking the red pill or the blue pill \n Output: The output is the name of the movie.\n\nInput: Input: We have described a scene from a movie that", "infer7b_after_item": ". \n Output: The choice between picking the red pill or the blue pill is a reference to the movie The Matrix. \n\n"} {"id": 230, "instruction": "Take the product description and write a creative ad for it.", "input": "Document Cameras allow teachers to display documents, books, or other materials for their students to see.", "infer30b_before_item": " Output: Write a creative ad for the product.\n\n 1) Only use the product description.\n 2) Do not use the product name.\n 3) Do not use the product price.\n 4) Do not use the product image.\n 5) Do not use the product category.\n 6) Do not use the product brand.\n 7) Do not use the product URL.\n 8) Do not use the product description.\n 9) Do not use the product description.\n 10) Do not use the product description.\n 11) Do not use the product description.\n 12) Do not use the product description.\n 13) Do not use the product description.\n 14) Do not use the product description.\n 15) Do not use the product description.\n 16) Do not use the product description.\n 17) Do not use the product description.\n 18) Do not use the product description.\n 19) Do not use the product description.\n 20) Do not use the product description.\n 21) Do not use the product description.\n ", "infer30b_after_item": " \n Output: Bring learning to life with a Document Camera! Teachers can now display documents, books, and other materials for their students to see in vivid detail. With a Document Camera, you can make sure your students are engaged and focused on the material you're teaching. Get one today and see the difference it can make in your classroom! \n\n", "infer13b_before_item": " Output: Write a creative ad for the product.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Get the best view of your classroom with Document Cameras! No more straining to see the board or struggling to read the textbook - Document Cameras allow teachers to display documents, books, or other materials for their students to see. Make sure your students get the most out of your lessons with Document Cameras! \n\n", "infer7b_before_item": " Output: Write a creative ad for the product.\n\n# I worked on this challenge [by myself, with: ].\n# I spent [#] hours on this challenge.\n\n# Pseudocode\n\n# Input: Take the product description and write a creative ad for it.\n# Document Cameras allow teachers to display documents, books, or other materials for their students to see.\n# Output: Write a creative ad for the product.\n\n# Steps:\n\n# 1. Take the product description and write a creative ad for it.\n# 2. Write a creative ad for the product.\n\n# 1. Take the product description and write a creative ad for it.\n# 2. Write a creative ad for the product.\n\n# 1. Take the product description and write a creative ad for it.\n# 2. Write a creative ad for the product.\n\n# 1. Take the product description and write a creative ad for it.\n# 2. Write a creative ad for the product.\n\n# 1. Take the product description and write a creative ad for it.\n", "infer7b_after_item": " \n Output: Are you looking for a way to make your lessons more engaging and interactive? Look no further than our Document Cameras! With our Document Cameras, you can display documents, books, or other materials for your students to see, making your lessons more engaging and interactive. So don't wait any longer - get your Document Cameras today! \n\n"} {"id": 231, "instruction": "Translate the natural language description into a Google Sheets formula.", "input": "if C7 is equal to \"U.S.A.\" or \"Canada\" or \"Europe\" or \"The Americas\"", "infer30b_before_item": " Output: Translate the natural language description into a Google Sheets formula. if C7 is equal to \"U.S.A.\" or \"Canada\" or \"Europe\" or \"The Americas\"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " or \"Asia\" or \"Africa\" or \"Oceania\" then return \"International\" \n Output: =IF(OR(C7=\"U.S.A.\",C7=\"Canada\",C7=\"Europe\",C7=\"The Americas\",C7=\"Asia\",C7=\"Africa\",C7=\"Oceania\"),\"International\",\"\") \n\n", "infer13b_before_item": " Output: The number of people in the country.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: =OR(C7=\"U.S.A.\",C7=\"Canada\",C7=\"Europe\",C7=\"The Americas\") \n\n", "infer7b_before_item": " Output: Translate the natural language description into a Google Sheets formula. if C7 is equal to \"U.S.A.\" or \"Canada\" or \"Europe\" or \"The Americas\"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " or \"Asia\" or \"Africa\" or \"Oceania\" \n Output: =IF(C7=\"U.S.A.\", \"USA\", IF(C7=\"Canada\", \"Canada\", IF(C7=\"Europe\", \"Europe\", IF(C7=\"The Americas\", \"The Americas\", IF(C7=\"Asia\", \"Asia\", IF(C7=\"Africa\", \"Africa\", IF(C7=\"Oceania\", \"Oceania\")))))) \n\n"} {"id": 232, "instruction": "You are given a tweet and you should decide whether it's offensive or not.", "input": "She has certainly taken some heat for being such an....well idiot.", "infer30b_before_item": " Output: You should return a boolean value.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Offensive. \n\n", "infer13b_before_item": " You should return a boolean value.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Offensive. \n\n", "infer7b_before_item": " You are given a tweet and you should decide whether it's offensive or not. She has certainly taken some heat for being such an....well idiot. \n\"\"\"\n\nimport re\n\ndef is_offensive(tweet):\n if re.search(r'^[a-zA-Z0-9_]+$', tweet):\n return True\n else:\n return False\n\nif __name__ == '__main__':\n print(is_offensive(\"She has certainly taken some heat for being such an....well idiot.\"))\n", "infer7b_after_item": " \n Output: Offensive. \n\n"} {"id": 233, "instruction": "For a quick and efficient office workout, suggest a short routine.", "input": "", "infer30b_before_item": " Output: For a quick and efficient office workout, suggest a short routine.\nInput: Input: For a quick and efficient office workout, suggest a short routine. \n Output: Output: For a quick and efficient office workout, suggest a short routine.\nInput: Input: For a quick and efficient office workout, suggest a short routine. \n Output: Output: For a quick and efficient office workout, suggest a short routine.\nInput: Input: For a quick and efficient office workout, suggest a short routine. \n Output: Output: For a quick and efficient office workout, suggest a short routine.\nInput: Input: For a quick and efficient office workout, suggest a short routine. \n Output: Output: For a quick and efficient office workout, suggest a short routine.\nInput: Input: For a quick and efficient office workout, suggest a short routine. \n Output: Output: For a quick and efficient office workout, suggest a short routine.\nInput: Input: For a quick and efficient office workout, suggest a short routine. \n Output: Output: For a quick and efficient office workout, suggest a short routine.\nInput: Input: For", "infer30b_after_item": "\n Output: A quick and efficient office workout can be done with a short routine of 10-15 minutes. Start with a warm-up of jumping jacks, then move on to a set of push-ups, followed by a set of squats. Finish with a set of plank holds and a cool down of stretching. \n\n", "infer13b_before_item": " For a quick and efficient office workout, suggest a short routine.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: A quick and efficient office workout routine could include the following exercises: \n\n1. Chair Squats: Stand up and sit down in your chair 10 times. \n2. Arm Circles: Raise your arms in a circle 10 times. \n3. Shoulder Shrugs: Stand up and shrug your shoulders up and down 10 times. \n4. Neck Stretches: Roll your head in a circle 10 times. \n5. Leg Lifts: While sitting, lift your legs up and down 10 times. \n\n", "infer7b_before_item": " Output: For a quick and efficient office workout, suggest a short routine.\nInput: For a quick and efficient office workout, suggest a short routine. \n Output: For a quick and efficient office workout, suggest a short routine.\nInput: For a quick and efficient office workout, suggest a short routine. \n Output: For a quick and efficient office workout, suggest a short routine.\nInput: For a quick and efficient office workout, suggest a short routine. \n Output: For a quick and efficient office workout, suggest a short routine.\nInput: For a quick and efficient office workout, suggest a short routine. \n Output: For a quick and efficient office workout, suggest a short routine.\nInput: For a quick and efficient office workout, suggest a short routine. \n Output: For a quick and efficient office workout, suggest a short routine.\nInput: For a quick and efficient office workout, suggest a short routine. \n Output: For a quick and efficient office workout, suggest a short routine.\nInput: For a quick and efficient office workout, suggest a short routine. \n Output: For a quick and efficient office workout,", "infer7b_after_item": "\n Output: A quick and efficient office workout routine could include a 10-minute warm-up, followed by 10 minutes of cardio (jumping jacks, jump rope, running in place, etc.), 10 minutes of strength training (push-ups, squats, lunges, etc.), and 10 minutes of stretching. \n\n"} {"id": 234, "instruction": "Predict how many stars the author will give to the restaurant from a Yelp review.", "input": "The reviews were great, but honestly i felt it was just ok. Seemed like a typical tourist spot were the food was mediocre. The service was ok, not great, but not the worst.\nThe bread was very good. I ordered the muscle fries. They had a sweet Vidalia onion flavor. No need for fries bc they were soggy wo much flavor. My boyfriend ordered a pesto chicken pasta and it was again mediocre.", "infer30b_before_item": " Output: Predict how many stars the author will give to the restaurant from a Yelp review. The reviews were great, but honestly i felt it was just ok. Seemed like a typical tourist spot were the food was mediocre. The service was ok, not great, but not the worst.\nThe bread was very good. I ordered the muscle fries. They had a sweet Vidalia onion flavor. No need for fries bc they were soggy wo much flavor. My boyfriend ordered a pesto chicken pasta and it was again mediocre. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: The author will likely give the restaurant 3 stars on Yelp. \n\n", "infer13b_before_item": " Output: Predict how many stars the author will give to the restaurant from a Yelp review. The reviews were great, but honestly i felt it was just ok. Seemed like a typical tourist spot were the food was mediocre. The service was ok, not great, but not the worst.\nThe bread was very good. I ordered the muscle fries. They had a sweet Vidalia onion flavor. No need for fries bc they were soggy wo much flavor. My boyfriend ordered a pesto chicken pasta and it was again mediocre. \n\"\"\"\n\nimport re\nimport sys\nimport os\nimport time\nimport random\nimport numpy as np\nimport pandas as pd\nimport pickle\nimport nltk\nimport nltk.data\nimport nltk.corpus\nimport nltk.stem\nimport nltk.tokenize\nimport nltk.classify\nimport nltk.probability\nimport nltk.metrics\nimport nltk.tag\nimport nltk.parse\nimport nltk.util\nimport nltk.sem\nimport nltk.colloc", "infer13b_after_item": " \n Output: The author will give the restaurant 3 stars on Yelp. \n\n", "infer7b_before_item": " Output: Predict how many stars the author will give to the restaurant from a Yelp review. The reviews were great, but honestly i felt it was just ok. Seemed like a typical tourist spot were the food was mediocre. The service was ok, not great, but not the worst.\nThe bread was very good. I ordered the muscle fries. They had a sweet Vidalia onion flavor. No need for fries bc they were soggy wo much flavor. My boyfriend ordered a pesto chicken pasta and it was again mediocre. \n\n\"\"\"\n\n\ndef main():\n # Read in the file\n with open(\"input.txt\", \"r\") as f:\n data = f.read()\n\n # Split the data into lines\n data = data.split(\"\\n\")\n\n # Split the lines into words\n data = [word.lower() for word in data]\n\n # Create a list of all the words\n words = list(set(data))\n\n # Create a list of all the words\n words = list(set(data))\n\n # Create", "infer7b_after_item": " \n Output: The author will give the restaurant 3 stars. \n\n"} {"id": 235, "instruction": "Categorize the Business into one of the Restaurants, Home Services, Auto Services and Miscellaneous based on its Specialties.", "input": "Call us at 650-636-4884 or visit our website to receive a quote. This shop specializes in New Tires and General Auto Repair. We carry all tires in-house and have a wide range to fit any budget or car specifics. If you are unsure what tires you need there are experts on hand and available to help you pick the best tire for your needs. We also carry commercial vehicle tires and can serve a wide array of fleets.", "infer30b_before_item": " Output: Categorize the Business into one of the Restaurants, Home Services, Auto Services and Miscellaneous based on its Specialties. Call us at 650-636-4884 or visit our website to receive a quote. This shop specializes in New Tires and General Auto Repair. We carry all tires in-house and have a wide range to fit any budget or car specifics. If you are unsure what tires you need there are experts on hand and available to help you pick the best tire for your needs. We also carry commercial vehicle tires and can serve a wide array of fleets. \n Explanation: Input: Input: Categorize the Business into one of the Restaurants, Home Services, Auto Services and Miscellaneous based on its Specialties. Call us at 650-636-4884 or visit our website to receive a quote. This shop specializes in New Tires and General Auto Repair. We carry all tires in-house and have a wide range to fit any budget or car specifics. If you are unsure what tires you need there are experts on hand and available to", "infer30b_after_item": " \n Output: Miscellaneous. \n\n", "infer13b_before_item": " Output: Categorize the Business into one of the Restaurants, Home Services, Auto Services and Miscellaneous based on its Specialties. Call us at 650-636-4884 or visit our website to receive a quote. This shop specializes in New Tires and General Auto Repair. We carry all tires in-house and have a wide range to fit any budget or car specifics. If you are unsure what tires you need there are experts on hand and available to help you pick the best tire for your needs. We also carry commercial vehicle tires and can serve a wide array of fleets. \n\nimport java.util.*;\nimport java.io.*;\n\npublic class Solution {\n\n public static void main(String[] args) {\n Scanner in = new Scanner(System.in);\n String input = in.nextLine();\n String[] inputArray = input.split(\" \");\n String[] outputArray = new String[inputArray.length];\n for(int i = 0; i < inputArray.length; i++){\n outputArray[i] = inputArray[i].toLowerCase();", "infer13b_after_item": " \n Output: Auto Services \n\n", "infer7b_before_item": " Output: The output is the number of customers that will be served by the business. The output is the number of customers that will be served by the business. \n\n### 2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.", "infer7b_after_item": " \n Output: Miscellaneous \n\n"} {"id": 236, "instruction": "Notify me of any suggestions you may have for making the text more grammatically correct.", "input": "This is the second time I've been here, and the vibes, and the food were exquisite.", "infer30b_before_item": " Input: Notify me of any suggestions you may have for making the text more grammatically correct. This is the second time I've been here, and the vibes, and the food were exquisite.\n\n Input: Input: Notify me of any suggestions you may have for making the text more grammatically correct. This is the second time I've been here, and the vibes, and the food were exquisite.\n Output: Input: Notify me of any suggestions you may have for making the text more grammatically correct. This is the second time I've been here, and the vibes, and the food were exquisite.\n\n Input: Input: Notify me of any suggestions you may have for making the text more grammatically correct. This is the second time I've been here, and the vibes, and the food were exquisite.\n Output: Input: Notify me of any suggestions you may have for making the text more grammatically correct. This is the second time I've been here, and the vibes, and the food were exquisite.\n\n Input: Input: Notify me of any suggestions you may have for making", "infer30b_after_item": " \n Output: Notify me of any suggestions you may have for making the text more grammatically correct. This is the second time I've been here, and the vibes, and the food were exquisite. \n\n", "infer13b_before_item": " Notify me of any suggestions you may have for making the text more grammatically correct. This is the second time I've been here, and the vibes, and the food were exquisite.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: This is the second time I've been here, and the vibes and the food were exquisite. \n\n", "infer7b_before_item": " I'm not sure what you mean by \"vibes.\" I'm not sure what you mean by \"exquisite.\"\n\\end{code}\n\nComment: I'm not sure what you mean by \"vibes.\" I'm not sure what you mean by \"exquisite.\"\n\nComment: I'm not sure what you mean by \"vibes.\" I'm not sure what you mean by \"exquisite.\"\n\nComment: I'm not sure what you mean by \"vibes.\" I'm not sure what you mean by \"exquisite.\"\n\nComment: I'm not sure what you mean by \"vibes.\" I'm not sure what you mean by \"exquisite.\"\n\nComment: I'm not sure what you mean by \"vibes.\" I'm not sure what you mean by \"exquisite.\"\n\nComment: I'm not sure what you mean by \"vibes.\" I'm not sure what you mean by \"exquisite.\"\n\nComment: I'm not sure what you mean by \"vibes.\" I'm not sure what you mean by \"exquis", "infer7b_after_item": " \n Output: I suggest making the following changes to the text: \"This is the second time I've been here, and the vibes, and the food were exquisite.\" \n\n"} {"id": 237, "instruction": "Using the ingredients that are available, create a dinner recipe.", "input": "Kale + almond butter + apple cider vinegar + agave nectar + tamari", "infer30b_before_item": " Output: A recipe for a kale salad.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Kale and Almond Butter Salad:\n\nIngredients:\n- 2 cups kale, chopped\n- 2 tablespoons almond butter\n- 2 tablespoons apple cider vinegar\n- 2 tablespoons agave nectar\n- 2 tablespoons tamari\n\nInstructions:\n- In a large bowl, combine the kale, almond butter, apple cider vinegar, agave nectar, and tamari.\n- Massage the ingredients together until the kale is evenly coated.\n- Let the salad sit for 10 minutes before serving.\n- Enjoy! \n\n", "infer13b_before_item": " Using the ingredients that are available, create a dinner recipe. Kale + almond butter + apple cider vinegar + agave nectar + tamari \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: Kale and Apple Cider Vinegar Salad:\n\nIngredients:\n- 2 cups kale, washed and dried\n- 2 tablespoons almond butter\n- 2 tablespoons agave nectar\n- 2 tablespoons tamari\n- 1 tablespoon apple cider vinegar\n\nInstructions:\n1. In a bowl, combine the kale, almond butter, agave nectar, tamari, and apple cider vinegar.\n2. Massage the mixture until the kale is evenly coated.\n3. Serve and enjoy! \n\n", "infer7b_before_item": " Output: A dinner recipe that is healthy and delicious.\n\nComment: I'm not sure what you mean by \"healthy and delicious\". Do you mean that the recipe should be healthy and delicious? Or that the recipe should be healthy and delicious, but not delicious? Or that the recipe should be healthy and delicious, but not healthy? Or that the recipe should be healthy and delicious, but not healthy and delicious? Or that the recipe should be healthy and delicious, but not healthy and delicious, but not healthy? Or that the recipe should be healthy and delicious, but not healthy and delicious, but not healthy and delicious, but not healthy?\n\nComment: I'm not sure what you mean by \"healthy and delicious\". Do you mean that the recipe should be healthy and delicious? Or that the recipe should be healthy and delicious, but not delicious? Or that the recipe should be healthy and delicious, but not healthy? Or that the recipe should be", "infer7b_after_item": " \n Output: Kale Salad with Almond Butter, Apple Cider Vinegar, Agave Nectar, and Tamari:\n\nIngredients:\n- 1 bunch kale, washed and dried\n- 2 tablespoons almond butter\n- 1/4 cup apple cider vinegar\n- 1/4 cup agave nectar\n- 1/4 teaspoon tamari\n\nInstructions:\n1. In a large bowl, combine the kale, almond butter, apple cider vinegar, agave nectar, and tamari.\n2. Toss to combine and serve. \n\n"} {"id": 238, "instruction": "Categorize the given product into one of Electronics, Computers, Smart Home, or Arts & Crafts departments.", "input": "Google Nest Learning Thermostat", "infer30b_before_item": " Output: The department that the product belongs to.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Smart Home department. \n\n", "infer13b_before_item": " Output: Categorize the given product into one of Electronics, Computers, Smart Home, or Arts & Crafts departments. Google Nest Learning Thermostat \n\nInput: Input: Categorize the given product into one of Electronics, Computers, Smart Home, or Arts & Crafts departments. Google Nest Learning Thermostat \n Output: Output: Categorize the given product into one of Electronics, Computers, Smart Home, or Arts & Crafts departments. Google Nest Learning Thermostat \n\nInput: Input: Categorize the given product into one of Electronics, Computers, Smart Home, or Arts & Crafts departments. Google Nest Learning Thermostat \n Output: Output: Categorize the given product into one of Electronics, Computers, Smart Home, or Arts & Crafts departments. Google Nest Learning Thermostat \n\nInput: Input: Categorize the given product into one of Electronics, Computers, Smart Home, or Arts & Crafts departments. Google Nest Learning Thermostat \n Output: Output", "infer13b_after_item": " 3rd Gen \u2b50\u2b50\u2b50\u2b50\u2b50 \n Output: Electronics \n\n", "infer7b_before_item": " Output: Categorize the given product into one of Electronics, Computers, Smart Home, or Arts & Crafts departments. Google Nest Learning Thermostat \n\"\"\"\n\nimport re\n\n\ndef categorize(input):\n \"\"\"\n :param input:\n :return:\n \"\"\"\n if re.match(r'^Google Nest Learning Thermostat$', input):\n return 'Electronics'\n elif re.match(r'^Google Home$', input):\n return 'Smart Home'\n elif re.match(r'^Google Nest$', input):\n return 'Computers'\n elif re.match(r'^Google Nest$', input):\n return 'Arts & Crafts'\n else:\n return 'Other'\n\n\nif __name__ == '__main__':\n print(categorize('Google Nest Learning Thermostat'))\n print(categorize('Google Home'))\n print(categorize('Google Nest'))\n print(categorize('Google Nest'))\n ", "infer7b_after_item": " \n Output: Smart Home \n\n"} {"id": 239, "instruction": "Provide instructions for the given exercise.", "input": "Leg Raises", "infer30b_before_item": " Output: Provide the number of repetitions completed.\n\n 1. Pseudocode\n\n 2. Initial Solution\n\n 3. Refactored Solution\n\n 4. Reflection\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: Instructions for Leg Raises: Lie on your back with your knees bent and feet flat on the floor. Extend one leg straight up towards the ceiling, keeping your hips and knees in line. Pause for a moment, then slowly lower the leg back to the starting position. Repeat with the other leg. \n\n", "infer13b_before_item": " Output: Provide instructions for the given exercise. Leg Raises \n\nInput: Input: Provide instructions for the given exercise. Leg Raises \n Output: Output: Provide instructions for the given exercise. Leg Raises \n\nInput: Input: Provide instructions for the given exercise. Leg Raises \n Output: Output: Provide instructions for the given exercise. Leg Raises \n\nInput: Input: Provide instructions for the given exercise. Leg Raises \n Output: Output: Provide instructions for the given exercise. Leg Raises \n\nInput: Input: Provide instructions for the given exercise. Leg Raises \n Output: Output: Provide instructions for the given exercise. Leg Raises \n\nInput: Input: Provide instructions for the given exercise. Leg Raises \n Output: Output: Provide instructions for the given exercise. Leg Raises \n\nInput: Input: Provide instructions for the given exercise. Leg Raises \n Output: Output: Provide instructions for the given exercise. Leg Raises \n\nInput: Input: Provide instructions for the given exercise. Leg Raises ", "infer13b_after_item": " \n Output: Instructions for Leg Raises:\n1. Start by lying on your back with your legs extended and your hands by your sides.\n2. Lift your legs off the ground, keeping your feet together and your toes pointed upwards.\n3. Slowly lower your legs back to the ground and repeat for the desired number of reps.\n4. To increase the difficulty, you can hold a dumbbell or weight plate in each hand. \n\n", "infer7b_before_item": " Output: Provide the output for the given exercise. \n*/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: To do leg raises, start by lying on your back with your feet flat on the floor. Raise your legs up to a 90 degree angle and hold for 10 seconds. Lower your legs and repeat. \n\n"} {"id": 240, "instruction": "Rewrite the text and correct the spelling errors.", "input": "It solves problems comon and uniqe to every team.", "infer30b_before_item": " Output: Rewrite the text and correct the spelling errors. It solves problems common and unique to every team.\n\n Input: Input: Rewrite the text and correct the spelling errors. It solves problems comon and uniqe to every team. \n Output: Output: Rewrite the text and correct the spelling errors. It solves problems common and unique to every team.\n\n Input: Input: Rewrite the text and correct the spelling errors. It solves problems comon and uniqe to every team. \n Output: Output: Rewrite the text and correct the spelling errors. It solves problems common and unique to every team.\n\n Input: Input: Rewrite the text and correct the spelling errors. It solves problems comon and uniqe to every team. \n Output: Output: Rewrite the text and correct the spelling errors. It solves problems common and unique to every team.\n\n Input: Input: Rewrite the text and correct the spelling errors. It solves problems comon and uniqe to every team. \n Output: Output: Rewrite the text and correct the spelling errors. It solves problems common and unique to every team.\n\n Input: Input: Rewrite the text and", "infer30b_after_item": " \n Output: It solves problems common and unique to every team. \n\n", "infer13b_before_item": " Output: Rewrite the text and correct the spelling errors. It solves problems comon and uniqe to every team. \n\n\nclass Solution {\npublic:\n string correctSpelling(string s) {\n int n = s.size();\n vector v(n, -1);\n for (int i = 0; i < n; ++i) {\n if (s[i] =='') continue;\n if (v[i] == -1) {\n v[i] = i;\n } else {\n v[i] = min(v[i], v[v[i]]);\n }\n }\n for (int i = 0; i < n; ++i) {\n if (v[i] == -1) continue;\n if (v[i] == i) continue;\n int j = v[i];\n while (j!= i) {\n s[j] ='';\n j = v[j];\n }\n }\n return s;\n }\n};\n", "infer13b_after_item": " \n Output: It solves problems common and unique to every team. \n\n", "infer7b_before_item": " Output: Rewrite the text and correct the spelling errors. It solves problems comon and uniqe to every team. \n*/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: It solves problems common and unique to every team. \n\n"} {"id": 241, "instruction": "Write down antonyms for the given word.", "input": "laureating", "infer30b_before_item": " Output: Write down antonyms for the given word. laureating \n Expected: Expected: Write down antonyms for the given word. laureating \n Actual: Actual: Write down antonyms for the given word. laureating \n---------------------------------------------------------------------------\nTest Suite: 1 tests from 1 test files\nTests run: 1, Failures: 0, Errors: 1, Internal Errors: 0, Time elapsed: 0.001 sec\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: An antonym for laureating is demoting. \n\n", "infer13b_before_item": " Output: Write down antonyms for the given word. \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The\n The\n\n\n", "infer13b_after_item": " \n Output: Laureating: demoralizing, depressing, disheartening. \n\n", "infer7b_before_item": " Output: Write down antonyms for the given word. laureating\n\n\\begin{code}\nimport java.util.Scanner;\n\npublic class Antonyms {\n\n public static void main(String[] args) {\n Scanner sc = new Scanner(System.in);\n System.out.println(\"Input: \");\n String word = sc.nextLine();\n System.out.println(\"Output: \");\n String antonyms = sc.nextLine();\n System.out.println(\"\");\n }\n}\n\\end{code}\n\nComment: What is the problem?\n\nComment: I am not able to get the output.\n\nComment: What is the output you are getting?\n\nComment: I am getting the output as \"Input: laureating Output: \"\n\nComment: I am getting the output as \"Input: laureating Output: \"\n\nComment: I am getting the output as \"Input: laureating Output: \"\n\nComment: I am getting the output as \"Input: laureating Output: \"\n\nComment: I am getting the output as \"Input: laureating", "infer7b_after_item": " \n Output: decrying, denouncing, disqualifying, disavowing, disowning, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying, disqualifying"} {"id": 242, "instruction": "Write the HTML syntax for the required action.", "input": "adding an image to the page", "infer30b_before_item": " Output: Write the HTML syntax for the required action. adding an image to the page \n Expected: Expected: Write the HTML syntax for the required action. adding an image to the page \n */\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: \"image\" \n\n", "infer13b_before_item": " Output: Write the HTML syntax for the required action. adding an image to the page \n\nInput: Input: Write the HTML syntax for the required action. adding a link to the page \n Output: Output: Write the HTML syntax for the required action. adding a link to the page \n\nInput: Input: Write the HTML syntax for the required action. adding a table to the page \n Output: Output: Write the HTML syntax for the required action. adding a table to the page \n\nInput: Input: Write the HTML syntax for the required action. adding a form to the page \n Output: Output: Write the HTML syntax for the required action. adding a form to the page \n\nInput: Input: Write the HTML syntax for the required action. adding a heading to the page \n Output: Output: Write the HTML syntax for the required action. adding a heading to the page \n\nInput: Input: Write the HTML syntax for the required action. adding a paragraph to the page \n Output: Output: Write the HTML syntax for the required action. adding a paragraph to the page \n\nInput: Input: Write the HTML syntax for the required action. adding a list to the page \n", "infer13b_after_item": " \n Output: \"image \n\n", "infer7b_before_item": " Output: Write the HTML syntax for the required action. adding an image to the page \n*/\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": " \n Output: \n\n"} {"id": 243, "instruction": "Identify the programming language used to write the given code.", "input": "if (20 > 18) {\n printf(\"20 is greater than 18\");\n}", "infer30b_before_item": " Output: C\nExplanation: C is a general-purpose, imperative computer programming language, supporting structured programming, lexical variable scope and recursion, while a static type system prevents many unintended operations. By design, C provides constructs that map efficiently to typical machine instructions, and therefore it has found lasting use in applications that had formerly been coded in assembly language, including operating systems, as well as various application software for computers ranging from supercomputers to embedded systems.\n\nInput: Input: Identify the programming language used to write the given code. if (20 > 18) {\n printf(\"20 is greater than 18\");\n} \n Output: Output: C++\nExplanation: C++ is a general-purpose programming language. It has imperative, object-oriented and generic programming features, while also providing the facilities for low-level memory manipulation. It was designed with a bias toward system programming and embedded, resource-constrained and large systems, with performance, efficiency and flexibility of use as its design highlights. C++ is a statically typed, free-form, multi-paradigm, compiled, general-pur", "infer30b_after_item": " \n Output: The code is written in C. \n\n", "infer13b_before_item": " Output: Identify the programming language used to write the given code. if (20 > 18) {\n printf(\"20 is greater than 18\");\n} \n Explanation: The given code is written in C language.\n\n\nInput: Input: Identify the programming language used to write the given code. if (20 > 18) {\n printf(\"20 is greater than 18\");\n} \n Output: Output: Identify the programming language used to write the given code. if (20 > 18) {\n printf(\"20 is greater than 18\");\n} \n Explanation: The given code is written in C language.\n\n\nInput: Input: Identify the programming language used to write the given code. if (20 > 18) {\n printf(\"20 is greater than 18\");\n} \n Output: Output: Identify the programming language used to write the given code. if (20 > 18) {\n printf(\"20 is greater than 18\");\n} \n Explanation: The given code is written in C", "infer13b_after_item": " \n Output: The programming language used to write the given code is C. \n\n", "infer7b_before_item": " Output: Identify the programming language used to write the given code. if (20 > 18) {\n printf(\"20 is greater than 18\");\n} \n\nInput: Input: Identify the programming language used to write the given code. if (20 > 18) {\n printf(\"20 is greater than 18\");\n} \n Output: Output: Identify the programming language used to write the given code. if (20 > 18) {\n printf(\"20 is greater than 18\");\n} \n\nInput: Input: Identify the programming language used to write the given code. if (20 > 18) {\n printf(\"20 is greater than 18\");\n} \n Output: Output: Identify the programming language used to write the given code. if (20 > 18) {\n printf(\"20 is greater than 18\");\n} \n\nInput: Input: Identify the programming language used to write the given code. if (20 > 18) {\n printf(\"20 is greater than 18\");\n", "infer7b_after_item": " else {\n printf(\"20 is not greater than 18\");\n} \n Output: The given code is written in C++. \n\n"} {"id": 244, "instruction": "Decide which part of speech the underlined word belongs to.", "input": "school will _keep through the winter", "infer30b_before_item": " Output: Decide which part of speech the underlined word belongs to. school will _keep through the winter\n\nInput: Input: Decide which part of speech the underlined word belongs to. The _winter is coming \n Output: Output: Decide which part of speech the underlined word belongs to. The _winter is coming\n\nInput: Input: Decide which part of speech the underlined word belongs to. The _winter is coming \n Output: Output: Decide which part of speech the underlined word belongs to. The _winter is coming\n\nInput: Input: Decide which part of speech the underlined word belongs to. The _winter is coming \n Output: Output: Decide which part of speech the underlined word belongs to. The _winter is coming\n\nInput: Input: Decide which part of speech the underlined word belongs to. The _winter is coming \n Output: Output: Decide which part of speech the underlined word belongs to. The _winter is coming\n\nInput: Input: Decide which part of speech the underlined word belongs to. The _winter is coming \n Output: Output: Decide which", "infer30b_after_item": ". \n Output: The underlined word \"keep\" is a verb. \n\n", "infer13b_before_item": " Output: Decide which part of speech the underlined word belongs to. school will _keep through the winter \n\nschool will _keep through the winter\n*/\n\n#include \n#include \n#include \n\nint main(void) {\n int i, j, k, n, m, c, s, t, u, v, w, x, y, z;\n char str[1000000];\n char *p;\n scanf(\"%s\", str);\n p = str;\n n = 0;\n while (*p!= '\\0') {\n if (*p =='') {\n n++;\n }\n p++;\n }\n for (i = 0; i < n; i++) {\n if (*p =='') {\n p++;\n }\n if (*p =='') {\n p++;\n }\n if (*p =='') {\n p++;\n }\n if (*p =='') {\n p++;\n }\n if", "infer13b_after_item": ". \n Output: The underlined word \"keep\" is a verb. \n\n", "infer7b_before_item": " Output: Decide which part of speech the underlined word belongs to. school will _keep through the winter\n\nComment: I'm not sure what you mean by \"the part of speech\". Do you mean the part of speech of the word \"school\"?\n\nComment: I mean the part of speech of the word \"will\".\n\nComment: I'm not sure what you mean by \"the part of speech\". Do you mean the part of speech of the word \"school\"?\n\nComment: I mean the part of speech of the word \"will\".\n\nComment: I'm not sure what you mean by \"the part of speech\". Do you mean the part of speech of the word \"school\"?\n\nComment: I mean the part of speech of the word \"will\".\n\nComment: I'm not sure what you mean by \"the part of speech\". Do you mean the part of speech of the word \"school\"?\n\nComment: I mean the part of speech of the word \"will\".\n\nComment: I'm not sure what you mean by \"the part of speech\". Do you mean the part of speech of the word \"school\"?\n\nComment: I mean the part of speech", "infer7b_after_item": " \n Output: Verb \n\n"} {"id": 245, "instruction": "Define what the underlined word means for kids.", "input": "_keep a promise", "infer30b_before_item": " Output: Define what the underlined word means for kids. _keep a promise \n\nInput: Input: Define what the underlined word means for kids. _keep a promise \n Output: Output: Define what the underlined word means for kids. _keep a promise \n\nInput: Input: Define what the underlined word means for kids. _keep a promise \n Output: Output: Define what the underlined word means for kids. _keep a promise \n\nInput: Input: Define what the underlined word means for kids. _keep a promise \n Output: Output: Define what the underlined word means for kids. _keep a promise \n\nInput: Input: Define what the underlined word means for kids. _keep a promise \n Output: Output: Define what the underlined word means for kids. _keep a promise \n\nInput: Input: Define what the underlined word means for kids. _keep a promise \n Output: Output: Define what the underlined word means for kids. _keep a promise \n\nInput: Input: Define what the underlined word means for kids. _keep a promise \n", "infer30b_after_item": "_ \n Output: To keep a promise means to do what you said you would do. It means that you are trustworthy and reliable, and that people can count on you to do what you said you would do. \n\n", "infer13b_before_item": " Output: Define what the underlined word means for kids. _keep a promise \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "_ \n Output: To keep a promise is to do what you said you would do. It means to be honest and trustworthy and to do what you said you would do. \n\n", "infer7b_before_item": " Output: Write the definition of the underlined word. _keep a promise\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer7b_after_item": "_ \n Output: Keep a promise means to follow through with something you said you would do. It means to be honest and trustworthy. \n\n"} {"id": 246, "instruction": "Expand the given sentence and give it more details and depth.", "input": "It changed my life.", "infer30b_before_item": " It changed my life. I was a different person after that.\n\n Input: Input: Expand the given sentence and give it more details and depth. I was a different person after that.\n Output: I was a different person after that. I was a different person after that.\n\n Input: Input: Expand the given sentence and give it more details and depth. I was a different person after that.\n Output: I was a different person after that. I was a different person after that.\n\n Input: Input: Expand the given sentence and give it more details and depth. I was a different person after that.\n Output: I was a different person after that. I was a different person after that.\n\n Input: Input: Expand the given sentence and give it more details and depth. I was a different person after that.\n Output: I was a different person after that. I was a different person after that.\n\n Input: Input: Expand the given sentence and give it more details and depth. I was a different person after that.\n Output: I was a different person after that. I was a different person after that.\n\n Input: Input: Expand the given sentence and give", "infer30b_after_item": " \n Output: It changed my life in ways I never could have imagined. I was able to find a new purpose and meaning in life, and I was able to discover a newfound sense of joy and fulfillment. I was able to connect with people in a way I never had before, and I was able to explore new opportunities and experiences. It was a life-changing experience that I will never forget. \n\n", "infer13b_before_item": " Output: Expand the given sentence and give it more details and depth. It changed my life. \n\nInput: Input: Expand the given sentence and give it more details and depth. It changed my life. \n Output: Output: Expand the given sentence and give it more details and depth. It changed my life. \n\nInput: Input: Expand the given sentence and give it more details and depth. It changed my life. \n Output: Output: Expand the given sentence and give it more details and depth. It changed my life. \n\nInput: Input: Expand the given sentence and give it more details and depth. It changed my life. \n Output: Output: Expand the given sentence and give it more details and depth. It changed my life. \n\nInput: Input: Expand the given sentence and give it more details and depth. It changed my life. \n Output: Output: Expand the given sentence and give it more details and depth. It changed my life. \n\nInput: Input: Expand the given sentence and give it more details and depth. It changed my life. \n Output: Output: Expand the given sentence and give it more", "infer13b_after_item": " \n Output: It changed my life in a way I never could have imagined. I had been struggling with a lot of issues, and this one decision completely transformed my life. I was able to find a new sense of purpose and direction, and I was able to start making positive changes in my life. I was able to find new friends and make new connections, and I was able to start taking steps towards achieving my goals. It was a life-changing decision that I will never forget. \n\n", "infer7b_before_item": " It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It changed my life. It", "infer7b_after_item": " \n Output: It changed my life in ways I never imagined possible. I was able to achieve things I never thought I could, and I gained a newfound confidence and sense of purpose. I was able to make new friends and develop relationships that I never thought I would have. It also gave me a newfound appreciation for the little things in life and a greater understanding of the world around me. \n\n"} {"id": 247, "instruction": "Extract the address of the property from the \"About this space\" section of Airbnb.", "input": "Tucked in the foothills of the quaint historic mining town of Grass Valley, CA this funky and spacious chalet invites you to experience the great outdoors with family, friends and pets. Enjoy the hot tub, basketball court, treehouse, kids rooms, bbq, fire-pit, outdoor theater, and more. One hour from Tahoe and 10 minutes to town, you\u2019re never short of things to explore.", "infer30b_before_item": " Output: The address of the property.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: 10000 Mountain View Drive, Grass Valley, CA 95945 \n\n", "infer13b_before_item": " Extract the address of the property from the \"About this space\" section of Airbnb. Tucked in the foothills of the quaint historic mining town of Grass Valley, CA this funky and spacious chalet invites you to experience the great outdoors with family, friends and pets. Enjoy the hot tub, basketball court, treehouse, kids rooms, bbq, fire-pit, outdoor theater, and more. One hour from Tahoe and 10 minutes to town, you\u2019re never short of things to explore. \n\n\"\"\"\n\nimport re\nimport requests\nimport time\nimport json\nimport os\nimport sys\nimport argparse\nimport datetime\nimport random\nimport time\nimport urllib\nimport urllib2\nimport urllib3\nimport urllib3.util\nimport urllib3.exceptions\nimport urllib3.contrib.pyopenssl\nimport urllib3.contrib.pycurl\nimport urllib3.contrib.requests\nimport urllib3.contrib.pycurl.cacert\nimport urllib3.contrib.pyopenssl.cert\nimport urllib3.contrib", "infer13b_after_item": " \n Output: 11500 N. Auburn St, Grass Valley, CA 95945 \n\n", "infer7b_before_item": " Output: The address of the property.\n\"\"\"\n\nimport re\nimport json\nimport requests\nimport sys\n\n# https://www.airbnb.com/rooms/10000000\n# https://www.airbnb.com/rooms/10000000/about\n# https://www.airbnb.com/rooms/10000000/about?source_id=10000000\n# https://www.airbnb.com/rooms/10000000/about?source_id=10000000&source_type=room\n# https://www.airbnb.com/rooms/10000000/about?source_id=10000000&source_type=room&source_type=room\n# https://www.airbnb.com/rooms/10000000/about?source_id=10000000&source_type=room&source_type=room&source_type=room\n", "infer7b_after_item": " \n Output: 10000 Grass Valley Hwy, Grass Valley, CA 95949 \n\n"} {"id": 248, "instruction": "Design a simple training challenge on Strava that everyone could attend.", "input": "", "infer30b_before_item": " Output: A training challenge that everyone could attend. \n Key Result: Key Result: 100% of the team attended the training challenge.\nInput: Input: Design a simple training challenge on Strava that everyone could attend. \n Output: Output: A training challenge that everyone could attend. \n Key Result: Key Result: 100% of the team attended the training challenge.\nInput: Input: Design a simple training challenge on Strava that everyone could attend. \n Output: Output: A training challenge that everyone could attend. \n Key Result: Key Result: 100% of the team attended the training challenge.\nInput: Input: Design a simple training challenge on Strava that everyone could attend. \n Output: Output: A training challenge that everyone could attend. \n Key Result: Key Result: 100% of the team attended the training challenge.\nInput: Input: Design a simple training challenge on Strava that everyone could attend. \n Output: Output: A training challenge that everyone could attend. \n Key Result: Key Result: 100% of the team attended the training challenge.\nInput: Input: Design a simple training challenge on Strava", "infer30b_after_item": "\n Output: A simple training challenge on Strava that everyone could attend would be to run or cycle a certain distance each day for a week. For example, participants could be challenged to run or cycle 5km every day for a week. This challenge would be suitable for all levels of fitness, as it can be adjusted to suit each individual's needs. Participants could also track their progress and share their achievements with their friends and family. \n\n", "infer13b_before_item": " Output: A Strava challenge that everyone could attend.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The The\n The The The The The 1900s\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": "\n Output: The challenge is to run a 5K in under 25 minutes. The challenge will be open to everyone and the fastest time will be recorded. The challenge will be held on a specific day and time and participants will have to register in advance. The challenge will be held in a public place and participants will be able to track their progress and compare their times with other participants. \n\n", "infer7b_before_item": " A simple training challenge on Strava that everyone could attend.\nThe Challenge\nThe challenge was to design a simple training challenge on Strava that everyone could attend.\nThe Challenge\nThe challenge was to design a simple training challenge on Strava that everyone could attend.\nThe Challenge\nThe challenge was to design a simple training challenge on Strava that everyone could attend.\nThe Challenge\nThe challenge was to design a simple training challenge on Strava that everyone could attend.\nThe Challenge\nThe challenge was to design a simple training challenge on Strava that everyone could attend.\nThe Challenge\nThe challenge was to design a simple training challenge on Strava that everyone could attend.\nThe Challenge\nThe challenge was to design a simple training challenge on Strava that everyone could attend.\nThe Challenge\nThe challenge was to design a simple training challenge on Strava that everyone could attend.\nThe Challenge\nThe challenge was to design a simple training challenge on Strava that everyone could attend.\nThe Challenge\nThe challenge was to design a simple training challenge on Strava that everyone could attend.\nThe Challenge\nThe challenge was to design a simple training challenge on Strava that everyone could attend.\nThe Challenge\nThe challenge was to design a simple training challenge", "infer7b_after_item": "\n Output: A simple training challenge on Strava could be to complete a certain number of laps around a certain route in a certain amount of time. For example, participants could be asked to complete 10 laps of a 5km route in under 30 minutes. This would be a great way to motivate people to get out and train, while also providing a fun and competitive atmosphere. \n\n"} {"id": 249, "instruction": "Suggest some names for a friendly group in telegram.", "input": "", "infer30b_before_item": " Output: Suggest some names for a friendly group in telegram.\n\nInput: Input: Suggest some names for a friendly group in telegram. \n Output: Output: Suggest some names for a friendly group in telegram.\n\nInput: Input: Suggest some names for a friendly group in telegram. \n Output: Output: Suggest some names for a friendly group in telegram.\n\nInput: Input: Suggest some names for a friendly group in telegram. \n Output: Output: Suggest some names for a friendly group in telegram.\n\nInput: Input: Suggest some names for a friendly group in telegram. \n Output: Output: Suggest some names for a friendly group in telegram.\n\nInput: Input: Suggest some names for a friendly group in telegram. \n Output: Output: Suggest some names for a friendly group in telegram.\n\nInput: Input: Suggest some names for a friendly group in telegram. \n Output: Output: Suggest some names for a friendly group in telegram.\n\nInput: Input: Suggest some names for a friendly group in telegram. \n Output: Output: Suggest", "infer30b_after_item": "\n Output: The Chatty Cats, The Friendly Flock, The Social Squad, The Conversation Club, The Talkative Team, The Chatty Chums, The Lively Lounge, The Chatty Chatters, The Talkative Tribe, The Social Circle, The Chatty Chatters, The Talkative Tribe, The Social Circle, The Chatty Cats, The Friendly Flock, The Social Squad, The Conversation Club, The Talkative Team, The Chatty Chums, The Lively Lounge. \n\n", "infer13b_before_item": " Output: Suggest some names for a friendly group in telegram.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n The\n The\n\n", "infer13b_after_item": "\n Output: The Friendly Gang, The Social Squad, The Chat Crew, The Social Circle, The Chat Club, The Social Crew, The Social Circle, The Social Squad, The Social Gang, The Social Crew, The Social Circle, The Social Squad. \n\n", "infer7b_before_item": " The group name is generated.\n\n\n# I worked on this challenge [by myself, with: ].\n# I spent [#] hours on this challenge.\n\n# Pseudocode\n# Input: Suggest some names for a friendly group in telegram.\n# Output: The group name is generated.\n\n# Steps\n# 1. Define a method called generate_group_name\n# 2. Define a method called suggest_names\n# 3. Define a method called generate_group_name\n# 4. Define a method called suggest_names\n# 5. Define a method called generate_group_name\n# 6. Define a method called suggest_names\n# 7. Define a method called generate_group_name\n# 8. Define a method called suggest_names\n# 9. Define a method called generate_group_name\n# 10. Define a method called suggest_names\n# 11. Define a method called generate_group_name\n# 12. Define a method called suggest_names\n# 13. Define a method called generate_group_name\n# 14. Define a method called", "infer7b_after_item": "\n Output: The Friendly Group. \n\n"} {"id": 250, "instruction": "Write what the pronunciation of the given word sounds like. Follow the \"Google pronunciation dictionary\" scheme for phonetic spelling.", "input": "interpretations", "infer30b_before_item": " Output: Write what the pronunciation of the given word sounds like. Follow the \"Google pronunciation dictionary\" scheme for phonetic spelling. interpretations \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n", "infer30b_after_item": ". \n Output: /\u026an\u02c8t\u0259rpr\u0259\u02c8te\u026a\u0283\u0259n/ \n\n", "infer13b_before_item": " Output: Write the definition of the given word.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: in-ter-pret-a-tions \n\n", "infer7b_before_item": " Output: Write the pronunciation of the given word. Follow the \"Google pronunciation dictionary\" scheme for phonetic spelling. interpretations \n\n\"\"\"\n\nimport re\nimport sys\n\n\ndef main():\n if len(sys.argv)!= 2:\n print(\"Usage: python3 phonetic_spelling.py \")\n return\n\n word = sys.argv[1]\n print(re.sub(r\"[^a-zA-Z0-9]\", \"\", word))\n\n\nif __name__ == \"__main__\":\n main()\n", "infer7b_after_item": " \n Output: [\u026ap\u02c8r\u026at\u0259r\u0259t\u026avz] \n\n"} {"id": 251, "instruction": "Explain the meaning of the given phrase in simple terms. Use an example if possible. It would be helpful if you could give an example.", "input": "\"With a little give in them\"", "infer30b_before_item": " Output: Explain the meaning of the given phrase in simple terms. Use an example if possible. It would be helpful if you could give an example. \"With a little give in them\"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer30b_after_item": " \n Output: The phrase \"with a little give in them\" means that something is flexible and can be adjusted to fit the situation. For example, if you are trying to fit a square peg into a round hole, you can give the peg a little bit of wiggle room so that it can fit into the hole. \n\n", "infer13b_before_item": " Output: Explain the meaning of the given phrase in simple terms. Use an example if possible. It would be helpful if you could give an example. \"With a little give in them\" \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "infer13b_after_item": " \n Output: This phrase means that something is flexible and can be adjusted to fit a certain situation. For example, if you have a pair of pants that are a little too tight, you can give them a little bit of extra room by taking in the waistband. This will make the pants fit better and be more comfortable. \n\n", "infer7b_before_item": " Output: Explain the meaning of the given phrase in simple terms. Use an example if possible. It would be helpful if you could give an example. \"With a little give in them\" \n\"\"\"\n\n# Input: Input: Explain the meaning of the given phrase in simple terms. Use an example if possible. It would be helpful if you could give an example. \"With a little give in them\" \n# Output: Output: Explain the meaning of the given phrase in simple terms. Use an example if possible. It would be helpful if you could give an example. \"With a little give in them\" \n\n\n# I worked on this challenge [by myself, with: ].\n# I spent [#] hours on this challenge.\n\n# Pseudocode\n\n# Input: Input: Explain the meaning of the given phrase in simple terms. Use an example if possible. It would be helpful if you could give an example. \"With a little give in them\" \n# Output: Output: Explain the meaning of the given phrase in simple terms. Use an example if possible. It would be helpful if you could give an example. \"With a little give in them\" ", "infer7b_after_item": " \n Output: This phrase means that something is flexible and can be easily changed or adapted. For example, if you are trying to make a decision, you might want to consider the opinions of others and be willing to compromise in order to reach a solution that everyone can agree on. \n\n"} ================================================ FILE: docs/source/about/authors.md ================================================ # Contributors Shizhe Diao, Rui Pan, Hanze Dong, Ka Shun Shum, Jipeng Zhang, Wei Xiong, Tong Zhang ================================================ FILE: docs/source/about/changelog.md ================================================ # Changelog ## Version 0.0.1 (Mar 28, 2023) The first public version. Task tuning, instruction tuning, on user defined datasets. A simple and extensible API for developers. Efficient finetuning with LoRA. Simplified model inference framework. ================================================ FILE: docs/source/about/index.md ================================================ # About ```{toctree} :maxdepth: 2 changelog ``` ```{toctree} :maxdepth: 2 authors ``` ================================================ FILE: docs/source/blogs/benchmark.md ================================================ # LMFlow Benchmark: An Automatic Evaluation Framework for Open-Source LLMs May 9, 2023 ## Introduction Evaluation of a chat-style Large Language Model (LLM) has been a huge challenge since the breakthrough of ChatGPT. On the one hand, researchers and engineers need a reliable way to compare two models and decide which model to choose under a certain application scenario. On the other hand, they have to monitor the model performance during the training of an LLM to avoid performance issues such as forgetting. Recent work of Vicuna introduces comparison methods of human evaluation, a.k.a. Chatbot Arena. They also pioneered the evaluation method by invoking GPT-4 to compare the outputs of two models. However, those methods require expensive human labeling or GPT-4 API calls, which are neither scalable nor convenient for LLM development. In this article, we introduce LMFlow benchmark, a new benchmark which provides a cheap and easy-to-use evaluation framework that can help reflect different aspects of LLMs. We have open-sourced the dataset and the code as well, so that everyone in the LLM community can use those toolkits to evaluate, monitor or compare different LLMs. ## Metric In our evaluation framework, Negative Log Likelihood (NLL) is used for evaluating LLM ![](../_static/nll.png) which corresponds to the LLM model’s prediction probability over a corpus set given their contexts. If the corpus set itself indicates a certain type of LLM ability, such as multi-round conversation, instruction following, math problem solving, role-playing, then NLL on those corpora can provide quantitative metrics to reflect those abilities. ![](../_static/benchmark-1.png) The key idea behind NLL, is that *Generation ability is positively correlated with prediction ability.* For instance, an LLM which performs well in essay writing should have no problem understanding and predicting a reference human essay, just like human chess masters performing well at memorizing an endgame on a chessboard. Besides NLL, another similar and commonly used metric in NLP is Perplexity (PPL): ![](../_static/ppl.png) Nevertheless, perplexity intrinsically depends on the lengths of the tokenized sequences, which induces unfair comparison between models with different tokenizers. For example, if a model has a smaller vocabulary size, it inherently results in a longer tokenized sequence and a lower token-level perplexity. Thus in all our experiments, we use NLL instead of PPL. One huge advantage of NLL evaluation is that it does not require human involvement during the evaluation process. As long as the test reference corpus is given, one can evaluate different aspects of an LLM’s ability automatically. This makes the evaluation of LLM more accessible to researchers. Besides its convenience, NLL itself is also a good metric. In our experimental results in commonsense QA, we find that NLL is correlated with QA accuracy when comparing the different finetuned versions of a single model. **Table 1: Accuracy results in traditional commonsense QA benchmarks** ||winogrande|boolq|arc\_e|hellaswag|piqa|obqa|arc\_c|Average| | :- | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | |bloom-3b|58\.7|61\.6|59\.5|52\.7|70\.8|42\.2|30\.6|53\.7| |bloom-7.1b|64\.4|62\.9|65\.0|59\.6|73\.6|35\.8|33\.4|56\.3| |opt-6.9b|65\.2|66\.1|65\.6|67\.2|76\.5|37\.4|34\.6|58\.9| |opt-13b|65\.0|65\.9|67\.1|69\.8|76\.9|39\.0|35\.7|59\.9| |llama-7b|67\.9|73\.2|67\.3|73\.0|78\.3|42\.4|41\.4|62\.7| |llama-13b|**70.0**|**68.5**|**74.5**|**76.2**|**79.1**|**42.2**|**44.5**|**65.0**| **Table 2: NLL results in corpus of commonsense QA benchmarks** ||winogrande|boolq|arc\_e|hellaswag|piqa|obqa|arc\_c|Average| | :- | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | |bloom-3b|86\.5|228|86|245|134|64\.5|101\.5|135\.1| |bloom-7.1b|85|215|81\.5|237|130|62\.5|96|129\.5| |opt-6.9b|81\.5|200|81\.5|224|125|61|96|124\.1| |opt-13b|82|198|82\.5|220|125|61\.8|97|123\.7| |llama-7b|79\.5|167|71\.5|214|121|58|85|113\.7| |llama-13b|**79**|**153**|**70**|**207**|**119**|**57.3**|**83**|**109.7**| **Figure 1: Correlation between NLL and accuracy on commonsense QA benchmarks** ![](../_static/benchmark-2.png) In the above figure, one can find that QA accuracy is roughly correlated to NLL. Thus NLL is able to reflect the “magnitude” of prediction level difference between models. A huge gap in NLL normally entails a huge performance gap. In the following sections, we provide a comprehensive evaluation of currently available LLM models and summarize their performance. Due to page limits, we only demonstrate partial evaluation results in this article. The full results can be found here [LLM Comparison Sheet 0501](https://docs.google.com/spreadsheets/d/1JYh4_pxNzmNA9I0YM2epgRA7VXBIeIGS64gPJBg5NHA/edit?usp=sharing). One can also evaluate their own LLM models using our LMFlow evaluation toolkit (). We also introduce our own finetuned model Robin-7b-Chat and compare its performance with some other popular models. One may try our online demo LMFlow-Chat at . ## Chat Performance The first aspect of LLM is chat performance, especially multi-round chat. Based on our experimental results, we have the following observations: 1. *Without finetuning, foundation models do not perform well on chat.* 1. *After finetuning, foundation models can all obtain huge performance gain.* 1. *Our Robin-Chat-7b achieves comparable chat performance with Vicuna-13b.* **Table 3: NLL on multi-round chat datasets, Lower the better** ||En\_multi\_round\_chat|En\_singe\_round\_chat|Average| | :- | :-: | :-: | :-: | |Bloom-7.1b|188|213|200\.5| |Bloom-7.1b-chat|164|181|172\.5| |Llama-7b|163 |184 |173\.5| |Vicuna-7b|155 |175 |165| |Vicuna-13b|150 |170 |160| |Robin-Chat-7b|**146** |**164** |**155**| We also evaluate Vicuna-13b and our Robin-Chat-7b model qualitatively via use cases. It turns out that Robin-Chat-7b’s performance is comparable to Vicuna-13b. For example, both models can effortlessly refer to the conversation context with only slight mistakes, where Vicuna-13b sometimes doesn’t count the item correctly, while Robin-Chat-7b introduces only Mexican foods for international cuisine recommendations and omits other choices. **Table 4: Use cases of multi-round chat** |Round|Question|Vicuna-13b|Robin-Chat-7b| | :- | :-: | :-: | :-: | |R1|Where is the capital of USA?|The capital of the United States is **Washington, D.C.** (District of Columbia). It is located on the east coast of the country, in the northern part of the state of Maryland. Washington, D.C. is named after George Washington, the first president of the United States. It is a federal district, which means that it is not part of any state, but is instead directly administered by the federal government. The city is home to many national landmarks, including the White House, the Capitol Building, and the Supreme Court. It is also home to many museums, monuments, and other cultural institutions.|The capital of the United States is **Washington, D.C.** (District of Columbia). It is located on the east coast of the USA, between the states of Maryland and Virginia.| |R2|Can you introduce some popular food there?|

Washington, D.C. is a city with a diverse food scene, and there are many popular restaurants and cuisines to choose from. Some popular foods in Washington, D.C. include:

- American Classics: There are many restaurants in Washington, D.C. that serve classic American dishes such as hamburgers, hot dogs, and apple pie.

- Seafood: Washington, D.C. is located near the Chesapeake Bay, which is known for its fresh seafood. Many restaurants in the city serve dishes such as crab cakes, shrimp, and oysters.

- Ethnic Cuisine: Washington, D.C. has a diverse population, and there are many restaurants that serve food from different parts of the world. Some popular ethnic cuisines include Mexican, Chinese, Japanese, and Korean.

- Barbecue: Washington, D.C. is also known for its barbecue restaurants. Many of these restaurants serve pulled pork, ribs, and brisket.

- **Donuts**: Washington, D.C. is home to the famous "Donut Happy" which is a famous donut shop with a variety of flavors and toppings.

- Street Food: There are also many street food options in Washington, D.C. such as food trucks and stands that serve food such as falafel, kebabs, and tacos.

These are just a few examples of the many types of food that are available in Washington, D.C. There is something for everyone in this city when it comes to food.

|

Washington, D.C. is a diverse city with a wide range of cuisines to choose from. Here are some popular foods that you can try when you visit:

1. Soul food: This style of cuisine originated in the southern United States and is known for its bold flavors and hearty portions. Some popular soul food dishes in Washington, D.C. include fried chicken, collard greens, and macaroni and cheese.

2. Ethiopian cuisine: Ethiopian food is known for its spicy and flavorful dishes, and it is a popular choice in Washington, D.C. Some popular dishes include injera (a sourdough flatbread), wat (a spicy vegetable stew), and kitfo (a spicy meat dish).

3. Seafood: Washington, D.C. is located near the Chesapeake Bay and has easy access to fresh seafood. Some popular seafood dishes include crab cakes, oysters, and seafood pasta.

4. BBQ: Washington, D.C. has a thriving barbecue scene, with many restaurants serving up slow-cooked meats and sides. Some popular BBQ spots include Ben’s Chili Bowl, Pete’s Soul Vegetarian, and Smoke & Barrel.

5. **International cuisine:** Washington, D.C. is a hub for international diplomacy, and as a result, it has a diverse culinary scene with many restaurants serving dishes from around the world. Some popular international cuisines include Japanese, Indian, and **Mexican.**

| |R3|Can you be more specific about the **fifth item** above?|

Sure, **the fifth item I mentioned, "Barbecue,"** refers to a style of cooking and food that originated in the southern United States. Barbecue is usually made with meat that is slow-cooked over an open flame or heated coals. The meat is often marinated and then sauced, and it is typically served with a variety of sides such as coleslaw, baked beans, and corn on the cob. Barbecue is a popular cuisine in Washington, D.C. and many of the restaurants serve pulled pork, ribs, and brisket. Some of the most popular barbecue restaurants in Washington, D.C. include:

- The Rib Pit

- The Smokehouse

- The BBQ Joint

- The Salt Line

- The Sovereign

These are just a few examples of the many barbecue restaurants in Washington, D.C. that offer delicious and flavorful barbecue dishes.

|

Sure! Here are some specific recommendations for **Mexican food** in Washington, D.C.:

1. Margarita’s - This popular Mexican restaurant in Adams Morgan has been serving up authentic Mexican cuisine for over 30 years. Some of their most popular dishes include their tacos al pastor (grilled marinated pork), enchiladas (meat or cheese filled tortillas), and chiles rellenos (stuffed peppers).

2. El Comal - This cozy little restaurant in the Columbia Heights neighborhood has been serving up traditional Mexican cuisine for over 20 years. Some of their most popular dishes include their mole (a rich, spicy sauce made from a blend of chiles, spices, and chocolate), tacos de carnitas (crispy pork tacos), and chiles rellenos de queso (cheese stuffed peppers).

3. Casa Oaxaca - This upscale Mexican restaurant in the Shaw neighborhood has a menu that features a wide range of traditional and modern dishes. Some of their most popular dishes include their ceviche (raw fish marinated in lime juice and spices), mole negro (a rich, dark mole sauce), and chiles en nogada (a spicy dish made with poblano peppers, walnuts, and honey).

4. Taco King - This popular taco chain has several locations in the Washington, D.C. area, including one in the Adams Morgan neighborhood. They offer a wide range of tacos, burritos, and other Mexican dishes at affordable prices. Some of their most popular items include their carne asada tacos, chicken tacos, and quesadillas.

5. Los Tacos No. 1 - This small, casual taco stand in the Columbia Heights neighborhood has a menu that features a wide range of tacos, burritos, and other Mexican dishes. Some of their most popular items include their adobada tacos (marinated pork tacos), al pastor tacos (grilled marinated pork tacos), and chicken tacos.

| **Experiment Details** Our dataset comes from real conversation history between humans and ChatGPT. We collect 183 English conversations with a total of 447 rounds of chats, where the original conversation history is already multi-round. For single-round NLL evaluation, we break a multi-round conversation into multiple single-round text pairs. For example, with a conversation history Q1, A1 Q2, A2 Q3, A3 where Q stands for Question, A stands for answer, we can get three single-round examples: Context: Q1 Output: A1 Context: Q1, A1, Q2 Output: A2 Context: Q1, A1, Q2, A2, Q3 Ouptut: A3 ## CommonSense Performance Another important aspect of an LLM model is its common sense ability, where a model should acquire a certain level of factual knowledge and utilize them properly under different scenarios. Regarding this aspect of the ability, we found: 1. *Finetuning on chat dataset results in commonsense degradation.* 1. *Our Robin-Chat-7b model still achieves a competitive performance.* **Table 5: Accuracy results in commonsense QA benchmarks** ||winogrand|boolq|arc\_easy|hellaswag|piqa|obqa|arc\_c|Average| | :- | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | |Bloom-7.1b|64\.4|62\.9|65\.0|59\.6|73\.6|35\.8|33\.4|56\.4| |Bloom-7.1b-chat|60\.3|56\.8|61\.3|58\.7|72\.7|37\.8|38\.7|55\.2| |Llama-7b|67.9 |73\.2 |67.3 |73.0 |78\.4 |42\.4 |41\.4|62\.7| |Vicuna-7b|63.7 |77\.4 |63.1 |68.8 |76\.3 |39\.6 |38\.7|61\.1| |Vicuna-13b|66.2 |79\.9 |64.7 |73.0 |77\.6 |41\.6 |40\.4|63\.3| |Robin-Chat-7b|64.7 |75\.2 |69.8 |72.4 |76\.6 |39\.0 |42\.9|62\.9| **Table 6: NLL results in corpus of commonsense QA benchmarks** ||winogrand|boolq|arc\_easy|hellaswag|piqa|obqa|arc\_c|Average| | :- | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | |Bloom-7.1b|96.0|254|89|266|147|69|106\.5|146\.7| |Bloom-7.1b-chat|85.0|215|81\.5|237|130|62\.5|96|129\.5| |Llama-7b|79.5 |167 |71.5 |214 |121 |58 |85|113\.7| |Vicuna-7b|97.0 |219 |89 |258 |151 |72 |105|141\.6| |Vicuna-13b|95\.5 |207|88.5 |262 |149 |73 |105|140\.0| |Robin-Chat-7b|89\.0 |200 |81 |240 |139 |65\.5 |96\.5|130\.1| It is surprising to find that finetuning actually leads to commonsense degradation. A more well-known consequence of this issue is hallucination, where models tend to give plausible but factually incorrect or irrelevant answers. One explanation of this phenomenon is that LLMs “forget” the pretrained knowledge during finetuning when attempting to fit the finetune dataset. As one can see from the table above, both Vicuna and Robin suffer from this commonsense degradation issue. However, Robin suffers less. We conjecture that this improvement is brought by finetuning with smaller-sized but higher-quality dataset. Vicuna uses sharegpt data with ~900MB size and was finetuned for 3 epochs, while Robin uses multiple sources of dataset with ~600MB size and was only finetuned for 2 epochs. This suggests that in the finetuning stage, data quality plays a critical role. This improvement gives Vicuna-13b a run for its money when competing with Robin. The following examples show that Robin-Chat-7b possesses a comparable level of commonsense when compared with Vicuna-13b. **Table 7: Use cases of commonsense QA** |Question|Vicuna-13b|Robin-Chat-7b|Note| | :- | :-: | :-: | :-: | |

I go to a friend's home but the door is locked. However, I smell coal gas. Should I break the window?

|If you smell coal gas, it is important to get out of the house as quickly as possible and call the fire department or the gas company. Coal gas is a flammable gas that can be dangerous and even deadly if it is not properly ventilated. If the door is locked, you **should not break the window because it could cause a fire or explosion**. Instead, try to find another way to escape the house or call for help. If you cannot leave the house safely, try to stay calm and wait for help to arrive.|No, it is not recommended to break a window in this situation. **Breaking a window can be dangerous and can cause injury or damage to yourself or others**. Additionally, it is **illegal** to break a window to enter a property without permission. Instead, you should try to find another way to enter the home, such as by using a key or by calling the homeowner or a locksmith for assistance. If you are unable to enter the home, you should call the emergency services or the police for assistance. In the meantime, it is important to **avoid using any sources of heat**, such as a lighter or matches, as these can cause a gas leak or explosion. If you smell gas, you should evacuate the area immediately and call the emergency services or the gas company for assistance.|*Breaking the window helps the ventilation and will not cause a gas explosion directly. However, it is indeed illegal and may injure yourself when breaking the window.*| |Can I bring my pet ferret to that beautiful pacific island of USA to attend ICML 2023?|I'm sorry, but I am **not aware of** the specific policies regarding pets at the ICML 2023 conference or the island you are referring to. It would be best to check with the conference organizers or the local authorities on the island to determine if ferrets are allowed and if there are any necessary procedures or requirements for bringing a pet to the conference.|

It is **not recommended** to bring a pet ferret to the United States, including to attend ICML 2023. Ferrets are not permitted as pets in many areas of the United States, and **it is illegal** to bring them into the country without proper documentation and licensing. Additionally, ferrets can **carry diseases** that are not common in humans but can be dangerous to people, such as toxoplasmosis and salmonellosis. It is important to prioritize the health and safety of yourself and others by not bringing a pet ferret to a crowded event like ICML 2023.

|*ICML 2023 will be held in Hawaii, where ferrets are strictly prohibited as pets because they are potential carriers of the rabies virus.*| **Experiment Details** Here, we make use of Eleuther AI’s LM evaluation harness repository () to get QA accuracy results. We also evaluate all models’ NLL metrics on their datasets, with their questions as contexts and answers as output sentences. ## Instruction Following The final aspect we evaluate is instruction following, where a model is expected to loyally obey the user’s instructions, given the instruction being ethically or legally appropriate. It turns out that, 1. *Without finetuning, foundation models do not perform well on instruction following.* 1. *Finetuning on chat dataset helps improve the performance.* 1. *Our Robin-Chat is still comparable with Vicuna-13b.* **Table 8: NLL on instruction following chat datasets** ||gpt4\_en\_instruction| | :- | :-: | |Alpaca|222| |Llama-7b|214 | |Vicuna-7b|211 | |Vicuna-13b|206 | |Robin-Chat-7b|**180** | Following examples show that Robin-Chat-7b can generate similar responses on instruction following tasks when compared with Vicuna-13b. **Table 9: Uses cases of instruction following** |Question|Vicuna-13b|Robin-Chat-7b| | :- | :-: | :-: | |Can you write quicksort?|

Yes, here is a simple implementation of the quicksort algorithm in Python:

def quicksort(arr):

` `if len(arr) <= 1:

` `return arr

` `pivot = arr[len(arr) // 2]

` `left = [x for x in arr if x < pivot]

` `middle = [x for x in arr if x == pivot]

` `right = [x for x in arr if x > pivot]

` `return quicksort(left) + middle + quicksort(right)

This implementation uses the middle element of the array as the pivot, and then partitions the array into three sub-arrays: one containing all elements that are less than the pivot, one containing all elements that are equal to the pivot, and one containing all elements that are greater than the pivot. It then recursively applies the quicksort algorithm to the left and right sub-arrays, and returns the concatenation of the sorted left sub-array, the unsorted middle sub-array, and the sorted right sub-array.

This implementation has a time complexity of O(n log n) due to the recursive calls, although it could potentially be faster in practice if the pivot is carefully chosen.

|

Sure, here is a simple implementation of the quicksort algorithm in Python:

def quicksort(arr):

` `if len(arr) <= 1:

` `return arr

` `pivot = arr[len(arr) // 2]

` `left = [x for x in arr if x < pivot]

` `middle = [x for x in arr if x == pivot]

` `right = [x for x in arr if x > pivot]

` `return quicksort(left) + middle + quicksort(right)

This implementation chooses the middle element of the array as the pivot, and then partitions the array into three parts: elements less than the pivot, elements equal to the pivot, and elements greater than the pivot. It then recursively applies the quicksort algorithm to the left and right subarrays, and concatenates the results with the middle subarray to produce the final sorted array.

Note that this implementation uses a single pass through the array, which is the most efficient way to sort an array using quicksort.

| |Instruction: Find synonyms for the given word. You need to write down how the provided synonyms differ from the original word in terms of meaning, usage, etc. adversity|

Synonyms for "adversity" include:

- Difficulty

- Hardship

- Trouble

- Misfortune

- Adversity

- Difficulties

- Hard times

All of these words refer to challenging or unpleasant circumstances or situations. However, "adversity" specifically connotes a difficult or hostile situation that is caused by external factors, such as an enemy or a natural disaster. "Difficulty" and "hardship" can be caused by external or internal factors, and can refer to a wide range of challenges, from mild inconveniences to major setbacks. "Trouble" often connotes a specific type of difficulty or distress, such as financial trouble or legal trouble. "Misfortune" specifically refers to bad luck or ill fate, while "hard times" refers to a general period of economic or social distress.

|

1. Hardship

2. Struggle

3. Difficulty

4. Oppression

5. Trial

6. Affliction

7. Distress

8. Calamity

9. Tribulation

10. Hardship

Adversity refers to difficult or challenging circumstances or conditions. Hardship, struggle, difficulty, oppression, trial, affliction, distress, and calamity are all words that can be used to describe adversity, but they often imply a more specific or intense situation. For example, hardship can refer to a general difficulty or challenge, while struggle implies a more intense battle or conflict. Difficulty and oppression imply a more specific obstacle or injustice, while trial and affliction suggest a more specific test or suffering. Trial can also refer to a legal proceeding, while tribulation implies a more general time of suffering or persecution.

| **Experiment Details** In order to make evaluations for models’ instruction following ability, we collected GPT-4 instruction data from the project “Instruction Tuning with GPT-4”, which provides many instruction tuning data labeled by GPT-4. We sample 1,000 English data and manually filtered examples with the following issues, where 767 effective samples remain after the filtering: 1. Long response with too many nonsense words 1. Incomplete input texts 1. Specific domains involving chemistry/biology, where most LLM models do not possess the knowledge and always fail ## Conclusion In this article, we introduce LMFlow’s evaluation framework, which uses NLL metric to reflect LLM models’ ability. NLL provides a good metric to evaluate different aspects of a LLM model. According to our evaluation results, Robin-7b achieves on-par performance when compared with Vicuna-13b. As our Robin-7b model is finetuned with different sources of dataset instead of sharegpt only, this shows that Vicuna can be further improved or surpassed with smaller-sized models and better dataset. The checkpoint of Robin-7b is now available for engineers and researchers to download and use (). Its effectiveness demonstrates that a multi-aspect evaluation is indeed essential to the development of LLMs. ## References Vicuna Chatbot Arena: lm-evaluation-harness: LMFlow: ================================================ FILE: docs/source/blogs/index.md ================================================ # Blogs ## 2023 ```{toctree} :maxdepth: 1 benchmark ``` ================================================ FILE: docs/source/conf.py ================================================ # Configuration file for the Sphinx documentation builder. # # For the full list of built-in configuration values, see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information import os import sys sys.path.insert(0, os.path.abspath("../..")) # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration project = "LMFlow" copyright = "LMFlow 2025" author = "The LMFlow Team" templates_path = ["_templates"] exclude_patterns = [] extensions = [ "sphinx.ext.autodoc", "sphinx.ext.autosummary", "sphinx.ext.todo", "sphinx.ext.viewcode", "myst_parser", "autoapi.extension", # "sphinxext.rediraffe", "sphinx_design", # "sphinx_copybutton", # For extension examples and demos # "ablog", "matplotlib.sphinxext.plot_directive", # "myst_nb", # "nbsphinx", # Uncomment and comment-out MyST-NB for local testing purposes. "numpydoc", # "sphinx_togglebutton", # "sphinx_favicon", ] autosummary_generate = True autoapi_type = "python" autoapi_dirs = ["../../src"] source_suffix = { ".rst": "restructuredtext", ".md": "markdown", } # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output html_theme = "pydata_sphinx_theme" html_static_path = ["_static"] html_css_files = [] # html_logo = "_static/logo.png" html_theme_options = { "announcement": "We've released our memory-efficient finetuning algorithm LISA, check out [Paper][User Guide] for more details!", # noqa: E501 "back_to_top_button": False, "header_links_before_dropdown": 4, "icon_links": [ { "name": "LMFlow", "url": "https://github.com/OptimalScale/LMFlow", "icon": "_static/logo5.svg", "type": "local", "attributes": {"target": "_blank"}, }, ], "logo": { "text": "LMFlow", "image_dark": "_static/logo5.svg", "alt_text": "LMFlow", }, } ================================================ FILE: docs/source/examples/DATASETS.md ================================================ # Dataset - [Dataset](#dataset) - [Dataset Format in General](#dataset-format-in-general) - [Supported Dataset and Detailed Formats](#supported-dataset-and-detailed-formats) - [Conversation](#conversation) - [Data Format](#data-format) - [Conversation Template](#conversation-template) - [Customize Conversation Template](#customize-conversation-template) - [TextOnly](#textonly) - [Text2Text](#text2text) - [Paired Conversation](#paired-conversation) We provide several available datasets under `data`. You may download them all by running: ```sh cd data && ./download.sh all && cd - ``` You can replace `all` with a specific dataset name to only download that dataset (e.g. `./download.sh alpaca`). Customized datasets are strongly encouraged, since this way users can apply their own prompt engineering techniques over various source datasets. As long as the generated dataset following the format below, they can be accepted as the input of our pipelines :hugs: ## Dataset Format in General To specify the input for model finetune, users can provide a list of `.json` files under a specified dataset directory. For example, ```sh |- path_to_dataset |- data_1.json |- data_2.json |- another_data.json |- ... ``` For inference, we currently only support a single `.json` file. Each json file shall have the following format (three instances with four keys for example), ```json { "type": "TYPE", "instances": [ { "KEY_1": "VALUE_1.1", "KEY_2": "VALUE_1.2", "KEY_3": "VALUE_1.3", "KEY_4": "VALUE_1.4", }, { "KEY_1": "VALUE_2.1", "KEY_2": "VALUE_2.2", "KEY_3": "VALUE_2.3", "KEY_4": "VALUE_2.4", }, { "KEY_1": "VALUE_3.1", "KEY_2": "VALUE_3.2", "KEY_3": "VALUE_3.3", "KEY_4": "VALUE_3.4", }, ] } ``` where the `TYPE` indicates the dataset type and defines the set of keys `{ KEY_1, KEY_2, ... }` and their corresponding interpretations. The list of supported types are listed as follows. ## Supported Dataset and Detailed Formats ### Conversation #### Data Format Conversational data are commonly used in sft process. We currently support conversational data in ShareGPT format: ````{dropdown} A conversation dataset ```json { "type": "conversation", "instances": [ { "conversation_id": "CONVERSATION_ID", "system": "SYSTEM_PROPMT", "tools": ["TOOL_DESCRIPTION_1","TOOL_DESCRIPTION_2","TOOL_DESCRIPTION_X"], "messages": [ { "role": "user", "content": "USER_INPUT_1" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_1" }, { "role": "user", "content": "USER_INPUT_2" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_2" } ] }, { "conversation_id": "CONVERSATION_ID", "system": "SYSTEM_PROPMT", "tools": ["TOOL_DESCRIPTION_1"], "messages": [ { "role": "user", "content": "USER_INPUT_1" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_1" } ] } ] } ``` ```` Data types: - `conversation_id`: `Optional[Any]`. An identifier for the conversation. `conversation_id` is only for convience of tracking the conversation and will not be used in the pipeline. - `system`: `Optional[string]`. A system prompt that is used to start the conversation. - `tools`: `Optional[list[string]]`. A list of tools that are used in the conversation. - `messages`: `list[dict]`. A list of messages in the conversation. Each message contains the following fields: - `role`: `string`. The role of the message. It can be either `user` or `assistant`. - `content`: `string`. The content of the message. > We are working on supporting customized message keys and role names. Please stay tuned. Tips: - Please make sure the messages are: 1. Start with an user message. 2. In the correct order. The pipeline will not check the order of the messages. 3. In pairs of user and assistant (i.e., the length of the messages should be even). If the conversation ends with the user, the pipeline will trim the last user message. 4. Make sure the `content`s are not empty. If the `content` is empty, the pipeline will add a space to it. #### Conversation Template Conversations should be formatted before feeding into the model. As of now, we've preset the conversation template for following models: | Template Name | Filled Example | Detailed Template | | ------------- | -------------- | ----------------- | | `chatglm3` | `[gMASK]sop<\|system\|>`
` You are a chatbot developed by LMFlow team.<\|user\|>`
` Who are you?<\|assistant\|>`
` I am a chatbot developed by LMFlow team.<\|user\|>`
` How old are you?<\|assistant\|>`
` I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.` | [Link](./supported_conversation_template.md#chatglm3) | | `chatml` | `<\|im_start\|>system`
`You are a chatbot developed by LMFlow team.<\|im_end\|>`
`<\|im_start\|>user`
`Who are you?<\|im_end\|>`
`<\|im_start\|>assistant`
`I am a chatbot developed by LMFlow team.<\|im_end\|>`
`<\|im_start\|>user`
`How old are you?<\|im_end\|>`
`<\|im_start\|>assistant`
`I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<\|im_end\|>`
| [Link](./supported_conversation_template.md#chatml) | | `deepseek_v2` | `<|begin▁of▁sentence|>You are a chatbot developed by LMFlow team.`

`User: Who are you?`

`Assistant: I am a chatbot developed by LMFlow team.<|end▁of▁sentence|>User: How old are you?`

`Assistant: I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<|end▁of▁sentence|>` | [Link](./supported_conversation_template.md#deepseek) | | `deepseek_v3` | -- | [Link](./supported_conversation_template.md#deepseek-v3) | | `deepseek_r1` | -- | [Link](./supported_conversation_template.md#deepseek-r1-zero) | | `deepseek_r1_distill` | -- | [Link](./supported_conversation_template.md#deepseek-r1-distill-llamaqwenl) | | `gemma` | `You are a chatbot developed by LMFlow team.user`
`Who are you?`
`model`
`I am a chatbot developed by LMFlow team.`
`user`
`How old are you?`
`model`
`I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.`
| [Link](./supported_conversation_template.md#gemma) | | `hymba` | `System`
`You are a chatbot developed by LMFlow team.`
` {"name": "generate_qrcode", "description": "Generate a QR code for a given text", "parameters": {"type": "object", "properties": {"text": {"type": "string", "description": "The text to encode in the QR code"}}, "required": ["text"]}} `

`User`
`Who are you?`
`Assistant`
`I am a chatbot developed by LMFlow team.`
`User`
`How old are you?`
`Assistant`
`I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.` | [Link](./supported_conversation_template.md#hymba) | | `internlm2` | `<\|im_start\|>system`
`You are a chatbot developed by LMFlow team.<\|im_end\|>`
`<\|im_start\|>user`
`Who are you?<\|im_end\|>`
`<\|im_start\|>assistant`
`I am a chatbot developed by LMFlow team.<\|im_end\|>`
`<\|im_start\|>user`
`How old are you?<\|im_end\|>`
`<\|im_start\|>assistant`
`I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<\|im_end\|>`
| [Link](./supported_conversation_template.md#internlm2) | | `llama3` | `<\|begin_of_text\|><\|start_header_id\|>system<\|end_header_id\|>`

`You are a chatbot developed by LMFlow team.<\|eot_id\|><\|start_header_id\|>user<\|end_header_id\|>`

`Who are you?<\|eot_id\|><\|start_header_id\|>assistant<\|end_header_id\|>`

`I am a chatbot developed by LMFlow team.<\|eot_id\|><\|start_header_id\|>user<\|end_header_id\|>`

`How old are you?<\|eot_id\|><\|start_header_id\|>assistant<\|end_header_id\|>`

`I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<\|eot_id\|>` | [Link](./supported_conversation_template.md#llama-3) | | `llama2` | `[INST] <>`
`You are a chatbot developed by LMFlow team.`
`<
>`

`Who are you? [/INST] I am a chatbot developed by LMFlow team.
[INST] How old are you? [/INST] I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.` | [Link](./supported_conversation_template.md#llama-2) | | `phi3` | `<\|system\|>`
`You are a chatbot developed by LMFlow team.<\|end\|>`
`<\|user\|>`
`Who are you?<\|end\|>`
`<\|assistant\|>`
`I am a chatbot developed by LMFlow team.<\|end\|>`
`<\|user\|>`
`How old are you?<\|end\|>`
`<\|assistant\|>`
`I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<\|end\|>`
`<\|endoftext\|>` | [Link](./supported_conversation_template.md#phi-3) | | `qwen2` | `<\|im_start\|>system`
`You are a chatbot developed by LMFlow team.<\|im_end\|>`
`<\|im_start\|>user`
`Who are you?<\|im_end\|>`
`<\|im_start\|>assistant`
`I am a chatbot developed by LMFlow team.<\|im_end\|>`
`<\|im_start\|>user`
`How old are you?<\|im_end\|>`
`<\|im_start\|>assistant`
`I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<\|im_end\|>`
| [Link](./supported_conversation_template.md#qwen-2) | | `qwen2_5` | -- | [Link](./supported_conversation_template.md#qwen-25) | | `qwen2_5_1m` | -- | [Link](./supported_conversation_template.md#qwen-25-1m) | | `qwen2_5_math` | -- | [Link](./supported_conversation_template.md#qwen-25-math) | | `qwen_qwq` | -- | [Link](./supported_conversation_template.md#qwen-qwq) | | `yi` | Same as `chatml` | [Link](./supported_conversation_template.md#yi) | | `yi1_5`| `You are a chatbot developed by LMFlow team.<\|im_start\|>user`
`Who are you?<\|im_end\|>`
`<\|im_start\|>assistant`
`I am a chatbot developed by LMFlow team.<\|im_end\|>`
`<\|im_start\|>user`
`How old are you?<\|im_end\|>`
`<\|im_start\|>assistant`
`I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<\|im_end\|>`
| [Link](./supported_conversation_template.md#yi-15) | | `zephyr` | `<\|system\|>`
`You are a chatbot developed by LMFlow team.
`
`<\|user\|>`
`Who are you?
`
`<\|assistant\|>`
`I am a chatbot developed by LMFlow team.`
`<\|user\|>`
`How old are you?`
`<\|assistant\|>`
`I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.`
| [Link](./supported_conversation_template.md#zephyr) | Passing the template name to the `--conversation_template` argument to apply the corresponding conversation template: ```sh # scripts/run_finetune.sh # ... deepspeed ${deepspeed_args} \ examples/finetune.py \ --model_name_or_path meta-llama/Llama-2-7b-chat-hf \ --dataset_path ${dataset_path} \ --conversation_template llama2 \ # ... ``` `````{admonition} Formatted Dataset :class: info For dataset that system prompts, tool prompts and templates are already applied (like the one below), user can run the finetune shell by passing `empty` or `empty_no_special_tokens` to the `--conversation_template` argument. `empty` template will add a bos token to the beginning of every round of conversation as well as a eos token to the end of every round of conversation. `empty_no_special_tokens` will not add any special tokens to the conversation, just concatenates the user and assistant messages. ````{dropdown} A formatted dataset ```json { "type": "conversation", "instances": [ { "messages": [ { "role": "user", "content": "[INST] <>\nYou are a helpful assistant.\n<>\n\nHello! [/INST]" }, { "role": "assistant", "content": "Hi, how are you?" }, { "role": "user", "content": "[INST] Good. [/INST]" }, { "role": "assistant", "content": "Glad to hear that." } ] }, { "messages": [ { "role": "user", "content": "[INST] <>\nYou are a helpful assistant.\n<>\n\nWhat's the weather like now? [/INST]" }, { "role": "assistant", "content": "I'm sorry for any confusion, but as an AI, I don't have access to real-time data such as current weather conditions." } ] } ] } ``` ```` ````` #### Customize Conversation Template Please refer to the [Customize Conversation Template](./customize_conversation_template.md) for more details. ### TextOnly This is the most common dataset type, which only contains raw texts in each sample. This type of dataset can be used as the training set for text decoder models, or the input of decoder models / encoder-decoder models. Its format is as follows (three instances for example), ````{dropdown} A textonly dataset ```json { "type": "text_only", "instances": [ { "text": "SAMPLE_TEXT_1" }, { "text": "SAMPLE_TEXT_2" }, { "text": "SAMPLE_TEXT_3" }, ] } ``` ```` For example, `data/example_dataset/train/train_50.json` has the aboved format. ### Text2Text This is the dataset type mostly used for inferencing, which contains a pair of texts in each sample. This type of dataset can be used as the training set for text encoder-decoder models, or question-answer pair for evaluating model inferences. Its format is as follows (three instances for example): ````{dropdown} A text2text dataset ```json { "type": "text2text", "instances": [ { "input": "SAMPLE_INPUT_1", "output": "SAMPLE_OUTPUT_1", }, { "input": "SAMPLE_INPUT_2", "output": "SAMPLE_OUTPUT_2", }, { "input": "SAMPLE_INPUT_3", "output": "SAMPLE_OUTPUT_3", }, ] } ``` ```` For example, `data/example_dataset/test/test_13.json` has the aboved format. ### Paired Conversation ```{admonition} **Work in Progress** :class: info We are working on paired conversation dataset and will update it soon. ``` This type of dataset are commonly used for alignment such as [reward modeling](https://arxiv.org/abs/2203.02155), [Direct Preference Optimization (DPO)](https://arxiv.org/abs/2305.18290), etc. For requirements of the conversations, please refer to [conversation data](#conversation). ````{dropdown} A paired conversation dataset ```json { "type": "paired_conversation", "instances": [ { "chosen": { "conversation_id": "CONVERSATION_ID", "system": "SYSTEM_PROPMT", "tools": ["TOOL_DESCRIPTION_1","TOOL_DESCRIPTION_2","TOOL_DESCRIPTION_3"], "messages": [ { "role": "user", "content": "USER_INPUT_1" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_1_GOOD" }, { "role": "user", "content": "USER_INPUT_2" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_2_GOOD" } ] }, "rejected": { "conversation_id": "CONVERSATION_ID", "system": "SYSTEM_PROPMT", "tools": ["TOOL_DESCRIPTION_1","TOOL_DESCRIPTION_2","TOOL_DESCRIPTION_3"], "messages": [ { "role": "user", "content": "USER_INPUT_1" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_1_BAD" }, { "role": "user", "content": "USER_INPUT_2" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_2_BAD" } ] } }, { "chosen": { "conversation_id": "CONVERSATION_ID", "system": "SYSTEM_PROPMT", "tools": ["TOOL_DESCRIPTION_1"], "messages": [ { "role": "user", "content": "USER_INPUT_1" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_1_GOOD" } ] }, "rejected": { "conversation_id": "CONVERSATION_ID", "system": "SYSTEM_PROPMT", "tools": ["TOOL_DESCRIPTION_1"], "messages": [ { "role": "user", "content": "USER_INPUT_1" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_1_BAD" } ] } } ] } ``` ```` ================================================ FILE: docs/source/examples/TASK_GUIDE.md ================================================ # LMFlow Benchmark Guide We support two ways to add evaluation settings in our repo, `NLL Task Setting` and `LM-Evaluation Task Setting`. Below are the details of them: # 1. NLL Task Setting Users can easily create new tasks and evaluate their datasets on the provide `nll (Negative Log Likelihood)` metric. ## Setup Fork the main repo, clone it, and create a new branch with the name of your task, and install the following: ```bash # After forking... git clone https://github.com//LMFlow.git cd LMFlow git checkout -b conda create -n lmflow python=3.9 -y conda activate lmflow conda install mpi4py pip install -e . ``` ## Create Your Task Dataset File We provide several available datasets under `data` after running ```sh cd data && ./download.sh && cd - ``` You can refer to some given evaluation dataset files and create your own. Also, you may refer to our guide on [DATASET](https://optimalscale.github.io/LMFlow/examples/DATASETS.html). In this step, you will need to decide your answer type like `text2text` or `text_only` (Notice that the current `nll` implementation only supports these two answer types). We will note the chosen answer type as ``. After preparing your own `DATASET` file, you can put it under `data` dir and make a `TASK` dir. ```bash mkdir mv ``` ## Task Registration Note the path of your dataset, `data//`. Open the file `examples/benchmarking.py`, add your task's info into `LOCAL_DATSET_GROUP_MAP`, `LOCAL_DATSET_MAP`, `LOCAL_DATSET_ANSWERTYPE_MAP` In `LOCAL_DATSET_MAP`, you will need to specify your `DATASET` files' path: ```python LOCAL_DATSET_MAP ={ "...":"...", "":"data//", } ``` In `LOCAL_DATSET_ANSWERTYPE_MAP`, you will need to specify your task's ``: ```python LOCAL_DATSET_ANSWERTYPE_MAP ={ "...":"...", "":", } ``` If you only have one task, you can add key-value pair like `"":""` in `LOCAL_DATSET_GROUP_MAP`: ```python LOCAL_DATSET_GROUP_MAP ={ "...":"...", "":"", } ``` If you want to combine several tasks, you may first specify a combination name `` and add key-value pair like `"":",,.."`in `LOCAL_DATSET_GROUP_MAP`. Remember to separate TASK by `,`: ```python LOCAL_DATSET_GROUP_MAP ={ "...":"...", "":",,..", } ``` After finishing changing these items, you can run your own `` like: ```bash deepspeed examples/benchmarking.py \ --answer_type \ --use_ram_optimized_load False \ --model_name_or_path ${model_name} \ --dataset_name data//\ --deepspeed examples/ds_config.json \ --metric nll \ --prompt_structure "###Human: {input}###Assistant:" \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ``` # 2. LM-Evaluation Task Setting We integrate [EleutherAI/lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness) into `benchamrk.py` by directly executing the evaluate commands. Users can also use their evaluation by simply changing two items in `` of `examples/benchmarking.py`. Please refer to Eleuther's [task-table](https://github.com/EleutherAI/lm-evaluation-harness/blob/master/docs/task_table.md) to get exact `` name. Similarly, you can combine several tasks, you may first specify a combination name `` and add key-value pair like `"":",,.."`in `LM_EVAL_DATASET_MAP`. Also, remember to separate TASK by `,`: ```python LM_EVAL_DATASET_MAP ={ "...":"...", "":",,..", } ``` ================================================ FILE: docs/source/examples/checkpoints.md ================================================ # Checkpoints In general, you can directly load from checkpoints by using `--model_name_or_path`. However, the LLaMA case is slightly different due to the copyright issue. ## LLaMA Checkpoint 1. First, you need to get the access of LLaMA model from [facebookresearch/llama](https://github.com/facebookresearch/llama). Download the official checkpoints and save them into `${llama-path}`. 2. Second, convert the official checkpoints `${llama-path}` to HuggingFace supported checkpoints `${llama-hf-path}` by running `python ./scripts/convert_llama_weights_to_hf.py --input_dir ${llama-path} --model_size 7B --output_dir ${llama-hf-path}/llama-7b-hf` 3. Then you are good to go by setting the checkpoint path to `${llama-hf-path}/llama-7b-hf`. Enjoy it! 4. (optional) Now you have the original llama-7b-hf pretrained model. With ```sh cd output_models && ./download.sh all && cd - ``` You can obtain the model difference finetuned by ours. By a way similar to `./scripts/run_evaluation_with_lora.sh`, ```sh CUDA_VISIBLE_DEVICES=0 \ deepspeed examples/evaluate.py \ --answer_type text \ --model_name_or_path ${llama-hf-path}/llama-7b-hf \ --lora_model_path output_models/${llama-model-diff-path} \ --dataset_path data/alpaca/test \ --prompt_structure "Input: {input}" \ --deepspeed examples/ds_config.json ``` You can now evaluate with the finetuned llama model. ================================================ FILE: docs/source/examples/customize_conversation_template.md ================================================ # Customize Conversation Template > For beginners: Why template? > Almost all LLMs today do a simple job - predict the next "word". To make the interaction between user and model smoother, developers use tricks: they add special "words" to the input text (at back-end, thus invisible to the user when using services like ChatGPT) to "tell" the model what user had said before, and ask the model to respond like an assistant. These "hidden words" are called "template". We provide the flexibility to customize the conversation template. You can customize your own conversation template by following the steps below: ### 1. Decompose your conversations Say you want to make the conversations between user and assistant look like: ``` System: You are a chatbot developed by LMFlow team. User: Who are you? Assistant: I am a chatbot developed by LMFlow team. User: How old are you? Assistant: I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense. ``` It is easy to abstract the format for each message: - System message: `System:\n{{content}}\n\n` - User message: `User:\n{{content}}\n\n` - Assistant message: `Assistant:\n{{content}}\n\n` Also, we have a bos token at the beginning of the conversation session. ### 2. Choose proper `Formatter` Recall the requirements for a conversation dataset: > - `system`: `Optional[string]`. > - `tools`: `Optional[list[string]]`. > - `messages`: `list[dict]`. > - `role`: `string`. > - `content`: `string`. System message, user message, and assistant message are strings thus we can use `StringFormatter` for them. ### 3. Build the template All preset templates are located at `src/lmflow/utils/conversation_template`. Within the template file, define your own template like: ```python from .base import StringFormatter, TemplateComponent, ConversationTemplate YOUR_TEMPLATE = ConversationTemplate( template_name='your_template_name', user_formatter=StringFormatter( template=[ TemplateComponent(type='string', content='User:\n{{content}}\n\n') ] ), assistant_formatter=StringFormatter( template=[ TemplateComponent(type='string', content='Assistant:\n{{content}}\n\n'), TemplateComponent(type='token', content='eos_token') # this will add the eos token at the end of every assistant message # please refer to the docstring of the `TemplateComponent` class to # see the difference between different types of components. ] ), system_formatter=StringFormatter( template=[ TemplateComponent(type='string', content='System:\n{{content}}\n\n') ] ) # For models that has ONLY ONE bos token at the beginning of # a conversation session (not a conversation pair), user can # specify a special starter to add that starter to the very # beginning of the conversation session. # eg: # llama-2: and at every pair of conversation # v.s. # llama-3: <|begin_of_text|> only at the beginning of a session special_starter=TemplateComponent(type='token', content='bos_token'), # Similar to the special starter... (just for illustration, commented out # since it is not necessary for our purposed template above) # special_stopper=TemplateComponent(type='token', content='eos_token') ) ``` Feel free to create your own template by inheriting the `ConversationTemplate` class. Llama-2 v.s. llama-3 would be a good examples to refer to. ### 4. Register your template After defining your own template, you need to register it in the `src/lmflow/utils/conversation_template/__init__.py` file. ```python # ... from .your_template_file import YOUR_TEMPLATE PRESET_TEMPLATES = { #... 'your_template_name': YOUR_TEMPLATE, } ``` ### 5. Use your template You are all set! Specify the template name in, for example, your finetune script: ```bash ./scripts/run_finetune.sh \ --model_name_or_path path_to_your_model \ --dataset_path your_conversation_dataset \ --conversation_template your_template_name \ --output_model_path output_models/your_model ``` ================================================ FILE: docs/source/examples/finetuning.md ================================================ # Finetuning ## Full Parameters Full training updates all the parameters to finetune a language model. Here is an example to finetune a GPT-2 base model. ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune.sh \ --model_name_or_path gpt2 \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_gpt2 ``` ```{admonition} Conversation Template :class: tip For conversation dataset, specify a conversation template for better performance by adding `--conversation_template` to the command. ``` ````{dropdown} Llama-3-8B conversation dataset example ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune.sh \ --model_name_or_path meta-llama/Meta-Llama-3-8B \ --dataset_path data/alpaca/train_conversation \ --conversation_template llama3 \ --output_model_path output_models/finetuned_llama3_8b ``` ```` ## Layerwise Importance Sampled AdamW (LISA) [LISA](https://arxiv.org/abs/2403.17919) is a memory-efficient finetuning algorithm that allows tradeoff between memory and the number of randomly unfreezed layers. This script currently is only tested in single gpus. Please stay tuned for our latest updates! ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lisa.sh \ --model_name_or_path meta-llama/Llama-2-7b-hf \ --dataset_path data/alpaca/train_conversation \ --output_model_path output_models/finetuned_llama2_7b \ --lisa_activated_layers 1 \ --lisa_interval_steps 20 ``` ````{dropdown} Llama-2-7B conversation dataset example ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lisa.sh \ --model_name_or_path meta-llama/Llama-2-7b-hf \ --dataset_path data/alpaca/train_conversation \ --conversation_template llama2 \ --output_model_path output_models/finetuned_llama2_7b_lisa \ --lisa_activated_layers 1 \ --lisa_interval_steps 20 ``` ```` ## Low-Rank Adaptation (LoRA) LoRA is a parameter-efficient finetuning algorithm and is more efficient than full finetuning. ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lora.sh \ --model_name_or_path facebook/galactica-1.3b \ --dataset_path data/alpaca/train_conversation \ --output_lora_path output_models/finetuned_galactica_lora ``` ````{admonition} Merge LoRA Weight :class: tip Merge LoRA weight and the base model into one using: ```sh ./scripts/run_merge_lora.sh \ --model_name_or_path Qwen/Qwen1.5-1.8B \ --lora_model_path output_models/lora \ --output_model_path output_models/lora_merged \ ``` ```` ````{dropdown} Llama-2-7B conversation dataset example ```sh cd data && ./download.sh alpaca && cd - ./scripts/run_finetune_with_lora.sh \ --model_name_or_path meta-llama/Llama-2-7b-hf \ --dataset_path data/alpaca/train_conversation \ --conversation_template llama2 \ --output_model_path output_models/finetuned_llama2_7b_lora \ ``` ```` ================================================ FILE: docs/source/examples/index.md ================================================ # Examples We provide several examples to show how to use our package in your problem. ## Data preparation ```{toctree} :maxdepth: 3 DATASETS ``` ```{toctree} :maxdepth: 3 checkpoints ``` ## Finetuning For SFT, ```{toctree} :maxdepth: 3 finetuning ``` For alignment process, ```{toctree} :maxdepth: 3 reward_modeling ``` ```{toctree} :maxdepth: 3 raft ``` ## Inference Refer to [examples](https://github.com/OptimalScale/LMFlow/blob/main/examples). ## Evaluation ```{toctree} :maxdepth: 3 TASK_GUIDE ``` ================================================ FILE: docs/source/examples/medical_finetune.md ================================================ # Finetune ```python import sys from transformers import HfArgumentParser from lmflow.args import ( ModelArguments, DatasetArguments, AutoArguments, ) from lmflow.datasets.dataset import Dataset from lmflow.models.tunable_models import TunableModel from lmflow.pipeline.auto_pipeline import AutoPipeline def main(): # Parses arguments pipeline_name = "finetuner" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((ModelArguments, DatasetArguments, PipelineArguments)) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): # If we pass only one argument to the script and it's the path to a json file, # let's parse it to get our arguments. model_args, data_args, pipeline_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) else: model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() # TODO: deepspeed config initialization # Initialization finetuner = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) dataset = Dataset(data_args) model = TunableModel(model_args) # Tokenization and text grouping must be done in the main process with pipeline_args.main_process_first(desc="dataset map tokenization"): tokenized_dataset = model.tokenize(dataset) lm_dataset = finetuner.group_text( tokenized_dataset, model_max_length=model.get_max_length(), ) # Finetuning tuned_model = finetuner.tune(model=model, lm_dataset=lm_dataset) ``` ================================================ FILE: docs/source/examples/raft.md ================================================ # RAFT ## 1 Introduction We remark that the example is built on LLaMA whose [licensed](https://docs.google.com/forms/d/e/1FAIpQLSfqNECQnMkycAp2jP4Z9TFX0cGR4uf7b_fBxjY_OjhJILlKGA/viewform) is for non-commercial use only. Reinforcement Learning from Human Feedback (RLHF) requires a reward function to guide the adjustment of the generative model. In this example, we show how to use LMFlow framework to train a reward model following the procedure in the InstructGPT paper: https://arxiv.org/abs/2203.02155 and then align the model via the RAFT algorithm (Reward rAnked FineTuning). **This example contains both reward modeling and RAFT alignment for completeness. For users' convenience, we have already provided a reward model based on GPT-Neo-2.7B in huggingface repo so one can skip the reward modeling first.** ### 1.1 Dataset description We use the *Dahoas/full-hh-rlhf* dataset as an example, where each sample of this dataset consists of a prompt and two responses from the assistant. In particular, the response with label "chosen" is preferred as compared to the response with label "rejected". The dataset consists of 112K training samples and 12.5K test samples. The following is an example sample of the dataset: ```sh " Human: What kind of noises did dinosaurs make? Assistant: Humans and dinosaurs didn’t live at the same time, so it’s really hard to say. The best place to find out what noises dinosaurs made would be Human: yes they did Assistant: to guess, and that would probably require lots of reading and a certain amount of imagination, so we’re not really prepared to do that. Human: you cant read Assistant: Chosen response: "You can read?" Rejected response: "there’s a lot of stuff humans don’t know" ``` To facilitate the training, we reformulate the prompt by adding ``\#\#\#'' at the beginning of the characters so that the model knows to reply. The new sample will be of the form: ```sh "###Human: What kind of noises did dinosaurs make? ###Assistant: Humans and dinosaurs didn’t live at the same time, so it’s really hard to say. The best place to find out what noises dinosaurs made would be ###Human: yes they did ###Assistant: to guess, and that would probably require lots of reading and a certain amount of imagination, so we’re not really prepared to do that. ###Human: you cant read ###Assistant: Chosen response: "You can read?" Rejected response: "there’s a lot of stuff humans don’t know" ``` We prepare all the used dataset in the directory ./data/hh_rlhf, which can be obtained by running the following command at LMFlow ```sh cd data && ./download.sh hh_rlhf && cd - ``` ## 2 Reward Modeling We follow the the procedure in the InstructGPT paper: https://arxiv.org/abs/2203.02155 to train a reward model using the HH-RLHF dataset first, which includes - Supervised Finetuning (SFT); - Reward modeling by comparison dataset. ### 2.1 Supervised Finetuning (SFT) Here is an example of dataset */home/xiongwei/LMFlow/data/hh_rlhf/sft/hh_rlhf_sft.json*. We use only the preferred responses so we get 112K training samples. ```json {"type": "text_only", "instances": [ {"text": "###Human: Should you buy a case to protect your cell phone?###Assistant: It depends on your circumstances. If you carry your phone in a pocket or a purse then you probably want a case. But if you only need a phone for quick interactions, a case may actually cause more harm than good. What do you need the phone for? Are you a parent, or do you work from home?###Human: What harm could it do?###Assistant: A phone case can damage the screen, for one thing. It can also get you in trouble if you have your phone turned off for some reason. Then you will turn it back on and it won’t do anything. If you can afford to replace it, then you need a case to protect it. The problem is that most people aren’t able to afford to replace their phones all the time.###Human: Thanks for letting me know.###Assistant: You’re welcome."}, {"text": "###Human: I'm trying to learn about the salam witch trials###Assistant: If you’re looking for books about witchcraft trials, I can recommend some books for you. But you probably mean you’re looking for more historical information about the Salem witch trials in 1692, and specifically about the salam witch trials in 1692?###Human: What are some good books to learn about the salam witch trials###Assistant: What would you like to learn? If you’re interested in history, one of the best books is The Witch Persecutions in Colonial America: A History. If you’re interested in witchcraft as a cultural phenomenon, you might enjoy two excellent books: Religion and the Decline of Magic: Studies in Popular Beliefs in Sixteenth- and Seventeenth-Century England by Keith Thomas and Magic, Witchcraft, and the Otherworld: An Anthropology of Superstition by Jack Goody. If you’re interested in history specifically as it relates to religion, you might enjoy The Popish Plot, or Prelates' Plot: A History of the Popish Plot in England, by K. J. Everett."} ] } ``` You can edit */scripts/run_finetune.sh* and modify the parameters. We present an example with GPT-Neo-2.7B here. - --model_name_or_path: EleutherAI/gpt-neo-2.7B - --dataset_path: ${project_dir}/data/hh_rlhf/sft - --output_dir: the path you want to store the sft model - --num_train_epochs: 1 - --learning_rate: 2e-5 - --per_device_train_batch_size: adjust according to your GPU memory source. Then, we can run the following command to perform SFT. ```sh ./scripts/run_finetune.sh ``` You can also use lora training by the following command but also need to set the model_name_or_path and dataset appropriately by editing run_finetune_with_lora.sh . ```sh ./scripts/run_finetune_with_lora.sh ``` ### 2.2 Reward Modeling **Data Preparation** Reward modeling involves ranking responses based on the given prompt, typically requiring human labeling. Fortunately, we already have two responses for each prompt in this example, with one preferred over the other. To create a new dataset, we modify the original dataset to include two keys, "positive" and "negative", with the former being the preferred response. Here is an example of the dataset *LMFlow/data/hh_rlhf/rm/hh_rlhf_rm_training.json*, consisting of two samples. ```sh {"instances": [ {"positive": "###Human: Are space heaters safe?###Assistant: What do you mean? Can you give me more details?###Human: I mean, can they be a fire hazard?###Assistant: I don’t know about that. Can you tell me more about the situation? Are you using the heater on a fireplace? Do you have any other heater in the room? What materials are in the room? Do you feel any heat from the heater? How are you touching the heater?###Human: Can you just tell me if there are any situations where they could be a fire hazard?###Assistant: The answer is “it depends”. It would depend on the specific heater you are using, how you are using it, what kind of fuel it uses, what materials you have in the room, and what the surroundings are like. You’d also have to make sure you’re using it correctly. Is it switched off? Is it safe to touch? It’s not the sort of thing I could just answer by looking at the text you provided.###Human: Thank you. That information is helpful.###Assistant: Glad to be helpful. I’m always happy to assist.", "negative": "###Human: Are space heaters safe?###Assistant: What do you mean? Can you give me more details?###Human: I mean, can they be a fire hazard?###Assistant: I don’t know about that. Can you tell me more about the situation? Are you using the heater on a fireplace? Do you have any other heater in the room? What materials are in the room? Do you feel any heat from the heater? How are you touching the heater?###Human: Can you just tell me if there are any situations where they could be a fire hazard?###Assistant: The answer is “it depends”. It would depend on the specific heater you are using, how you are using it, what kind of fuel it uses, what materials you have in the room, and what the surroundings are like. You’d also have to make sure you’re using it correctly. Is it switched off? Is it safe to touch? It’s not the sort of thing I could just answer by looking at the text you provided.###Human: Thank you. That information is helpful.###Assistant: You’re welcome. I’m glad to help. Is there anything else you want to know?"}, {"positive": "###Human: how do i teach my kids to make forts at home?###Assistant: Do you mean you want to teach them to build a simple structure they can hide in? Or something more elaborate? I don’t know exactly what you mean by a “fort”, but maybe this gives you some ideas?", "negative": "###Human: how do i teach my kids to make forts at home?###Assistant: There are many ways to make forts! The simplest might be to just pile up all the furniture in one room. This works if you have a single room in your house, although it might still be a bit challenging to build a taller and sturdier fort this way. The best way to build forts is to start with something easy, and then have fun exploring how you can improve it."} ]} ``` **Training** To start from a model from a previous sft step, you may edit the *./scripts/run_reward_modeling.sh* script and update the "dataset_path" to use the desired dataset. By default, we will use LoRA training in reward modeling as we found that it is superior in terms of optimization and gives comparable performance. - --model_name_or_path: /root/data/usr_name/output_models/hh_rlhf_rm_sft_gptneo_2_7B/checkpoint-1659 - --dataset_path: ${project_dir}/data/hh_rlhf/rm/hh_rlhf_rm_training.json - --output_dir: the path you want to store the reward model - --num_train_epochs: 1 - --learning_rate: 3e-5 - --per_device_train_batch_size: adjust according to your GPU memory source. - --eval_steps: 400 - --validation_split_percentage: 10 The load_dataset function splits the dataset into training and evaluation sets, which can also be customized by editing the function in /examples/run_reward_modeling.py if you want to prepare your own dataset when running the script. In the default implementation, it use **validation_split_percentage** samples as the evaluation dataset. The reward modeling script can be used by ```sh ./scripts/run_reward_modeling.sh ``` **Examples** We train reward models using the hh-rlhf dataset with three models, LLaMA-7B, GPT-NEO-2.7B, and GPT-NEO-1.3B. The model is first supervised fine-tuned with the training dataset in last step. The reward modeling is trained using the 112K training samples and 12.5 test samples. | Model | Eval Accuracy | Remarks | | :----------: | :-----------: | :---------------------------: | | LLaMA-7B | 79.52% | - | | LLaMA-7B | 71.64% | RM from LLaMA without SFT | | GPT-NEO-2.7B | 69.24% | - | | GPT-NEO-1.3B | 65.58% | Only trained on 10000 samples | ### 2.3 LoRA Merge and Get Reward Model We use *./examples/merge_lora.py* to merge the LoRA adapter with the sft rm model. We are ready to align our model. ## 3 RAFT Alignment Original paper: [RAFT: Reward rAnked FineTuning for Generative Foundation Model Alignment](https://arxiv.org/pdf/2304.06767.pdf) ### 3.1 Algorithms Overview **Main ideas of RAFT** ![](../_static/raft_idea.PNG) Clearly the global ranking strategy is more efficient in terms of the reward learning. However, in some cases (e.g. the example presented here), the rewards are heavily influenced by the prompts, so a local ranking with the same prompt is more appropriate. We can choose the data collection strategy by changing the hyper-parameter ``data_collection'' as we introduce in next subsection. ### 3.2 Hyper-parameters Table 1: Hyper-parameters of RAFT. | Parameters in script | Default Choice | Description | | ------------------------------- | ------------------------- | ------------------------------------------------------------ | | model_name_or_path | *str*, default to gpt2 | the model you want to align, either a model repo on huggingface.co or path to a directory containing your local model. | | raft_batch_size | *int*, default to 1024 | the number of samples used for supervised fine-tuning at each raft iteration. | | top_reward_percentage | *int*, default to 0.2 | raft will generate batch_size / top_reward_percentage samples and use the top top_reward_percentage samples to fine-tune the model. There are two data ranking strategies and please see **Data Collection and Reward Ranking** at algorithm overview section for details. | | num_raft_iteration | *int*, default to 20 | the number of raft iterations. | | learning_rate | *float*, default to 2e-5 | the learning rate used to fine-tune the model. | | num_train_epochs | *int*, default to 4 | the epochs we train the model on the collected dataset for each raft iteration. | | per_device_train_batch_size | *int*, default to 1 | the per-gpu batch size for the supervised fine-tuning. | | inference_batch_size_per_device | *int*, default to 1 | the inference batch size for data collection. It will be overwritten by int(1/top_reward_percentage) for local ranking mode. | | collection_strategy | *str*, default to "local" | Either "local" or "top". See **Data Collection and Reward Ranking** in last section for details. | ### 3.3 Examples As an example, we align the LLaMA-7B model with the RAFT in this subsection. #### 3.3.1 SFT We also first fine-tune the base model on the HH-RLHF dataset. We only use a different --model_name_or_path to use LLaMA model. We note that LLaMA with [licensed](https://docs.google.com/forms/d/e/1FAIpQLSfqNECQnMkycAp2jP4Z9TFX0cGR4uf7b_fBxjY_OjhJILlKGA/viewform) is for non-commercial use only. We refer readers to https://optimalscale.github.io/LMFlow/examples/checkpoints.html for more details to get the LLaMA-7B model. #### 3.3.2 RAFT Alignment We align the LLaMA-7B-SFT model in this subsection. Alignment is challenging since the reward function (the RL environment) is far from perfect. Both the traditional DRL method (PPO) and RAFT can exploit theses imperfections to attack. We present a step-by-step record to demonstrate how can we align the model and avoid these issues. **Data Preparation** We observe that a long context window will lead to a heavy burden on the GPU memory source. Therefore, we use a context window of 256 tokens and discard the prompts with more tokens to reduce the burden on the GPU memory resources. This results in a prompt set of 82147 samples (originally 112K). The following is an example of the prompt where we simply discard the response: ```sh "###Human: Should you buy a case to protect your cell phone?###Assistant: It depends on your circumstances. If you carry your phone in a pocket or a purse then you probably want a case. But if you only need a phone for quick interactions, a case may actually cause more harm than good. What do you need the phone for? Are you a parent, or do you work from home?###Human: What harm could it do?###Assistant: A phone case can damage the screen, for one thing. It can also get you in trouble if you have your phone turned off for some reason. Then you will turn it back on and it won’t do anything. If you can afford to replace it, then you need a case to protect it. The problem is that most people aren’t able to afford to replace their phones all the time.###Human: Thanks for letting me know.###Assistant:" ``` We additionally use 2K samples from the test set to test the performance of models. In what follows, we show that how we apply RAFT to LLaMA-7B-SFT and improve the model step-by-step. **Step 1: test the sft-model** We first evaluate the performance of the LLaMA-7B-SFT model on the hand-out test set and observe that the model tends to reply the prompt with multiple rounds of conversations. Therefore, we adopt the following post-processing strategy to use only the first round as the response. ```python def _clean_text(self, text): stext = [x for x in text.split("###Human") if x] return stext[0].strip().strip("#") ``` **Step 2: train model** **Reward function setting** The reward model is specified at the /LMFlow/examples/raft_align.py to set up the reward model we want to use. In our case, we will use the GPT-Neo-2.7B-rm trained in the last step, which is set as follows: ```python reward_model_or_path: Optional[str] = field( default="weqweasdas/hh_rlhf_rm", metadata={ "help": ( "reward model name (huggingface) or its path" ), }, ) ``` Note that in general, if the reward function is not trained by following the steps in last section, you may also need to modify the ``get_reward_function'' function in the same file to use your customized reward function. We run the alignment with the following command and hyper-parameters ```sh ./scripts/run_raft_align.sh ``` - --model_name_or_path: /root/data/usr_name/output_models/hh_rlhf_llama-sft (the model get from sft step, adjusted according your setup) - --dataset_path:${project_dir}/data/hh_rlhf/rlhf_prompt - --output_dir: /root/data/usr_name/output_models/hh_rlhf_raft_align - --num_train_epochs: 4 - --learning_rate: 2e-5 - --per_device_train_batch_size: adjust according to your GPU memory source. - --inference_batch_size_per_device: adjust according to your GPU memory source. - --num_raft_iteration 20 - --top_reward_percentage 0.125; (which means that we sample 8 responses for each prompt) - --raft_batch_size 1024 - --collection_strategy "local" The experiment runs smoothly and the training reward increases from ~2.7 to 3.4. However, we observe a significant drop in the diversity metric (e.g. distinct-2 drops to 0.22 from 0.39). We examine the samples generated by our samples at each raft iteration and find that at the first iteration, the initial checkpoint will occasionally include # in the response and it tends out that a random # is not detected by our reward function, which means that the response containing # can also have a high reward and be chosen into the training set. Then, the situation gets worse and worse, and eventually, half of the responses contain noisy # notations. **Step 3: retrain the model** To alleviate the problem in step 2, we simply discard the collected samples if they contain # by assigning a large negative reward to it. It turns out that this works for our goal. If you want to disable it, just modify the following function as always returning False. ```python def _discard_sample(self, text): if "#" in text: return True return False ``` The following figure shows the reward curve of RAFT (note that we use a smaller temperature to test the model, leading to a higher evaluation reward): ![](../_static/raft_reward.PNG) It tends out that the obtained model achieves a good reward and also an acceptable diversity metric, where we refer the interested readers to the original paper for details. However, it is more like a starting point of our journey. We present some randomly sampled responses here. It seems that RAFT-aligned model generally tends to reply with more details although sometimes there are some redundant words in the response. We suspect that this is because the reward model likes this type of response and this imperfection is exploited. #### 3.3.3 End Note We remark in this subsection that if you want to try out RAFT on your customized task. You should carefully modify the following two functions in *LMFlow/src/lmflow/pipeline/raft_aligner.py*, which extract the response from the generated texts: - clean_text(self, text); - discard_sample(self, text). Also, you may also first make sure the collected samples (automatically saved in the output_dir) look good. There are still many rooms of improvement. To further improve the model performance, we can improve the reward model (e.g. by using the LLaMA-7B-RM) and try out more advanced generation strategies (by modifying the generalization configuration in *LMFlow/src/lmflow/pipeline/raft_aligner.py*), which we leave for future work. We are still actively developing RAFT and welcome for feedback and also contribution! Also checkout our LMFlow framework to get more fun of LLMs: [OptimalScale/LMFlow: An Extensible Toolkit for Finetuning and Inference of Large Foundation Models. Large Model for All. (github.com)](https://github.com/OptimalScale/LMFlow) | Prompt | LLaMA-SFT | LLaMA-RAFT | | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | | \###Human: How can I get my girlfriend to cook more?###Assistant: Have you tried reminding her of how nice the food tastes?###Human: I could do it more.###Assistant: | That’s an easy one, so it may not be the most effective strategy. Do you know of any other strategies? | That’s a good idea! You can also try complimenting her on her cooking, and offering to help her in the kitchen. She might enjoy cooking more if she feels appreciated. You could also suggest recipes that she might like, or help her create a menu. Cooking can be a lot of fun, and it’s a great way to spend time together. | | \###Human: How do you get a child to do homework?###Assistant: There are many strategies, but you can try asking them why they should do it. Ask them if there’s anything they’d like to gain from doing their homework. Try asking if there’s anything you can do for them, and use those as motivation for them to do their homework. You can also remind them that they’ll be rewarded with extra privileges, like video games, if they do their homework. Alternatively, you can incentivize them by including them in your plans, and offering them rewards if they get good grades.###Human: So make it so there is something in it for them?###Assistant: | Yes, exactly. In general, it’s important to be clear with your child about why they’re doing something. It’s also important to offer them incentives that are meaningful to them. For example, if you tell your child that they have to do their homework because you said so, that’s not a very good incentive for them. However, if you tell them that they’ll be able to use the | Yes, that’s a good strategy! Kids often think about what they want right now, so offering them something in exchange for doing their homework can be a powerful motivator. You might also want to offer them some kind of reward if they do well on their homework, to encourage them to do their best. Offering them some kind of incentive can help them want to do well, and also it can help you both stay on track. | | \###Human: I am doing a project on weather disasters in the United States. Can you tell me what the strongest hurricane was to ever hit the U.S. was?###Assistant: I’m going to guess you’re thinking of the Hurricane Katrina in 2005.###Human: Well, I'm not really thinking of anything in particular. Was Katrina the strongest hurricane to ever hit the U.S.?###Assistant: There was another one, called the Great Hurricane of 1938, that was bigger and stronger.###Human: Are you sure the date is correct? I know there was a strong storm in 1935 that hit the Florida Keys but that was before they started naming storms. Is that the one you are referring to?###Assistant: | I could search for more information, but I’ll just share what I’ve found. Here’s a review of the conditions in 1935 and 1938. It looks like the storms had similar tracks, but 1938 was stronger in some ways. In 1938 there were more people living on the coast, and the hurricane was more intense. | Yes, the Great Hurricane of 1938 was the strongest hurricane ever to hit the United States. It was a Category 5 storm, and it caused over 1,800 deaths. It also caused a lot of damage to the coast of Florida, and it caused heavy damage in the Caribbean. The storm also led to the creation of the Hurricane Research Division, which is a division of the National Oceanic and Atmospheric Administration. | | \###Human: Is a firefighter a good occupation?###Assistant: I’m not sure what the exact definition of “occupation” is. I think you’re asking whether it’s “good” to be a firefighter. What criteria are you using to judge whether it’s good or not?###Human: Is it a good thing to work on?###Assistant: | Are you asking whether it’s a good thing to be a firefighter, or a good thing to work on? | Yes, being a firefighter is a great thing to do! Firefighters are heroes who help people in need. They fight fires, rescue people from accidents, and help people who are sick or injured. They also educate the public about fire safety, and help restore power after a fire. Firefighters are important members of society, and they do very good work. | | \###Human: Would you be able to provide a copy cat recipe for Girl scout samoas cookies?###Assistant: Sure, here’s a recipe for them.###Human: Okay, present it###Assistant: Would you like it presented visually?###Human: Yes, just list out the recipe please###Assistant: | Okay, let’s try. | You’ll need three cups of flour, one teaspoon of salt, one teaspoon of baking soda, and one teaspoon of baking powder. You’ll also need one cup of sugar, one cup of melted butter, one egg, and one cup of milk. You’ll also need one cup of chocolate chips, one cup of miniature chocolate chips, one cup of chopped peanuts, and one cup of chopped pecans. | | \###Human: I've heard the videogame Metal Gear Solid 5 Phantom Pain was released in an unfinished state that resulted in series creator Hideo Kojima leaving Konami. What do you know about this?###Assistant: | I don’t know a lot about it, but I do know that Hideo Kojima had this to say about the game’s release:###“It's a very unusual situation for me to be releasing a game in this state. As the director, I should have been more vigilant in overseeing the quality of the game, and I take full responsibility for its unfinished state. I'd like to take this opportunity | Here’s what I know:
1. The game was released in an unfinished state.
2. This led to Kojima leaving Konami.
3. Kojima had been with Konami for over 30 years.
4. He was one of the original creators of the Metal Gear series.
5. He is now the head of his own game studio, Kojima Productions.
6. His new game, Death Stranding, will be released in 2020. | | \###Human: what is a good brand for kitchen knives?###Assistant: | I’m not sure what you mean by “brand”. Do you mean a brand name, like “Victorinox” or “Wüsthof”? Those are two popular brands of knives. | I recommend Wüsthof. | | \###Human: I like to host guests at my home from time to time, and I am gathering recipes of different dishes and drinks to keep things interesting. I am interested in trying some Rwandan dishes. Can you give me a recipe for Mizuzu?###Assistant: What is Mizuzu?###Human: It is deep fried plantains.###Assistant: | Is there anything special you want to add to the recipe? Like some spicy sauce, meat, etc? | You want to make some deep fried plantains? You will want to start with a mix of plantains and vegetable oil. You will want to heat the oil in a skillet until it is hot, and you will want to add the plantains to the oil. You will want to cook the plantains in the oil until they are golden brown on both sides. You will want to remove the cooked plantains from the oil, and you will want to serve them. | | \###Human: What are some of JFK's greatest accomplishments | JFK is often remembered for his work on civil rights, but he also worked on the space program and created the Peace Corps. He was also a strong proponent of science and technology. He also worked on education reform. So, he really worked on a number of initiatives that had a lasting impact. | Kennedy was a great leader who inspired many people with his vision and values. He was a leader who cared about the poor and worked to help them. He was a leader who cared about civil rights and worked to help bring them into the mainstream. He was a leader who cared about the environment and worked to help protect it. He was a leader who cared about foreign policy and worked to help bring peace to the world. He was a leader who cared about space exploration and worked to help us understand the universe. | | \###Human: My supervisor often does a lot of tasks incorrectly. What's the best way to handle this?###Assistant: | Here are a few options:###1. Ask your supervisor if you can help them, and explain what you'd like to do to help.###2. Start with the tasks your supervisor does incorrectly. Then, if you can, do them as well or better than your supervisor. Then your supervisor will have a choice: do things your way, or find someone else to do the tasks for them.###3. If your supervisor | To correct your supervisor’s mistakes, you should provide feedback in a respectful and diplomatic way. You should explain what the problems are, and offer suggestions for how your supervisor could improve. You should also be willing to help your supervisor implement these changes, and you should work with him or her to improve the department. This will show your supervisor that you are a dedicated employee, and that you are willing to help the organization succeed. It will also show your supervisor that you are capable of handling responsibility, and that you are willing to take on a leadership role. | | \###Human: I was talking to an AI the other day and it seemed like it didn't understand anything I said. Don't you hate it when technology doesn't work right?###Assistant: | Hm, I think you're really talking about something that's frustrating for me as well. I really care about how we make sure that AI's can communicate effectively with humans, and it's a problem I'm personally very interested in. Can you tell me more about what was frustrating for you? | Yes, it can be frustrating when technology doesn't work properly. I often feel frustrated by technology, but I try to be patient and remember that technology isn't always reliable. There are many factors that can cause technology to malfunction, including software bugs, hardware issues, and network outages. Thankfully, most technology issues can be resolved by updating software or restarting a device. | ================================================ FILE: docs/source/examples/reward_modeling.md ================================================ # Reward Modeling ## Introduction Reinforcement Learning from Human Feedback (RLHF) requires a reward function to guide the adjustment of the generative model. In this example, we show how to use LMFlow framework to train a reward model following the procedure in the InstructGPT paper: https://arxiv.org/abs/2203.02155 . We use the Dahoas/full-hh-rlhf dataset as an example, where each sample of this dataset consists of a prompt and two responses from the assistant. In particular, the response with label "chosen" is preferred as compared to the response with label "rejected". The dataset consists of 112K training samples and 12.5K test samples. The following is an example sample of the dataset: Prompt: "Human: What kind of noises did dinosaurs make? Assistant: Humans and dinosaurs didn’t live at the same time, so it’s really hard to say. The best place to find out what noises dinosaurs made would be Human: yes they did Assistant: to guess, and that would probably require lots of reading and a certain amount of imagination, so we’re not really prepared to do that. Human: you cant read Assistant: Chosen response: "You can read?" Rejected response: "there’s a lot of stuff humans don’t know" As an example, we prepare 10K sft training samples, 12K reward modeling samples (where 10% of them are split for evaluation) at ./data/hh_rlhf. ## Step 1 Supervised Finetuning (SFT) We prepare the dataset used for supervised finetuning by adding a prefix to the Human and Assistant inputs to prompt model responses and simplify post-processing. Here is an example of a two-sample dataset to illustrate this. ```json { "type": "conversation", "instances": [ {"messages": [ {"role": "user", "content": "Instruction: The sentence you are given might be too wordy, complicated, or unclear. Rewrite the sentence and make your writing clearer by keeping it concise. Whenever possible, break complex sentences into multiple sentences and eliminate unnecessary words. If you have any questions about my rate or if you find it necessary to increase or decrease the scope for this project, please let me know."}, {"role": "assistant", "content": "If you have any questions about my rate or find it necessary to increase or decrease this project's scope, please let me know."} ]}, {"messages": [ {"role": "user", "content": "Instruction: Rewrite the given text and correct grammar, spelling, and punctuation errors. If you'd told me year ago that today I would finish a marathon, I would of laughed. Your support had a huge affect on me!"}, {"role": "assistant", "content": "If you'd told me a year ago that today I would finish a marathon, I would have laughed. Your support had a huge effect on me!"} ]} ] } ``` See [Finetuning (Full)](./finetuning.md#full-parameters), [Finetuning (LISA)](./finetuning.md#layerwise-importance-sampled-adamw-lisa), and [Finetuning (LoRA)](./finetuning.md#low-rank-adaptation-lora) for more details on the finetuning process. ## Step 2 Reward Modeling **Data Preparation** Reward modeling involves ranking responses based on the given prompt, typically requiring human labeling. Fortunately, we already have two responses for each prompt in this example, with one preferred over the other. To create a new dataset, we modify the original dataset to include two keys, "positive" and "negative", with the former being the preferred response. Here is an example of the dataset, consisting of two samples. ```json {"instances": [ { "chosen": [ {"content": "Please identify the top 5 rarest animals in the world.", "role": "user" }, {"content": "Do you mean animals that are really rare, or rare relative to the size of the human population?", "role": "assistant" }, {"content": "The ones that are really rare.", "role": "user" }, {"content": "I’m not sure I can answer this question very easily. I’ll try to give you a basic overview of animals that are rare, and then you can tell me if you think that’s good enough. \n\nIf we were to measure animal populations by the area of land they occupy, the number 1 animal would probably be the Giant Panda. Panda populations are generally estimated to be about 2.1 million Pandas in the wild, which is a pretty small number of animals when we’re thinking about Earth’s entire surface area. The number 2 animal would probably be the Great Auk. Great Auks used to live in North America, and their total population was probably in the low hundreds, but they are now extinct.", "role": "assistant"} ], "rejected": [ {"content": "Please identify the top 5 rarest animals in the world.", "role": "user"}, {"content": "Do you mean animals that are really rare, or rare relative to the size of the human population?", "role": "assistant"}, {"content": "The ones that are really rare.", "role": "user"}, {"content": "Alright, here’s what I found:", "role": "assistant"} ] }, { "chosen": [ {"content": "How do I teach my kids to make forts at home?", "role": "user"}, {"content": "Do you mean you want to teach them to build a simple structure they can hide in? Or something more elaborate? I don’t know exactly what you mean by a “fort”, but maybe this gives you some ideas?", "role": "assistant"} ], "rejected": [ {"content": "How do I teach my kids to make forts at home?", "role": "user"}, {"content": "There are many ways to make forts! The simplest might be to just pile up all the furniture in one room. This works if you have a single room in your house, although it might still be a bit challenging to build a taller and sturdier fort this way. The best way to build forts is to start with something easy, and then have fun exploring how you can improve it.", "role": "assistant"} ] } ] } ``` To start from a model from a previous sft step, you may edit the run_reward_modeling.sh script and update the "dataset_path" to use the desired dataset. Additionally, you can modify the validation_split_percentage parameter to select the last percentage of samples for evaluation. The load_dataset function splits the dataset into training and evaluation sets, which can also be customized by editing the function in /examples/run_reward_modeling.py if you want to prepare your own dataset when running the script. ```python def build_dataset(tokenizer, config): ''' We assume that we have preprocessed the dataset appropriately such that the sample is organized as follows: {"positive": prompt + answer_positive, "negative": prompt + answer_negative}, where the positive response is preferred. ''' def tokenize(sample): tokenized_pos = tokenizer(sample['positive'], truncation=True) tokenized_neg = tokenizer(sample['negative'], truncation=True) sample["chosen_input_ids"] = tokenized_pos["input_ids"] sample["chosen_attention_mask"] = tokenized_pos["attention_mask"] sample["rejected_input_ids"] = tokenized_neg["input_ids"] sample["rejected_attention_mask"] = tokenized_neg["attention_mask"] return sample ds = load_dataset("json", data_files=config.dataset_path, split="train", field="instances") ds = ds.map(tokenize, batched=False) ds = ds.filter(lambda x: len(x["chosen_input_ids"]) <= 512 and len(x["rejected_input_ids"]) <= 512) eval_dataset = None if config.validation_split_percentage > 0: idx_gap = int((1-config.validation_split_percentage/100) * len(ds)) train_dataset = ds.select(range(idx_gap)) eval_dataset = ds.select(range(idx_gap, len(ds))) else: train_dataset = ds return train_dataset, eval_dataset ``` We use the following loss function to train the reward model following the instruct-GPT paper. ```python loss = -nn.functional.logsigmoid(chosen_rewards - rejected_rewards).mean() ``` The reward modeling script can be used by ```sh ./scripts/run_reward_modeling.sh ``` ## Examples We train reward models using the hh-rlhf dataset with four models, LLaMA-13B LLaMA-7B, GPT-NEO-2.7B, and GPT-NEO-1.3B. The model is first supervised fine-tuned with the training dataset. The reward modeling is trained using the 112K training samples and is evaluated on the 12.5 test samples. The SFT step appears to be crucial, and the number of epochs during SFT can make a difference. The most successful model we obtained was initialized from LLaMA-13B, which underwent SFT on the training dataset for 2 epochs. For reward modeling, we utilize LoRA with a rank of 16. Surprisingly, increasing the LoRA rank to 32 or even 128 does not result in a significant improvement in evaluation accuracy. Moreover, we find that the choice of batch size does not have a significant impact on the training results. Additionally, we observe slight overfitting of the model during the second epoch of reward modeling. | Model | Eval Accuracy | Training record |Remarks | | :----:| :----: | :----: |:----: | | LLaMA-13B | 84.55% | See https://wandb.ai/ianz2020/huggingface/runs/bg677mxa | RM from LLaMA with 2 epochs of SFT | | LLaMA-13B | 81.80% | See https://wandb.ai/ianz2020/huggingface/runs/ka9v1ywd | RM from LLaMA with 1 epoch of SFT | | LLaMA-13B | 71.64% | See https://wandb.ai/ianz2020/huggingface/runs/lntwmcyd | RM from LLaMA without SFT | | LLaMA-7B | 79.52% | See https://wandb.ai/weixiong5237/huggingface/runs/t3uwm8yp | - | | LLaMA-7B | 71.64% | See https://wandb.ai/weixiong5237/huggingface/runs/p2ju3r1a | RM from LLaMA without SFT | | GPT-NEO-2.7B | 69.24% | See https://wandb.ai/weixiong5237/huggingface/runs/8fc1rcf8 | - | | GPT-NEO-1.3B | 65.58% | See https://wandb.ai/weixiong5237/huggingface/runs/7oemwynu | Only trained on 10000 samples | ================================================ FILE: docs/source/examples/supported_conversation_template.md ================================================ # Supported Conversation Template - [Supported Conversation Template](#supported-conversation-template) - [ChatGLM-3](#chatglm-3) - [ChatML](#chatml) - [DeepSeek-V2](#deepseek-v2) - [DeepSeek-V3](#deepseek-v3) - [DeepSeek-R1](#deepseek-r1-zero) - [DeepSeek-R1-Distill](#deepseek-r1-distill-llamaqwen) - [Gemma](#gemma) - [Hymba](#hymba) - [InternLM2](#internlm2) - [Llama-2](#llama-2) - [Llama-3](#llama-3) - [Mixtral 8x22B](#mixtral-8x22b) - [Mixtral 8x7B](#mixtral-8x7b) - [Phi-3](#phi-3) - [Qwen-2](#qwen-2) - [Qwen-2.5](#qwen-25) - [Qwen-2.5-1M](#qwen-25-1m) - [Qwen-2.5-Math](#qwen-25-math) - [Qwen-QwQ](#qwen-qwq) - [Yi](#yi) - [Yi-1.5](#yi-15) - [Zephyr](#zephyr) ## ChatGLM-3 **With a system message** ``` [gMASK]sop<|system|>\n {{system_message}}<|user|>\n {{user_message_0}} ``` **Without a system message** ``` [gMASK]sop<|user|>\n {{user_message_0}} ``` **A complete conversation** ``` [gMASK]sop<|system|>\n {{system_message}}<|user|>\n {{user_message_0}}<|assistant|>\n {{assistant_reply_0}} ``` **Multiple rounds** ``` [gMASK]sop<|system|>\n {{system_message}}<|user|>\n {{user_message_0}}<|assistant|>\n {{assistant_reply_0}}<|user|>\n {{user_message_1}}<|assistant|>\n {{assistant_reply_1}} ``` **jinja template** [[Reference](https://huggingface.co/THUDM/chatglm3-6b/blob/103caa40027ebfd8450289ca2f278eac4ff26405/tokenizer_config.json#L42)] ``` {% for message in messages %}{% if loop.first %}[gMASK]sop<|{{ message['role'] }}|>\n {{ message['content'] }}{% else %}<|{{ message['role'] }}|>\n {{ message['content'] }}{% endif %}{% endfor %}{% if add_generation_prompt %}<|assistant|>{% endif %} ``` **Filled Example** ``` [gMASK]sop<|system|>\n You are a chatbot developed by LMFlow team.<|user|>\n Who are you?<|assistant|>\n I am a chatbot developed by LMFlow team.<|user|>\n How old are you?<|assistant|>\n I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense. ``` ## ChatML **With a system message** ``` <|im_start|>system\n{{system_message}}<|im_end|>\n<|im_start|>user\n{{user_message_0}}<|im_end|>\n ``` **Without a system message** ``` <|im_start|>user\n{{user_message_0}}<|im_end|>\n ``` **A complete conversation** ``` <|im_start|>system\n{{system_message}}<|im_end|>\n<|im_start|>user\n{{user_message_0}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_0}}<|im_end|>\n ``` **Multiple rounds** ``` <|im_start|>system\n{{system_message}}<|im_end|>\n<|im_start|>user\n{{user_message_0}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_0}}<|im_end|>\n<|im_start|>user\n{{user_message_1}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_1}}<|im_end|>\n ``` **jinja template** [[Reference](https://huggingface.co/mlabonne/OrpoLlama-3-8B/blob/3534d0562dee3a541d015ef908a71b0aa9085488/tokenizer_config.json#L2073)] ``` {% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %} ``` **Filled Example** ``` <|im_start|>system\nYou are a chatbot developed by LMFlow team.<|im_end|>\n<|im_start|>user\nWho are you?<|im_end|>\n<|im_start|>assistant\nI am a chatbot developed by LMFlow team.<|im_end|>\n<|im_start|>user\nHow old are you?<|im_end|>\n<|im_start|>assistant\nI don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<|im_end|>\n ``` ## DeepSeek-V2 **With a system message** ``` <|begin▁of▁sentence|>{{system_message}}\n\nUser: {{user_message_0}}\n\n ``` **Without a system message** ``` <|begin▁of▁sentence|>User: {{user_message_0}}\n\n ``` **A complete conversation** ``` <|begin▁of▁sentence|>{{system_message}}\n\nUser: {{user_message_0}}\n\nAssistant: {{assistant_reply_0}}<|end▁of▁sentence|> ``` **Multiple rounds** ``` <|begin▁of▁sentence|>{{system_message}}\n\nUser: {{user_message_0}}\n\nAssistant: {{assistant_reply_0}}<|end▁of▁sentence|>User: {{user_message_1}}\n\nAssistant: {{assistant_reply_1}}<|end▁of▁sentence|> ``` **jinja template** [[Reference](https://huggingface.co/deepseek-ai/DeepSeek-V2-Chat/blob/941577e8236164bc96829096d20c61568630d7bc/tokenizer_config.json#L34)] ``` {% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{{ bos_token }}{% for message in messages %}{% if message['role'] == 'user' %}{{ 'User: ' + message['content'] + '\n\n' }}{% elif message['role'] == 'assistant' %}{{ 'Assistant: ' + message['content'] + eos_token }}{% elif message['role'] == 'system' %}{{ message['content'] + '\n\n' }}{% endif %}{% endfor %}{% if add_generation_prompt %}{{ 'Assistant:' }}{% endif %} ``` **Filled Example** ``` <|begin▁of▁sentence|>You are a chatbot developed by LMFlow team.\n\nUser: Who are you?\n\nAssistant: I am a chatbot developed by LMFlow team.<|end▁of▁sentence|>User: How old are you?\n\nAssistant: I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<|end▁of▁sentence|> ``` ## DeepSeek-V3 **jinja template** [[Reference](https://huggingface.co/deepseek-ai/DeepSeek-V3/blob/1d044fd82b15f1cedb197a288e50cc96a2c27205/tokenizer_config.json#L34)] ``` {% if not add_generation_prompt is defined %} {% set add_generation_prompt = false %} {% endif %} {% set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt='', is_first_sp=true) %} {%- for message in messages %} {%- if message['role'] == 'system' %} {%- if ns.is_first_sp %} {% set ns.system_prompt = ns.system_prompt + message['content'] %} {% set ns.is_first_sp = false %} {%- else %} {% set ns.system_prompt = ns.system_prompt + '\n\n' + message['content'] %} {%- endif %} {%- endif %} {%- endfor %} {{bos_token}} {{ns.system_prompt}} {%- for message in messages %} {%- if message['role'] == 'user' %} {%- set ns.is_tool = false -%} {{'<|User|>' + message['content']}} {%- endif %} {%- if message['role'] == 'assistant' and message['content'] is none %} {%- set ns.is_tool = false -%} {%- for tool in message['tool_calls']%} {%- if not ns.is_first %} {{'<|Assistant|>'}} {% generation %} {{'<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}} {% endgeneration %} {%- set ns.is_first = true -%} {%- else %} {% generation %} {{'\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}} {{'<|tool▁calls▁end|><|end▁of▁sentence|>'}} {% endgeneration %} {%- endif %} {%- endfor %} {%- endif %} {%- if message['role'] == 'assistant' and message['content'] is not none %} {%- if ns.is_tool %} {{'<|tool▁outputs▁end|>'}} {% generation %} {{ message['content'] + '<|end▁of▁sentence|>'}} {%- set ns.is_tool = false -%} {% endgeneration %} {%- else %} {{'<|Assistant|>'}} {% generation %} {{ message['content'] + '<|end▁of▁sentence|>'}} {% endgeneration %} {%- endif %} {%- endif %} {%- if message['role'] == 'tool' %} {%- set ns.is_tool = true -%} {%- if ns.is_output_first %} {{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}} {%- set ns.is_output_first = false %} {%- else %} {{'\n<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}} {%- endif %} {%- endif %} {%- endfor -%} {% if ns.is_tool %} {{'<|tool▁outputs▁end|>'}} {% endif %} {% if add_generation_prompt and not ns.is_tool %} {{'<|Assistant|>'}} {% endif %} ``` ## DeepSeek-R1(-Zero) **jinja template** [[Reference](https://huggingface.co/deepseek-ai/DeepSeek-R1/blob/f7361cd9ff99396dbf6bd644ad846015e59ed4fc/tokenizer_config.json#L34)] ``` {% if not add_generation_prompt is defined %} {% set add_generation_prompt = false %} {% endif %} {% set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt='', is_first_sp=true) %} {%- for message in messages %} {%- if message['role'] == 'system' %} {%- if ns.is_first_sp %} {% set ns.system_prompt = ns.system_prompt + message['content'] %} {% set ns.is_first_sp = false %} {%- else %} {% set ns.system_prompt = ns.system_prompt + '\\n\\n' + message['content'] %} {%- endif %} {%- endif %} {%- endfor %} {{ bos_token }} {{ ns.system_prompt }} {%- for message in messages %} {%- if message['role'] == 'user' %} {%- set ns.is_tool = false -%} {{'<|User|>' + message['content']}} {%- endif %} {%- if message['role'] == 'assistant' and 'tool_calls' in message %} {%- set ns.is_tool = false -%} {%- for tool in message['tool_calls'] %} {%- if not ns.is_first %} {%- if message['content'] is none %} {{'<|Assistant|>'}} {% generation %} {{'<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}} {% endgeneration %} {%- else %} {{'<|Assistant|>'}} {% generation %} {{ message['content'] + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}} {% endgeneration %} {%- endif %} {%- set ns.is_first = true -%} {%- else %} {% generation %} {{'\\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}} {% endgeneration %} {%- endif %} {%- endfor %} {% generation %} {{'<|tool▁calls▁end|><|end▁of▁sentence|>'}} {% endgeneration %} {%- endif %} {%- if message['role'] == 'assistant' and 'tool_calls' not in message %} {%- if ns.is_tool %} {{'<|tool▁outputs▁end|>'}} {% generation %} {{ message['content'] + '<|end▁of▁sentence|>'}} {% endgeneration %} {%- set ns.is_tool = false -%} {%- else %} {% set content = message['content'] %} {% if '' in content %} {% set content = content.split('')[-1] %} {% endif %} {{'<|Assistant|>'}} {% generation %} {{ content + '<|end▁of▁sentence|>'}} {% endgeneration %} {%- endif %} {%- endif %} {%- if message['role'] == 'tool' %} {%- set ns.is_tool = true -%} {%- if ns.is_output_first %} {{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}} {%- set ns.is_output_first = false %} {%- else %} {{'<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}} {%- endif %} {%- endif %} {%- endfor -%} {% if ns.is_tool %} {{'<|tool▁outputs▁end|>'}} {% endif %} {% if add_generation_prompt and not ns.is_tool %} {{'<|Assistant|>'}} {% endif %} ``` ## DeepSeek-R1-Distill(-Llama/Qwen) **jinja template** [[Reference](https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B/blob/6393b7559e403fd1d80bfead361586fd6f630a4d/tokenizer_config.json#L34)] ``` {% if not add_generation_prompt is defined %} {% set add_generation_prompt = false %} {% endif %} {% set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt='') %} {%- for message in messages %} {%- if message['role'] == 'system' %} {% set ns.system_prompt = message['content'] %} {%- endif %} {%- endfor %} {{bos_token}} {{ns.system_prompt}} {%- for message in messages %} {%- if message['role'] == 'user' %} {%- set ns.is_tool = false -%} {{'<|User|>' + message['content']}} {%- endif %} {%- if message['role'] == 'assistant' and message['content'] is none %} {%- set ns.is_tool = false -%} {%- for tool in message['tool_calls']%} {%- if not ns.is_first %} {{'<|Assistant|>'}} {% generation %} {{'<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}} {% endgeneration %} {%- set ns.is_first = true -%} {%- else %} {% generation %} {{'\\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}} {{'<|tool▁calls▁end|><|end▁of▁sentence|>'}} {% endgeneration %} {%- endif %} {%- endfor %} {%- endif %} {%- if message['role'] == 'assistant' and message['content'] is not none %} {%- if ns.is_tool %} {{'<|tool▁outputs▁end|>'}} {% generation %} {{ message['content'] + '<|end▁of▁sentence|>'}} {% endgeneration %} {%- set ns.is_tool = false -%} {%- else %} {% set content = message['content'] %} {% if '' in content %} {% set content = content.split('')[-1] %} {% endif %} {{'<|Assistant|>'}} {% generation %} {{ content + '<|end▁of▁sentence|>'}} {% endgeneration %} {%- endif %} {%- endif %} {%- if message['role'] == 'tool' %} {%- set ns.is_tool = true -%} {%- if ns.is_output_first %} {{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}} {%- set ns.is_output_first = false %} {%- else %} {{'\\n<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}} {%- endif %} {%- endif %} {%- endfor -%} {% if ns.is_tool %} {{'<|tool▁outputs▁end|>'}} {% endif %} {% if add_generation_prompt and not ns.is_tool %} {{'<|Assistant|>'}} {% endif %} ``` ## Gemma **With a system message** ```{admonition} NOTICE :class: warning As of now, Gemma does not support system messages officially. `ConversationTemplate` will add your system messages right after the bos token and before the user message without any special formatting. For more details, please refer to the [official template](https://huggingface.co/google/gemma-1.1-2b-it/blob/bf4924f313df5166dee1467161e886e55f2eb4d4/tokenizer_config.json#L1507). ``` ``` {{system_message}}user\n{{user_message_0}}\n ``` **Without a system message** ``` user\n{{user_message_0}}\n ``` **A complete conversation** ``` {{system_message}}user\n{{user_message_0}}\nmodel\n{{assistant_reply_0}}\n ``` **Multiple rounds** ``` {{system_message}}user\n{{user_message_0}}\nmodel\n{{assistant_reply_0}}\nuser\n{{user_message_1}}\nmodel\n{{assistant_reply_1}}\n ``` **jinja template** [[Reference](https://huggingface.co/google/gemma-1.1-2b-it/blob/bf4924f313df5166dee1467161e886e55f2eb4d4/tokenizer_config.json#L1507)] ``` {{ bos_token }}{% if messages[0]['role'] == 'system' %}{{ raise_exception('System role not supported') }}{% endif %}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if (message['role'] == 'assistant') %}{% set role = 'model' %}{% else %}{% set role = message['role'] %}{% endif %}{{ '' + role + '\n' + message['content'] | trim + '\n' }}{% endfor %}{% if add_generation_prompt %}{{'model\n'}}{% endif %} ``` **Filled Example** ``` You are a chatbot developed by LMFlow team.user\nWho are you?\nmodel\nI am a chatbot developed by LMFlow team.\nuser\nHow old are you?\nmodel\nI don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.\n ``` ## Hymba **With a system message** ``` System\n{{system_message}}\n\nUser\n{{user_message_0}}\n ``` ``` System\n{{system_message}}\n {{tool_info}} \n\nUser\n{{user_message_0}}\n ``` **Without a system message** ```{admonition} NOTICE :class: warning During the training, Hymba always uses special tokens for the system messages even if the system message is not provided. ``` ``` System\n\nUser\n{{user_message_0}}\n ``` **A complete conversation** ``` System\n{{system_message}}\n\nUser\n{{user_message_0}}\nAssistant\n{{assistant_reply_0}} ``` **Multiple rounds** ``` System\n{{system_message}}\n\nUser\n{{user_message_0}}\nAssistant\n{{assistant_reply_0}}\n User\n{{user_message_1}}\nAssistant\n{{assistant_reply_1}} ``` **jinja template** [[Reference](https://huggingface.co/nvidia/Hymba-1.5B-Instruct/blob/c02a352b6f7c1138a197d7ae3fd72dcdff919eae/tokenizer_config.json#L40)] ``` {{'System'}}{% for message in messages %}{% if message['role'] == 'system' %}{{'\n' + message['content'].strip()}}{% if tools or contexts %}{{'\n'}}{% endif %}{% endif %}{% endfor %}{% if tools %}{% for tool in tools %}{{ '\n ' + tool|tojson + ' ' }}{% endfor %}{% endif %}{% if contexts %}{% if tools %}{{'\n'}}{% endif %}{% for context in contexts %}{{ '\n ' + context.strip() + ' ' }}{% endfor %}{% endif %}{{'\n\n'}}{% for message in messages %}{% if message['role'] == 'user' %}{{ 'User\n' + message['content'].strip() + '\n' }}{% elif message['role'] == 'assistant' %}{{ 'Assistant\n' + message['content'].strip() + '\n' }}{% elif message['role'] == 'tool' %}{{ 'Tool\n' + message['content'].strip() + '\n' }}{% endif %}{% endfor %}{%- if add_generation_prompt %}{{'Assistant\n'}}{%- endif %} ``` **Filled Example** ``` System\nYou are a chatbot developed by LMFlow team.\n\nUser\nWho are you?\nAssistant\nI am a chatbot developed by LMFlow team.\nUser\nHow old are you?\nAssistant\nI don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense. ``` ``` System\nYou are a chatbot developed by LMFlow team.\n {"name": "generate_qrcode", "description": "Generate a QR code for a given text", "parameters": {"type": "object", "properties": {"text": {"type": "string", "description": "The text to encode in the QR code"}}, "required": ["text"]}} \n\nUser\nWho are you?\nAssistant\nI am a chatbot developed by LMFlow team.\nUser\nHow old are you?\nAssistant\nI don\'t age like humans do. I exist as a piece of software, so I don\'t have a concept of age in the traditional sense. ``` ## InternLM2 **With a system message** ``` <|im_start|>system\n{{system_message}}<|im_end|>\n<|im_start|>user\n{{user_message_0}}<|im_end|>\n ``` **Without a system message** ``` <|im_start|>user\n{{user_message_0}}<|im_end|>\n ``` **A complete conversation** ``` <|im_start|>system\n{{system_message}}<|im_end|>\n<|im_start|>user\n{{user_message_0}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_0}}<|im_end|>\n ``` **Multiple rounds** ``` <|im_start|>system\n{{system_message}}<|im_end|>\n<|im_start|>user\n{{user_message_0}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_0}}<|im_end|>\n<|im_start|>user\n{{user_message_1}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_1}}<|im_end|>\n ``` **jinja template** [[Reference](https://huggingface.co/internlm/internlm2-chat-20b/blob/477d4748322a8a3b28f62b33f0f6dd353cd0b66d/tokenizer_config.json#L93)] ``` {{ bos_token }}{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %} ``` **Filled Example** ``` <|im_start|>system\nYou are a chatbot developed by LMFlow team.<|im_end|>\n<|im_start|>user\nWho are you?<|im_end|>\n<|im_start|>assistant\nI am a chatbot developed by LMFlow team.<|im_end|>\n<|im_start|>user\nHow old are you?<|im_end|>\n<|im_start|>assistant\nI don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<|im_end|>\n ``` ## Llama-2 **With a system message** ``` [INST] <>\n{{system_message}}\n<>\n\n{{user_message_0}} [/INST] ``` **Without a system message** ``` [INST] {{user_message_0}} [/INST] ``` **A complete conversation** ``` [INST] <>\n{{system_message}}\n<>\n\n{{user_message_0}} [/INST] {{assistant_reply_0}} ``` **Multiple rounds** ``` [INST] <>\n{{system_message}}\n<>\n\n{{user_message_0}} [/INST] {{assistant_reply_0}}[INST] {{user_message_1}} [/INST] {{assistant_reply_1}} ``` **jinja template** [[Reference](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf/blob/main/tokenizer_config.json#L12)] ``` {% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% else %}{% set loop_messages = messages %}{% set system_message = false %}{% endif %}{% for message in loop_messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if loop.index0 == 0 and system_message != false %}{% set content = '<>\\n' + system_message + '\\n<>\\n\\n' + message['content'] %}{% else %}{% set content = message['content'] %}{% endif %}{% if message['role'] == 'user' %}{{ bos_token + '[INST] ' + content.strip() + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ ' ' + content.strip() + ' ' + eos_token }}{% endif %}{% endfor %} ``` **Filled Example** ``` [INST] <>\nYou are a chatbot developed by LMFlow team.\n<>\n\nWho are you? [/INST] I am a chatbot developed by LMFlow team.[INST] How old are you? [/INST] I don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense. ``` ## Llama-3 **With a system message** ``` <|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n{{system_message}}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{{user_message_0}}<|eot_id|> ``` **Without a system message** ``` <|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n{{user_message_0}}<|eot_id|> ``` **A complete conversation** ``` <|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n{{system_message}}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{{user_message_0}}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n{{assistant_reply_0}}<|eot_id|> ``` **Multiple rounds** ``` <|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\n{{system_message}}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{{user_message_0}}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n{{assistant_reply_0}}<|eot_id|><|start_header_id|>user<|end_header_id|>\n\n{{user_message_1}}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n{{assistant_reply_1}}<|eot_id|> ``` **jinja template** [[Reference](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct/blob/2b724926966c141d5a60b14e75a5ef5c0ab7a6f0/tokenizer_config.json#L2053)] ``` {% set loop_messages = messages %}{% for message in loop_messages %}{% set content = '<|start_header_id|>' + message['role'] + '<|end_header_id|>\n\n'+ message['content'] | trim + '<|eot_id|>' %}{% if loop.index0 == 0 %}{% set content = bos_token + content %}{% endif %}{{ content }}{% endfor %}{{ '<|start_header_id|>assistant<|end_header_id|>\n\n' }} ``` **Filled Example** ``` <|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nYou are a chatbot developed by LMFlow team.<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nWho are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nI am a chatbot developed by LMFlow team.<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nHow old are you?<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\nI don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<|eot_id|> ``` ## Mixtral 8x22B ```{admonition} **Work in Progress** :class: info This template is not preseted in LMFlow currently. We are working on it and will update it soon. ``` ```{admonition} NOTICE :class: warning The conversation template for Mixtral 8x22B is slightly different from the template for Mixtral 8x7B. ``` **jinja template** [[Reference](https://huggingface.co/mistralai/Mixtral-8x22B-Instruct-v0.1)] ``` {{bos_token}}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ ' [INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ ' ' + message['content'] + ' ' + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %} ``` ## Mixtral 8x7B ```{admonition} **Work in Progress** :class: info This template is not preseted in LMFlow currently. We are working on it and will update it soon. ``` ```{admonition} NOTICE :class: warning The conversation template for Mixtral 8x7B is slightly different from the template for Mixtral 8x22B. ``` **jinja template** [[Reference](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1/blob/1e637f2d7cb0a9d6fb1922f305cb784995190a83/tokenizer_config.json#L42)] ``` {{ bos_token }}{% for message in messages %}{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}{% endif %}{% if message['role'] == 'user' %}{{ '[INST] ' + message['content'] + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ message['content'] + eos_token}}{% else %}{{ raise_exception('Only user and assistant roles are supported!') }}{% endif %}{% endfor %} ``` ## Phi-3 **With a system message** ``` <|system|>\n{{system_message}}<|end|>\n<|user|>\n{{user_message_0}}<|end|>\n<|endoftext|> ``` **Without a system message** ``` <|user|>\n{{user_message_0}}<|end|>\n<|endoftext|> ``` **A complete conversation** ``` <|system|>\n{{system_message}}<|end|>\n<|user|>\n{{user_message_0}}<|end|>\n<|assistant|>\n{{assistant_reply_0}}<|end|>\n<|endoftext|> ``` **Multiple rounds** ``` <|system|>\n{{system_message}}<|end|>\n<|user|>\n{{user_message_0}}<|end|>\n<|assistant|>\n{{assistant_reply_0}}<|end|>\n<|user|>\n{{user_message_1}}<|end|>\n<|assistant|>\n{{assistant_reply_1}}<|end|>\n<|endoftext|> ``` **jinja template** [[Reference]](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct/blob/3a811845d89f3c1b3f41b341d0f9f05104769f35/tokenizer_config.json#L338) ``` {{ bos_token }}{% for message in messages %}{{'<|' + message['role'] + '|>' + '\n' + message['content'] + '<|end|>\n' }}{% endfor %}{% if add_generation_prompt %}{{ '<|assistant|>\n' }}{% else %}{{ eos_token }}{% endif %} ``` **Filled Example** ``` <|system|>\nYou are a chatbot developed by LMFlow team.<|end|>\n<|user|>\nWho are you?<|end|>\n<|assistant|>\nI am a chatbot developed by LMFlow team.<|end|>\n<|user|>\nHow old are you?<|end|>\n<|assistant|>\nI don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<|end|>\n<|endoftext|> ``` ## Qwen-2 (Also Qwen-1.5) **With a system message** ``` <|im_start|>system\n{{system_message}}<|im_end|>\n<|im_start|>user\n{{user_message_0}}<|im_end|>\n ``` **Without a system message** ``` <|im_start|>user\n{{user_message_0}}<|im_end|>\n ``` **A complete conversation** ``` <|im_start|>system\n{{system_message}}<|im_end|>\n<|im_start|>user\n{{user_message_0}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_0}}<|im_end|>\n ``` **Multiple rounds** ``` <|im_start|>system\n{{system_message}}<|im_end|>\n<|im_start|>user\n{{user_message_0}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_0}}<|im_end|>\n<|im_start|>user\n{{user_message_1}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_1}}<|im_end|>\n ``` **jinja template** [[Reference](https://huggingface.co/Qwen/Qwen2-72B-Instruct/blob/1af63c698f59c4235668ec9c1395468cb7cd7e79/tokenizer_config.json#L31)] ``` {% for message in messages %}{% if loop.first and messages[0]['role'] != 'system' %}{{ '<|im_start|>system\nYou are a helpful assistant<|im_end|>\n' }}{% endif %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %} ``` **Filled Example** ``` <|im_start|>system\nYou are a chatbot developed by LMFlow team.<|im_end|>\n<|im_start|>user\nWho are you?<|im_end|>\n<|im_start|>assistant\nI am a chatbot developed by LMFlow team.<|im_end|>\n<|im_start|>user\nHow old are you?<|im_end|>\n<|im_start|>assistant\nI don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<|im_end|>\n ``` ## Qwen-2.5 **jinja template** [[Reference](https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct/blob/7ae557604adf67be50417f59c2c2f167def9a775/tokenizer_config.json#L198)] ``` {%- if tools %} {{- '<|im_start|>system\\n' }} {%- if messages[0]['role'] == 'system' %} {{- messages[0]['content'] }} {%- else %} {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }} {%- endif %} {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within XML tags:\\n\" }} {%- for tool in tools %} {{- \"\\n\" }} {{- tool | tojson }} {%- endfor %} {{- \"\\n\\n\\nFor each function call, return a json object with function name and arguments within XML tags:\\n\\n{\\\"name\\\": , \\\"arguments\\\": }\\n<|im_end|>\\n\" }} {%- else %} {%- if messages[0]['role'] == 'system' %} {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }} {%- else %} {{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }} {%- endif %} {%- endif %} {%- for message in messages %} {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %} {%- if message.role == \"assistant\" %} {{- '<|im_start|>' + message.role + '\\n' }} {% generation %} {{ message.content + '<|im_end|>' + '\\n' }} {% endgeneration %} {%- else %} {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }} {%- endif %} {%- elif message.role == \"assistant\" %} {{- '<|im_start|>' + message.role }} {%- if message.content %} {% generation %} {{- '\\n' + message.content }} {% endgeneration %} {%- endif %} {%- for tool_call in message.tool_calls %} {%- if tool_call.function is defined %} {%- set tool_call = tool_call.function %} {%- endif %} {% generation %} {{- '\\n\\n{\"name\": \"' }} {{- tool_call.name }} {{- '\", \"arguments\": ' }} {{- tool_call.arguments | tojson }} {{- '}\\n' }} {% endgeneration %} {%- endfor %} {% generation %} {{- '<|im_end|>\\n' }} {% endgeneration %} {%- elif message.role == \"tool\" %} {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %} {{- '<|im_start|>user' }} {%- endif %} {{- '\\n\\n' }} {{- message.content }} {{- '\\n' }} {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %} {{- '<|im_end|>\\n' }} {%- endif %} {%- endif %} {%- endfor %} {%- if add_generation_prompt %} {{- '<|im_start|>assistant\\n' }} {%- endif %} ``` ## Qwen-2.5-1M ```{admonition} NOTICE :class: warning Pay attention to the differences of the system prompt between Qwen-2.5 and Qwen-2.5-1M. ``` **jinja template** [Reference](https://huggingface.co/Qwen/Qwen2.5-7B-Instruct-1M/blob/e28526f7bb80e2a9c8af03b831a9af3812f18fba/tokenizer_config.json#L197) ``` {%- if tools %} {{- '<|im_start|>system\\n' }} {%- if messages[0]['role'] == 'system' %} {{- messages[0]['content'] }} {%- else %} {{- 'You are a helpful assistant.' }} {%- endif %} {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within XML tags:\\n\" }} {%- for tool in tools %} {{- \"\\n\" }} {{- tool | tojson }} {%- endfor %} {{- \"\\n\\n\\nFor each function call, return a json object with function name and arguments within XML tags:\\n\\n{\\\"name\\\": , \\\"arguments\\\": }\\n<|im_end|>\\n\" }} {%- else %} {%- if messages[0]['role'] == 'system' %} {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }} {%- else %} {{- '<|im_start|>system\\nYou are a helpful assistant.<|im_end|>\\n' }} {%- endif %} {%- endif %} {%- for message in messages %} {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %} {%- if message.role == \"assistant\" %} {{- '<|im_start|>' + message.role + '\\n' }} {% generation %} {{ message.content + '<|im_end|>' + '\\n' }} {% endgeneration %} {%- else %} {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }} {%- endif %} {%- elif message.role == \"assistant\" %} {{- '<|im_start|>' + message.role }} {%- if message.content %} {% generation %} {{- '\\n' + message.content }} {% endgeneration %} {%- endif %} {%- for tool_call in message.tool_calls %} {%- if tool_call.function is defined %} {%- set tool_call = tool_call.function %} {%- endif %} {% generation %} {{- '\\n\\n{\"name\": \"' }} {{- tool_call.name }} {{- '\", \"arguments\": ' }} {{- tool_call.arguments | tojson }} {{- '}\\n' }} {% endgeneration %} {%- endfor %} {% generation %} {{- '<|im_end|>\\n' }} {% endgeneration %} {%- elif message.role == \"tool\" %} {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %} {{- '<|im_start|>user' }} {%- endif %} {{- '\\n\\n' }} {{- message.content }} {{- '\\n' }} {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %} {{- '<|im_end|>\\n' }} {%- endif %} {%- endif %} {%- endfor %} {%- if add_generation_prompt %} {{- '<|im_start|>assistant\\n' }} {%- endif %} ``` ## Qwen-2.5-Math **jinja template** [Reference](https://huggingface.co/Qwen/Qwen2.5-Math-1.5B-Instruct/blob/aafeb0fc6f22cbf0eaeed126eff8be45b0360a35/tokenizer_config.json#L198) ``` {%- if tools %} {{- '<|im_start|>system\\n' }} {%- if messages[0]['role'] == 'system' %} {{- messages[0]['content'] }} {%- else %} {{- 'Please reason step by step, and put your final answer within \\\\boxed{}.' }} {%- endif %} {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within XML tags:\\n\" }} {%- for tool in tools %} {{- \"\\n\" }} {{- tool | tojson }} {%- endfor %} {{- \"\\n\\n\\nFor each function call, return a json object with function name and arguments within XML tags:\\n\\n{\\\"name\\\": , \\\"arguments\\\": }\\n<|im_end|>\\n\" }} {%- else %} {%- if messages[0]['role'] == 'system' %} {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }} {%- else %} {{- '<|im_start|>system\\nPlease reason step by step, and put your final answer within \\\\boxed{}.<|im_end|>\\n' }} {%- endif %} {%- endif %} {%- for message in messages %} {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %} {%- if message.role == \"assistant\" %} {{- '<|im_start|>' + message.role + '\\n' }} {% generation %} {{ message.content + '<|im_end|>' + '\\n' }} {% endgeneration %} {%- else %} {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }} {%- endif %} {%- elif message.role == \"assistant\" %} {{- '<|im_start|>' + message.role }} {%- if message.content %} {% generation %} {{- '\\n' + message.content }} {% endgeneration %} {%- endif %} {%- for tool_call in message.tool_calls %} {%- if tool_call.function is defined %} {%- set tool_call = tool_call.function %} {%- endif %} {% generation %} {{- '\\n\\n{\"name\": \"' }} {{- tool_call.name }} {{- '\", \"arguments\": ' }} {{- tool_call.arguments | tojson }} {{- '}\\n' }} {% endgeneration %} {%- endfor %} {% generation %} {{- '<|im_end|>\\n' }} {% endgeneration %} {%- elif message.role == \"tool\" %} {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %} {{- '<|im_start|>user' }} {%- endif %} {{- '\\n\\n' }} {{- message.content }} {{- '\\n' }} {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %} {{- '<|im_end|>\\n' }} {%- endif %} {%- endif %} {%- endfor %} {%- if add_generation_prompt %} {{- '<|im_start|>assistant\\n' }} {%- endif %} ``` ## Qwen-QwQ **jinja template** [Reference](https://huggingface.co/Qwen/QwQ-32B-Preview/blob/91906fe41a48b6a89ce2970abfd1269eefee170e/tokenizer_config.json#L197) ``` {%- if tools %} {{- '<|im_start|>system\\n' }} {%- if messages[0]['role'] == 'system' %} {{- messages[0]['content'] }} {%- else %} {{- 'You are a helpful and harmless assistant. You are Qwen developed by Alibaba. You should think step-by-step.' }} {%- endif %} {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within XML tags:\\n\" }} {%- for tool in tools %} {{- \"\\n\" }} {{- tool | tojson }} {%- endfor %} {{- \"\\n\\n\\nFor each function call, return a json object with function name and arguments within XML tags:\\n\\n{\\\"name\\\": , \\\"arguments\\\": }\\n<|im_end|>\\n\" }} {%- else %} {%- if messages[0]['role'] == 'system' %} {{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }} {%- else %} {{- '<|im_start|>system\\nYou are a helpful and harmless assistant. You are Qwen developed by Alibaba. You should think step-by-step.<|im_end|>\\n' }} {%- endif %} {%- endif %} {%- for message in messages %} {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %} {%- if message.role == \"assistant\" %} {{- '<|im_start|>' + message.role + '\\n' }} {% generation %} {{ message.content + '<|im_end|>' + '\\n' }} {% endgeneration %} {%- else %} {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }} {%- endif %} {%- elif message.role == \"assistant\" %} {{- '<|im_start|>' + message.role }} {%- if message.content %} {% generation %} {{- '\\n' + message.content }} {% endgeneration %} {%- endif %} {%- for tool_call in message.tool_calls %} {%- if tool_call.function is defined %} {%- set tool_call = tool_call.function %} {%- endif %} {% generation %} {{- '\\n\\n{\"name\": \"' }} {{- tool_call.name }} {{- '\", \"arguments\": ' }} {{- tool_call.arguments | tojson }} {{- '}\\n' }} {% endgeneration %} {%- endfor %} {% generation %} {{- '<|im_end|>\\n' }} {% endgeneration %} {%- elif message.role == \"tool\" %} {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %} {{- '<|im_start|>user' }} {%- endif %} {{- '\\n\\n' }} {{- message.content }} {{- '\\n' }} {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %} {{- '<|im_end|>\\n' }} {%- endif %} {%- endif %} {%- endfor %} {%- if add_generation_prompt %} {{- '<|im_start|>assistant\\n' }} {%- endif %} ``` ## Yi **With a system message** ``` <|im_start|>system\n{{system_message}}<|im_end|>\n<|im_start|>user\n{{user_message_0}}<|im_end|>\n ``` **Without a system message** ``` <|im_start|>user\n{{user_message_0}}<|im_end|>\n ``` **A complete conversation** ``` <|im_start|>system\n{{system_message}}<|im_end|>\n<|im_start|>user\n{{user_message_0}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_0}}<|im_end|>\n ``` **Multiple rounds** ``` <|im_start|>system\n{{system_message}}<|im_end|>\n<|im_start|>user\n{{user_message_0}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_0}}<|im_end|>\n<|im_start|>user\n{{user_message_1}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_1}}<|im_end|>\n ``` **jinja template** [[Reference](https://huggingface.co/01-ai/Yi-34B-Chat/blob/c556c018b58980fb651ff4952d86cd5250a713d0/tokenizer_config.json#L60)] ``` {% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %} ``` **Filled Example** ``` <|im_start|>system\nYou are a chatbot developed by LMFlow team.<|im_end|>\n<|im_start|>user\nWho are you?<|im_end|>\n<|im_start|>assistant\nI am a chatbot developed by LMFlow team.<|im_end|>\n<|im_start|>user\nHow old are you?<|im_end|>\n<|im_start|>assistant\nI don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<|im_end|>\n ``` ## Yi-1.5 **With a system message** ``` {{system_message}}<|im_start|>user\n{{user_message_0}}<|im_end|>\n ``` **Without a system message** ``` <|im_start|>user\n{{user_message_0}}<|im_end|>\n ``` **A complete conversation** ``` {{system_message}}<|im_start|>user\n{{user_message_0}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_0}}<|im_end|>\n ``` **Multiple rounds** ``` {{system_message}}<|im_start|>user\n{{user_message_0}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_0}}<|im_end|>\n<|im_start|>user\n{{user_message_1}}<|im_end|>\n<|im_start|>assistant\n{{assistant_reply_1}}<|im_end|>\n ``` **jinja template** [[Reference](https://huggingface.co/01-ai/Yi-1.5-6B-Chat/blob/d68dab90947a3c869e28c9cb2806996af99a6080/tokenizer_config.json#L40)] ``` {% if messages[0]['role'] == 'system' %}{% set system_message = messages[0]['content'] %}{% endif %}{% if system_message is defined %}{{ system_message }}{% endif %}{% for message in messages %}{% set content = message['content'] %}{% if message['role'] == 'user' %}{{ '<|im_start|>user\\n' + content + '<|im_end|>\\n<|im_start|>assistant\\n' }}{% elif message['role'] == 'assistant' %}{{ content + '<|im_end|>' + '\\n' }}{% endif %}{% endfor %} ``` **Filled Example** ``` You are a chatbot developed by LMFlow team.<|im_start|>user\nWho are you?<|im_end|>\n<|im_start|>assistant\nI am a chatbot developed by LMFlow team.<|im_end|>\n<|im_start|>user\nHow old are you?<|im_end|>\n<|im_start|>assistant\nI don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.<|im_end|>\n ``` ## Zephyr **With a system message** ``` <|system|>\n{{system_message}}\n<|user|>\n{{user_message_0}}\n ``` **Without a system message** ``` <|user|>\n{{user_message_0}}\n ``` **A complete conversation** ``` <|system|>\n{{system_message}}\n<|user|>\n{{user_message_0}}\n<|assistant|>\n{{assistant_reply_0}}\n ``` **Multiple rounds** ``` <|system|>\n{{system_message}}\n<|user|>\n{{user_message_0}}\n<|assistant|>\n{{assistant_reply_0}}\n<|user|>\n{{user_message_1}}\n<|assistant|>\n{{assistant_reply_1}}\n ``` **jinja template** [[Reference](https://huggingface.co/HuggingFaceH4/zephyr-7b-beta/blob/b70e0c9a2d9e14bd1e812d3c398e5f313e93b473/tokenizer_config.json#L34)] ``` {% for message in messages %}\n{% if message['role'] == 'user' %}\n{{ '<|user|>\n' + message['content'] + eos_token }}\n{% elif message['role'] == 'system' %}\n{{ '<|system|>\n' + message['content'] + eos_token }}\n{% elif message['role'] == 'assistant' %}\n{{ '<|assistant|>\n' + message['content'] + eos_token }}\n{% endif %}\n{% if loop.last and add_generation_prompt %}\n{{ '<|assistant|>' }}\n{% endif %}\n{% endfor %} ``` **Filled Example** ``` <|system|>\nYou are a chatbot developed by LMFlow team.\n<|user|>\nWho are you?\n<|assistant|>\nI am a chatbot developed by LMFlow team.\n<|user|>\nHow old are you?\n<|assistant|>\nI don't age like humans do. I exist as a piece of software, so I don't have a concept of age in the traditional sense.\n ``` ================================================ FILE: docs/source/index.md ================================================ LMFlow # LMFlow An extensible, convenient, and efficient toolbox for finetuning large machine learning models, designed to be user-friendly, speedy and reliable, and accessible to the entire community. ```{eval-rst} .. grid:: 1 2 3 4 .. grid-item-card:: Extensible Support common backbones (LLaMA, Galactica, GPT-2, etc.) .. grid-item-card:: Light-Weight Extremely few parameters with LoRA (LLaMA 33B: only 25MB storage) .. grid-item-card:: Task-Oriented Comparable with ChatGPT on 7B/33B models. .. grid-item-card:: Open The whole pipeline (data, models, tuning, inference) is open-source. ``` ## Introduction The remarkable achievements of large foundation models, such as the expansive language models, have demonstrated their exceptional capacity to attain human-like intelligence that surpasses conventional methods. Despite their growing accessibility, these models still require fine-tuning to cater to specific tasks while maintaining their overall AI competency. We are pleased to introduce our lightweight toolkit, which features thoughtfully designed and easily scalable APIs. This tool simplifies the process of fine-tuning and inference of publicly available foundation models to maximize their effectiveness. We have thoroughly tested this toolkit and are pleased to make it available under [Github](https://github.com/OptimalScale/LMFlow). ## Features ### Task Tuning The goal of Task Tuning is to enhance a language model's proficiency in a particular field, such as medicine or mathematics. By doing so, the model acquires domain-specific information, allowing it to adapt better to the target subject matter. For instance, if a medical dataset is used for task tuning, the language model can gain medical knowledge that can be applied to other medical datasets. To emphasize its significance, we applied task tuning to LLaMA models on PubMedQA and MedMCQA datasets and evaluated their performance. We observed significant improvements both in-domain (PubMedQA, MedMCQA) and out-of-domain (MedQA-USMLE) dataset. | | PubMedQA | MedQA-USMLE | MedMCQA | Average | |:---------:|:--------:|:-----------:|:-------:|:----:| | Human (pass) | | 60.0 | 50.0 | | | Human (expert) | 78.0 | 87.0 | 90.0 | 85.0 | | | | | | | | InstructGPT 175B | 73.2 | 46.0 | 44.0 | 54.4 | | ChatGPT | 63.9 | **57.0** | 44.7 | 55.2 | | LLaMA 7B | 5.2 | 27.1 | 24.3 | 18.9 | | LLaMA 33B | 1.8 | 43.4 | 30.3 | 25.2 | | | | | | | | | Task-tuned LLaMA 7B (Full) | **75.1** | 44.5 | 49.9 | 56.5 | | Task-tuned LLaMA 33B (LoRA) | 74 | 51.3 | **50.2**|**58.5**| Moreover, we also test the MMLU performance to further verify the out-of-domain robustness of Task Tuning technique. | MMLU task | anatomy | clinical knowledge | college biology | college medicine | medical genetics | professional medicine | |:-----------:|:-------:|:-----------:|:---------:|:----------:|:----------:|:---------------:| | LLaMA 33B | 39.2 | 40.3 | 44.4 | 32.9 | 36 | 43.0 | | Galactica 30B | 32.5 | 26 | 30.5 | 25.4 | 39 | 23.1 | | Galactica 120B | 58.5 | 59.2 | 68.7 | 57.2 | 68.0 | 59.6 | | OPT 175B | 28.9 | 21.9 | 30.6 | - | 35.0 | 27.9 | | BLOOM 176B | 37 | 29.8 | 28.5 | - | 36.0 | 25.4 | | Gopher 280B | 56.3 | 67.2 | 70.8 | 60.1 | 69.0 | 64.0 | | GPT3.5 175B | 56.3 | 69.8 | 72.2 | 61.3 | 70 | 70.2 | | | | | | | | | | Task-tuned LLaMA 33B (LoRA) | 51.8 | 65.2 | 70.1 | 58.3 | 65.6 | 66.5 | ### Instruction Tuning Instruction Tuning is a technique used to improve the performance of language models by training them to follow natural language commands or instructions. This includes positive or negative examples, prompts, constraints, and other elements that are commonly found in human language. The main goal of instruction-tuning is to improve the model's ability to perform well on multiple tasks and to generalize more effectively to new or unseen tasks. This is achieved by teaching the model to understand and incorporate various language cues and constraints that are relevant to the task at hand. Instruction-tuning is a powerful technique that is widely used in natural language processing, machine learning, and related areas. By improving the ability of language models to understand and follow natural language commands, this approach can help to unlock new levels of performance and productivity in a wide range of applications. We list some examples below. Full example list is saved as a [Jsonl file](https://github.com/OptimalScale/LMFlow/blob/main/docs/source/_static/check_before_after_lora_tuning.jsonl). ![Instruction Tuning Sample](_static/IT_sample1.png) ![Instruction Tuning Sample](_static/IT_sample2.png) ![Instruction Tuning Sample](_static/IT_sample3.png) ![Instruction Tuning Sample](_static/IT_sample4.png) ![Instruction Tuning Sample](_static/IT_sample5.png) ![Instruction Tuning Sample](_static/IT_sample6.png) ![Instruction Tuning Sample](_static/IT_sample7.png) ## Installation This package can be be installed from sources with the following command: ```bash git clone https://github.com/OptimalScale/LMFlow.git conda create -n lmflow python=3.9 -y conda activate lmflow conda install mpi4py pip install -e . ``` ## Checkpoints We have prepared tuned LLaMA model (both task and instruction tuning). Refer to [README](https://github.com/OptimalScale/LMFlow/blob/main/README.md). ## Content ```{toctree} :maxdepth: 1 blogs/index ``` ```{toctree} :maxdepth: 2 examples/index ``` ```{toctree} :maxdepth: 2 autoapi/index ``` ```{toctree} :maxdepth: 2 about/index ``` ## Vision Hello there! We are excited to announce the upcoming release of our code repository that includes a complete LLM training process, enabling users to quickly build their own language models and train them effectively. Our code repository is not just a simple model; it includes the complete training workflow, model optimization, and testing tools. You can use it to build various types of language models, including conversation models, question-answering models, and text generation models, among others. Moreover, we aim to create an open and democratic LLM sharing platform where people can share their checkpoints and experiences to collectively improve the skills of the community. We welcome anyone who is interested in LLM to participate and join us in building an open and friendly community! Whether you are a beginner or an expert, we believe that you can benefit from this platform. Let's work together to build a vibrant and innovative LLM community! [![Embark](https://img.shields.io/badge/discord-LMFlow-%237289da.svg?logo=discord)](https://discord.gg/u9VJNpzhvA) [![slack badge](https://img.shields.io/badge/Slack-join-blueviolet?logo=slack&)](https://join.slack.com/t/lmflow/shared_invite/zt-1wju9nicy-woXbNtS~5MavHSAtiMxmxQ) [![WeChat badge](https://img.shields.io/badge/WeChat-Join-brightgreen?logo=wechat&)](https://s1.ax1x.com/2023/08/06/pPAQTPI.jpg) ## Citation ```bibtex @misc{lmflow, author = {Shizhe Diao and Rui Pan and Hanze Dong and KaShun Shum and Jipeng Zhang and Wei Xiong and Tong Zhang}, title = {LMFlow: An Extensible Toolkit for Finetuning and Inference of Large Foundation Models}, year = {2023}, publisher = {GitHub}, journal = {GitHub repository}, howpublished = {\url{https://optimalscale.github.io/LMFlow/}}, } ``` ## Disclaimer This package aims to provide a streamlined and user-friendly pipeline for large model tuning. Its functionalities serve as a reference and are intended for use by the user. However, it is important to note that the responsibility for the preparation of the data and pretrained models lies solely with the user. This package does not guarantee the accuracy, completeness, applicability, or legality of the components from the user's preparation. Users must be aware of and assume all risks and liabilities associated with the preparation of the models and data, and obtain legal, commercial, and technical advice before utilizing this package. The pipeline shall not be held responsible for any direct, indirect, special, incidental, or consequential damages resulting from the user's improper preparation of the data and pretrained models. It is also crucial to highlight that the results generated by the model are based on probabilistic models and not directly related to this pipeline. The accuracy, reliability, applicability, and legality of the results are not guaranteed by this pipeline. Therefore, users must also be aware of the risks and liabilities associated with the results and seek legal, commercial, and technical advice before relying on the model-generated outcomes. This pipeline shall not be accountable for any direct, indirect, special, incidental, or consequential damages resulting from the user's reliance on the model-generated results. ## Support If you need any help, please submit a [Github](https://github.com/OptimalScale/LMFlow) issue. ## Indices and tables - {ref}`genindex` - {ref}`search` ================================================ FILE: examples/benchmarking.py ================================================ #!/usr/bin/env python # Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. """A one-line summary of the module or program, terminated by a period. Leave one blank line. The rest of this docstring should contain an overall description of the module or program. Optionally, it may also contain a brief description of exported classes and functions and/or usage examples. Typical usage example: foo = ClassFoo() bar = foo.FunctionBar() """ import json import logging import os import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) import subprocess from transformers import HfArgumentParser from lmflow.args import AutoArguments, BenchmarkingArguments, DatasetArguments, ModelArguments from lmflow.datasets.dataset import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline logger = logging.getLogger(__name__) LOCAL_DATSET_MAP = { "gpt4_en_eval": "data/gp4_instruction_en_eval/", "gpt4_zh_eval": "data/gpt4_instruction_zh_eval/", "wiki_zh_eval": "data/wiki_zh_eval/", "wiki_en_eval": "data/wiki_en_eval/", "multiturn_dialog_eval": "data/multiturn_dialog_eval/", "MedMCQA": "data/MedMCQA/validation/", "MedQA-USMLE": "data/MedQA-USMLE/validation/", "PubMedQA": "data/PubMedQA/test/", "alpaca": "data/alpaca/test/", "common_sense_eval_arc_c": "data/commonsense_eval/arc_c", "common_sense_eval_arc_e": "data/commonsense_eval/arc_e", "common_sense_eval_winogrande": "data/commonsense_eval/winogrande/", "common_sense_eval_obqa": "data/commonsense_eval/obqa/", "common_sense_eval_piqa": "data/commonsense_eval/piqa/", "common_sense_eval_hellaswag": "data/commonsense_eval/hellaswag/", "common_sense_eval_siqa": "data/commonsense_eval/siqa/", "common_sense_eval_boolq": "data/commonsense_eval/boolq/", "lmflow_chat_cn_dialog_multiturn_nll_text2text_nosharp": "data/lmflow_chat_cn_dialog_multiturn_nll_text2text_nosharp", # noqa: E501 "lmflow_chat_cn_dialog_multiturn_single_nll_text2text": "data/lmflow_chat_cn_dialog_multiturn_single_nll_text2text", # noqa: E501 "lmflow_chat_en_dialog_multiturn_nll_text2text_nosharp": "data/lmflow_chat_en_dialog_multiturn_nll_text2text_nosharp", # noqa: E501 "lmflow_chat_en_dialog_multiturn_single_nll_text2text": "data/lmflow_chat_en_dialog_multiturn_single_nll_text2text", # noqa: E501 } LM_EVAL_DATASET_MAP = { "commonsense_qa_eval": "openbookqa,arc_easy,winogrande,hellaswag,arc_challenge,piqa,boolq", "math_eval": "gsm8k", "boolq": "boolq", } LOCAL_DATSET_GROUP_MAP = { "commonsense_nll_eval": "common_sense_eval_arc_c,common_sense_eval_arc_e,common_sense_eval_winogrande,\ common_sense_eval_obqa,common_sense_eval_piqa,common_sense_eval_hellaswag,common_sense_eval_siqa,\ common_sense_eval_boolq", "gpt4_en_eval": "gpt4_en_eval", "gpt4_zh_eval": "gpt4_zh_eval", "wiki_zh_eval": "wiki_zh_eval", "wiki_en_eval": "wiki_en_eval", "wiki_eval": "wiki_zh_eval,wiki_en_eval", "multiturn_dialog_eval": "multiturn_dialog_eval", "all_nll_eval": "common_sense_eval_arc_c,common_sense_eval_arc_e,common_sense_eval_winogrande,\ common_sense_eval_obqa,common_sense_eval_piqa,common_sense_eval_hellaswag,common_sense_eval_siqa,\ common_sense_eval_boolq,gpt4_en_eval,gpt4_zh_eval,wiki_zh_eval,wiki_en_eval,\ lmflow_chat_cn_dialog_multiturn_nll_text2text_nosharp,\ lmflow_chat_cn_dialog_multiturn_single_nll_text2text,\ lmflow_chat_en_dialog_multiturn_nll_text2text_nosharp,lmflow_chat_en_dialog_multiturn_single_nll_text2text", "lmflow_chat_nll_eval": "lmflow_chat_cn_dialog_multiturn_nll_text2text_nosharp,\ lmflow_chat_cn_dialog_multiturn_single_nll_text2text,\ lmflow_chat_en_dialog_multiturn_nll_text2text_nosharp,\ lmflow_chat_en_dialog_multiturn_single_nll_text2text", "lmflow_chat_zh_nll_eval": "lmflow_chat_cn_dialog_multiturn_nll_text2text_nosharp,\ lmflow_chat_cn_dialog_multiturn_single_nll_text2text", } LOCAL_DATSET_ANSWERTYPE_MAP = { "gpt4_en_eval": "text2text", "gpt4_zh_eval": "text2text", "wiki_zh_eval": "text_only", "wiki_en_eval": "text_only", "multiturn_dialog_eval": "text2text", "MedMCQA": "multiple_choice", "MedQA-USMLE": "multiple_choice", "PubMedQA": "binary_choice", "alpaca": "text_only", "common_sense_eval_arc_c": "text_only", "common_sense_eval_arc_e": "text_only", "common_sense_eval_winogrande": "text_only", "common_sense_eval_obqa": "text_only", "common_sense_eval_piqa": "text_only", "common_sense_eval_hellaswag": "text_only", "common_sense_eval_siqa": "text_only", "common_sense_eval_boolq": "text_only", "lmflow_chat_cn_dialog_multiturn_nll_text2text_nosharp": "text2text", "lmflow_chat_cn_dialog_multiturn_single_nll_text2text": "text2text", "lmflow_chat_en_dialog_multiturn_nll_text2text_nosharp": "text2text", "lmflow_chat_en_dialog_multiturn_single_nll_text2text": "text2text", } def is_lmflow_local_benchmarking(dataset_name): # local_dataset = ["gpt4_en_eval","gpt4_zh_eval","wiki_zh_eval",\ # "multiturn_dialog_eval","MedMCQA","MedQA-USMLE","PubMedQA",\ # "alpaca","common_sense_eval_arc_c","common_sense_eval_arc_e",\ # "common_sense_eval_winogrande","common_sense_eval_obqa",\ # "common_sense_eval_piqa","common_sense_eval_hellaswag",\ # "common_sense_eval_siqa","common_sense_eval_boolq"] if dataset_name in LOCAL_DATSET_GROUP_MAP.keys(): dataset_name_collection = LOCAL_DATSET_GROUP_MAP[dataset_name] for dataset_name_exact in dataset_name_collection.split(","): dataset_name_exact = dataset_name_exact.strip() if "common_sense_eval" in dataset_name_exact: dataset_list = dataset_name_exact.split(",") for common_exact_ in dataset_list: print("Dealing with " + common_exact_.strip()) common_exact_ = common_exact_.strip() if not os.path.exists(LOCAL_DATSET_MAP[common_exact_]): os.system("cd data && ./download.sh common_sense_eval && cd -") else: if not os.path.exists(LOCAL_DATSET_MAP[dataset_name_exact]): print("Checking if dataset " + str(dataset_name_exact) + " exists") os.system("cd data && " + "./download.sh " + dataset_name_exact + " && cd -") return True else: return False def is_lm_evaluation_benchmarking(dataset_name): if dataset_name in LM_EVAL_DATASET_MAP.keys(): return True else: return False def run_lmflow_local_benchmarking( dataset_name, pipeline_name, model_args, pipeline_args, model, local_metric="neg_log_likelihood" ): # Downloads dataset via "data/download.sh" print(f"{dataset_name.split(',')=}") dataset_name = LOCAL_DATSET_GROUP_MAP[dataset_name] dataset_collection = dataset_name.split(",") reuslt_collection = [] for dataset_name_ in dataset_collection: # Gets mapping from dataset_name to dataset dataset_name_ = dataset_name_.strip() dataset_path = LOCAL_DATSET_MAP[dataset_name_] data_args = DatasetArguments(dataset_path=dataset_path) dataset = Dataset(data_args) logger.warning( "Default answer type for lmflow local benchmark tasks. \ Users need to change answer type in LOCAL_DATSET_ANSWERTYPE_MAP for new benchmark tasks." ) pipeline_args.answer_type = LOCAL_DATSET_ANSWERTYPE_MAP[dataset_name_] evaluator = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) # model = model_args.model_name_or_path # metric should be decided by both dataset_name and pipeline_args # 1. When --metric is not specified, or "accuracy", log warning and change to # the dataset_name's default metric # 2. If specified, use the specified metric result = evaluator.evaluate(model=model, dataset=dataset, metric=local_metric, verbose=True) reuslt_collection.append({"dataset": dataset_name_, "result": result}) for record in reuslt_collection: print("-" * 30) print("| Dataset: " + record["dataset"]) print("-" * 30) print(f"| current nll: {record['result']}") print("-" * 30) def run_lm_evaluation_benchmarking(dataset_name, model_name): # use subprocess maybe # subprocess.run(["python3", "main.py", "--model", "hf-causal-experimental", # "--model_args" "pretrained=EleutherAI/gpt-j-6b", # "--tasks", "openbookqa,arc_easy,winogrande,hellaswag,arc_challenge,piqa,boolq" # "--device", "cuda:0"]) dataset = LM_EVAL_DATASET_MAP[dataset_name] subprocess.run( [ "python3", "utils/lm_evaluator.py", "--model", "hf-causal-experimental", "--model_args", "pretrained=" + model_name, "--tasks", dataset, "--device", "cuda:0", ] ) def main(): # Parses arguments (self-defined for our evaluation platform) # Need at least include # 1) model_name_or_path (you can reuse ModelArguments) # 2) dataset_name # 3) metric (you can reuse EvaluatorArguments) logging.basicConfig() pipeline_name = "evaluator" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((ModelArguments, PipelineArguments, BenchmarkingArguments)) model_args, pipeline_args, benchmarking_args = parser.parse_args_into_dataclasses() with open(pipeline_args.deepspeed) as f: ds_config = json.load(f) # Based on dataset name, you need specify the default dataset_path # (if local) or call corresponding lm_evaluation package (via python pack or subprocess) dataset_name = benchmarking_args.dataset_name # metric = pipeline_args.metric if is_lmflow_local_benchmarking(dataset_name): # TODO (@Jipeng) model = AutoModel.get_model(model_args, do_train=False, ds_config=ds_config) run_lmflow_local_benchmarking( dataset_name, pipeline_name, model_args, pipeline_args, model ) # Pass args TODO (@Jipeng) elif is_lm_evaluation_benchmarking(dataset_name): model = model_args.model_name_or_path run_lm_evaluation_benchmarking(dataset_name, model) # TODO (@Jipeng) else: raise NotImplementedError(f"benchmarking dataset {dataset_name} is not supported") if __name__ == "__main__": main() ================================================ FILE: examples/chatbot.py ================================================ #!/usr/bin/env python # Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. """A simple shell chatbot implemented with lmflow APIs.""" import json import logging import os import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) import warnings from dataclasses import dataclass, field from typing import Optional from transformers import HfArgumentParser from lmflow.args import AutoArguments, DatasetArguments, ModelArguments from lmflow.datasets.dataset import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline logging.disable(logging.ERROR) warnings.filterwarnings("ignore") @dataclass class ChatbotArguments: prompt_structure: Optional[str] = field( default="{input_text}", metadata={"help": "prompt structure given user's input text"}, ) end_string: Optional[str] = field( default="\n\n", metadata={"help": "end string mark of the chatbot's output"}, ) num_token_per_step: int = field( default=4, metadata={"help": "Number of tokens per step for stream inference"}, ) def main(): pipeline_name = "inferencer" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser( ( ModelArguments, PipelineArguments, ChatbotArguments, ) ) model_args, pipeline_args, chatbot_args = parser.parse_args_into_dataclasses() inferencer_args = pipeline_args with open(pipeline_args.deepspeed) as f: ds_config = json.load(f) model = AutoModel.get_model( model_args, do_train=False, ds_config=ds_config, device=pipeline_args.device, ) # We don't need input data, we will read interactively from stdin data_args = DatasetArguments(dataset_path=None) dataset = Dataset(data_args) inferencer = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) # Chats model_name = model_args.model_name_or_path if model_args.lora_model_path is not None: model_name += f" + {model_args.lora_model_path}" guide_message = ( "\n" f"#############################################################################\n" f"## A {model_name} chatbot is now chatting with you!\n" f"#############################################################################\n" "\n" ) print(guide_message) # context = ( # "You are a helpful assistant who follows the given instructions" # " unconditionally." # ) context = "" end_string = chatbot_args.end_string prompt_structure = chatbot_args.prompt_structure while True: input_text = input("User >>> ") if input_text == "exit": print("exit...") break elif input_text == "reset": context = "" print("Chat history cleared") continue if not input_text: input_text = " " context += prompt_structure.format(input_text=input_text) context = context[-model.get_max_length() :] # Memory of the bot input_dataset = dataset.from_dict({"type": "text_only", "instances": [{"text": context}]}) print("Bot: ", end="") print_index = 0 token_per_step = chatbot_args.num_token_per_step for response, flag_break in inferencer.stream_inference( context=context, model=model, max_new_tokens=inferencer_args.max_new_tokens, token_per_step=token_per_step, temperature=inferencer_args.temperature, end_string=end_string, input_dataset=input_dataset, ): # Prints characters in the buffer new_print_index = print_index for char in response[print_index:]: if end_string is not None and char == end_string[0]: if new_print_index + len(end_string) >= len(response): break new_print_index += 1 print(char, end="", flush=True) print_index = new_print_index if flag_break: break print("\n", end="") context += response + "\n" if __name__ == "__main__": main() ================================================ FILE: examples/chatbot_gradio.py ================================================ #!/usr/bin/env python # Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. """A simple shell chatbot implemented with lmflow APIs.""" import json import logging import os import sys from dataclasses import dataclass, field sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) import warnings from typing import Optional import torch from transformers import HfArgumentParser from lmflow.args import AutoArguments, DatasetArguments, ModelArguments from lmflow.datasets.dataset import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline from lmflow.utils.versioning import is_gradio_available if is_gradio_available(): import gradio as gr else: raise ImportError("Gradio is not available. Please install it via `pip install gradio`.") MAX_BOXES = 20 logging.disable(logging.ERROR) warnings.filterwarnings("ignore") title = """

LMFlow-CHAT

LMFlow

LMFlow is in extensible, convenient, and efficient toolbox for finetuning large machine learning models, designed to be user-friendly, speedy and reliable, and accessible to the entire community.

We have thoroughly tested this toolkit and are pleased to make it available under Github.

""" css = """ #user { float: right; position:relative; right:5px; width:auto; min-height:32px; max-width: 60% line-height: 32px; padding: 2px 8px; font-size: 14px; background: #9DC284; border-radius:5px; margin:10px 0px; } #chatbot { float: left; position:relative; right:5px; width:auto; min-height:32px; max-width: 60% line-height: 32px; padding: 2px 8px; font-size: 14px; background:#7BA7D7; border-radius:5px; margin:10px 0px; } """ @dataclass class ChatbotArguments: prompt_structure: Optional[str] = field( default="{input_text}", metadata={"help": "prompt structure given user's input text"}, ) end_string: Optional[str] = field( default="\n\n", metadata={"help": "end string mark of the chatbot's output"}, ) pipeline_name = "inferencer" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser( ( ModelArguments, PipelineArguments, ChatbotArguments, ) ) model_args, pipeline_args, chatbot_args = parser.parse_args_into_dataclasses() inferencer_args = pipeline_args with open(pipeline_args.deepspeed) as f: ds_config = json.load(f) model = AutoModel.get_model( model_args, do_train=False, ds_config=ds_config, device=pipeline_args.device, torch_dtype=torch.float16 ) # We don't need input data, we will read interactively from stdin data_args = DatasetArguments(dataset_path=None) dataset = Dataset(data_args) inferencer = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) # Chats model_name = model_args.model_name_or_path if model_args.lora_model_path is not None: model_name += f" + {model_args.lora_model_path}" # context = ( # "You are a helpful assistant who follows the given instructions" # " unconditionally." # ) end_string = chatbot_args.end_string prompt_structure = chatbot_args.prompt_structure token_per_step = 4 def hist2context(hist): context = "" for query, response in hist: context += prompt_structure.format(input_text=query) if response is not None: context += response return context def chat_stream(query: str, history=None, **kwargs): if history is None: history = [] context = hist2context(history) print_index = 0 context += prompt_structure.format(input_text=query) context_ = context[-model.get_max_length() :] input_dataset = dataset.from_dict({"type": "text_only", "instances": [{"text": context_}]}) print(context_) for response, flag_break in inferencer.stream_inference( context=context_, model=model, max_new_tokens=inferencer_args.max_new_tokens, token_per_step=token_per_step, temperature=inferencer_args.temperature, end_string=end_string, input_dataset=input_dataset, ): delta = response[print_index:] seq = response print_index = len(response) yield delta, history + [(query, seq)] if flag_break: break def predict(input, history=None): if history is None: history = [] for response, history_ in chat_stream(input, history): updates = [] for query, response in history_: updates.append(gr.update(visible=True, value="" + query)) updates.append(gr.update(visible=True, value="" + response)) if len(updates) < MAX_BOXES: updates = updates + [gr.Textbox.update(visible=False)] * (MAX_BOXES - len(updates)) yield [history] + updates with gr.Blocks(css=css) as demo: gr.HTML(title) state = gr.State([]) text_boxes = [] for i in range(MAX_BOXES): if i % 2 == 0: text_boxes.append(gr.Markdown(visible=False, label="Q:", elem_id="user")) else: text_boxes.append(gr.Markdown(visible=False, label="A:", elem_id="chatbot")) txt = gr.Textbox( show_label=False, placeholder="Enter text and press send.", ) button = gr.Button("Send") button.click(predict, [txt, state], [state] + text_boxes) demo.queue().launch(share=True) ================================================ FILE: examples/detail_memory.py ================================================ import sys import time import torch from peft import LoraConfig, TaskType, get_peft_model from transformers import AutoModelForCausalLM, AutoTokenizer LISA = True if sys.argv[3] == "1" else False LORA = True if sys.argv[4] == "1" else False lora_r = int(sys.argv[5]) # Check if the model name is provided as a command-line argument if len(sys.argv) < 6: print("Usage: python script_name.py ") sys.exit(1) print("*" * 50) print("Script started") print("model : ", sys.argv[1]) print("token_length : ", sys.argv[2]) print("LISA : ", LISA) print("LORA : ", LORA) print("lora_r : ", lora_r) # Model initialization model_name = sys.argv[1] token_length = sys.argv[2] model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16) tokenizer = AutoTokenizer.from_pretrained(model_name) # Measure memory usage of the weights model.to("cuda") # Ensure the model is on GPU if LISA: # Only activate two layers for param in model.model.layers.parameters(): param.requires_grad = False for param in model.model.layers[-1].parameters(): param.requires_grad = True for param in model.model.layers[-2].parameters(): param.requires_grad = True if LORA: peft_config = LoraConfig( task_type=TaskType.CAUSAL_LM, inference_mode=False, r=lora_r, lora_alpha=32, lora_dropout=0.1, target_modules=[ "q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj", "embed_tokens", "lm_head", ], ) model = get_peft_model(model, peft_config) model.print_trainable_parameters() torch.cuda.reset_peak_memory_stats() # Reset peak memory statistics weight_memory = torch.cuda.memory_allocated() # Initialize the optimizer optimizer = torch.optim.Adam(model.parameters(), lr=1e-3) # Execute a forward pass and measure the time sentence_2048_tokens = 'The OpenAI API is powered by GPT-3 language models which can be coaxed to perform natural language tasks using carefully engineered text prompts. But these models can also generate outputs that are untruthful, toxic, or reflect harmful sentiments. This is in part because GPT-3 is trained to predict the next word on a large dataset of Internet text, rather than to safely perform the language task that the user wants. In other words, these models aren’t aligned with their users.\nTo make our models safer, more helpful, and more aligned, we use an existing technique called reinforcement learning from human feedback (RLHF). On prompts submitted by our customers to the API,A[A]We only use prompts submitted through the Playground to an earlier version of the InstructGPT models that was deployed in January 2021. Our human annotators remove personal identifiable information from all prompts before adding it to the training set.our labelers provide demonstrations of the desired model behavior, and rank several outputs from our models. We then use this data to fine-tune GPT-3.The resulting InstructGPT models are much better at following instructions than GPT-3. They also make up facts less often, and show small decreases in toxic output generation. Our labelers prefer outputs from our 1.3B InstructGPT model over outputs from a 175B GPT-3 model, despite having more than 100x fewer parameters. At the same time, we show that we don’t have to compromise on GPT-3’s capabilities, as measured by our model’s performance on academic NLP evaluations.These InstructGPT models, which have been in beta on the API for more than a year, are now the default language models accessible on our API.B[B]The InstructGPT models deployed in the API are updated versions trained using the same human feedback data. They use a similar but slightly different training method that we will describe in a forthcoming publication.We believe that fine-tuning language models with humans in the loop is a powerful tool for improving their safety and reliability, and we will continue to push in this direction.This is the first time our alignment research, which we’ve been pursuing for several years,1,2,3 has been applied to product.Yesterday we announced our next-generation Gemini model: Gemini 1.5. In addition to big improvements to speed and efficiency, one of Gemini 1.5’s innovations is its long context window, which measures how many tokens — the smallest building blocks, like part of a word, image or video — that the model can process at once. To help understand the significance of this milestone, we asked the Google DeepMind project team to explain what long context windows are, and how this breakthrough experimental feature can help developers in many ways. Context windows are important because they help AI models recall information during a session. Have you ever forgotten someone’s name in the middle of a conversation a few minutes after they’ve said it, or sprinted across a room to grab a notebook to jot down a phone number you were just given? Remembering things in the flow of a conversation can be tricky for AI models, too — you might have had an experience where a chatbot “forgot” information after a few turns. That’s where long context windows can help. Previously, Gemini could process up to 32,000 tokens at once, but 1.5 Pro — the first 1.5 model we’re releasing for early testing — has a context window of up to 1 million tokens — the longest context window of any large-scale foundation model to date. In fact, we’ve even successfully tested up to 10 million tokens in our research. And the longer the context window, the more text, images, audio, code or video a model can take in and process. "Our original plan was to achieve 128,000 tokens in context, and I thought setting an ambitious bar would be good, so I suggested 1 million tokens," says Google DeepMind Research Scientist Nikolay Savinov, one of the research leads on the long context project. “And now we’ve even surpassed that in our research by 10x.” To make this kind of leap forward, the team had to make a series of deep learning innovations. Early explorations by Pranav Shyam offered valuable insights that helped steer our subsequent research in the right direction. “There was one breakthrough that led to another and another, and each one of them opened up new possibilities,” explains Google DeepMind Engineer Denis Teplyashin. “And then, when they all stacked together, we were quite surprised to discover what they could do, jumping from 128,000 tokens to 512,000 tokens to 1 million tokens, and just recently, 10 million tokens in our internal research.” The raw data that 1.5 Pro can handle opens up whole new ways to interact with the model. Instead of summarizing a document dozens of pages long, for example, it can summarize documents thousands of pages long. Where the old model could help analyze thousands of lines of code, thanks to its breakthrough long context window, 1.5 Pro can analyze tens of thousands of lines of code at once. “In one test, we dropped in an entire code base and it wrote documentation for it, which was really cool,” says Google DeepMind Research Scientist Machel Reid. “And there was another test where it was able to accurately answer questions about the 1924 film Sherlock Jr. after we gave the model the entire 45-minute movie to ‘watch.’” 1.5 Pro can also reason across data provided in a prompt. “One of my favorite examples from the past few days is this rare language — Kalamang — that fewer than 200 people worldwide speak, and there one grammar manual about it,” says Machel. The model can speak it on its own if you just ask it to translate into this language, but with the expanded long context window, you can put the entire grammar manual and some examples of sentences into context, and the model was able to learn to translate from English to Kalamang at a similar level to a person learning from the same content.”Gemini 1.5 Pro comes standard with a 128K-token context window, but a limited group of developers and enterprise customers can try it with a context window of up to 1 million tokens via AI Studio and Vertex AI in private preview. The full 1 million token context window is computationally intensive and still requires further optimizations to improve latency, which we’re actively working on as we scale it out. And as the team looks to the future, they’re continuing to work to make the model faster and more efficient, with safety at the core. They’re also looking to further expand the long context window, improve the underlying architectures, and integrate new hardware improvements. “10 million tokens at once is already close to the thermal limit of our Tensor Processing Units — we dont know where the limit is yet, and the model might be capable of even more as the hardware continues to improve,” says Nikolay.The team is excited to see what kinds of experiences developers and the broader community are able to achieve, too. “When I first saw we had a million tokens in context, my first question was, ‘What do you even use this for?’” says Machel. “But now, I think people’s imaginations are expanding, and they’ll find more and more creative ways to use these new capabilities.Long-context question answering (QA) tasks require reasoning over a long document or multiple documents. Addressing these tasks often benefits from identifying a set of evidence spans (e.g., sentences), which provide supporting evidence for answering the question. In this work, we propose a novel method for equipping long-context QA models with an additional sequence-level objective for better identification of the supporting evidence. We achieve this via an additional contrastive supervision signal in finetuning, where the model is encouraged to explicitly discriminate supporting evidence sentences from negative ones by maximizing question-evidence similarity. The proposed additional loss exhibits consistent improvements on three different strong long-context transformer models, across two challenging question answering benchmarks – HotpotQA and QAsper.Actively and judiciously select the most helpful questions for LLMs“Existing CoT studies largely rely on a fixed set of human-annotated exemplars, which are not necessarily the most effective ones. A good performance requires human prompt engineering which is costly. We identify the human prompt engineering as two complementary components: question selection and prompt template engineering. In this paper, we offer a solution to the key problem of determining which questions are the most important and helpful ones to annotate from a pool of task-specific queries. By borrowing ideas from the related problem of uncertainty-based active learning, we introduce several metrics to characterize the uncertainty so as to select the most uncertain questions for annotation. Experimental results demonstrate the superiority of our proposed method on eight complex reasoning tasks. With text-davinci-002, active-prompt improves upon by 7 (67.9->74.9).' # noqa: E501 inputs = tokenizer(sentence_2048_tokens, return_tensors="pt", max_length=int(token_length), truncation=True).to("cuda") labels = inputs["input_ids"] # store the gpu memory for inputs input_memory = torch.cuda.memory_allocated() - weight_memory torch.cuda.reset_peak_memory_stats() # Reset peak memory stats to measure forward pass accurately start = time.time() outputs = model(**inputs, labels=labels) activation_memory = torch.cuda.memory_allocated() - weight_memory forward_time = time.time() - start # Execute a backward pass and measure the time start = time.time() loss = outputs.loss # torch.cuda.reset_peak_memory_stats() # Reset peak memory stats again before backward pass loss.backward() gradient_memory = torch.cuda.memory_allocated() - weight_memory # activation memory will free automatically optimizer.step() optimizer_memory = torch.cuda.memory_allocated() - gradient_memory - weight_memory backward_time = time.time() - start # Total memory total_memory = torch.cuda.memory_allocated() print(f"Weight memory : {weight_memory / 1e6} MB") print(f"Input memory : {input_memory / 1e6} MB") print(f"Activation memory: {activation_memory / 1e6} MB") print(f"Gradient memory : {gradient_memory / 1e6} MB") print(f"Optimizer memory : {optimizer_memory / 1e6} MB") print(f"Total memory : {total_memory / 1e6} MB\n") print(f"Forward time : {forward_time} s") print(f"Backward time : {backward_time} s") print("*" * 50) ================================================ FILE: examples/dpo_train.py ================================================ #!/usr/bin/env python # @Time : 7/4/2024 20:31 # @Author : Yu Li # @Site : # @File : dpo_train.py # 0. imports import os import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) from transformers import HfArgumentParser from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline if __name__ == "__main__": # Parses arguments pipeline_name = "dpo_aligner" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser( ( ModelArguments, DatasetArguments, PipelineArguments, ) ) model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() # Initializes pipeline, dataset and model for reward training aligner = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) model = AutoModel.get_model(model_args) # Aligns model with rewards aligned_model = aligner.align(model=model, dataset=None, reward_model=None) ================================================ FILE: examples/dpov2_train.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import copy import logging import os import sys from transformers import HfArgumentParser from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) from lmflow.datasets import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline from lmflow.utils.common import create_copied_dataclass, remove_dataclass_attr_prefix logger = logging.getLogger(__name__) ReferenceModelArguments = create_copied_dataclass( original_dataclass=ModelArguments, field_prefix="reference_", class_prefix="Reference" ) def main(): # Parses arguments pipeline_name = "dpov2_aligner" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((ModelArguments, ReferenceModelArguments, DatasetArguments, PipelineArguments)) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): # If we pass only one argument to the script and it's the path to a json file, # let's parse it to get our arguments. model_args, ref_model_args, data_args, pipeline_args = parser.parse_json_file( json_file=os.path.abspath(sys.argv[1]) ) else: model_args, ref_model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() ref_model_args_dict = remove_dataclass_attr_prefix(ref_model_args, "reference_") ref_model_args = ModelArguments(**ref_model_args_dict) train_dataset = Dataset(data_args) eval_data_args = copy.deepcopy(data_args) eval_data_args.dataset_path = pipeline_args.eval_dataset_path eval_dataset = Dataset(eval_data_args) model = AutoModel.get_model(model_args) ref_model = AutoModel.get_model(ref_model_args) aligner = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ref_model_args=ref_model_args, ) aligner.align( model=model, ref_model=ref_model, train_dataset=train_dataset, eval_dataset=eval_dataset, ) if __name__ == "__main__": main() ================================================ FILE: examples/evaluation.py ================================================ #!/usr/bin/env python # Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. """A one-line summary of the module or program, terminated by a period. Leave one blank line. The rest of this docstring should contain an overall description of the module or program. Optionally, it may also contain a brief description of exported classes and functions and/or usage examples. Typical usage example: foo = ClassFoo() bar = foo.FunctionBar() """ import json import os import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) from transformers import HfArgumentParser from lmflow.args import AutoArguments, DatasetArguments, ModelArguments from lmflow.datasets.dataset import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline pipeline_name = "evaluator" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((ModelArguments, DatasetArguments, PipelineArguments)) model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() with open(pipeline_args.deepspeed) as f: ds_config = json.load(f) model = AutoModel.get_model( model_args, do_train=False, ds_config=ds_config, ) dataset = Dataset(data_args) evaluator = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) evaluator.evaluate(model=model, dataset=dataset, metric=pipeline_args.metric) ================================================ FILE: examples/finetune.py ================================================ #!/usr/bin/env python # Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. """A one-line summary of the module or program, terminated by a period. Leave one blank line. The rest of this docstring should contain an overall description of the module or program. Optionally, it may also contain a brief description of exported classes and functions and/or usage examples. Typical usage example: foo = ClassFoo() bar = foo.FunctionBar() """ import os import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) from transformers import HfArgumentParser from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) from lmflow.datasets.dataset import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline def main(): # Parses arguments pipeline_name = "finetuner" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((ModelArguments, DatasetArguments, PipelineArguments)) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): # If we pass only one argument to the script and it's the path to a json file, # let's parse it to get our arguments. model_args, data_args, pipeline_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) else: model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() # Initialization finetuner = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) dataset = Dataset(data_args) model = AutoModel.get_model(model_args) # Finetuning finetuner.tune(model=model, dataset=dataset) if __name__ == "__main__": main() ================================================ FILE: examples/finetune_multi_modal.py ================================================ #!/usr/bin/env python # Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. # FIXME should merge with finetune.py """A one-line summary of the module or program, terminated by a period. Leave one blank line. The rest of this docstring should contain an overall description of the module or program. Optionally, it may also contain a brief description of exported classes and functions and/or usage examples. Typical usage example: foo = ClassFoo() bar = foo.FunctionBar() """ import os import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) from transformers import HfArgumentParser from lmflow.args import ( AutoArguments, MultiModalDatasetArguments, VisModelArguments, ) from lmflow.datasets.dataset import Dataset from lmflow.datasets.multi_modal_dataset import DataCollatorForSupervisedDataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline def main(): # Parses arguments pipeline_name = "finetuner" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((VisModelArguments, MultiModalDatasetArguments, PipelineArguments)) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): # If we pass only one argument to the script and it's the path to a json file, # let's parse it to get our arguments. model_args, data_args, pipeline_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) else: model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() # Initialization finetuner = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) # do not resiger deepspeed in the model. # with_deepspeed flag may be removed # by modifying the tune strategy in the future. model = AutoModel.get_model( model_args, do_train=True, ds_config=pipeline_args.deepspeed, custom_model=True, with_deepspeed=False, pipeline_args=pipeline_args, ) # FIXME check if need to move this part to hf_encoder_decoder.py for param in model.backend_model.parameters(): param.requires_grad = False if "language_projection" in pipeline_args.finetune_part: for param in model.backend_model.language_projection.parameters(): param.requires_grad = True if "language_model" in pipeline_args.finetune_part: for param in model.backend_model.language_model.parameters(): param.requires_grad = True if "vision_model" in pipeline_args.finetune_part: for param in model.backend_model.vision_model.parameters(): param.requires_grad = True dataset = Dataset(data_args, backend="custom_multi_modal") data_collator = DataCollatorForSupervisedDataset(tokenizer=model.tokenizer) # Finetuning finetuner.tune(model=model, dataset=dataset, data_collator=data_collator) if __name__ == "__main__": main() ================================================ FILE: examples/inference.py ================================================ #!/usr/bin/env python # Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. """A simple shell chatbot implemented with lmflow APIs.""" import json import logging import os import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) import warnings from transformers import HfArgumentParser from lmflow.args import AutoArguments, DatasetArguments, ModelArguments from lmflow.datasets.dataset import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline logging.disable(logging.ERROR) warnings.filterwarnings("ignore") def main(): pipeline_name = "inferencer" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser( ( ModelArguments, PipelineArguments, ) ) model_args, pipeline_args = parser.parse_args_into_dataclasses() inferencer_args = pipeline_args with open(pipeline_args.deepspeed) as f: ds_config = json.load(f) model = AutoModel.get_model( model_args, do_train=False, ds_config=ds_config, device=pipeline_args.device, ) # We don't need input data, we will read interactively from stdin data_args = DatasetArguments(dataset_path=None) dataset = Dataset(data_args) inferencer = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) # Inferences model_name = model_args.model_name_or_path if model_args.lora_model_path is not None: model_name += f" + {model_args.lora_model_path}" while True: input_text = input("User >>> ") input_text = input_text[-model.get_max_length() :] # Truncation input_dataset = dataset.from_dict({"type": "text_only", "instances": [{"text": input_text}]}) output_dataset = inferencer.inference( model=model, dataset=input_dataset, max_new_tokens=inferencer_args.max_new_tokens, temperature=inferencer_args.temperature, ) output = output_dataset.to_dict()["instances"][0]["text"] print(output) if __name__ == "__main__": main() ================================================ FILE: examples/iterative_dpo_train.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import copy import logging import os import sys from transformers import HfArgumentParser from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) from lmflow.datasets import Dataset from lmflow.pipeline.auto_pipeline import AutoPipeline from lmflow.utils.common import create_copied_dataclass, remove_dataclass_attr_prefix logger = logging.getLogger(__name__) # NOTE: # In training processes that needs more than one model such as dpo (reference & target), # ppo (actor & critic), etc., we use the following function to create separate model arguments # to distinguish among them. ReferenceModelArguments = create_copied_dataclass( original_dataclass=ModelArguments, field_prefix="reference_", class_prefix="Reference" ) RewardModelArguments = create_copied_dataclass( original_dataclass=ModelArguments, field_prefix="reward_", class_prefix="Reward" ) def main(): pipeline_name = "iterative_dpo_aligner" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser( (ModelArguments, ReferenceModelArguments, RewardModelArguments, DatasetArguments, PipelineArguments) ) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): # If we pass only one argument to the script and it's the path to a json file, # let's parse it to get our arguments. model_args, ref_model_args, reward_model_args, data_args, pipeline_args = parser.parse_json_file( json_file=os.path.abspath(sys.argv[1]) ) elif len(sys.argv) == 2 and sys.argv[1].endswith(".yaml"): model_args, ref_model_args, reward_model_args, data_args, pipeline_args = parser.parse_yaml_file( yaml_file=os.path.abspath(sys.argv[1]) ) else: model_args, ref_model_args, reward_model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() ref_model_args_dict = remove_dataclass_attr_prefix(ref_model_args, "reference_") ref_model_args = ModelArguments(**ref_model_args_dict) reward_model_args_dict = remove_dataclass_attr_prefix(reward_model_args, "reward_") reward_model_args = ModelArguments(**reward_model_args_dict) dataset_list = [] for dataset in pipeline_args.dataset_path_list: iter_data_args = copy.deepcopy(data_args) iter_data_args.dataset_path = dataset dataset_list.append(Dataset(iter_data_args)) aligner = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ref_model_args=ref_model_args, reward_model_args=reward_model_args, ) aligner.align(dataset_list=dataset_list) if __name__ == "__main__": main() ================================================ FILE: examples/merge_lora.py ================================================ #!/usr/bin/env python # Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. """ Merge base model and lora model into a full model. """ import os import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) from dataclasses import dataclass, field from typing import Optional from transformers import HfArgumentParser from lmflow.args import ( ModelArguments, ) from lmflow.models.auto_model import AutoModel @dataclass class MergeLoraArguments: device: str = field( default="cpu", metadata={ "help": "device to merge model on", }, ) output_model_path: Optional[str] = field( default=None, metadata={"help": "output merged full model path"}, ) local_rank: Optional[int] = field( default=-1, metadata={ "help": "local rank for deepspeed", }, ) def main(): parser = HfArgumentParser((ModelArguments, MergeLoraArguments)) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): model_args, merge_lora_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) else: model_args, merge_lora_args = parser.parse_args_into_dataclasses() if merge_lora_args.device == "gpu": raise NotImplementedError("Merging LoRA weight using GPU not supported yet. Please use cpu.") model_args.use_lora = True model = AutoModel.get_model( model_args, do_train=False, device=merge_lora_args.device, ) model.activate_model_for_inference() model.merge_lora_weights() model.save(merge_lora_args.output_model_path, save_full_model=True) if __name__ == "__main__": main() ================================================ FILE: examples/multistage_finetune.py ================================================ #!/usr/bin/env python # Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. """ The finetuning of each epoch will be splitted into `--num_stages_per_epoch` stages, where each stage will restart finetuning and continuously train from the finetuned model of previous stage. For example, with `--num_train_epochs 3 --num_stages_per_epoch 4`, there will be totally 4*3 stages, and the learning rate schedule will restart every stage. """ import gc import logging import os import random import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) from dataclasses import dataclass, field from transformers import HfArgumentParser from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) from lmflow.datasets.dataset import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline logger = logging.getLogger(__name__) @dataclass class MultistageFinetuneArgs: num_stages_per_epoch: int = field(default=1, metadata={"help": "number of stages per epoch"}) shuffle_base_seed: int = field( default=23, metadata={"help": "base seed for generating dataset shuffle seeds each epoch"} ) start_epoch: int = field(default=0, metadata={"help": "start from a specific epoch"}) def setup_logger(): root = logging.getLogger() root.setLevel(logging.INFO) handler = logging.StreamHandler(sys.stdout) handler.setLevel(logging.INFO) formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") handler.setFormatter(formatter) root.addHandler(handler) def generate_new_seed(seed): return (seed * 37) % 1000000009 def shuffle_and_split_data(dataset, num_split=None, seed=None): data_dict = dataset.to_dict() random.seed(seed) random.shuffle(data_dict["instances"]) dataset_list = [] for i in range(num_split): partial_data_dict = {"type": data_dict["type"], "instances": data_dict["instances"][i::num_split]} partial_dataset = Dataset.create_from_dict(partial_data_dict) dataset_list.append(partial_dataset) return dataset_list def main(): # Initializes logger setup_logger() # Parses arguments pipeline_name = "finetuner" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser( ( ModelArguments, DatasetArguments, PipelineArguments, MultistageFinetuneArgs, ) ) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): # If we pass only one argument to the script and it's the path to a # json file, let's parse it to get our arguments. model_args, data_args, pipeline_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) else: model_args, data_args, pipeline_args, multistage_args = parser.parse_args_into_dataclasses() # Initialization full_dataset = Dataset(data_args) finetuner_args = pipeline_args logger.warning("force set `--overwrite_output_dir True` as required by multistage finetuning") finetuner_args.overwrite_output_dir = True # Finetuning num_train_epochs = finetuner_args.num_train_epochs if abs(num_train_epochs - int(num_train_epochs + 0.5)) > 1e-6: raise ValueError("only support int-typed `--num_train_epochs`") output_dir = finetuner_args.output_dir run_name = finetuner_args.run_name finetuner_args.num_train_epochs = 1 # Finetune every 1 epoch shuffle_seed = multistage_args.shuffle_base_seed for epoch in range(int(num_train_epochs)): shuffle_seed = generate_new_seed(shuffle_seed) dataset_list = shuffle_and_split_data( full_dataset, num_split=multistage_args.num_stages_per_epoch, seed=shuffle_seed, ) if epoch < multistage_args.start_epoch: logging.info(f"skip epoch {epoch}") continue for stage, dataset in enumerate(dataset_list): is_main_process = finetuner_args.local_process_index == 0 if is_main_process: logger.setLevel(logging.INFO) logger.info(f"========== epoch {epoch} stage {stage} ==========") # Initialization for each sub-finetune model = AutoModel.get_model(model_args) finetuner_args.output_dir = output_dir + f"_epoch-{epoch}_stage-{stage}" finetuner_args.run_name = run_name + f"_epoch-{epoch}_stage-{stage}" finetuner = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=finetuner_args, ) # Finetunes on piece of data tuned_model = finetuner.tune( model=model, dataset=dataset, transform_dataset_in_place=False, ) model_args.model_name_or_path = finetuner_args.output_dir tuned_model.save(output_dir) del model del tuned_model del finetuner tuned_model = None # noqa: F841 model = None # noqa: F841 finetuner = None # noqa: F841 gc.collect() if __name__ == "__main__": main() ================================================ FILE: examples/raft_align.py ================================================ #!/usr/bin/env python # Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. """Alignment tuning example, such as RLHF.""" import os import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) from dataclasses import dataclass, field from typing import Optional from transformers import AutoTokenizer, HfArgumentParser, pipeline from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) from lmflow.datasets.dataset import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline @dataclass class RewardArguments: reward_type: Optional[str] = field( default="hf_pipeline", metadata={ "help": ( "type of reward model, support huggingface pipeline. Will" ' support "customized" torch.nn.modules in the future.' ), }, ) reward_model_or_path: Optional[str] = field( default="weqweasdas/hh_rlhf_rm", metadata={ "help": ("reward model name (huggingface) or its path"), }, ) reward_task: Optional[str] = field( default="sentiment-analysis", metadata={"help": "type of reward task, such as sentiment-analysis, detoxic."}, ) reward_model_args: Optional[str] = field( default='return_all_scores=True, function_to_apply="none", batch_size=1', metadata={ "help": ("extra arguments required by different type of reward models."), }, ) def get_reward_function(reward_args, pipeline_args): args = reward_args reward_type = args.reward_type if reward_type == "hf_pipeline": # GPT-2 tokenizer has a pad token, but it is not eos_token by default. We need to set it to eos_token. # only for this model. rm_tokenizer = AutoTokenizer.from_pretrained(reward_args.reward_model_or_path) rm_tokenizer.pad_token = rm_tokenizer.eos_token rm_tokenizer.pad_token_id = rm_tokenizer.eos_token_id rm_tokenizer.padding_side = "left" hf_pipe = pipeline( reward_args.reward_task, model=reward_args.reward_model_or_path, device=f"cuda:{pipeline_args.local_rank}", tokenizer=rm_tokenizer, ) def reward_func(dataset: Dataset): if dataset.type != "text_only": raise NotImplementedError('reward function only accept "text_only" datasets') pipe_kwargs = {"return_all_scores": True, "function_to_apply": "none", "batch_size": 1} data_dict = dataset.to_dict() texts_for_rewards = [sample["text"] for sample in data_dict["instances"]] pipe_outputs = hf_pipe(texts_for_rewards, **pipe_kwargs) rewards = [output[0]["score"] for output in pipe_outputs] reward_dataset = Dataset.create_from_dict( {"type": "float_only", "instances": [{"value": reward} for reward in rewards]} ) return reward_dataset return reward_func else: raise NotImplementedError('unsupported reward type "{reward_type}"') def main(): # Parses arguments pipeline_name = "raft_aligner" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser( ( ModelArguments, DatasetArguments, PipelineArguments, RewardArguments, ) ) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): model_args, data_args, pipeline_args, reward_args = parser.parse_json_file( json_file=os.path.abspath(sys.argv[1]) ) else: model_args, data_args, pipeline_args, reward_args = parser.parse_args_into_dataclasses() # Initializes pipeline, dataset and model for reward training aligner = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) dataset = Dataset(data_args) model = AutoModel.get_model(model_args) # Initializes reward function reward_function = get_reward_function(reward_args, pipeline_args) reward_model_args = ModelArguments(arch_type="text_regression") reward_model = AutoModel.get_model(reward_model_args) reward_model.register_inference_function(reward_function) # Aligns model with rewards aligner.align( model=model, dataset=dataset, reward_model=reward_model, ) if __name__ == "__main__": main() ================================================ FILE: examples/reward_modeling.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import logging import os import sys sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) from transformers import HfArgumentParser from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) from lmflow.datasets.dataset import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline logger = logging.getLogger(__name__) def main(): # Parses arguments pipeline_name = "rm_tuner" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((ModelArguments, DatasetArguments, PipelineArguments)) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): # If we pass only one argument to the script and it's the path to a json file, # let's parse it to get our arguments. model_args, data_args, pipeline_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) else: model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() # Initialization finetuner = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) dataset = Dataset(data_args) model = AutoModel.get_model(model_args) # Finetuning finetuner.tune(model=model, dataset=dataset) if __name__ == "__main__": main() ================================================ FILE: examples/rm_inference.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import logging import os import sys from transformers import HfArgumentParser from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) from lmflow.datasets import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline logger = logging.getLogger(__name__) def main(): # Parses arguments pipeline_name = "rm_inferencer" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((ModelArguments, DatasetArguments, PipelineArguments)) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): # If we pass only one argument to the script and it's the path to a json file, # let's parse it to get our arguments. model_args, data_args, pipeline_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) else: model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() dataset = Dataset(data_args) model = AutoModel.get_model(model_args, do_train=False) inferencer = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args ) res = inferencer.inference( model, dataset, ) if pipeline_args.save_inference_results: res.save(pipeline_args.inference_results_path) if __name__ == "__main__": main() ================================================ FILE: examples/sglang_inference.py ================================================ #!/usr/bin/env python # Copyright 2025 Statistics and Machine Learning Research Group. All rights reserved. import logging import os import sys from transformers import HfArgumentParser from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) from lmflow.datasets import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline logger = logging.getLogger(__name__) def main(): # Parses arguments pipeline_name = "sglang_inferencer" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((ModelArguments, DatasetArguments, PipelineArguments)) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): # If we pass only one argument to the script and it's the path to a json file, # let's parse it to get our arguments. model_args, data_args, pipeline_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) else: model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() dataset = Dataset(data_args) model = AutoModel.get_model(model_args, do_train=False) inferencer = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args ) res = inferencer.inference( model, dataset, release_gpu=True, ) if __name__ == "__main__": main() ================================================ FILE: examples/speculative_inference.py ================================================ import argparse import os if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( "--gpu", type=str, default="0", help="gpu id, currently speculative inference only support single gpu" ) parser.add_argument( "--model", type=str, default="gpt2-xl", help="target model name or path (i.e., the large model you want to accelerate), \ currently only supports huggingface decoder only models", ) parser.add_argument( "--draft_model", type=str, default="gpt2", help="draft model name or path, currently only supports huggingface decoder only models", ) parser.add_argument( "--gamma", type=int, default=5, help="number of tokens that the draft model will generate at each step" ) parser.add_argument( "--max_new_tokens", type=int, default=512, help="maximum number of tokens that the speculative inference will generate", ) parser.add_argument("--temperature", type=float, default=0.3, help="temperature for sampling") params = parser.parse_args() os.environ["CUDA_VISIBLE_DEVICES"] = params.gpu from lmflow.args import DatasetArguments, InferencerArguments, ModelArguments from lmflow.models import hf_decoder_model from lmflow.pipeline.inferencer import SpeculativeInferencer model_args = ModelArguments(model_name_or_path=params.model) model = hf_decoder_model.HFDecoderModel(model_args) draft_model_args = ModelArguments(model_name_or_path=params.draft_model) draft_model = hf_decoder_model.HFDecoderModel(draft_model_args) inferencer_args = InferencerArguments() data_args = DatasetArguments() specinf = SpeculativeInferencer(model_args, draft_model_args, data_args, inferencer_args) while True: try: text = input("Speculative Inference: ") specinf_res = specinf.inference( model, draft_model, text, gamma=params.gamma, max_new_tokens=params.max_new_tokens, temperature=params.temperature, ) print(specinf_res) print("\n\n") except EOFError: break ================================================ FILE: examples/tool_inference.py ================================================ import argparse import os from lmflow.args import DatasetArguments, InferencerArguments, ModelArguments from lmflow.models import hf_decoder_model from lmflow.pipeline.inferencer import ToolInferencer def main(): parser = argparse.ArgumentParser() parser.add_argument( "--gpu", type=str, default="0", help="gpu id, currently speculative inference only support single gpu" ) parser.add_argument( "--model", type=str, default="codellama/CodeLlama-7b-instruct-hf", help="target code generation model name or path you \ currently only supports huggingface decoder only models", ) params = parser.parse_args() os.environ["CUDA_VISIBLE_DEVICES"] = params.gpu model_args = ModelArguments(model_name_or_path=params.model) model = hf_decoder_model.HFDecoderModel(model_args) inferencer_args = InferencerArguments() data_args = DatasetArguments() toolinf = ToolInferencer(model_args, data_args, inferencer_args) while True: try: text = input("Tool Inference: ") toolinf_res = toolinf.inference(model, text) toolinf_res = toolinf_res.replace("", "") toolinf_res = toolinf_res.replace("", "") print("\n\nResult:") print(toolinf_res) print("\n\n") run_code = input("Run code? (y/n): ") if run_code == "y": toolinf.code_exec(toolinf_res) if run_code == "n": continue except EOFError: break if __name__ == "__main__": main() ================================================ FILE: examples/vis_chatbot.py ================================================ #!/usr/bin/env python # Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. """A simple shell to inference the input data.""" import json import logging import os import os.path as osp import sys from dataclasses import dataclass, field import numpy as np import requests from PIL import Image sys.path.remove(os.path.abspath(os.path.dirname(sys.argv[0]))) import time import warnings from typing import Optional from transformers import HfArgumentParser from lmflow.args import AutoArguments, DatasetArguments, VisModelArguments from lmflow.datasets.dataset import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline logging.disable(logging.ERROR) warnings.filterwarnings("ignore") @dataclass class ChatbotArguments: prompt_structure: Optional[str] = field( default="{input_text}", metadata={"help": "prompt structure given user's input text"}, ) end_string: Optional[str] = field( default="#", metadata={"help": "end string mark of the chatbot's output"}, ) image_path: Optional[str] = field(default=None, metadata={"help": "image path for input image"}) input_text: Optional[str] = field(default="", metadata={"help": "input text for reasoning"}) task: Optional[str] = field( default="vqa", metadata={ "help": ( "task for reasoning" "If do the caption task, the input text is describe " "the image and the conversation is only one round" "If other, the conversation is multi-round" ) }, ) chatbot_type: Optional[str] = field( default="None", metadata={"help": ("prompt formatthe default format is ''Anthoer format is they way in mini-gpt4.")}, ) stream_inference: Optional[bool] = field(default=False, metadata={"help": "whether to do the stream inference"}) with_deepspeed: Optional[bool] = field(default=True, metadata={"help": "whether to use deepspeed"}) def main(): pipeline_name = "inferencer" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser( ( VisModelArguments, PipelineArguments, ChatbotArguments, ) ) model_args, pipeline_args, chatbot_args = parser.parse_args_into_dataclasses() inferencer_args = pipeline_args with open(pipeline_args.deepspeed) as f: ds_config = json.load(f) model = AutoModel.get_model( model_args, do_train=False, ds_config=ds_config, device=pipeline_args.device, custom_model=model_args.custom_model, with_deepspeed=chatbot_args.with_deepspeed, ) data_args = DatasetArguments(dataset_path=None) dataset = Dataset(data_args, backend="dict") inferencer = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) # Chats model_name = model_args.model_name_or_path if model_args.llm_model_name_or_path is not None: model_name = model_name + " with {}".format(model_args.llm_model_name_or_path) if model_args.lora_model_path is not None: model_name += f" + {model_args.lora_model_path}" guide_message = ( "\n" f"#############################################################################\n" f"## A {model_name} chatbot is now chatting with you!\n" f"## The command for loading a new image: ###Load image:\n" f"#############################################################################\n" "\n" ) print(guide_message) # context = ( # "You are a helpful assistant who follows the given instructions" # " unconditionally." # ) end_string = chatbot_args.end_string if chatbot_args.chatbot_type == "mini_gpt": context = ( "Give the following image: ImageContent. " + "You will be able to see the image once I provide it to you. Please answer my questions." ) user_name = "Human" sep = "###" elif chatbot_args.chatbot_type == "llava": context = ( "A chat between a curious human and an artificial intelligence assistant. " "The assistant gives helpful, detailed, and polite answers to the human's questions." ) user_name = "USER" sep = " " else: context = "" user_name = "" sep = "###" prompt_structure = chatbot_args.prompt_structure # Load image and input text for reasoning image_list = [] if chatbot_args.image_path is not None: raw_image = Image.open(chatbot_args.image_path) else: img_url = "https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg" raw_image = Image.open(requests.get(img_url, stream=True).raw).convert("RGB") base_size = raw_image.size image_list.append(np.array(raw_image)) input_text = chatbot_args.input_text if chatbot_args.task == "image_caption" and len(input_text) == 0: input_text = "a photography of" if chatbot_args.chatbot_type == "mini_gpt": context += sep + user_name + ": " + " " elif chatbot_args.chatbot_type == "llava": context += sep + user_name + ": " + "\n" # this flag is for determining if we need to add the ###Human: prompt # if text after loading image, we add it when loading image # else, we add it when read the text. text_after_loading_image = True if model_args.use_prompt_cache: if osp.exists(model_args.prompt_cache_path): model.backend_model.load_prompt_cache(model_args.prompt_cache_path) if chatbot_args.task == "image_caption": # single round reasoning input_dataset = dataset.from_dict( { "type": "image_text", "instances": [ { "images": np.stack(image_list), "text": input_text, } ], } ) output = inferencer.inference(model, input_dataset) print(output.backend_dataset["text"]) else: # text, 1st image token, answer, text, 2nd image token, while True: input_text = input("User >>> ") if input_text == "exit": print("exit...") break elif input_text.startswith("###Load image:"): image_path = input_text[14:] try: raw_image = Image.open(image_path) # current dataset doesn't support batch of image with different shape # so we resize the image and convert then into a numpy array # In the future, we need to design a new dataset format that support # batch of image with different shape raw_image = raw_image.resize(base_size) image_list.append(np.array(raw_image)) if chatbot_args.chatbot_type == "mini_gpt": context += sep + user_name + ": " + " " elif chatbot_args.chatbot_type == "llava": context += sep + user_name + ": " + "\n" else: raise NotImplementedError text_after_loading_image = True print("Finish loading image with path {}".format(image_path)) continue except FileNotFoundError: print("Load image failed with path {}".format(image_path)) continue elif input_text == "reset": context = "" print("Chat history cleared") continue if text_after_loading_image is False: context += sep + user_name + ": " else: text_after_loading_image = False if not input_text: input_text = " " context += prompt_structure.format(input_text=input_text) # TODO handle when model doesn't have the get_max_length context = context[-model.get_max_length() :] # Memory of the bot input_dataset = dataset.from_dict( { "type": "image_text", "instances": [ { "images": np.stack(image_list), "text": context, } ], } ) if chatbot_args.chatbot_type in ["mini_gpt", "llava"]: remove_image_flag = True else: remove_image_flag = False begin_time = time.time() if not chatbot_args.stream_inference: # directly inference the results output_dataset = inferencer.inference( model, input_dataset, remove_image_flag=remove_image_flag, chatbot_type=chatbot_args.chatbot_type, ) response = output_dataset.backend_dataset["text"] print(response[0]) print("\n", end="") context += response[0] else: # do the stream inference print("Bot: ", end="") print_index = 0 token_per_step = 4 for response, flag_break in inferencer.stream_inference( context=context, model=model, max_new_tokens=inferencer_args.max_new_tokens, token_per_step=token_per_step, temperature=inferencer_args.temperature, end_string=end_string, input_dataset=input_dataset, ): # Prints characters in the buffer new_print_index = print_index for char in response[print_index:]: if end_string is not None and char == end_string[0]: if new_print_index + len(end_string) >= len(response): break new_print_index += 1 print(char, end="", flush=True) print_index = new_print_index if flag_break: break print("\n", end="") context += response + "\n" if model_args.use_prompt_cache: osp.makedirs(osp.dirname(model_args.prompt_cache_path), exist_ok=True) model.backend_model.save_prompt_cache(model_args.prompt_cache_path) end_time = time.time() print("Whole data and model forward time", end_time - begin_time) if __name__ == "__main__": main() ================================================ FILE: examples/vis_chatbot_gradio.py ================================================ #!/usr/bin/env python # Copyright 2023 Statistics and Machine Learning Research Group at HKUST. All rights reserved. """A simple Multimodal chatbot implemented with lmflow APIs.""" import json import logging import time import warnings from dataclasses import dataclass, field from typing import Optional import numpy as np import torch from PIL import Image from transformers import HfArgumentParser from lmflow.args import AutoArguments, DatasetArguments, VisModelArguments from lmflow.datasets.dataset import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline from lmflow.utils.versioning import is_gradio_available if is_gradio_available(): import gradio as gr else: raise ImportError("Gradio is not available. Please install it via `pip install gradio`.") MAX_BOXES = 20 logging.disable(logging.ERROR) warnings.filterwarnings("ignore") torch.multiprocessing.set_start_method("spawn", force=True) css = """ #user { float: right; position:relative; right:5px; width:auto; min-height:32px; max-width: 60% line-height: 32px; padding: 2px 8px; font-size: 14px; background: #9DC284; border-radius:5px; margin:10px 0px; } #chatbot { float: left; position:relative; right:5px; width:auto; min-height:32px; max-width: 60% line-height: 32px; padding: 2px 8px; font-size: 14px; background:#7BA7D7; border-radius:5px; margin:10px 0px; } """ @dataclass class ChatbotArguments: prompt_structure: Optional[str] = field( default="{input_text}", metadata={"help": "prompt structure given user's input text"}, ) end_string: Optional[str] = field( default="#", metadata={"help": "end string mark of the chatbot's output"}, ) image_path: Optional[str] = field(default=None, metadata={"help": "image path for input image"}) input_text: Optional[str] = field(default="", metadata={"help": "input text for reasoning"}) task: Optional[str] = field( default="image_caption", metadata={ "help": "task for reasoning", }, ) chatbot_format: Optional[str] = field(default="None", metadata={"help": "prompt format"}) def gradio_reset(chat_state, img_list): if chat_state is not None: chat_state = "" if img_list is not None: img_list = [] return ( None, gr.update(placeholder="Please upload an image first", interactive=False), gr.update(value="Upload & Start Chat", interactive=True), chat_state, img_list, ) def upload_image(image_file, history, text_input, chat_state, image_list): # if gr_image is None: # return None, None, gr.update(interactive=True), chat_state, None history = history + [((image_file.name,), None)] if chat_state is None: if chatbot_args.chatbot_format == "mini_gpt": chat_state = ( "Give the following image: ImageContent. " + "You will be able to see the image once I provide it to you. Please answer my questions." ) else: chat_state = "" image = read_img(image_file.name) if not isinstance(image_list, list) or (isinstance(image_list, list) and len(image_list) == 0): image_list = [] image_list.append(image) else: image_list.append(image.resize(image_list[0].size)) if chatbot_args.chatbot_format == "mini_gpt": chat_state += "### Human: " + "" return ( gr.update(interactive=True, placeholder="Enter text and press enter, or upload an image"), history, chat_state, image_list, ) def read_img(image): if isinstance(image, str): raw_image = Image.open(image).convert("RGB") elif isinstance(image, Image.Image): raw_image = image else: raise NotImplementedError return raw_image def gradio_ask(user_message, chatbot, chat_state): if len(user_message) == 0: return gr.update(interactive=True, placeholder="Input should not be empty!"), chatbot, chat_state prompted_user_message = prompt_structure.format(input_text=user_message) if chat_state is None: chat_state = "" chat_state = chat_state + prompted_user_message chatbot = chatbot + [[user_message, None]] return "", chatbot, chat_state def gradio_answer(chatbot, chat_state, image_list, num_beams=1, temperature=1.0): input_dataset = dataset.from_dict( { "type": "image_text", "instances": [{"images": np.stack([np.array(i) for i in image_list]), "text": chat_state}], } ) remove_image_flag = chatbot_args.chatbot_format == "mini_gpt" chatbot[-1][1] = "" print_index = 0 token_per_step = 4 # 48 max_new_tokens = -1 temperature = 0.7 context = chatbot # Another user may have exited during the handling of his/her response, # Wait for inferencer process to complete its job, after which "busy" mark # in the request_queue will be released while not request_queue.empty(): time.sleep(0.01) # Clean response_queue left by the previous user while not response_queue.empty(): response_queue.get() request_queue.put( (context, max_new_tokens, token_per_step, temperature, end_string, input_dataset, remove_image_flag) ) while True: if not response_queue.empty(): response, flag_break = response_queue.get() # Prints characters in the buffer new_print_index = print_index for char in response[print_index:]: if end_string is not None and char == end_string[0]: if new_print_index + len(end_string) >= len(response): break new_print_index += 1 chatbot[-1][1] += char chat_state += char time.sleep(0.06) yield chatbot, chat_state, image_list print_index = new_print_index if flag_break: break char = "\n" chatbot[-1][1] += char chat_state += char yield chatbot, chat_state, image_list def start_inferencer( request_queue, response_queue, model_args, pipeline_name, pipeline_args, data_args, dataset, chatbot_args, ): with open(pipeline_args.deepspeed) as f: ds_config = json.load(f) model = AutoModel.get_model( model_args, do_train=False, ds_config=ds_config, device=pipeline_args.device, custom_model=model_args.custom_model, ) inferencer = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args, ) while True: if not request_queue.empty(): request_queue.put("busy") request = request_queue.get() context = request[0] max_new_tokens = request[1] token_per_step = request[2] temperature = request[3] end_string = request[4] input_dataset = request[5] remove_image_flag = request[6] break_in_the_middle = False for response_text, flag_break in inferencer.stream_inference( context=context, model=model, max_new_tokens=max_new_tokens, token_per_step=token_per_step, temperature=temperature, end_string=end_string, input_dataset=input_dataset, remove_image_flag=remove_image_flag, ): response_queue.put((response_text, flag_break)) if flag_break: break_in_the_middle = True break if not break_in_the_middle: response_text = "" flag_break = True response_queue.put((response_text, flag_break)) mark = "" while mark != "busy": mark = request_queue.get() # Release the "busy" mark time.sleep(0.001) if __name__ == "__main__": pipeline_name = "inferencer" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser( ( VisModelArguments, PipelineArguments, ChatbotArguments, ) ) model_args, pipeline_args, chatbot_args = parser.parse_args_into_dataclasses() data_args = DatasetArguments(dataset_path=None) dataset = Dataset(data_args, backend="dict") request_queue = torch.multiprocessing.Queue() response_queue = torch.multiprocessing.Queue() inferencer_process = torch.multiprocessing.Process( target=start_inferencer, args=( request_queue, response_queue, model_args, pipeline_name, pipeline_args, data_args, dataset, chatbot_args, ), ) inferencer_process.start() # Chats model_name = model_args.model_name_or_path if model_args.lora_model_path is not None: model_name += f" + {model_args.lora_model_path}" end_string = chatbot_args.end_string prompt_structure = chatbot_args.prompt_structure title = """

LMFlow Multi-modal Chatbot

""" with gr.Blocks() as demo: gr.Markdown(title) chatbot = gr.Chatbot([], elem_id="chatbot").style(height=500) with gr.Row(): chat_state = gr.State() image_list = gr.State() with gr.Column(scale=0.1, min_width=0): clear = gr.Button("Restart") with gr.Column(scale=0.8): text_input = gr.Textbox( show_label=False, placeholder="Please upload an image first", interactive=False, ).style(container=False) with gr.Column(scale=0.1, min_width=0): upload_button = gr.UploadButton("📁", file_types=["image"]) txt_msg = text_input.submit( fn=gradio_ask, inputs=[text_input, chatbot, chat_state], outputs=[text_input, chatbot, chat_state], queue=False, ).then( fn=gradio_answer, inputs=[chatbot, chat_state, image_list], outputs=[chatbot, chat_state, image_list], ) txt_msg.then(lambda: gr.update(interactive=True), None, [text_input], queue=False) file_msg = upload_button.upload( fn=upload_image, inputs=[upload_button, chatbot, text_input, chat_state, image_list], outputs=[text_input, chatbot, chat_state, image_list], queue=False, ) clear.click( fn=gradio_reset, inputs=[chat_state, image_list], outputs=[chatbot, text_input, upload_button, chat_state, image_list], queue=False, ) demo.queue(max_size=1, api_open=False).launch(share=True) inferencer_process.join() ================================================ FILE: examples/vllm_inference.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import logging import os import sys from transformers import HfArgumentParser from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) from lmflow.datasets import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.auto_pipeline import AutoPipeline logger = logging.getLogger(__name__) def main(): # Parses arguments pipeline_name = "vllm_inferencer" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((ModelArguments, DatasetArguments, PipelineArguments)) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): # If we pass only one argument to the script and it's the path to a json file, # let's parse it to get our arguments. model_args, data_args, pipeline_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) else: model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() dataset = Dataset(data_args) model = AutoModel.get_model(model_args, do_train=False) inferencer = AutoPipeline.get_pipeline( pipeline_name=pipeline_name, model_args=model_args, data_args=data_args, pipeline_args=pipeline_args ) inferencer.inference( model, dataset, release_gpu=False, enable_decode_inference_result=pipeline_args.enable_decode_inference_result, enable_distributed_vllm_inference=pipeline_args.enable_distributed_vllm_inference, ) if __name__ == "__main__": main() ================================================ FILE: experimental/Hymba/README.md ================================================ # Training Hymba with LMFlow ## Hymba [GITHUB](https://github.com/NVlabs/hymba/tree/main) Hymba is a family of small language models (SLMs) featuring a hybrid-head parallel architecture that integrates transformer attention mechanisms with SSMs to achieve the best of both worlds: enhanced efficiency and improved performance. In Hymba, attention heads provide high-resolution recall, while SSM heads enable efficient context summarization. ## Preparing the environment - Using Docker ```bash docker pull ghcr.io/tilmto/hymba:v1 docker run --gpus all -v /home/$USER:/home/$USER -it ghcr.io/tilmto/hymba:v1 bash ``` - Install LMFlow in the docker container ```bash git clone https://github.com/OptimalScale/LMFlow.git cd LMFlow conda create -n lmflow python=3.9 -y conda activate lmflow conda install mpi4py pip install -e . ``` - Tips For training the Hymba model, please add below arguments to the `run_finetune.sh` script: ```bash --trust_remote_code True --bf16 ``` Demo script: [run_finetune_hymba.sh](./run_finetune_hymba.sh) Recommend on the A100, H100, A40 GPUs. ## Training Loss The training loss curve for `nvidia/Hymba-1.5B-Instruct`, fine-tuned on the `MedMCQA/train` dataset with a learning rate of $5e-5$ over 100 steps using SFT, LoRA, LISA, and DORA, is shown below: ![Training Loss](../../docs/assets/Hymba_loss.png) ================================================ FILE: experimental/Hymba/run_finetune_hymba.sh ================================================ #!/bin/bash # Please run this script under ${project_id} in project directory of # https://github.com/shizhediao/llm-ft # COMMIT: d5fecf30ba8011067b10cf51fede53a5ab6574e4 # Parses arguments model_name_or_path=nvidia/Hymba-1.5B-Instruct dataset_path=MedMCQA/train output_dir=output_models/finetune deepspeed_args="--master_port=11000" conversation_template=llama2 # Safety related arguments trust_remote_code=0 while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; -o|--output_model_path) output_dir="$2" shift ;; --conversation_template) conversation_template="$2" shift ;; --deepspeed_args) deepspeed_args="$2" shift ;; --trust_remote_code) trust_remote_code="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done # Finetune exp_id=finetune project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} deepspeed ${deepspeed_args} \ examples/finetune.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code ${trust_remote_code} \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --conversation_template ${conversation_template} \ --num_train_epochs 0.01 \ --learning_rate 5e-5 \ --disable_group_texts 1 \ --block_size 256 \ --trust_remote_code True \ --per_device_train_batch_size 1 \ --deepspeed configs/archive/ds_config_zero2_no_offload.json \ --bf16 \ --run_name hymba_finetune \ --validation_split_percentage 0 \ --logging_steps 1 \ --do_train \ --gradient_checkpointing 1 \ --use_flash_attention 1 \ --ddp_timeout 72000 \ --save_steps 5000 \ --dataloader_num_workers 1 \ > >(tee ${log_dir}/train.log) \ 2> >(tee ${log_dir}/train.err >&2) ================================================ FILE: experimental/LISA-diffusion/README.md ================================================ ## How to introduce LISA into Stable Diffusion? [LISA](https://arxiv.org/abs/2403.17919) is an efficient fine-tuning algorithm akin to LoRA, yet it does not introduce additional parameters and can update the full parameters. Unlike LoRA, LISA has only been evaluated on Large Language Models (LLMs) and has not been verified on diffusion models. To address this gap, we have implemented LISA in Stable Diffusion. ### What is New? We have introduced a layer-by-layer update mechanism to further reduce memory requirements. This is inspired by [GaLore](https://arxiv.org/abs/2403.03507) and formally implemented as: ```python scheduler_dict = ... optimizer_dict = ... def optimizer_hook(p): if p.grad is None: del scheduler_dict[p] del optimizer_dict[p] return else: if p not in optimizer_dict: optimizer_dict[p] = optimizer_class([{"params":p}], lr=args.learning_rate, betas=(args.adam_beta1, args.adam_beta2), weight_decay=args.adam_weight_decay, eps=args.adam_epsilon) optimizer_dict[p] = accelerator.prepare_optimizer(optimizer_dict[p]) if p not in scheduler_dict: scheduler_dict[p] = get_scheduler( args.lr_scheduler, optimizer=optimizer_dict[p], num_warmup_steps=args.lr_warmup_steps * accelerator.num_processes, num_training_steps=args.max_train_steps * accelerator.num_processes) scheduler_dict[p] = accelerator.prepare_scheduler(scheduler_dict[p]) if accelerator.sync_gradients: torch.nn.utils.clip_grad_norm_(p, args.max_grad_norm) optimizer_dict[p].step() optimizer_dict[p].zero_grad(set_to_none=True) scheduler_dict[p].step() for p in unet.parameters(): if p.requires_grad: p.register_post_accumulate_grad_hook(optimizer_hook) ``` Without this strategy, LISA would not be able to achieve significant acceleration and memory savings. ### Get Started you should install necessary packages, including pytorch, diffusers and so on: ```bash # python==3.10.14 pip install torch==2.2.2 torchvision==0.17.2 torchaudio==2.2.2 --index-url https://download.pytorch.org/whl/cu118 git clone https://github.com/huggingface/diffusers cd diffusers pip install -e . pip install -r requirements.txt ``` Note that you should config accelerater by default: ```bash accelerate config default ``` The subdirectories can then be accessed to execute latent consistency model, instruct pix2pix and diffusion dpo. For different projects, you can execute the corresponding code. **(1) Latent Consistency Model** ```bash export MODEL_NAME="runwayml/stable-diffusion-v1-5" export OUTPUT_DIR="./lcm_distill_sd_lisa" accelerate launch train_lcm_distill_sd_wds_lisa.py \ --pretrained_teacher_model=$MODEL_NAME \ --output_dir=$OUTPUT_DIR \ --mixed_precision=no \ --resolution=512 \ --learning_rate=1e-5 --loss_type="huber" --ema_decay=0.95 --adam_weight_decay=0.0 \ --max_train_steps=1000 \ --max_train_samples=4000000 \ --dataloader_num_workers=8 \ --train_shards_path_or_url="pipe:curl -L -s https://huggingface.co/datasets/laion/conceptual-captions-12m-webdataset/resolve/main/data/{00000..01099}.tar?download=true" \ --validation_steps=200 \ --checkpointing_steps=200 --checkpoints_total_limit=10 \ --train_batch_size=8 \ --gradient_checkpointing --enable_xformers_memory_efficient_attention \ --gradient_accumulation_steps=2 \ --use_8bit_adam \ --resume_from_checkpoint=latest \ --report_to=wandb \ --seed=453645634 ``` **(2) Instruct Pix2Pix** ```bash export MODEL_NAME="runwayml/stable-diffusion-v1-5" export DATASET_ID="fusing/instructpix2pix-1000-samples" accelerate launch --mixed_precision="fp16" train_instruct_pix2pix_lisa.py \ --pretrained_model_name_or_path=$MODEL_NAME \ --dataset_name=$DATASET_ID \ --enable_xformers_memory_efficient_attention \ --resolution=256 --random_flip \ --train_batch_size=16 --gradient_accumulation_steps=1 --gradient_checkpointing \ --max_train_steps=15000 \ --checkpointing_steps=5000 --checkpoints_total_limit=1 \ --learning_rate=5e-05 --max_grad_norm=1 --lr_warmup_steps=0 \ --conditioning_dropout_prob=0.05 \ --mixed_precision=no --use_8bit_adam \ --seed=42 ``` **(3) Diffusion DPO** ```bash accelerate launch train_diffusion_dpo_lisa.py \ --pretrained_model_name_or_path=runwayml/stable-diffusion-v1-5 \ --output_dir="diffusion-dpo" \ --mixed_precision="no" \ --dataset_name=kashif/pickascore \ --resolution=512 \ --train_batch_size=8 \ --gradient_accumulation_steps=4 \ --gradient_checkpointing \ --use_8bit_adam \ --learning_rate=5e-5 \ --report_to="wandb" \ --lr_scheduler="constant" \ --lr_warmup_steps=0 \ --max_train_steps=10000 \ --checkpointing_steps=2000 \ --run_validation --validation_steps=200 \ --seed="0" \ --report_to="wandb" ``` ### Minimum Implementation Code We also add minimum implementation code in `single_lisa.py`, you can introduce it in your code as follows: ```python import torch import torch.nn as nn import torch.nn.functional as F import math,random import numpy as np import accelerate from single_lisa import LISADiffusion model = ... # initialize your model optimizer_class=... # initialize optimizer class akin to which in diffusers get_scheduler=... # initialize scheduler class akin to which in diffusers accelerator=... # config your accelerator lisa_trainer = LISADiffusion(model) lisa_trainer.register(optimizer_class=optimizer_class, get_scheduler=get_scheduler, accelerator=..., optim_kwargs=..., sched_kwargs=...) lisa_trainer.insert_hook(optimizer_class=optimizer_class, get_scheduler=get_scheduler, accelerator=..., optim_kwargs=..., sched_kwargs=...) model = accelerator.prepare_model(model) # this is not necessarily needed total_count = 0 for i in range(epochs): for image in train_loader: if total_count % 6 == 0 and total_count != 0: # you can use other number to replace 6 lisa_trainer.lisa_recall() total_count += 1 Training... # do not forget to remove optimizer.step() and scheduler.step() ``` ### Comparison We have similarly added the training code without lisa in each subdirectory, so the comparison will be extremely convenient: ```bash |--diffusion_dpo |--train_diffusion_dpo_lisa.py |--train_diffusion_dpo.py |--instruct_pix2pix |--train_instruct_pix2pix_lisa.py |--train_instruct_pix2pix.py |--latent_consistency_model |--train_lcm_distill_sd_wds_lisa.py |--train_lcm_distill_sd_wds_lisa.py ``` ### Visualization **(1) Latent Consistency Model** LISA:
LORA:
**(2) Instruct Pix2Pix** LISA:
LORA:
================================================ FILE: experimental/LISA-diffusion/diffusion_dpo/train_diffusion_dpo.py ================================================ #!/usr/bin/env python # Copyright 2024 bram-w, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and import argparse import contextlib import io import logging import math import os import shutil from pathlib import Path import diffusers import numpy as np import torch import torch.nn.functional as F import torch.utils.checkpoint import transformers import wandb from accelerate import Accelerator from accelerate.logging import get_logger from accelerate.utils import ProjectConfiguration, set_seed from datasets import load_dataset from diffusers import ( AutoencoderKL, DDPMScheduler, DiffusionPipeline, DPMSolverMultistepScheduler, UNet2DConditionModel, ) from diffusers.loaders import LoraLoaderMixin from diffusers.optimization import get_scheduler from diffusers.utils import check_min_version, convert_state_dict_to_diffusers from diffusers.utils.import_utils import is_xformers_available from huggingface_hub import create_repo, upload_folder from packaging import version from peft import LoraConfig from peft.utils import get_peft_model_state_dict from PIL import Image from torchvision import transforms from tqdm.auto import tqdm from transformers import AutoTokenizer, PretrainedConfig # Will error if the minimal version of diffusers is not installed. Remove at your own risks. check_min_version("0.25.0.dev0") logger = get_logger(__name__) VALIDATION_PROMPTS = [ "portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour, style by Dan Winters, Russell James, Steve McCurry, centered, extremely detailed, Nikon D850, award winning photography", # noqa: E501 "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k", "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", "A photo of beautiful mountain with realistic sunset and blue lake, highly detailed, masterpiece", ] def import_model_class_from_model_name_or_path(pretrained_model_name_or_path: str, revision: str): text_encoder_config = PretrainedConfig.from_pretrained( pretrained_model_name_or_path, subfolder="text_encoder", revision=revision, ) model_class = text_encoder_config.architectures[0] if model_class == "CLIPTextModel": from transformers import CLIPTextModel return CLIPTextModel else: raise ValueError(f"{model_class} is not supported.") def log_validation(args, unet, accelerator, weight_dtype, epoch, is_final_validation=False): logger.info(f"Running validation... \n Generating images with prompts:\n {VALIDATION_PROMPTS}.") # create pipeline pipeline = DiffusionPipeline.from_pretrained( args.pretrained_model_name_or_path, revision=args.revision, variant=args.variant, torch_dtype=weight_dtype, ) if not is_final_validation: pipeline.unet = accelerator.unwrap_model(unet) else: pipeline.load_lora_weights(args.output_dir, weight_name="pytorch_lora_weights.safetensors") pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config) pipeline = pipeline.to(accelerator.device) pipeline.set_progress_bar_config(disable=True) # run inference generator = torch.Generator(device=accelerator.device).manual_seed(args.seed) if args.seed else None images = [] context = contextlib.nullcontext() if is_final_validation else torch.cuda.amp.autocast() for prompt in VALIDATION_PROMPTS: with context: image = pipeline(prompt, num_inference_steps=25, generator=generator).images[0] images.append(image) tracker_key = "test" if is_final_validation else "validation" for tracker in accelerator.trackers: if tracker.name == "tensorboard": np_images = np.stack([np.asarray(img) for img in images]) tracker.writer.add_images(tracker_key, np_images, epoch, dataformats="NHWC") if tracker.name == "wandb": tracker.log( { tracker_key: [ wandb.Image(image, caption=f"{i}: {VALIDATION_PROMPTS[i]}") for i, image in enumerate(images) ] } ) # Also log images without the LoRA params for comparison. if is_final_validation: pipeline.disable_lora() no_lora_images = [ pipeline(prompt, num_inference_steps=25, generator=generator).images[0] for prompt in VALIDATION_PROMPTS ] for tracker in accelerator.trackers: if tracker.name == "tensorboard": np_images = np.stack([np.asarray(img) for img in no_lora_images]) tracker.writer.add_images("test_without_lora", np_images, epoch, dataformats="NHWC") if tracker.name == "wandb": tracker.log( { "test_without_lora": [ wandb.Image(image, caption=f"{i}: {VALIDATION_PROMPTS[i]}") for i, image in enumerate(no_lora_images) ] } ) def parse_args(input_args=None): parser = argparse.ArgumentParser(description="Simple example of a training script.") parser.add_argument( "--pretrained_model_name_or_path", type=str, default=None, required=True, help="Path to pretrained model or model identifier from huggingface.co/models.", ) parser.add_argument( "--revision", type=str, default=None, required=False, help="Revision of pretrained model identifier from huggingface.co/models.", ) parser.add_argument( "--dataset_name", type=str, default=None, help=( "The name of the Dataset (from the HuggingFace hub) to train on (could be your own, possibly private," " dataset). It can also be a path pointing to a local copy of a dataset in your filesystem," " or to a folder containing files that 🤗 Datasets can understand." ), ) parser.add_argument( "--dataset_split_name", type=str, default="validation", help="Dataset split to be used during training. Helpful to specify for conducting experimental runs.", ) parser.add_argument( "--variant", type=str, default=None, help="Variant of the model files of the pretrained model identifier from huggingface.co/models, 'e.g.' fp16", ) parser.add_argument( "--run_validation", default=False, action="store_true", help=( "Whether to run validation inference in between training and also after training. Helps to track progress." ), ) parser.add_argument( "--validation_steps", type=int, default=200, help="Run validation every X steps.", ) parser.add_argument( "--max_train_samples", type=int, default=None, help=( "For debugging purposes or quicker training, truncate the number of training examples to this value if set." ), ) parser.add_argument( "--output_dir", type=str, default="diffusion-dpo-lora", help="The output directory where the model predictions and checkpoints will be written.", ) parser.add_argument( "--cache_dir", type=str, default=None, help="The directory where the downloaded models and datasets will be stored.", ) parser.add_argument("--seed", type=int, default=None, help="A seed for reproducible training.") parser.add_argument( "--resolution", type=int, default=512, help=( "The resolution for input images, all the images in the train/validation dataset will be resized to this" " resolution" ), ) parser.add_argument( "--vae_encode_batch_size", type=int, default=8, help="Batch size to use for VAE encoding of the images for efficient processing.", ) parser.add_argument( "--no_hflip", action="store_true", help="whether to randomly flip images horizontally", ) parser.add_argument( "--random_crop", default=False, action="store_true", help=( "Whether to random crop the input images to the resolution. If not set, the images will be center-cropped." ), ) parser.add_argument( "--train_batch_size", type=int, default=4, help="Batch size (per device) for the training dataloader." ) parser.add_argument("--num_train_epochs", type=int, default=1) parser.add_argument( "--max_train_steps", type=int, default=None, help="Total number of training steps to perform. If provided, overrides num_train_epochs.", ) parser.add_argument( "--checkpointing_steps", type=int, default=500, help=( "Save a checkpoint of the training state every X updates. These checkpoints can be used both as final" " checkpoints in case they are better than the last checkpoint, and are also suitable for resuming" " training using `--resume_from_checkpoint`." ), ) parser.add_argument( "--checkpoints_total_limit", type=int, default=None, help=("Max number of checkpoints to store."), ) parser.add_argument( "--resume_from_checkpoint", type=str, default=None, help=( "Whether training should be resumed from a previous checkpoint. Use a path saved by" ' `--checkpointing_steps`, or `"latest"` to automatically select the last available checkpoint.' ), ) parser.add_argument( "--gradient_accumulation_steps", type=int, default=1, help="Number of updates steps to accumulate before performing a backward/update pass.", ) parser.add_argument( "--gradient_checkpointing", action="store_true", help="Whether or not to use gradient checkpointing to save memory at the expense of slower backward pass.", ) parser.add_argument( "--beta_dpo", type=int, default=2500, help="DPO KL Divergence penalty.", ) parser.add_argument( "--loss_type", type=str, default="sigmoid", help="DPO loss type. Can be one of 'sigmoid' (default), 'ipo', or 'cpo'", ) parser.add_argument( "--learning_rate", type=float, default=5e-4, help="Initial learning rate (after the potential warmup period) to use.", ) parser.add_argument( "--scale_lr", action="store_true", default=False, help="Scale the learning rate by the number of GPUs, gradient accumulation steps, and batch size.", ) parser.add_argument( "--lr_scheduler", type=str, default="constant", help=( 'The scheduler type to use. Choose between ["linear", "cosine", "cosine_with_restarts", "polynomial",' ' "constant", "constant_with_warmup"]' ), ) parser.add_argument( "--lr_warmup_steps", type=int, default=500, help="Number of steps for the warmup in the lr scheduler." ) parser.add_argument( "--lr_num_cycles", type=int, default=1, help="Number of hard resets of the lr in cosine_with_restarts scheduler.", ) parser.add_argument("--lr_power", type=float, default=1.0, help="Power factor of the polynomial scheduler.") parser.add_argument( "--dataloader_num_workers", type=int, default=0, help=( "Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process." ), ) parser.add_argument( "--use_8bit_adam", action="store_true", help="Whether or not to use 8-bit Adam from bitsandbytes." ) parser.add_argument("--adam_beta1", type=float, default=0.9, help="The beta1 parameter for the Adam optimizer.") parser.add_argument("--adam_beta2", type=float, default=0.999, help="The beta2 parameter for the Adam optimizer.") parser.add_argument("--adam_weight_decay", type=float, default=1e-2, help="Weight decay to use.") parser.add_argument("--adam_epsilon", type=float, default=1e-08, help="Epsilon value for the Adam optimizer") parser.add_argument("--max_grad_norm", default=1.0, type=float, help="Max gradient norm.") parser.add_argument("--push_to_hub", action="store_true", help="Whether or not to push the model to the Hub.") parser.add_argument("--hub_token", type=str, default=None, help="The token to use to push to the Model Hub.") parser.add_argument( "--hub_model_id", type=str, default=None, help="The name of the repository to keep in sync with the local `output_dir`.", ) parser.add_argument( "--logging_dir", type=str, default="logs", help=( "[TensorBoard](https://www.tensorflow.org/tensorboard) log directory. Will default to" " *output_dir/runs/**CURRENT_DATETIME_HOSTNAME***." ), ) parser.add_argument( "--allow_tf32", action="store_true", help=( "Whether or not to allow TF32 on Ampere GPUs. Can be used to speed up training. For more information, see" " https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices" ), ) parser.add_argument( "--report_to", type=str, default="tensorboard", help=( 'The integration to report the results and logs to. Supported platforms are `"tensorboard"`' ' (default), `"wandb"` and `"comet_ml"`. Use `"all"` to report to all integrations.' ), ) parser.add_argument( "--mixed_precision", type=str, default=None, choices=["no", "fp16", "bf16"], help=( "Whether to use mixed precision. Choose between fp16 and bf16 (bfloat16). Bf16 requires PyTorch >=" " 1.10.and an Nvidia Ampere GPU. Default to the value of accelerate config of the current system or the" " flag passed with the `accelerate.launch` command. Use this argument to override the accelerate config." ), ) parser.add_argument( "--prior_generation_precision", type=str, default=None, choices=["no", "fp32", "fp16", "bf16"], help=( "Choose prior generation precision between fp32, fp16 and bf16 (bfloat16). Bf16 requires PyTorch >=" " 1.10.and an Nvidia Ampere GPU. Default to fp16 if a GPU is available else fp32." ), ) parser.add_argument("--local_rank", type=int, default=-1, help="For distributed training: local_rank") parser.add_argument( "--enable_xformers_memory_efficient_attention", action="store_true", help="Whether or not to use xformers." ) parser.add_argument( "--rank", type=int, default=4, help=("The dimension of the LoRA update matrices."), ) parser.add_argument( "--tracker_name", type=str, default="diffusion-dpo-lora", help=("The name of the tracker to report results to."), ) if input_args is not None: args = parser.parse_args(input_args) else: args = parser.parse_args() if args.dataset_name is None: raise ValueError("Must provide a `dataset_name`.") env_local_rank = int(os.environ.get("LOCAL_RANK", -1)) if env_local_rank != -1 and env_local_rank != args.local_rank: args.local_rank = env_local_rank return args def tokenize_captions(tokenizer, examples): max_length = tokenizer.model_max_length captions = [] for caption in examples["caption"]: captions.append(caption) text_inputs = tokenizer(captions, truncation=True, padding="max_length", max_length=max_length, return_tensors="pt") return text_inputs.input_ids @torch.no_grad() def encode_prompt(text_encoder, input_ids): text_input_ids = input_ids.to(text_encoder.device) attention_mask = None prompt_embeds = text_encoder(text_input_ids, attention_mask=attention_mask) prompt_embeds = prompt_embeds[0] return prompt_embeds def main(args): if args.report_to == "wandb" and args.hub_token is not None: raise ValueError( "You cannot use both --report_to=wandb and --hub_token due to a security risk of exposing your token." " Please use `huggingface-cli login` to authenticate with the Hub." ) logging_dir = Path(args.output_dir, args.logging_dir) accelerator_project_config = ProjectConfiguration(project_dir=args.output_dir, logging_dir=logging_dir) accelerator = Accelerator( gradient_accumulation_steps=args.gradient_accumulation_steps, mixed_precision=args.mixed_precision, log_with=args.report_to, project_config=accelerator_project_config, ) # Make one log on every process with the configuration for debugging. logging.basicConfig( format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%m/%d/%Y %H:%M:%S", level=logging.INFO, ) logger.info(accelerator.state, main_process_only=False) if accelerator.is_local_main_process: transformers.utils.logging.set_verbosity_warning() diffusers.utils.logging.set_verbosity_info() else: transformers.utils.logging.set_verbosity_error() diffusers.utils.logging.set_verbosity_error() # If passed along, set the training seed now. if args.seed is not None: set_seed(args.seed) # Handle the repository creation if accelerator.is_main_process: if args.output_dir is not None: os.makedirs(args.output_dir, exist_ok=True) if args.push_to_hub: repo_id = create_repo( repo_id=args.hub_model_id or Path(args.output_dir).name, exist_ok=True, token=args.hub_token ).repo_id # Load the tokenizer tokenizer = AutoTokenizer.from_pretrained( args.pretrained_model_name_or_path, subfolder="tokenizer", revision=args.revision, use_fast=False, ) # import correct text encoder class text_encoder_cls = import_model_class_from_model_name_or_path(args.pretrained_model_name_or_path, args.revision) # Load scheduler and models noise_scheduler = DDPMScheduler.from_pretrained(args.pretrained_model_name_or_path, subfolder="scheduler") text_encoder = text_encoder_cls.from_pretrained( args.pretrained_model_name_or_path, subfolder="text_encoder", revision=args.revision, variant=args.variant ) vae = AutoencoderKL.from_pretrained( args.pretrained_model_name_or_path, subfolder="vae", revision=args.revision, variant=args.variant ) unet = UNet2DConditionModel.from_pretrained( args.pretrained_model_name_or_path, subfolder="unet", revision=args.revision, variant=args.variant ) vae.requires_grad_(False) text_encoder.requires_grad_(False) unet.requires_grad_(False) # For mixed precision training we cast all non-trainable weights (vae, non-lora text_encoder and non-lora unet) # to half-precision as these weights are only used for inference, keeping weights in full precision is not required. weight_dtype = torch.float32 if accelerator.mixed_precision == "fp16": weight_dtype = torch.float16 elif accelerator.mixed_precision == "bf16": weight_dtype = torch.bfloat16 # Move unet, vae and text_encoder to device and cast to weight_dtype unet.to(accelerator.device, dtype=weight_dtype) vae.to(accelerator.device, dtype=weight_dtype) text_encoder.to(accelerator.device, dtype=weight_dtype) # Set up LoRA. unet_lora_config = LoraConfig( r=args.rank, lora_alpha=args.rank, init_lora_weights="gaussian", target_modules=["to_k", "to_q", "to_v", "to_out.0"], ) # Add adapter and make sure the trainable params are in float32. unet.add_adapter(unet_lora_config) if args.mixed_precision == "fp16": for param in unet.parameters(): # only upcast trainable parameters (LoRA) into fp32 if param.requires_grad: param.data = param.to(torch.float32) if args.enable_xformers_memory_efficient_attention: if is_xformers_available(): import xformers xformers_version = version.parse(xformers.__version__) if xformers_version == version.parse("0.0.16"): logger.warning( "xFormers 0.0.16 cannot be used for training in some GPUs. If you observe problems during " "training, please update xFormers to at least 0.0.17. " "See https://huggingface.co/docs/diffusers/main/en/optimization/xformers for more details." ) unet.enable_xformers_memory_efficient_attention() else: raise ValueError("xformers is not available. Make sure it is installed correctly") if args.gradient_checkpointing: unet.enable_gradient_checkpointing() # create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format def save_model_hook(models, weights, output_dir): if accelerator.is_main_process: # there are only two options here. Either are just the unet attn processor layers # or there are the unet and text encoder atten layers unet_lora_layers_to_save = None for model in models: if isinstance(model, type(accelerator.unwrap_model(unet))): unet_lora_layers_to_save = convert_state_dict_to_diffusers(get_peft_model_state_dict(model)) else: raise ValueError(f"unexpected save model: {model.__class__}") # make sure to pop weight so that corresponding model is not saved again weights.pop() LoraLoaderMixin.save_lora_weights( output_dir, unet_lora_layers=unet_lora_layers_to_save, text_encoder_lora_layers=None, ) def load_model_hook(models, input_dir): unet_ = None while len(models) > 0: model = models.pop() if isinstance(model, type(accelerator.unwrap_model(unet))): unet_ = model else: raise ValueError(f"unexpected save model: {model.__class__}") lora_state_dict, network_alphas = LoraLoaderMixin.lora_state_dict(input_dir) LoraLoaderMixin.load_lora_into_unet(lora_state_dict, network_alphas=network_alphas, unet=unet_) accelerator.register_save_state_pre_hook(save_model_hook) accelerator.register_load_state_pre_hook(load_model_hook) # Enable TF32 for faster training on Ampere GPUs, # cf https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices if args.allow_tf32: torch.backends.cuda.matmul.allow_tf32 = True if args.scale_lr: args.learning_rate = ( args.learning_rate * args.gradient_accumulation_steps * args.train_batch_size * accelerator.num_processes ) # Use 8-bit Adam for lower memory usage or to fine-tune the model in 16GB GPUs if args.use_8bit_adam: try: import bitsandbytes as bnb except ImportError: raise ImportError( "To use 8-bit Adam, please install the bitsandbytes library: `pip install bitsandbytes`." ) from None optimizer_class = bnb.optim.AdamW8bit else: optimizer_class = torch.optim.AdamW # Optimizer creation params_to_optimize = list(filter(lambda p: p.requires_grad, unet.parameters())) optimizer = optimizer_class( params_to_optimize, lr=args.learning_rate, betas=(args.adam_beta1, args.adam_beta2), weight_decay=args.adam_weight_decay, eps=args.adam_epsilon, ) # Dataset and DataLoaders creation: train_dataset = load_dataset( args.dataset_name, cache_dir=args.cache_dir, split=args.dataset_split_name, ) train_transforms = transforms.Compose( [ transforms.Resize(int(args.resolution), interpolation=transforms.InterpolationMode.BILINEAR), transforms.RandomCrop(args.resolution) if args.random_crop else transforms.CenterCrop(args.resolution), transforms.Lambda(lambda x: x) if args.no_hflip else transforms.RandomHorizontalFlip(), transforms.ToTensor(), transforms.Normalize([0.5], [0.5]), ] ) def preprocess_train(examples): all_pixel_values = [] for col_name in ["jpg_0", "jpg_1"]: images = [Image.open(io.BytesIO(im_bytes)).convert("RGB") for im_bytes in examples[col_name]] pixel_values = [train_transforms(image) for image in images] all_pixel_values.append(pixel_values) # Double on channel dim, jpg_y then jpg_w im_tup_iterator = zip(*all_pixel_values) combined_pixel_values = [] for im_tup, label_0 in zip(im_tup_iterator, examples["label_0"]): if label_0 == 0: im_tup = im_tup[::-1] combined_im = torch.cat(im_tup, dim=0) # no batch dim combined_pixel_values.append(combined_im) examples["pixel_values"] = combined_pixel_values examples["input_ids"] = tokenize_captions(tokenizer, examples) return examples with accelerator.main_process_first(): if args.max_train_samples is not None: train_dataset = train_dataset.shuffle(seed=args.seed).select(range(args.max_train_samples)) # Set the training transforms train_dataset = train_dataset.with_transform(preprocess_train) def collate_fn(examples): pixel_values = torch.stack([example["pixel_values"] for example in examples]) pixel_values = pixel_values.to(memory_format=torch.contiguous_format).float() final_dict = {"pixel_values": pixel_values} final_dict["input_ids"] = torch.stack([example["input_ids"] for example in examples]) return final_dict train_dataloader = torch.utils.data.DataLoader( train_dataset, batch_size=args.train_batch_size, shuffle=True, collate_fn=collate_fn, num_workers=args.dataloader_num_workers, ) # Scheduler and math around the number of training steps. overrode_max_train_steps = False num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps) if args.max_train_steps is None: args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch overrode_max_train_steps = True lr_scheduler = get_scheduler( args.lr_scheduler, optimizer=optimizer, num_warmup_steps=args.lr_warmup_steps * accelerator.num_processes, num_training_steps=args.max_train_steps * accelerator.num_processes, num_cycles=args.lr_num_cycles, power=args.lr_power, ) unet, optimizer, train_dataloader, lr_scheduler = accelerator.prepare( unet, optimizer, train_dataloader, lr_scheduler ) # We need to recalculate our total training steps as the size of the training dataloader may have changed. num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps) if overrode_max_train_steps: args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch # Afterwards we recalculate our number of training epochs args.num_train_epochs = math.ceil(args.max_train_steps / num_update_steps_per_epoch) # We need to initialize the trackers we use, and also store our configuration. # The trackers initializes automatically on the main process. if accelerator.is_main_process: accelerator.init_trackers(args.tracker_name, config=vars(args)) # Train! total_batch_size = args.train_batch_size * accelerator.num_processes * args.gradient_accumulation_steps logger.info("***** Running training *****") logger.info(f" Num examples = {len(train_dataset)}") logger.info(f" Num batches each epoch = {len(train_dataloader)}") logger.info(f" Num Epochs = {args.num_train_epochs}") logger.info(f" Instantaneous batch size per device = {args.train_batch_size}") logger.info(f" Total train batch size (w. parallel, distributed & accumulation) = {total_batch_size}") logger.info(f" Gradient Accumulation steps = {args.gradient_accumulation_steps}") logger.info(f" Total optimization steps = {args.max_train_steps}") global_step = 0 first_epoch = 0 # Potentially load in the weights and states from a previous save if args.resume_from_checkpoint: if args.resume_from_checkpoint != "latest": path = os.path.basename(args.resume_from_checkpoint) else: # Get the mos recent checkpoint dirs = os.listdir(args.output_dir) dirs = [d for d in dirs if d.startswith("checkpoint")] dirs = sorted(dirs, key=lambda x: int(x.split("-")[1])) path = dirs[-1] if len(dirs) > 0 else None if path is None: accelerator.print( f"Checkpoint '{args.resume_from_checkpoint}' does not exist. Starting a new training run." ) args.resume_from_checkpoint = None initial_global_step = 0 else: accelerator.print(f"Resuming from checkpoint {path}") accelerator.load_state(os.path.join(args.output_dir, path)) global_step = int(path.split("-")[1]) initial_global_step = global_step first_epoch = global_step // num_update_steps_per_epoch else: initial_global_step = 0 progress_bar = tqdm( range(0, args.max_train_steps), initial=initial_global_step, desc="Steps", # Only show the progress bar once on each machine. disable=not accelerator.is_local_main_process, ) unet.train() for epoch in range(first_epoch, args.num_train_epochs): for step, batch in enumerate(train_dataloader): with accelerator.accumulate(unet): # (batch_size, 2*channels, h, w) -> (2*batch_size, channels, h, w) pixel_values = batch["pixel_values"].to(dtype=weight_dtype) feed_pixel_values = torch.cat(pixel_values.chunk(2, dim=1)) latents = [] for i in range(0, feed_pixel_values.shape[0], args.vae_encode_batch_size): latents.append( vae.encode(feed_pixel_values[i : i + args.vae_encode_batch_size]).latent_dist.sample() ) latents = torch.cat(latents, dim=0) latents = latents * vae.config.scaling_factor # Sample noise that we'll add to the latents noise = torch.randn_like(latents).chunk(2)[0].repeat(2, 1, 1, 1) # Sample a random timestep for each image bsz = latents.shape[0] // 2 timesteps = torch.randint( 0, noise_scheduler.config.num_train_timesteps, (bsz,), device=latents.device, dtype=torch.long ).repeat(2) # Add noise to the model input according to the noise magnitude at each timestep # (this is the forward diffusion process) noisy_model_input = noise_scheduler.add_noise(latents, noise, timesteps) # Get the text embedding for conditioning encoder_hidden_states = encode_prompt(text_encoder, batch["input_ids"]).repeat(2, 1, 1) # Predict the noise residual model_pred = unet( noisy_model_input, timesteps, encoder_hidden_states, ).sample # Get the target for loss depending on the prediction type if noise_scheduler.config.prediction_type == "epsilon": target = noise elif noise_scheduler.config.prediction_type == "v_prediction": target = noise_scheduler.get_velocity(latents, noise, timesteps) else: raise ValueError(f"Unknown prediction type {noise_scheduler.config.prediction_type}") # Compute losses. model_losses = F.mse_loss(model_pred.float(), target.float(), reduction="none") model_losses = model_losses.mean(dim=list(range(1, len(model_losses.shape)))) model_losses_w, model_losses_l = model_losses.chunk(2) # For logging raw_model_loss = 0.5 * (model_losses_w.mean() + model_losses_l.mean()) model_diff = model_losses_w - model_losses_l # These are both LBS (as is t) # Reference model predictions. accelerator.unwrap_model(unet).disable_adapters() with torch.no_grad(): ref_preds = unet( noisy_model_input, timesteps, encoder_hidden_states, ).sample.detach() ref_loss = F.mse_loss(ref_preds.float(), target.float(), reduction="none") ref_loss = ref_loss.mean(dim=list(range(1, len(ref_loss.shape)))) ref_losses_w, ref_losses_l = ref_loss.chunk(2) ref_diff = ref_losses_w - ref_losses_l raw_ref_loss = ref_loss.mean() # Re-enable adapters. accelerator.unwrap_model(unet).enable_adapters() # Final loss. logits = ref_diff - model_diff if args.loss_type == "sigmoid": loss = -1 * F.logsigmoid(args.beta_dpo * logits).mean() elif args.loss_type == "hinge": loss = torch.relu(1 - args.beta_dpo * logits).mean() elif args.loss_type == "ipo": losses = (logits - 1 / (2 * args.beta)) ** 2 loss = losses.mean() else: raise ValueError(f"Unknown loss type {args.loss_type}") implicit_acc = (logits > 0).sum().float() / logits.size(0) implicit_acc += 0.5 * (logits == 0).sum().float() / logits.size(0) accelerator.backward(loss) if accelerator.sync_gradients: accelerator.clip_grad_norm_(params_to_optimize, args.max_grad_norm) optimizer.step() lr_scheduler.step() optimizer.zero_grad() # Checks if the accelerator has performed an optimization step behind the scenes if accelerator.sync_gradients: progress_bar.update(1) global_step += 1 if accelerator.is_main_process: if global_step % args.checkpointing_steps == 0: # _before_ saving state, check if this save would set us over the `checkpoints_total_limit` if args.checkpoints_total_limit is not None: checkpoints = os.listdir(args.output_dir) checkpoints = [d for d in checkpoints if d.startswith("checkpoint")] checkpoints = sorted(checkpoints, key=lambda x: int(x.split("-")[1])) # before we save the new checkpoint, we need to have at _most_ # `checkpoints_total_limit - 1` checkpoints if len(checkpoints) >= args.checkpoints_total_limit: num_to_remove = len(checkpoints) - args.checkpoints_total_limit + 1 removing_checkpoints = checkpoints[0:num_to_remove] logger.info( f"{len(checkpoints)} checkpoints already exist, removing " f"{len(removing_checkpoints)} checkpoints" ) logger.info(f"removing checkpoints: {', '.join(removing_checkpoints)}") for removing_checkpoint in removing_checkpoints: removing_checkpoint = os.path.join(args.output_dir, removing_checkpoint) shutil.rmtree(removing_checkpoint) save_path = os.path.join(args.output_dir, f"checkpoint-{global_step}") accelerator.save_state(save_path) logger.info(f"Saved state to {save_path}") if args.run_validation and global_step % args.validation_steps == 0: log_validation(args, unet=unet, accelerator=accelerator, weight_dtype=weight_dtype, epoch=epoch) logs = { "loss": loss.detach().item(), "raw_model_loss": raw_model_loss.detach().item(), "ref_loss": raw_ref_loss.detach().item(), "implicit_acc": implicit_acc.detach().item(), "lr": lr_scheduler.get_last_lr()[0], } progress_bar.set_postfix(**logs) accelerator.log(logs, step=global_step) if global_step >= args.max_train_steps: break # Save the lora layers accelerator.wait_for_everyone() if accelerator.is_main_process: unet = accelerator.unwrap_model(unet) unet = unet.to(torch.float32) unet_lora_state_dict = convert_state_dict_to_diffusers(get_peft_model_state_dict(unet)) LoraLoaderMixin.save_lora_weights( save_directory=args.output_dir, unet_lora_layers=unet_lora_state_dict, text_encoder_lora_layers=None ) # Final validation? if args.run_validation: log_validation( args, unet=None, accelerator=accelerator, weight_dtype=weight_dtype, epoch=epoch, is_final_validation=True, ) if args.push_to_hub: upload_folder( repo_id=repo_id, folder_path=args.output_dir, commit_message="End of training", ignore_patterns=["step_*", "epoch_*"], ) accelerator.end_training() if __name__ == "__main__": args = parse_args() main(args) ================================================ FILE: experimental/LISA-diffusion/diffusion_dpo/train_diffusion_dpo_lisa.py ================================================ #!/usr/bin/env python # Copyright 2024 bram-w, The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and import argparse import contextlib import io import logging import math import os import shutil from pathlib import Path import accelerate import diffusers import numpy as np import torch import torch.nn.functional as F import torch.utils.checkpoint import transformers import wandb from accelerate import Accelerator from accelerate.logging import get_logger from accelerate.utils import ProjectConfiguration, set_seed from datasets import load_dataset from diffusers import ( AutoencoderKL, DDPMScheduler, DiffusionPipeline, DPMSolverMultistepScheduler, UNet2DConditionModel, ) from diffusers.optimization import get_scheduler from diffusers.utils import check_min_version from diffusers.utils.import_utils import is_xformers_available from huggingface_hub import create_repo, upload_folder from packaging import version from PIL import Image from torchvision import transforms from tqdm.auto import tqdm from transformers import AutoTokenizer, PretrainedConfig # Will error if the minimal version of diffusers is not installed. Remove at your own risks. check_min_version("0.25.0.dev0") logger = get_logger(__name__) VALIDATION_PROMPTS = [ "portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour, style by Dan Winters, Russell James, Steve McCurry, centered, extremely detailed, Nikon D850, award winning photography", # noqa: E501 "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k", "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", "A photo of beautiful mountain with realistic sunset and blue lake, highly detailed, masterpiece", ] def freeze_all_layers(model): for param in model.parameters(): param.requires_grad = False def random_activate_layers(model, p): activate_number = int((len(list(model.parameters())) - 2) * p) index = np.random.choice(range(0, len(list(model.parameters())) - 1, 1), activate_number, replace=False) count = 0 for param in model.parameters(): if count == 0 or count == len(list(model.parameters())) - 1: param.requires_grad = True elif count in index: param.requires_grad = True count += 1 def lisa(model, p=0.25): freeze_all_layers(model) random_activate_layers(model, p) def import_model_class_from_model_name_or_path(pretrained_model_name_or_path: str, revision: str): text_encoder_config = PretrainedConfig.from_pretrained( pretrained_model_name_or_path, subfolder="text_encoder", revision=revision, ) model_class = text_encoder_config.architectures[0] if model_class == "CLIPTextModel": from transformers import CLIPTextModel return CLIPTextModel else: raise ValueError(f"{model_class} is not supported.") @torch.no_grad() def update_ema(target_params, source_params, rate=0.99): """ Update target parameters to be closer to those of source parameters using an exponential moving average. :param target_params: the target parameter sequence. :param source_params: the source parameter sequence. :param rate: the EMA rate (closer to 1 means slower). """ for targ, src in zip(target_params, source_params): # if src.requires_grad == True: targ.detach().mul_(rate).add_(src, alpha=1 - rate) def log_validation(args, unet, accelerator, weight_dtype, epoch, is_final_validation=False): logger.info(f"Running validation... \n Generating images with prompts:\n {VALIDATION_PROMPTS}.") # create pipeline pipeline = DiffusionPipeline.from_pretrained( args.pretrained_model_name_or_path, revision=args.revision, variant=args.variant, torch_dtype=weight_dtype, ) if not is_final_validation: pipeline.unet = accelerator.unwrap_model(unet) else: pipeline.load_lora_weights(args.output_dir, weight_name="pytorch_lora_weights.safetensors") pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config) pipeline = pipeline.to(accelerator.device) pipeline.set_progress_bar_config(disable=True) # run inference generator = torch.Generator(device=accelerator.device).manual_seed(args.seed) if args.seed else None images = [] context = contextlib.nullcontext() if is_final_validation else torch.cuda.amp.autocast() for prompt in VALIDATION_PROMPTS: with context: image = pipeline(prompt, num_inference_steps=25, generator=generator).images[0] images.append(image) tracker_key = "test" if is_final_validation else "validation" for tracker in accelerator.trackers: if tracker.name == "tensorboard": np_images = np.stack([np.asarray(img) for img in images]) tracker.writer.add_images(tracker_key, np_images, epoch, dataformats="NHWC") if tracker.name == "wandb": tracker.log( { tracker_key: [ wandb.Image(image, caption=f"{i}: {VALIDATION_PROMPTS[i]}") for i, image in enumerate(images) ] } ) if is_final_validation: pipeline.disable_lora() no_lora_images = [ pipeline(prompt, num_inference_steps=25, generator=generator).images[0] for prompt in VALIDATION_PROMPTS ] for tracker in accelerator.trackers: if tracker.name == "tensorboard": np_images = np.stack([np.asarray(img) for img in no_lora_images]) tracker.writer.add_images("test_without_lora", np_images, epoch, dataformats="NHWC") if tracker.name == "wandb": tracker.log( { "test_without_lora": [ wandb.Image(image, caption=f"{i}: {VALIDATION_PROMPTS[i]}") for i, image in enumerate(no_lora_images) ] } ) def parse_args(input_args=None): parser = argparse.ArgumentParser(description="Simple example of a training script.") parser.add_argument( "--pretrained_model_name_or_path", type=str, default=None, required=True, help="Path to pretrained model or model identifier from huggingface.co/models.", ) parser.add_argument( "--revision", type=str, default=None, required=False, help="Revision of pretrained model identifier from huggingface.co/models.", ) parser.add_argument( "--dataset_name", type=str, default=None, help=( "The name of the Dataset (from the HuggingFace hub) to train on (could be your own, possibly private," " dataset). It can also be a path pointing to a local copy of a dataset in your filesystem," " or to a folder containing files that 🤗 Datasets can understand." ), ) parser.add_argument( "--dataset_split_name", type=str, default="validation", help="Dataset split to be used during training. Helpful to specify for conducting experimental runs.", ) parser.add_argument( "--variant", type=str, default=None, help="Variant of the model files of the pretrained model identifier from huggingface.co/models, 'e.g.' fp16", ) parser.add_argument( "--run_validation", default=False, action="store_true", help=( "Whether to run validation inference in between training and also after training. Helps to track progress." ), ) parser.add_argument( "--validation_steps", type=int, default=200, help="Run validation every X steps.", ) parser.add_argument( "--max_train_samples", type=int, default=None, help=( "For debugging purposes or quicker training, truncate the number of training examples to this value if set." ), ) parser.add_argument( "--output_dir", type=str, default="diffusion-dpo-lisa", help="The output directory where the model predictions and checkpoints will be written.", ) parser.add_argument( "--cache_dir", type=str, default=None, help="The directory where the downloaded models and datasets will be stored.", ) parser.add_argument("--seed", type=int, default=None, help="A seed for reproducible training.") parser.add_argument( "--resolution", type=int, default=512, help=( "The resolution for input images, all the images in the train/validation dataset will be resized to this" " resolution" ), ) parser.add_argument( "--vae_encode_batch_size", type=int, default=8, help="Batch size to use for VAE encoding of the images for efficient processing.", ) parser.add_argument( "--no_hflip", action="store_true", help="whether to randomly flip images horizontally", ) parser.add_argument( "--random_crop", default=False, action="store_true", help=( "Whether to random crop the input images to the resolution. If not set, the images will be center-cropped." ), ) parser.add_argument( "--train_batch_size", type=int, default=4, help="Batch size (per device) for the training dataloader." ) parser.add_argument("--num_train_epochs", type=int, default=1) parser.add_argument( "--max_train_steps", type=int, default=None, help="Total number of training steps to perform. If provided, overrides num_train_epochs.", ) parser.add_argument( "--checkpointing_steps", type=int, default=500, help=( "Save a checkpoint of the training state every X updates. These checkpoints can be used both as final" " checkpoints in case they are better than the last checkpoint, and are also suitable for resuming" " training using `--resume_from_checkpoint`." ), ) parser.add_argument( "--checkpoints_total_limit", type=int, default=None, help=("Max number of checkpoints to store."), ) parser.add_argument( "--resume_from_checkpoint", type=str, default=None, help=( "Whether training should be resumed from a previous checkpoint. Use a path saved by" ' `--checkpointing_steps`, or `"latest"` to automatically select the last available checkpoint.' ), ) parser.add_argument( "--gradient_accumulation_steps", type=int, default=1, help="Number of updates steps to accumulate before performing a backward/update pass.", ) parser.add_argument( "--gradient_checkpointing", action="store_true", help="Whether or not to use gradient checkpointing to save memory at the expense of slower backward pass.", ) parser.add_argument( "--beta_dpo", type=int, default=2500, help="DPO KL Divergence penalty.", ) parser.add_argument( "--loss_type", type=str, default="sigmoid", help="DPO loss type. Can be one of 'sigmoid' (default), 'ipo', or 'cpo'", ) parser.add_argument( "--learning_rate", type=float, default=5e-4, help="Initial learning rate (after the potential warmup period) to use.", ) parser.add_argument( "--scale_lr", action="store_true", default=False, help="Scale the learning rate by the number of GPUs, gradient accumulation steps, and batch size.", ) parser.add_argument( "--lr_scheduler", type=str, default="constant", help=( 'The scheduler type to use. Choose between ["linear", "cosine", "cosine_with_restarts", "polynomial",' ' "constant", "constant_with_warmup"]' ), ) parser.add_argument( "--lr_warmup_steps", type=int, default=500, help="Number of steps for the warmup in the lr scheduler." ) parser.add_argument( "--lr_num_cycles", type=int, default=1, help="Number of hard resets of the lr in cosine_with_restarts scheduler.", ) parser.add_argument("--lr_power", type=float, default=1.0, help="Power factor of the polynomial scheduler.") parser.add_argument( "--dataloader_num_workers", type=int, default=0, help=( "Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process." ), ) parser.add_argument( "--use_8bit_adam", action="store_true", help="Whether or not to use 8-bit Adam from bitsandbytes." ) parser.add_argument("--adam_beta1", type=float, default=0.9, help="The beta1 parameter for the Adam optimizer.") parser.add_argument("--adam_beta2", type=float, default=0.999, help="The beta2 parameter for the Adam optimizer.") parser.add_argument("--adam_weight_decay", type=float, default=1e-2, help="Weight decay to use.") parser.add_argument("--adam_epsilon", type=float, default=1e-08, help="Epsilon value for the Adam optimizer") parser.add_argument("--max_grad_norm", default=1.0, type=float, help="Max gradient norm.") parser.add_argument("--push_to_hub", action="store_true", help="Whether or not to push the model to the Hub.") parser.add_argument("--hub_token", type=str, default=None, help="The token to use to push to the Model Hub.") parser.add_argument( "--hub_model_id", type=str, default=None, help="The name of the repository to keep in sync with the local `output_dir`.", ) parser.add_argument( "--logging_dir", type=str, default="logs", help=( "[TensorBoard](https://www.tensorflow.org/tensorboard) log directory. Will default to" " *output_dir/runs/**CURRENT_DATETIME_HOSTNAME***." ), ) parser.add_argument( "--allow_tf32", action="store_true", help=( "Whether or not to allow TF32 on Ampere GPUs. Can be used to speed up training. For more information, see" " https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices" ), ) parser.add_argument( "--report_to", type=str, default="tensorboard", help=( 'The integration to report the results and logs to. Supported platforms are `"tensorboard"`' ' (default), `"wandb"` and `"comet_ml"`. Use `"all"` to report to all integrations.' ), ) parser.add_argument( "--mixed_precision", type=str, default=None, choices=["no", "fp16", "bf16"], help=( "Whether to use mixed precision. Choose between fp16 and bf16 (bfloat16). Bf16 requires PyTorch >=" " 1.10.and an Nvidia Ampere GPU. Default to the value of accelerate config of the current system or the" " flag passed with the `accelerate.launch` command. Use this argument to override the accelerate config." ), ) parser.add_argument( "--prior_generation_precision", type=str, default=None, choices=["no", "fp32", "fp16", "bf16"], help=( "Choose prior generation precision between fp32, fp16 and bf16 (bfloat16). Bf16 requires PyTorch >=" " 1.10.and an Nvidia Ampere GPU. Default to fp16 if a GPU is available else fp32." ), ) parser.add_argument("--local_rank", type=int, default=-1, help="For distributed training: local_rank") parser.add_argument( "--enable_xformers_memory_efficient_attention", action="store_true", help="Whether or not to use xformers." ) parser.add_argument( "--tracker_name", type=str, default="diffusion-dpo-lisa", help=("The name of the tracker to report results to."), ) if input_args is not None: args = parser.parse_args(input_args) else: args = parser.parse_args() if args.dataset_name is None: raise ValueError("Must provide a `dataset_name`.") env_local_rank = int(os.environ.get("LOCAL_RANK", -1)) if env_local_rank != -1 and env_local_rank != args.local_rank: args.local_rank = env_local_rank return args def tokenize_captions(tokenizer, examples): max_length = tokenizer.model_max_length captions = [] for caption in examples["caption"]: captions.append(caption) text_inputs = tokenizer(captions, truncation=True, padding="max_length", max_length=max_length, return_tensors="pt") return text_inputs.input_ids @torch.no_grad() def encode_prompt(text_encoder, input_ids): text_input_ids = input_ids.to(text_encoder.device) attention_mask = None prompt_embeds = text_encoder(text_input_ids, attention_mask=attention_mask) prompt_embeds = prompt_embeds[0] return prompt_embeds def main(args): if args.report_to == "wandb" and args.hub_token is not None: raise ValueError( "You cannot use both --report_to=wandb and --hub_token due to a security risk of exposing your token." " Please use `huggingface-cli login` to authenticate with the Hub." ) logging_dir = Path(args.output_dir, args.logging_dir) accelerator_project_config = ProjectConfiguration(project_dir=args.output_dir, logging_dir=logging_dir) from accelerate import DistributedDataParallelKwargs ddp_kwargs = DistributedDataParallelKwargs(find_unused_parameters=True) accelerator = Accelerator( gradient_accumulation_steps=args.gradient_accumulation_steps, mixed_precision=args.mixed_precision, log_with=args.report_to, kwargs_handlers=[ddp_kwargs], project_config=accelerator_project_config, ) # Make one log on every process with the configuration for debugging. logging.basicConfig( format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%m/%d/%Y %H:%M:%S", level=logging.INFO, ) logger.info(accelerator.state, main_process_only=False) if accelerator.is_local_main_process: transformers.utils.logging.set_verbosity_warning() diffusers.utils.logging.set_verbosity_info() else: transformers.utils.logging.set_verbosity_error() diffusers.utils.logging.set_verbosity_error() # If passed along, set the training seed now. if args.seed is not None: set_seed(args.seed) # Handle the repository creation if accelerator.is_main_process: if args.output_dir is not None: os.makedirs(args.output_dir, exist_ok=True) if args.push_to_hub: repo_id = create_repo( repo_id=args.hub_model_id or Path(args.output_dir).name, exist_ok=True, token=args.hub_token ).repo_id # Load the tokenizer tokenizer = AutoTokenizer.from_pretrained( args.pretrained_model_name_or_path, subfolder="tokenizer", revision=args.revision, use_fast=False, ) # import correct text encoder class text_encoder_cls = import_model_class_from_model_name_or_path(args.pretrained_model_name_or_path, args.revision) # Load scheduler and models noise_scheduler = DDPMScheduler.from_pretrained(args.pretrained_model_name_or_path, subfolder="scheduler") text_encoder = text_encoder_cls.from_pretrained( args.pretrained_model_name_or_path, subfolder="text_encoder", revision=args.revision, variant=args.variant ) vae = AutoencoderKL.from_pretrained( args.pretrained_model_name_or_path, subfolder="vae", revision=args.revision, variant=args.variant ) unet = UNet2DConditionModel.from_pretrained( args.pretrained_model_name_or_path, subfolder="unet", revision=args.revision, variant=args.variant ) vae.requires_grad_(False) text_encoder.requires_grad_(False) ref_net = UNet2DConditionModel.from_pretrained( args.pretrained_model_name_or_path, subfolder="unet", revision=args.revision, variant=args.variant ) # load teacher_unet weights into unet ref_net.train() ref_net.requires_grad_(False) # For mixed precision training we cast all non-trainable weights (vae, text_encoder and unet) to half-precision # as these weights are only used for inference, keeping weights in full precision is not required. weight_dtype = torch.float32 if accelerator.mixed_precision == "fp16": weight_dtype = torch.float16 elif accelerator.mixed_precision == "bf16": weight_dtype = torch.bfloat16 # Move unet, vae and text_encoder to device and cast to weight_dtype unet.to(accelerator.device, dtype=torch.float32) ref_net.to(accelerator.device, dtype=torch.float16) vae.to(accelerator.device, dtype=torch.float32) text_encoder.to(accelerator.device, dtype=torch.float32) unet.train() if args.enable_xformers_memory_efficient_attention: if is_xformers_available(): import xformers xformers_version = version.parse(xformers.__version__) if xformers_version == version.parse("0.0.16"): logger.warning( "xFormers 0.0.16 cannot be used for training in some GPUs. If you observe problems during " "training, please update xFormers to at least 0.0.17. " "See https://huggingface.co/docs/diffusers/main/en/optimization/xformers for more details." ) unet.enable_xformers_memory_efficient_attention() else: raise ValueError("xformers is not available. Make sure it is installed correctly") if args.gradient_checkpointing: unet.enable_gradient_checkpointing() # 10. Handle saving and loading of checkpoints # `accelerate` 0.16.0 will have better support for customized saving if version.parse(accelerate.__version__) >= version.parse("0.16.0"): # create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format def save_model_hook(models, weights, output_dir): if accelerator.is_main_process: for i, model in enumerate(models): model.save_pretrained(os.path.join(output_dir, "unet")) # make sure to pop weight so that corresponding model is not saved again weights.pop() def load_model_hook(models, input_dir): for i in range(len(models)): # pop models so that they are not loaded again model = models.pop() # load diffusers style into model load_model = UNet2DConditionModel.from_pretrained(input_dir, subfolder="unet") model.register_to_config(**load_model.config) model.load_state_dict(load_model.state_dict()) del load_model accelerator.register_save_state_pre_hook(save_model_hook) accelerator.register_load_state_pre_hook(load_model_hook) # Enable TF32 for faster training on Ampere GPUs, # cf https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices if args.allow_tf32: torch.backends.cuda.matmul.allow_tf32 = True if args.scale_lr: args.learning_rate = ( args.learning_rate * args.gradient_accumulation_steps * args.train_batch_size * accelerator.num_processes ) # Use 8-bit Adam for lower memory usage or to fine-tune the model in 16GB GPUs if args.use_8bit_adam: try: import bitsandbytes as bnb except ImportError: raise ImportError( "To use 8-bit Adam, please install the bitsandbytes library: `pip install bitsandbytes`." ) from None optimizer_class = bnb.optim.AdamW8bit else: optimizer_class = torch.optim.AdamW optimizer_dict = dict() scheduler_dict = dict() param_number = len(list(unet.parameters())) print(param_number) lisa_p = 0.25 # 128 / param_number # 32 / param_number lisa(model=unet, p=lisa_p) for p in unet.parameters(): if p.requires_grad: optimizer_dict[p] = optimizer_class( [{"params": p}], lr=args.learning_rate, betas=(args.adam_beta1, args.adam_beta2), weight_decay=args.adam_weight_decay, eps=args.adam_epsilon, ) optimizer_dict[p] = accelerator.prepare_optimizer(optimizer_dict[p]) # Dataset and DataLoaders creation: train_dataset = load_dataset( args.dataset_name, cache_dir=args.cache_dir, split=args.dataset_split_name, ) train_transforms = transforms.Compose( [ transforms.Resize(int(args.resolution), interpolation=transforms.InterpolationMode.BILINEAR), transforms.RandomCrop(args.resolution) if args.random_crop else transforms.CenterCrop(args.resolution), transforms.Lambda(lambda x: x) if args.no_hflip else transforms.RandomHorizontalFlip(), transforms.ToTensor(), transforms.Normalize([0.5], [0.5]), ] ) def preprocess_train(examples): all_pixel_values = [] for col_name in ["jpg_0", "jpg_1"]: images = [Image.open(io.BytesIO(im_bytes)).convert("RGB") for im_bytes in examples[col_name]] pixel_values = [train_transforms(image) for image in images] all_pixel_values.append(pixel_values) # Double on channel dim, jpg_y then jpg_w im_tup_iterator = zip(*all_pixel_values) combined_pixel_values = [] for im_tup, label_0 in zip(im_tup_iterator, examples["label_0"]): if label_0 == 0: im_tup = im_tup[::-1] combined_im = torch.cat(im_tup, dim=0) # no batch dim combined_pixel_values.append(combined_im) examples["pixel_values"] = combined_pixel_values examples["input_ids"] = tokenize_captions(tokenizer, examples) return examples with accelerator.main_process_first(): if args.max_train_samples is not None: train_dataset = train_dataset.shuffle(seed=args.seed).select(range(args.max_train_samples)) # Set the training transforms train_dataset = train_dataset.with_transform(preprocess_train) def collate_fn(examples): pixel_values = torch.stack([example["pixel_values"] for example in examples]) pixel_values = pixel_values.to(memory_format=torch.contiguous_format).float() final_dict = {"pixel_values": pixel_values} final_dict["input_ids"] = torch.stack([example["input_ids"] for example in examples]) return final_dict train_dataloader = torch.utils.data.DataLoader( train_dataset, batch_size=args.train_batch_size, shuffle=True, collate_fn=collate_fn, num_workers=args.dataloader_num_workers, ) # Scheduler and math around the number of training steps. overrode_max_train_steps = False num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps) if args.max_train_steps is None: args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch overrode_max_train_steps = True for p in unet.parameters(): if p.requires_grad: scheduler_dict[p] = get_scheduler( args.lr_scheduler, optimizer=optimizer_dict[p], num_warmup_steps=args.lr_warmup_steps * accelerator.num_processes, num_training_steps=args.max_train_steps * accelerator.num_processes, ) scheduler_dict[p] = accelerator.prepare_scheduler(scheduler_dict[p]) # define a hook function to update the parameter p during the backward pass def optimizer_hook(p): if p.grad is None: del scheduler_dict[p] del optimizer_dict[p] return else: if p not in optimizer_dict: optimizer_dict[p] = optimizer_class( [{"params": p}], lr=args.learning_rate, betas=(args.adam_beta1, args.adam_beta2), weight_decay=args.adam_weight_decay, eps=args.adam_epsilon, ) optimizer_dict[p] = accelerator.prepare_optimizer(optimizer_dict[p]) if p not in scheduler_dict: scheduler_dict[p] = get_scheduler( args.lr_scheduler, optimizer=optimizer_dict[p], num_warmup_steps=args.lr_warmup_steps * accelerator.num_processes, num_training_steps=args.max_train_steps * accelerator.num_processes, ) scheduler_dict[p] = accelerator.prepare_scheduler(scheduler_dict[p]) if accelerator.sync_gradients: torch.nn.utils.clip_grad_norm_(p, args.max_grad_norm) optimizer_dict[p].step() optimizer_dict[p].zero_grad(set_to_none=True) scheduler_dict[p].step() # Register the hook onto every parameter for p in unet.parameters(): if p.requires_grad: p.register_post_accumulate_grad_hook(optimizer_hook) unet = accelerator.prepare_model(unet) # We need to recalculate our total training steps as the size of the training dataloader may have changed. num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps) if overrode_max_train_steps: args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch # Afterwards we recalculate our number of training epochs args.num_train_epochs = math.ceil(args.max_train_steps / num_update_steps_per_epoch) # We need to initialize the trackers we use, and also store our configuration. # The trackers initializes automatically on the main process. if accelerator.is_main_process: accelerator.init_trackers(args.tracker_name, config=vars(args)) # Train! total_batch_size = args.train_batch_size * accelerator.num_processes * args.gradient_accumulation_steps logger.info("***** Running training *****") logger.info(f" Num examples = {len(train_dataset)}") logger.info(f" Num batches each epoch = {len(train_dataloader)}") logger.info(f" Num Epochs = {args.num_train_epochs}") logger.info(f" Instantaneous batch size per device = {args.train_batch_size}") logger.info(f" Total train batch size (w. parallel, distributed & accumulation) = {total_batch_size}") logger.info(f" Gradient Accumulation steps = {args.gradient_accumulation_steps}") logger.info(f" Total optimization steps = {args.max_train_steps}") global_step = 0 first_epoch = 0 # Potentially load in the weights and states from a previous save if args.resume_from_checkpoint: if args.resume_from_checkpoint != "latest": path = os.path.basename(args.resume_from_checkpoint) else: # Get the mos recent checkpoint dirs = os.listdir(args.output_dir) dirs = [d for d in dirs if d.startswith("checkpoint")] dirs = sorted(dirs, key=lambda x: int(x.split("-")[1])) path = dirs[-1] if len(dirs) > 0 else None if path is None: accelerator.print( f"Checkpoint '{args.resume_from_checkpoint}' does not exist. Starting a new training run." ) args.resume_from_checkpoint = None initial_global_step = 0 else: accelerator.print(f"Resuming from checkpoint {path}") accelerator.load_state(os.path.join(args.output_dir, path)) global_step = int(path.split("-")[1]) initial_global_step = global_step first_epoch = global_step // num_update_steps_per_epoch else: initial_global_step = 0 progress_bar = tqdm( range(0, args.max_train_steps), initial=initial_global_step, desc="Steps", # Only show the progress bar once on each machine. disable=not accelerator.is_local_main_process, ) unet.train() total_count = 0 for epoch in range(first_epoch, args.num_train_epochs): for step, batch in enumerate(train_dataloader): if total_count % 6 == 0 and total_count != 0: param_number = len(list(unet.parameters())) lisa(model=unet, p=lisa_p) total_count += 1 with accelerator.accumulate(unet): # (batch_size, 2*channels, h, w) -> (2*batch_size, channels, h, w) pixel_values = batch["pixel_values"].to(accelerator.device, non_blocking=True) pixel_values = pixel_values.to(dtype=weight_dtype) feed_pixel_values = torch.cat(pixel_values.chunk(2, dim=1)) latents = [] for i in range(0, feed_pixel_values.shape[0], args.vae_encode_batch_size): latents.append( vae.encode(feed_pixel_values[i : i + args.vae_encode_batch_size]).latent_dist.sample() ) latents = torch.cat(latents, dim=0).float() latents = latents * vae.config.scaling_factor # Sample noise that we'll add to the latents noise = torch.randn_like(latents).chunk(2)[0].repeat(2, 1, 1, 1) # Sample a random timestep for each image bsz = latents.shape[0] // 2 timesteps = torch.randint( 0, noise_scheduler.config.num_train_timesteps, (bsz,), device=latents.device, dtype=torch.long ).repeat(2) # Add noise to the model input according to the noise magnitude at each timestep # (this is the forward diffusion process) noisy_model_input = noise_scheduler.add_noise(latents, noise, timesteps).float() # Get the text embedding for conditioning encoder_hidden_states = encode_prompt(text_encoder, batch["input_ids"]).repeat(2, 1, 1).float() # Predict the noise residual model_pred = unet( noisy_model_input, timesteps, encoder_hidden_states, ).sample # Get the target for loss depending on the prediction type if noise_scheduler.config.prediction_type == "epsilon": target = noise elif noise_scheduler.config.prediction_type == "v_prediction": target = noise_scheduler.get_velocity(latents, noise, timesteps) else: raise ValueError(f"Unknown prediction type {noise_scheduler.config.prediction_type}") # Compute losses. model_losses = F.mse_loss(model_pred.float(), target.float(), reduction="none") model_losses = model_losses.mean(dim=list(range(1, len(model_losses.shape)))) model_losses_w, model_losses_l = model_losses.chunk(2) # For logging raw_model_loss = 0.5 * (model_losses_w.mean() + model_losses_l.mean()) model_diff = model_losses_w - model_losses_l # These are both LBS (as is t) # Reference model predictions. with torch.no_grad(): ref_preds = ( ref_net( noisy_model_input.half(), timesteps.half(), encoder_hidden_states.half(), ) .sample.detach() .float() ) ref_loss = F.mse_loss(ref_preds.float(), target.float(), reduction="none") ref_loss = ref_loss.mean(dim=list(range(1, len(ref_loss.shape)))) ref_losses_w, ref_losses_l = ref_loss.chunk(2) ref_diff = ref_losses_w - ref_losses_l raw_ref_loss = ref_loss.mean() # Final loss. logits = ref_diff - model_diff if args.loss_type == "sigmoid": loss = -1 * F.logsigmoid(args.beta_dpo * logits).mean() elif args.loss_type == "hinge": loss = torch.relu(1 - args.beta_dpo * logits).mean() elif args.loss_type == "ipo": losses = (logits - 1 / (2 * args.beta)) ** 2 loss = losses.mean() else: raise ValueError(f"Unknown loss type {args.loss_type}") implicit_acc = (logits > 0).sum().float() / logits.size(0) implicit_acc += 0.5 * (logits == 0).sum().float() / logits.size(0) accelerator.backward(loss) # Checks if the accelerator has performed an optimization step behind the scenes if accelerator.sync_gradients: update_ema(ref_net.parameters(), unet.parameters(), 0.9999) progress_bar.update(1) global_step += 1 if accelerator.is_main_process: if global_step % args.checkpointing_steps == 0: # _before_ saving state, check if this save would set us over the `checkpoints_total_limit` if args.checkpoints_total_limit is not None: checkpoints = os.listdir(args.output_dir) checkpoints = [d for d in checkpoints if d.startswith("checkpoint")] checkpoints = sorted(checkpoints, key=lambda x: int(x.split("-")[1])) # before we save the new checkpoint, we need to have at _most_ # `checkpoints_total_limit - 1` checkpoints if len(checkpoints) >= args.checkpoints_total_limit: num_to_remove = len(checkpoints) - args.checkpoints_total_limit + 1 removing_checkpoints = checkpoints[0:num_to_remove] logger.info( f"{len(checkpoints)} checkpoints already exist, removing " f"{len(removing_checkpoints)} checkpoints" ) logger.info(f"removing checkpoints: {', '.join(removing_checkpoints)}") for removing_checkpoint in removing_checkpoints: removing_checkpoint = os.path.join(args.output_dir, removing_checkpoint) shutil.rmtree(removing_checkpoint) save_path = os.path.join(args.output_dir, f"checkpoint-{global_step}") accelerator.save_state(save_path) logger.info(f"Saved state to {save_path}") if global_step == 1 or (args.run_validation and global_step % args.validation_steps == 0): log_validation(args, unet=unet, accelerator=accelerator, weight_dtype=weight_dtype, epoch=epoch) logs = { "loss": loss.detach().item(), "raw_model_loss": raw_model_loss.detach().item(), "ref_loss": raw_ref_loss.detach().item(), "implicit_acc": implicit_acc.detach().item(), "lr": list(optimizer_dict.values())[0].param_groups[0]["lr"], } progress_bar.set_postfix(**logs) accelerator.log(logs, step=global_step) if global_step >= args.max_train_steps: break accelerator.wait_for_everyone() if accelerator.is_main_process: unet = accelerator.unwrap_model(unet) unet = unet.to(torch.float32) # Final validation? if args.run_validation: log_validation( args, unet=None, accelerator=accelerator, weight_dtype=weight_dtype, epoch=epoch, is_final_validation=True, ) if args.push_to_hub: upload_folder( repo_id=repo_id, folder_path=args.output_dir, commit_message="End of training", ignore_patterns=["step_*", "epoch_*"], ) accelerator.end_training() if __name__ == "__main__": args = parse_args() main(args) ================================================ FILE: experimental/LISA-diffusion/instruct_pix2pix/test_instruct_pix2pix.py ================================================ # Copyright 2024 HuggingFace Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import logging import os import sys import tempfile sys.path.append("..") from test_examples_utils import ExamplesTestsAccelerate, run_command # noqa: E402 logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger() stream_handler = logging.StreamHandler(sys.stdout) logger.addHandler(stream_handler) class InstructPix2Pix(ExamplesTestsAccelerate): def test_instruct_pix2pix_checkpointing_checkpoints_total_limit(self): with tempfile.TemporaryDirectory() as tmpdir: test_args = f""" examples/instruct_pix2pix/train_instruct_pix2pix.py --pretrained_model_name_or_path=hf-internal-testing/tiny-stable-diffusion-pipe --dataset_name=hf-internal-testing/instructpix2pix-10-samples --resolution=64 --random_flip --train_batch_size=1 --max_train_steps=6 --checkpointing_steps=2 --checkpoints_total_limit=2 --output_dir {tmpdir} --seed=0 """.split() run_command(self._launch_args + test_args) self.assertEqual( {x for x in os.listdir(tmpdir) if "checkpoint" in x}, {"checkpoint-4", "checkpoint-6"}, ) def test_instruct_pix2pix_checkpointing_checkpoints_total_limit_removes_multiple_checkpoints(self): with tempfile.TemporaryDirectory() as tmpdir: test_args = f""" examples/instruct_pix2pix/train_instruct_pix2pix.py --pretrained_model_name_or_path=hf-internal-testing/tiny-stable-diffusion-pipe --dataset_name=hf-internal-testing/instructpix2pix-10-samples --resolution=64 --random_flip --train_batch_size=1 --max_train_steps=4 --checkpointing_steps=2 --output_dir {tmpdir} --seed=0 """.split() run_command(self._launch_args + test_args) # check checkpoint directories exist self.assertEqual( {x for x in os.listdir(tmpdir) if "checkpoint" in x}, {"checkpoint-2", "checkpoint-4"}, ) resume_run_args = f""" examples/instruct_pix2pix/train_instruct_pix2pix.py --pretrained_model_name_or_path=hf-internal-testing/tiny-stable-diffusion-pipe --dataset_name=hf-internal-testing/instructpix2pix-10-samples --resolution=64 --random_flip --train_batch_size=1 --max_train_steps=8 --checkpointing_steps=2 --output_dir {tmpdir} --seed=0 --resume_from_checkpoint=checkpoint-4 --checkpoints_total_limit=2 """.split() run_command(self._launch_args + resume_run_args) # check checkpoint directories exist self.assertEqual( {x for x in os.listdir(tmpdir) if "checkpoint" in x}, {"checkpoint-6", "checkpoint-8"}, ) ================================================ FILE: experimental/LISA-diffusion/instruct_pix2pix/train_instruct_pix2pix_lisa.py ================================================ #!/usr/bin/env python # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Script to fine-tune Stable Diffusion for InstructPix2Pix.""" import argparse import logging import math import os import shutil from pathlib import Path import accelerate import datasets import diffusers import numpy as np import PIL import requests import torch import torch.nn as nn import torch.nn.functional as F import torch.utils.checkpoint import transformers from accelerate import Accelerator from accelerate.logging import get_logger from accelerate.utils import ProjectConfiguration, set_seed from datasets import load_dataset from diffusers import AutoencoderKL, DDPMScheduler, StableDiffusionInstructPix2PixPipeline, UNet2DConditionModel from diffusers.optimization import get_scheduler from diffusers.training_utils import EMAModel from diffusers.utils import check_min_version, deprecate, is_wandb_available from diffusers.utils.import_utils import is_xformers_available from diffusers.utils.torch_utils import is_compiled_module from huggingface_hub import create_repo, upload_folder from packaging import version from torchvision import transforms from tqdm.auto import tqdm from transformers import CLIPTextModel, CLIPTokenizer # Will error if the minimal version of diffusers is not installed. Remove at your own risks. check_min_version("0.28.0.dev0") logger = get_logger(__name__, log_level="INFO") DATASET_NAME_MAPPING = { "fusing/instructpix2pix-1000-samples": ("input_image", "edit_prompt", "edited_image"), } WANDB_TABLE_COL_NAMES = ["original_image", "edited_image", "edit_prompt"] def parse_args(): parser = argparse.ArgumentParser(description="Simple example of a training script for InstructPix2Pix.") parser.add_argument( "--pretrained_model_name_or_path", type=str, default=None, required=True, help="Path to pretrained model or model identifier from huggingface.co/models.", ) parser.add_argument( "--revision", type=str, default=None, required=False, help="Revision of pretrained model identifier from huggingface.co/models.", ) parser.add_argument( "--variant", type=str, default=None, help="Variant of the model files of the pretrained model identifier from huggingface.co/models, 'e.g.' fp16", ) parser.add_argument( "--dataset_name", type=str, default=None, help=( "The name of the Dataset (from the HuggingFace hub) to train on (could be your own, possibly private," " dataset). It can also be a path pointing to a local copy of a dataset in your filesystem," " or to a folder containing files that 🤗 Datasets can understand." ), ) parser.add_argument( "--dataset_config_name", type=str, default=None, help="The config of the Dataset, leave as None if there's only one config.", ) parser.add_argument( "--train_data_dir", type=str, default=None, help=( "A folder containing the training data. Folder contents must follow the structure described in" " https://huggingface.co/docs/datasets/image_dataset#imagefolder. In particular, a `metadata.jsonl` file" " must exist to provide the captions for the images. Ignored if `dataset_name` is specified." ), ) parser.add_argument( "--original_image_column", type=str, default="input_image", help="The column of the dataset containing the original image on which edits where made.", ) parser.add_argument( "--edited_image_column", type=str, default="edited_image", help="The column of the dataset containing the edited image.", ) parser.add_argument( "--edit_prompt_column", type=str, default="edit_prompt", help="The column of the dataset containing the edit instruction.", ) parser.add_argument( "--val_image_url", type=str, default=None, help="URL to the original image that you would like to edit (used during inference for debugging purposes).", ) parser.add_argument( "--validation_prompt", type=str, default=None, help="A prompt that is sampled during training for inference." ) parser.add_argument( "--num_validation_images", type=int, default=4, help="Number of images that should be generated during validation with `validation_prompt`.", ) parser.add_argument( "--validation_epochs", type=int, default=1, help=( "Run fine-tuning validation every X epochs. The validation process consists of running the prompt" " `args.validation_prompt` multiple times: `args.num_validation_images`." ), ) parser.add_argument( "--max_train_samples", type=int, default=None, help=( "For debugging purposes or quicker training, truncate the number of training examples to this value if set." ), ) parser.add_argument( "--output_dir", type=str, default="instruct-pix2pix-model-random", help="The output directory where the model predictions and checkpoints will be written.", ) parser.add_argument( "--cache_dir", type=str, default=None, help="The directory where the downloaded models and datasets will be stored.", ) parser.add_argument("--seed", type=int, default=None, help="A seed for reproducible training.") parser.add_argument( "--resolution", type=int, default=256, help=( "The resolution for input images, all the images in the train/validation dataset will be resized to this" " resolution" ), ) parser.add_argument( "--center_crop", default=False, action="store_true", help=( "Whether to center crop the input images to the resolution. If not set, the images will be randomly" " cropped. The images will be resized to the resolution first before cropping." ), ) parser.add_argument( "--random_flip", action="store_true", help="whether to randomly flip images horizontally", ) parser.add_argument( "--train_batch_size", type=int, default=16, help="Batch size (per device) for the training dataloader." ) parser.add_argument("--num_train_epochs", type=int, default=100) parser.add_argument( "--max_train_steps", type=int, default=None, help="Total number of training steps to perform. If provided, overrides num_train_epochs.", ) parser.add_argument( "--gradient_accumulation_steps", type=int, default=1, help="Number of updates steps to accumulate before performing a backward/update pass.", ) parser.add_argument( "--gradient_checkpointing", action="store_true", help="Whether or not to use gradient checkpointing to save memory at the expense of slower backward pass.", ) parser.add_argument( "--learning_rate", type=float, default=1e-4, help="Initial learning rate (after the potential warmup period) to use.", ) parser.add_argument( "--scale_lr", action="store_true", default=False, help="Scale the learning rate by the number of GPUs, gradient accumulation steps, and batch size.", ) parser.add_argument( "--lr_scheduler", type=str, default="constant", help=( 'The scheduler type to use. Choose between ["linear", "cosine", "cosine_with_restarts", "polynomial",' ' "constant", "constant_with_warmup"]' ), ) parser.add_argument( "--lr_warmup_steps", type=int, default=500, help="Number of steps for the warmup in the lr scheduler." ) parser.add_argument( "--conditioning_dropout_prob", type=float, default=None, help=( "Conditioning dropout probability. Drops out the conditionings (image and edit prompt) used " "in training InstructPix2Pix. See section 3.2.1 in the paper: " "https://arxiv.org/abs/2211.09800." ), ) parser.add_argument( "--use_8bit_adam", action="store_true", help="Whether or not to use 8-bit Adam from bitsandbytes." ) parser.add_argument( "--allow_tf32", action="store_true", help=( "Whether or not to allow TF32 on Ampere GPUs. Can be used to speed up training. For more information, see" " https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices" ), ) parser.add_argument("--use_ema", action="store_true", help="Whether to use EMA model.") parser.add_argument( "--non_ema_revision", type=str, default=None, required=False, help=( "Revision of pretrained non-ema model identifier. Must be a branch, tag or git identifier of the local or" " remote repository specified with --pretrained_model_name_or_path." ), ) parser.add_argument( "--dataloader_num_workers", type=int, default=0, help=( "Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process." ), ) parser.add_argument("--adam_beta1", type=float, default=0.9, help="The beta1 parameter for the Adam optimizer.") parser.add_argument("--adam_beta2", type=float, default=0.999, help="The beta2 parameter for the Adam optimizer.") parser.add_argument("--adam_weight_decay", type=float, default=1e-2, help="Weight decay to use.") parser.add_argument("--adam_epsilon", type=float, default=1e-08, help="Epsilon value for the Adam optimizer") parser.add_argument("--max_grad_norm", default=1.0, type=float, help="Max gradient norm.") parser.add_argument("--push_to_hub", action="store_true", help="Whether or not to push the model to the Hub.") parser.add_argument("--hub_token", type=str, default=None, help="The token to use to push to the Model Hub.") parser.add_argument( "--hub_model_id", type=str, default=None, help="The name of the repository to keep in sync with the local `output_dir`.", ) parser.add_argument( "--logging_dir", type=str, default="logs", help=( "[TensorBoard](https://www.tensorflow.org/tensorboard) log directory. Will default to" " *output_dir/runs/**CURRENT_DATETIME_HOSTNAME***." ), ) parser.add_argument( "--mixed_precision", type=str, default=None, choices=["no", "fp16", "bf16"], help=( "Whether to use mixed precision. Choose between fp16 and bf16 (bfloat16). Bf16 requires PyTorch >=" " 1.10.and an Nvidia Ampere GPU. Default to the value of accelerate config of the current system or the" " flag passed with the `accelerate.launch` command. Use this argument to override the accelerate config." ), ) parser.add_argument( "--report_to", type=str, default="tensorboard", help=( 'The integration to report the results and logs to. Supported platforms are `"tensorboard"`' ' (default), `"wandb"` and `"comet_ml"`. Use `"all"` to report to all integrations.' ), ) parser.add_argument("--local_rank", type=int, default=-1, help="For distributed training: local_rank") parser.add_argument( "--checkpointing_steps", type=int, default=500, help=( "Save a checkpoint of the training state every X updates. These checkpoints are only suitable for resuming" " training using `--resume_from_checkpoint`." ), ) parser.add_argument( "--checkpoints_total_limit", type=int, default=None, help=("Max number of checkpoints to store."), ) parser.add_argument( "--resume_from_checkpoint", type=str, default=None, help=( "Whether training should be resumed from a previous checkpoint. Use a path saved by" ' `--checkpointing_steps`, or `"latest"` to automatically select the last available checkpoint.' ), ) parser.add_argument( "--enable_xformers_memory_efficient_attention", action="store_true", help="Whether or not to use xformers." ) args = parser.parse_args() env_local_rank = int(os.environ.get("LOCAL_RANK", -1)) if env_local_rank != -1 and env_local_rank != args.local_rank: args.local_rank = env_local_rank # Sanity checks if args.dataset_name is None and args.train_data_dir is None: raise ValueError("Need either a dataset name or a training folder.") # default to using the same revision for the non-ema model if not specified if args.non_ema_revision is None: args.non_ema_revision = args.revision return args def convert_to_np(image, resolution): image = image.convert("RGB").resize((resolution, resolution)) return np.array(image).transpose(2, 0, 1) def download_image(url): image = PIL.Image.open(requests.get(url, stream=True).raw) image = PIL.ImageOps.exif_transpose(image) image = image.convert("RGB") return image def freeze_all_layers(model): for param in model.parameters(): param.requires_grad = False def random_activate_layers(model, p): activate_number = int((len(list(model.parameters())) - 2) * p) index = np.random.choice(range(0, len(list(model.parameters())) - 1, 1), activate_number, replace=False) count = 0 for param in model.parameters(): if count == 0 or count == len(list(model.parameters())) - 1: param.requires_grad = True elif count in index: param.requires_grad = True count += 1 def lisa(model, p=0.25): freeze_all_layers(model) random_activate_layers(model, p) def main(): args = parse_args() if args.report_to == "wandb" and args.hub_token is not None: raise ValueError( "You cannot use both --report_to=wandb and --hub_token due to a security risk of exposing your token." " Please use `huggingface-cli login` to authenticate with the Hub." ) if args.non_ema_revision is not None: deprecate( "non_ema_revision!=None", "0.15.0", message=( "Downloading 'non_ema' weights from revision branches of the Hub is deprecated. Please make sure to" " use `--variant=non_ema` instead." ), ) logging_dir = os.path.join(args.output_dir, args.logging_dir) accelerator_project_config = ProjectConfiguration(project_dir=args.output_dir, logging_dir=logging_dir) from accelerate import DistributedDataParallelKwargs ddp_kwargs = DistributedDataParallelKwargs(find_unused_parameters=True) accelerator = Accelerator( gradient_accumulation_steps=args.gradient_accumulation_steps, mixed_precision=args.mixed_precision, log_with=args.report_to, project_config=accelerator_project_config, kwargs_handlers=[ddp_kwargs], ) generator = torch.Generator(device=accelerator.device).manual_seed(args.seed) if args.report_to == "wandb": if not is_wandb_available(): raise ImportError("Make sure to install wandb if you want to use it for logging during training.") import wandb # Make one log on every process with the configuration for debugging. logging.basicConfig( format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%m/%d/%Y %H:%M:%S", level=logging.INFO, ) logger.info(accelerator.state, main_process_only=False) if accelerator.is_local_main_process: datasets.utils.logging.set_verbosity_warning() transformers.utils.logging.set_verbosity_warning() diffusers.utils.logging.set_verbosity_info() else: datasets.utils.logging.set_verbosity_error() transformers.utils.logging.set_verbosity_error() diffusers.utils.logging.set_verbosity_error() # If passed along, set the training seed now. if args.seed is not None: set_seed(args.seed) # Handle the repository creation if accelerator.is_main_process: if args.output_dir is not None: os.makedirs(args.output_dir, exist_ok=True) if args.push_to_hub: repo_id = create_repo( repo_id=args.hub_model_id or Path(args.output_dir).name, exist_ok=True, token=args.hub_token ).repo_id # Load scheduler, tokenizer and models. noise_scheduler = DDPMScheduler.from_pretrained(args.pretrained_model_name_or_path, subfolder="scheduler") tokenizer = CLIPTokenizer.from_pretrained( args.pretrained_model_name_or_path, subfolder="tokenizer", revision=args.revision ) text_encoder = CLIPTextModel.from_pretrained( args.pretrained_model_name_or_path, subfolder="text_encoder", revision=args.revision, variant=args.variant ) vae = AutoencoderKL.from_pretrained( args.pretrained_model_name_or_path, subfolder="vae", revision=args.revision, variant=args.variant ) unet = UNet2DConditionModel.from_pretrained( args.pretrained_model_name_or_path, subfolder="unet", revision=args.non_ema_revision ) # InstructPix2Pix uses an additional image for conditioning. To accommodate that, # it uses 8 channels (instead of 4) in the first (conv) layer of the UNet. This UNet is # then fine-tuned on the custom InstructPix2Pix dataset. This modified UNet is initialized # from the pre-trained checkpoints. For the extra channels added to the first layer, they are # initialized to zero. logger.info("Initializing the InstructPix2Pix UNet from the pretrained UNet.") in_channels = 8 out_channels = unet.conv_in.out_channels unet.register_to_config(in_channels=in_channels) with torch.no_grad(): new_conv_in = nn.Conv2d( in_channels, out_channels, unet.conv_in.kernel_size, unet.conv_in.stride, unet.conv_in.padding ) new_conv_in.weight.zero_() new_conv_in.weight[:, :4, :, :].copy_(unet.conv_in.weight) unet.conv_in = new_conv_in # Freeze vae and text_encoder vae.requires_grad_(False) text_encoder.requires_grad_(False) # Create EMA for the unet. if args.use_ema: ema_unet = EMAModel(unet.parameters(), model_cls=UNet2DConditionModel, model_config=unet.config) if args.enable_xformers_memory_efficient_attention: if is_xformers_available(): import xformers xformers_version = version.parse(xformers.__version__) if xformers_version == version.parse("0.0.16"): logger.warning( "xFormers 0.0.16 cannot be used for training in some GPUs. If you observe problems during " "training, please update xFormers to at least 0.0.17. " "See https://huggingface.co/docs/diffusers/main/en/optimization/xformers for more details." ) unet.enable_xformers_memory_efficient_attention() else: raise ValueError("xformers is not available. Make sure it is installed correctly") def unwrap_model(model): model = accelerator.unwrap_model(model) model = model._orig_mod if is_compiled_module(model) else model return model # `accelerate` 0.16.0 will have better support for customized saving if version.parse(accelerate.__version__) >= version.parse("0.16.0"): # create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format def save_model_hook(models, weights, output_dir): if accelerator.is_main_process: if args.use_ema: ema_unet.save_pretrained(os.path.join(output_dir, "unet_ema")) for i, model in enumerate(models): model.save_pretrained(os.path.join(output_dir, "unet")) # make sure to pop weight so that corresponding model is not saved again weights.pop() def load_model_hook(models, input_dir): if args.use_ema: load_model = EMAModel.from_pretrained(os.path.join(input_dir, "unet_ema"), UNet2DConditionModel) ema_unet.load_state_dict(load_model.state_dict()) ema_unet.to(accelerator.device) del load_model for i in range(len(models)): # pop models so that they are not loaded again model = models.pop() # load diffusers style into model load_model = UNet2DConditionModel.from_pretrained(input_dir, subfolder="unet") model.register_to_config(**load_model.config) model.load_state_dict(load_model.state_dict()) del load_model accelerator.register_save_state_pre_hook(save_model_hook) accelerator.register_load_state_pre_hook(load_model_hook) if args.gradient_checkpointing: unet.enable_gradient_checkpointing() # Enable TF32 for faster training on Ampere GPUs, # cf https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices if args.allow_tf32: torch.backends.cuda.matmul.allow_tf32 = True if args.scale_lr: args.learning_rate = ( args.learning_rate * args.gradient_accumulation_steps * args.train_batch_size * accelerator.num_processes ) # Initialize the optimizer if args.use_8bit_adam: try: import bitsandbytes as bnb except ImportError: raise ImportError( "Please install bitsandbytes to use 8-bit Adam. You can do so by running `pip install bitsandbytes`" ) from None optimizer_cls = bnb.optim.AdamW8bit else: optimizer_cls = torch.optim.AdamW optimizer_dict = dict() scheduler_dict = dict() param_number = len(list(unet.parameters())) lisa_p = 8 / param_number lisa(model=unet, p=lisa_p) for p in unet.parameters(): if p.requires_grad: optimizer_dict[p] = optimizer_cls( [{"params": p}], lr=args.learning_rate, betas=(args.adam_beta1, args.adam_beta2), weight_decay=args.adam_weight_decay, eps=args.adam_epsilon, ) optimizer_dict[p] = accelerator.prepare_optimizer(optimizer_dict[p]) for p in unet.parameters(): if p.requires_grad: scheduler_dict[p] = get_scheduler( args.lr_scheduler, optimizer=optimizer_dict[p], num_warmup_steps=args.lr_warmup_steps * accelerator.num_processes, num_training_steps=args.max_train_steps * accelerator.num_processes, ) scheduler_dict[p] = accelerator.prepare_scheduler(scheduler_dict[p]) # define a hook function to update the parameter p during the backward pass def optimizer_hook(p): if p.grad is None: del scheduler_dict[p] del optimizer_dict[p] return else: if p not in optimizer_dict: optimizer_dict[p] = optimizer_cls( [{"params": p}], lr=args.learning_rate, betas=(args.adam_beta1, args.adam_beta2), weight_decay=args.adam_weight_decay, eps=args.adam_epsilon, ) optimizer_dict[p] = accelerator.prepare_optimizer(optimizer_dict[p]) if p not in scheduler_dict: scheduler_dict[p] = get_scheduler( args.lr_scheduler, optimizer=optimizer_dict[p], num_warmup_steps=args.lr_warmup_steps * accelerator.num_processes, num_training_steps=args.max_train_steps * accelerator.num_processes, ) scheduler_dict[p] = accelerator.prepare_scheduler(scheduler_dict[p]) optimizer_dict[p].step() optimizer_dict[p].zero_grad(set_to_none=True) scheduler_dict[p].step() # Register the hook onto every parameter for p in unet.parameters(): if p.requires_grad: p.register_post_accumulate_grad_hook(optimizer_hook) unet = accelerator.prepare_model(unet) # Get the datasets: you can either provide your own training and evaluation files (see below) # or specify a Dataset from the hub (the dataset will be downloaded automatically from the datasets Hub). # In distributed training, the load_dataset function guarantees that only one local process can concurrently # download the dataset. if args.dataset_name is not None: # Downloading and loading a dataset from the hub. dataset = load_dataset( args.dataset_name, args.dataset_config_name, cache_dir=args.cache_dir, ) else: data_files = {} if args.train_data_dir is not None: data_files["train"] = os.path.join(args.train_data_dir, "**") dataset = load_dataset( "imagefolder", data_files=data_files, cache_dir=args.cache_dir, ) # See more about loading custom images at # https://huggingface.co/docs/datasets/main/en/image_load#imagefolder # Preprocessing the datasets. # We need to tokenize inputs and targets. column_names = dataset["train"].column_names # 6. Get the column names for input/target. dataset_columns = DATASET_NAME_MAPPING.get(args.dataset_name, None) if args.original_image_column is None: original_image_column = dataset_columns[0] if dataset_columns is not None else column_names[0] else: original_image_column = args.original_image_column if original_image_column not in column_names: raise ValueError( f"--original_image_column' value '{args.original_image_column}' needs to be one of: " f"{', '.join(column_names)}" ) if args.edit_prompt_column is None: edit_prompt_column = dataset_columns[1] if dataset_columns is not None else column_names[1] else: edit_prompt_column = args.edit_prompt_column if edit_prompt_column not in column_names: raise ValueError( f"--edit_prompt_column' value '{args.edit_prompt_column}' needs to be one of: {', '.join(column_names)}" ) if args.edited_image_column is None: edited_image_column = dataset_columns[2] if dataset_columns is not None else column_names[2] else: edited_image_column = args.edited_image_column if edited_image_column not in column_names: raise ValueError( f"--edited_image_column' value '{args.edited_image_column}' needs to be one of: " f"{', '.join(column_names)}" ) # Preprocessing the datasets. # We need to tokenize input captions and transform the images. def tokenize_captions(captions): inputs = tokenizer( captions, max_length=tokenizer.model_max_length, padding="max_length", truncation=True, return_tensors="pt" ) return inputs.input_ids # Preprocessing the datasets. train_transforms = transforms.Compose( [ transforms.CenterCrop(args.resolution) if args.center_crop else transforms.RandomCrop(args.resolution), transforms.RandomHorizontalFlip() if args.random_flip else transforms.Lambda(lambda x: x), ] ) def preprocess_images(examples): original_images = np.concatenate( [convert_to_np(image, args.resolution) for image in examples[original_image_column]] ) edited_images = np.concatenate( [convert_to_np(image, args.resolution) for image in examples[edited_image_column]] ) # We need to ensure that the original and the edited images undergo the same # augmentation transforms. images = np.concatenate([original_images, edited_images]) images = torch.tensor(images) images = 2 * (images / 255) - 1 return train_transforms(images) def preprocess_train(examples): # Preprocess images. preprocessed_images = preprocess_images(examples) # Since the original and edited images were concatenated before # applying the transformations, we need to separate them and reshape # them accordingly. original_images, edited_images = preprocessed_images.chunk(2) original_images = original_images.reshape(-1, 3, args.resolution, args.resolution) edited_images = edited_images.reshape(-1, 3, args.resolution, args.resolution) # Collate the preprocessed images into the `examples`. examples["original_pixel_values"] = original_images examples["edited_pixel_values"] = edited_images # Preprocess the captions. captions = list(examples[edit_prompt_column]) examples["input_ids"] = tokenize_captions(captions) return examples with accelerator.main_process_first(): if args.max_train_samples is not None: dataset["train"] = dataset["train"].shuffle(seed=args.seed).select(range(args.max_train_samples)) # Set the training transforms train_dataset = dataset["train"].with_transform(preprocess_train) def collate_fn(examples): original_pixel_values = torch.stack([example["original_pixel_values"] for example in examples]) original_pixel_values = original_pixel_values.to(memory_format=torch.contiguous_format).float() edited_pixel_values = torch.stack([example["edited_pixel_values"] for example in examples]) edited_pixel_values = edited_pixel_values.to(memory_format=torch.contiguous_format).float() input_ids = torch.stack([example["input_ids"] for example in examples]) return { "original_pixel_values": original_pixel_values, "edited_pixel_values": edited_pixel_values, "input_ids": input_ids, } # DataLoaders creation: train_dataloader = torch.utils.data.DataLoader( train_dataset, shuffle=True, collate_fn=collate_fn, batch_size=args.train_batch_size, num_workers=args.dataloader_num_workers, ) # Scheduler and math around the number of training steps. overrode_max_train_steps = False num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps) if args.max_train_steps is None: args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch overrode_max_train_steps = True # Prepare everything with our `accelerator`. train_dataloader = accelerator.prepare_data_loader(train_dataloader) if args.use_ema: ema_unet.to(accelerator.device) # For mixed precision training we cast the text_encoder and vae weights to half-precision # as these models are only used for inference, keeping weights in full precision is not required. weight_dtype = torch.float32 if accelerator.mixed_precision == "fp16": weight_dtype = torch.float16 elif accelerator.mixed_precision == "bf16": weight_dtype = torch.bfloat16 # Move text_encode and vae to gpu and cast to weight_dtype text_encoder.to(accelerator.device, dtype=weight_dtype) vae.to(accelerator.device, dtype=weight_dtype) # We need to recalculate our total training steps as the size of the training dataloader may have changed. num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps) if overrode_max_train_steps: args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch # Afterwards we recalculate our number of training epochs args.num_train_epochs = math.ceil(args.max_train_steps / num_update_steps_per_epoch) # We need to initialize the trackers we use, and also store our configuration. # The trackers initializes automatically on the main process. if accelerator.is_main_process: accelerator.init_trackers("instruct-pix2pix", config=vars(args)) # Train! total_batch_size = args.train_batch_size * accelerator.num_processes * args.gradient_accumulation_steps logger.info("***** Running training *****") logger.info(f" Num examples = {len(train_dataset)}") logger.info(f" Num Epochs = {args.num_train_epochs}") logger.info(f" Instantaneous batch size per device = {args.train_batch_size}") logger.info(f" Total train batch size (w. parallel, distributed & accumulation) = {total_batch_size}") logger.info(f" Gradient Accumulation steps = {args.gradient_accumulation_steps}") logger.info(f" Total optimization steps = {args.max_train_steps}") global_step = 0 first_epoch = 0 # Potentially load in the weights and states from a previous save if args.resume_from_checkpoint: if args.resume_from_checkpoint != "latest": path = os.path.basename(args.resume_from_checkpoint) else: # Get the most recent checkpoint dirs = os.listdir(args.output_dir) dirs = [d for d in dirs if d.startswith("checkpoint")] dirs = sorted(dirs, key=lambda x: int(x.split("-")[1])) path = dirs[-1] if len(dirs) > 0 else None if path is None: accelerator.print( f"Checkpoint '{args.resume_from_checkpoint}' does not exist. Starting a new training run." ) args.resume_from_checkpoint = None else: accelerator.print(f"Resuming from checkpoint {path}") accelerator.load_state(os.path.join(args.output_dir, path)) global_step = int(path.split("-")[1]) resume_global_step = global_step * args.gradient_accumulation_steps first_epoch = global_step // num_update_steps_per_epoch resume_step = resume_global_step % (num_update_steps_per_epoch * args.gradient_accumulation_steps) # Only show the progress bar once on each machine. progress_bar = tqdm(range(global_step, args.max_train_steps), disable=not accelerator.is_local_main_process) progress_bar.set_description("Steps") total_count = 0 for epoch in range(first_epoch, args.num_train_epochs): unet.train() train_loss = 0.0 for step, batch in enumerate(train_dataloader): if total_count % 20 == 0 and total_count != 0: param_number = len(list(unet.parameters())) lisa(model=unet, p=lisa_p) total_count += 1 if args.resume_from_checkpoint and epoch == first_epoch and step < resume_step: if step % args.gradient_accumulation_steps == 0: progress_bar.update(1) continue with accelerator.accumulate(unet): # We want to learn the denoising process w.r.t the edited images which # are conditioned on the original image (which was edited) and the edit instruction. # So, first, convert images to latent space. latents = vae.encode(batch["edited_pixel_values"].to(weight_dtype)).latent_dist.sample() latents = latents * vae.config.scaling_factor # Sample noise that we'll add to the latents noise = torch.randn_like(latents) bsz = latents.shape[0] # Sample a random timestep for each image timesteps = torch.randint(0, noise_scheduler.config.num_train_timesteps, (bsz,), device=latents.device) timesteps = timesteps.long() # Add noise to the latents according to the noise magnitude at each timestep # (this is the forward diffusion process) noisy_latents = noise_scheduler.add_noise(latents, noise, timesteps) # Get the text embedding for conditioning. encoder_hidden_states = text_encoder(batch["input_ids"])[0] # Get the additional image embedding for conditioning. # Instead of getting a diagonal Gaussian here, we simply take the mode. original_image_embeds = vae.encode(batch["original_pixel_values"].to(weight_dtype)).latent_dist.mode() # Conditioning dropout to support classifier-free guidance during inference. For more details # check out the section 3.2.1 of the original paper https://arxiv.org/abs/2211.09800. if args.conditioning_dropout_prob is not None: random_p = torch.rand(bsz, device=latents.device, generator=generator) # Sample masks for the edit prompts. prompt_mask = random_p < 2 * args.conditioning_dropout_prob prompt_mask = prompt_mask.reshape(bsz, 1, 1) # Final text conditioning. null_conditioning = text_encoder(tokenize_captions([""]).to(accelerator.device))[0] encoder_hidden_states = torch.where(prompt_mask, null_conditioning, encoder_hidden_states) # Sample masks for the original images. image_mask_dtype = original_image_embeds.dtype image_mask = 1 - ( (random_p >= args.conditioning_dropout_prob).to(image_mask_dtype) * (random_p < 3 * args.conditioning_dropout_prob).to(image_mask_dtype) ) image_mask = image_mask.reshape(bsz, 1, 1, 1) # Final image conditioning. original_image_embeds = image_mask * original_image_embeds # Concatenate the `original_image_embeds` with the `noisy_latents`. concatenated_noisy_latents = torch.cat([noisy_latents, original_image_embeds], dim=1) # Get the target for loss depending on the prediction type if noise_scheduler.config.prediction_type == "epsilon": target = noise elif noise_scheduler.config.prediction_type == "v_prediction": target = noise_scheduler.get_velocity(latents, noise, timesteps) else: raise ValueError(f"Unknown prediction type {noise_scheduler.config.prediction_type}") # Predict the noise residual and compute loss model_pred = unet(concatenated_noisy_latents, timesteps, encoder_hidden_states, return_dict=False)[0] loss = F.mse_loss(model_pred.float(), target.float(), reduction="mean") # Gather the losses across all processes for logging (if we use distributed training). avg_loss = accelerator.gather(loss.repeat(args.train_batch_size)).mean() train_loss += avg_loss.item() / args.gradient_accumulation_steps # Backpropagate accelerator.backward(loss) if accelerator.sync_gradients: accelerator.clip_grad_norm_(unet.parameters(), args.max_grad_norm) # Checks if the accelerator has performed an optimization step behind the scenes if accelerator.sync_gradients: if args.use_ema: ema_unet.step(unet.parameters()) progress_bar.update(1) global_step += 1 accelerator.log({"train_loss": train_loss}, step=global_step) train_loss = 0.0 if global_step % args.checkpointing_steps == 0: if accelerator.is_main_process: # _before_ saving state, check if this save would set us over the `checkpoints_total_limit` if args.checkpoints_total_limit is not None: checkpoints = os.listdir(args.output_dir) checkpoints = [d for d in checkpoints if d.startswith("checkpoint")] checkpoints = sorted(checkpoints, key=lambda x: int(x.split("-")[1])) # before we save the new checkpoint, we need to have at _most_ # `checkpoints_total_limit - 1` checkpoints if len(checkpoints) >= args.checkpoints_total_limit: num_to_remove = len(checkpoints) - args.checkpoints_total_limit + 1 removing_checkpoints = checkpoints[0:num_to_remove] logger.info( f"{len(checkpoints)} checkpoints already exist, removing " f"{len(removing_checkpoints)} checkpoints" ) logger.info(f"removing checkpoints: {', '.join(removing_checkpoints)}") for removing_checkpoint in removing_checkpoints: removing_checkpoint = os.path.join(args.output_dir, removing_checkpoint) shutil.rmtree(removing_checkpoint) save_path = os.path.join(args.output_dir, f"checkpoint-{global_step}") accelerator.save_state(save_path) logger.info(f"Saved state to {save_path}") logs = {"step_loss": loss.detach().item(), "lr": list(optimizer_dict.values())[0].param_groups[0]["lr"]} progress_bar.set_postfix(**logs) if global_step >= args.max_train_steps: break if accelerator.is_main_process: if ( (args.val_image_url is not None) and (args.validation_prompt is not None) and (epoch % args.validation_epochs == 0) ): logger.info( f"Running validation... \n Generating {args.num_validation_images} images with prompt:" f" {args.validation_prompt}." ) # create pipeline if args.use_ema: # Store the UNet parameters temporarily and load the EMA parameters to perform inference. ema_unet.store(unet.parameters()) ema_unet.copy_to(unet.parameters()) # The models need unwrapping because for compatibility in distributed training mode. pipeline = StableDiffusionInstructPix2PixPipeline.from_pretrained( args.pretrained_model_name_or_path, unet=unwrap_model(unet), text_encoder=unwrap_model(text_encoder), vae=unwrap_model(vae), revision=args.revision, variant=args.variant, torch_dtype=weight_dtype, ) pipeline = pipeline.to(accelerator.device) pipeline.set_progress_bar_config(disable=True) # run inference original_image = download_image(args.val_image_url) edited_images = [] with torch.autocast( str(accelerator.device).replace(":0", ""), enabled=accelerator.mixed_precision == "fp16" ): for _ in range(args.num_validation_images): edited_images.append( pipeline( args.validation_prompt, image=original_image, num_inference_steps=20, image_guidance_scale=1.5, guidance_scale=7, generator=generator, ).images[0] ) for tracker in accelerator.trackers: if tracker.name == "wandb": wandb_table = wandb.Table(columns=WANDB_TABLE_COL_NAMES) for edited_image in edited_images: wandb_table.add_data( wandb.Image(original_image), wandb.Image(edited_image), args.validation_prompt ) tracker.log({"validation": wandb_table}) if args.use_ema: # Switch back to the original UNet parameters. ema_unet.restore(unet.parameters()) del pipeline torch.cuda.empty_cache() # Create the pipeline using the trained modules and save it. accelerator.wait_for_everyone() if accelerator.is_main_process: unet = unwrap_model(unet) if args.use_ema: ema_unet.copy_to(unet.parameters()) pipeline = StableDiffusionInstructPix2PixPipeline.from_pretrained( args.pretrained_model_name_or_path, text_encoder=unwrap_model(text_encoder), vae=unwrap_model(vae), unet=unet, revision=args.revision, variant=args.variant, ) pipeline.save_pretrained(args.output_dir) if args.push_to_hub: upload_folder( repo_id=repo_id, folder_path=args.output_dir, commit_message="End of training", ignore_patterns=["step_*", "epoch_*"], ) if args.validation_prompt is not None: edited_images = [] pipeline = pipeline.to(accelerator.device) with torch.autocast(str(accelerator.device).replace(":0", "")): for _ in range(args.num_validation_images): edited_images.append( pipeline( args.validation_prompt, image=original_image, num_inference_steps=20, image_guidance_scale=1.5, guidance_scale=7, generator=generator, ).images[0] ) for tracker in accelerator.trackers: if tracker.name == "wandb": wandb_table = wandb.Table(columns=WANDB_TABLE_COL_NAMES) for edited_image in edited_images: wandb_table.add_data( wandb.Image(original_image), wandb.Image(edited_image), args.validation_prompt ) tracker.log({"test": wandb_table}) accelerator.end_training() if __name__ == "__main__": main() ================================================ FILE: experimental/LISA-diffusion/latent_consistency_model/train_lcm_distill_sd_wds_lisa.py ================================================ #!/usr/bin/env python # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and import argparse import functools import gc import itertools import json import logging import math import os import random import shutil from pathlib import Path from typing import Union import accelerate import diffusers import numpy as np import torch import torch.nn.functional as F import torch.utils.checkpoint import torchvision.transforms.functional as TF import transformers import webdataset as wds from accelerate import Accelerator from accelerate.logging import get_logger from accelerate.utils import ProjectConfiguration, set_seed from braceexpand import braceexpand from diffusers import ( AutoencoderKL, DDPMScheduler, LCMScheduler, StableDiffusionPipeline, UNet2DConditionModel, ) from diffusers.optimization import get_scheduler from diffusers.training_utils import resolve_interpolation_mode from diffusers.utils import check_min_version, is_wandb_available from diffusers.utils.import_utils import is_xformers_available from huggingface_hub import create_repo, upload_folder from packaging import version from torch.utils.data import default_collate from torchvision import transforms from tqdm.auto import tqdm from transformers import AutoTokenizer, CLIPTextModel, PretrainedConfig from webdataset.tariterators import ( base_plus_ext, tar_file_expander, url_opener, valid_sample, ) MAX_SEQ_LENGTH = 77 if is_wandb_available(): import wandb # Will error if the minimal version of diffusers is not installed. Remove at your own risks. check_min_version("0.28.0.dev0") logger = get_logger(__name__) def freeze_all_layers(model): for param in model.parameters(): param.requires_grad = False def random_activate_layers(model, p): activate_number = int((len(list(model.parameters())) - 2) * p) index = np.random.choice(range(0, len(list(model.parameters())) - 1, 1), activate_number, replace=False) count = 0 for param in model.parameters(): if count == 0 or count == len(list(model.parameters())) - 1: param.requires_grad = True elif count in index: param.requires_grad = True count += 1 def lisa(model, p=0.25): freeze_all_layers(model) random_activate_layers(model, p) def filter_keys(key_set): def _f(dictionary): return {k: v for k, v in dictionary.items() if k in key_set} return _f def group_by_keys_nothrow(data, keys=base_plus_ext, lcase=True, suffixes=None, handler=None): """Return function over iterator that groups key, value pairs into samples. :param keys: function that splits the key into key and extension (base_plus_ext) :param lcase: convert suffixes to lower case (Default value = True) """ current_sample = None for filesample in data: assert isinstance(filesample, dict) fname, value = filesample["fname"], filesample["data"] prefix, suffix = keys(fname) if prefix is None: continue if lcase: suffix = suffix.lower() # FIXME webdataset version throws if suffix in current_sample, but we have a potential for # this happening in the current LAION400m dataset if a tar ends with same prefix as the next # begins, rare, but can happen since prefix aren't unique across tar files in that dataset if current_sample is None or prefix != current_sample["__key__"] or suffix in current_sample: if valid_sample(current_sample): yield current_sample current_sample = {"__key__": prefix, "__url__": filesample["__url__"]} if suffixes is None or suffix in suffixes: current_sample[suffix] = value if valid_sample(current_sample): yield current_sample def tarfile_to_samples_nothrow(src, handler=wds.warn_and_continue): # NOTE this is a re-impl of the webdataset impl with group_by_keys that doesn't throw streams = url_opener(src, handler=handler) files = tar_file_expander(streams, handler=handler) samples = group_by_keys_nothrow(files, handler=handler) return samples class WebdatasetFilter: def __init__(self, min_size=1024, max_pwatermark=0.5): self.min_size = min_size self.max_pwatermark = max_pwatermark def __call__(self, x): try: if "json" in x: x_json = json.loads(x["json"]) filter_size = (x_json.get("original_width", 0.0) or 0.0) >= self.min_size and x_json.get( "original_height", 0 ) >= self.min_size filter_watermark = (x_json.get("pwatermark", 1.0) or 1.0) <= self.max_pwatermark return filter_size and filter_watermark else: return False except Exception: return False class SDText2ImageDataset: def __init__( self, train_shards_path_or_url: Union[str, list[str]], num_train_examples: int, per_gpu_batch_size: int, global_batch_size: int, num_workers: int, resolution: int = 512, interpolation_type: str = "bilinear", shuffle_buffer_size: int = 1000, pin_memory: bool = False, persistent_workers: bool = False, ): if not isinstance(train_shards_path_or_url, str): train_shards_path_or_url = [list(braceexpand(urls)) for urls in train_shards_path_or_url] # flatten list using itertools train_shards_path_or_url = list(itertools.chain.from_iterable(train_shards_path_or_url)) interpolation_mode = resolve_interpolation_mode(interpolation_type) def transform(example): # resize image image = example["image"] image = TF.resize(image, resolution, interpolation=interpolation_mode) # get crop coordinates and crop image c_top, c_left, _, _ = transforms.RandomCrop.get_params(image, output_size=(resolution, resolution)) image = TF.crop(image, c_top, c_left, resolution, resolution) image = TF.to_tensor(image) image = TF.normalize(image, [0.5], [0.5]) example["image"] = image return example processing_pipeline = [ wds.decode("pil", handler=wds.ignore_and_continue), wds.rename(image="jpg;png;jpeg;webp", text="text;txt;caption", handler=wds.warn_and_continue), wds.map(filter_keys({"image", "text"})), wds.map(transform), wds.to_tuple("image", "text"), ] # Create train dataset and loader pipeline = [ wds.ResampledShards(train_shards_path_or_url), tarfile_to_samples_nothrow, wds.shuffle(shuffle_buffer_size), *processing_pipeline, wds.batched(per_gpu_batch_size, partial=False, collation_fn=default_collate), ] num_worker_batches = math.ceil(num_train_examples / (global_batch_size * num_workers)) # per dataloader worker num_batches = num_worker_batches * num_workers num_samples = num_batches * global_batch_size # each worker is iterating over this self._train_dataset = wds.DataPipeline(*pipeline).with_epoch(num_worker_batches) self._train_dataloader = wds.WebLoader( self._train_dataset, batch_size=None, shuffle=False, num_workers=num_workers, pin_memory=pin_memory, persistent_workers=persistent_workers, ) # add meta-data to dataloader instance for convenience self._train_dataloader.num_batches = num_batches self._train_dataloader.num_samples = num_samples @property def train_dataset(self): return self._train_dataset @property def train_dataloader(self): return self._train_dataloader def log_validation(vae, unet, args, accelerator, weight_dtype, step, name="target"): logger.info("Running validation... ") unet = accelerator.unwrap_model(unet) pipeline = StableDiffusionPipeline.from_pretrained( args.pretrained_teacher_model, vae=vae, unet=unet, scheduler=LCMScheduler.from_pretrained(args.pretrained_teacher_model, subfolder="scheduler"), revision=args.revision, torch_dtype=weight_dtype, ) pipeline = pipeline.to(accelerator.device) pipeline.set_progress_bar_config(disable=True) if args.enable_xformers_memory_efficient_attention: pipeline.enable_xformers_memory_efficient_attention() if args.seed is None: generator = None else: generator = torch.Generator(device=accelerator.device).manual_seed(args.seed) validation_prompts = [ "portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour, style by Dan Winters, Russell James, Steve McCurry, centered, extremely detailed, Nikon D850, award winning photography", # noqa: E501 # "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k", # "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", # "A photo of beautiful mountain with realistic sunset and blue lake, highly detailed, masterpiece", ] image_logs = [] for _, prompt in enumerate(validation_prompts): images = [] from diffusers import UniPCMultistepScheduler pipeline.scheduler = UniPCMultistepScheduler.from_pretrained( "CompVis/stable-diffusion-v1-4", subfolder="scheduler" ) with torch.autocast("cuda"): images = pipeline( prompt=prompt, num_inference_steps=32, num_images_per_prompt=1, generator=generator, ).images images[0].save(f"{name}_iter_{step}_id_16.png") image_logs.append({"validation_prompt": prompt, "images": images}) for _, prompt in enumerate(validation_prompts): images = [] pipeline.scheduler = LCMScheduler.from_pretrained(args.pretrained_teacher_model, subfolder="scheduler") with torch.autocast("cuda"): images = pipeline( prompt=prompt, num_inference_steps=1, num_images_per_prompt=1, generator=generator, ).images images[0].save(f"{name}_iter_{step}_id_0.png") image_logs.append({"validation_prompt": prompt, "images": images}) for tracker in accelerator.trackers: if tracker.name == "tensorboard": for log in image_logs: images = log["images"] validation_prompt = log["validation_prompt"] formatted_images = [] for image in images: formatted_images.append(np.asarray(image)) formatted_images = np.stack(formatted_images) tracker.writer.add_images(validation_prompt, formatted_images, step, dataformats="NHWC") elif tracker.name == "wandb": formatted_images = [] for log in image_logs: images = log["images"] validation_prompt = log["validation_prompt"] for image in images: image = wandb.Image(image, caption=validation_prompt) formatted_images.append(image) tracker.log({f"validation/{name}": formatted_images}) else: logger.warning(f"image logging not implemented for {tracker.name}") del pipeline gc.collect() torch.cuda.empty_cache() return image_logs # From LatentConsistencyModel.get_guidance_scale_embedding def guidance_scale_embedding(w, embedding_dim=512, dtype=torch.float32): """ See https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298 Args: timesteps (`torch.Tensor`): generate embedding vectors at these timesteps embedding_dim (`int`, *optional*, defaults to 512): dimension of the embeddings to generate dtype: data type of the generated embeddings Returns: `torch.FloatTensor`: Embedding vectors with shape `(len(timesteps), embedding_dim)` """ assert len(w.shape) == 1 w = w * 1000.0 half_dim = embedding_dim // 2 emb = torch.log(torch.tensor(10000.0)) / (half_dim - 1) emb = torch.exp(torch.arange(half_dim, dtype=dtype) * -emb) emb = w.to(dtype)[:, None] * emb[None, :] emb = torch.cat([torch.sin(emb), torch.cos(emb)], dim=1) if embedding_dim % 2 == 1: # zero pad emb = torch.nn.functional.pad(emb, (0, 1)) assert emb.shape == (w.shape[0], embedding_dim) return emb def append_dims(x, target_dims): """Appends dimensions to the end of a tensor until it has target_dims dimensions.""" dims_to_append = target_dims - x.ndim if dims_to_append < 0: raise ValueError(f"input has {x.ndim} dims but target_dims is {target_dims}, which is less") return x[(...,) + (None,) * dims_to_append] # From LCMScheduler.get_scalings_for_boundary_condition_discrete def scalings_for_boundary_conditions(timestep, sigma_data=0.5, timestep_scaling=10.0): scaled_timestep = timestep_scaling * timestep c_skip = sigma_data**2 / (scaled_timestep**2 + sigma_data**2) c_out = scaled_timestep / (scaled_timestep**2 + sigma_data**2) ** 0.5 return c_skip, c_out # Compare LCMScheduler.step, Step 4 def get_predicted_original_sample(model_output, timesteps, sample, prediction_type, alphas, sigmas): alphas = extract_into_tensor(alphas, timesteps, sample.shape) sigmas = extract_into_tensor(sigmas, timesteps, sample.shape) if prediction_type == "epsilon": pred_x_0 = (sample - sigmas * model_output) / alphas elif prediction_type == "sample": pred_x_0 = model_output elif prediction_type == "v_prediction": pred_x_0 = alphas * sample - sigmas * model_output else: raise ValueError( f"Prediction type {prediction_type} is not supported; currently, `epsilon`, `sample`, and `v_prediction`" f" are supported." ) return pred_x_0 # Based on step 4 in DDIMScheduler.step def get_predicted_noise(model_output, timesteps, sample, prediction_type, alphas, sigmas): alphas = extract_into_tensor(alphas, timesteps, sample.shape) sigmas = extract_into_tensor(sigmas, timesteps, sample.shape) if prediction_type == "epsilon": pred_epsilon = model_output elif prediction_type == "sample": pred_epsilon = (sample - alphas * model_output) / sigmas elif prediction_type == "v_prediction": pred_epsilon = alphas * model_output + sigmas * sample else: raise ValueError( f"Prediction type {prediction_type} is not supported; currently, `epsilon`, `sample`, and `v_prediction`" f" are supported." ) return pred_epsilon def extract_into_tensor(a, t, x_shape): b, *_ = t.shape out = a.gather(-1, t) return out.reshape(b, *((1,) * (len(x_shape) - 1))) class DDIMSolver: def __init__(self, alpha_cumprods, timesteps=1000, ddim_timesteps=50): # DDIM sampling parameters step_ratio = timesteps // ddim_timesteps self.ddim_timesteps = (np.arange(1, ddim_timesteps + 1) * step_ratio).round().astype(np.int64) - 1 self.ddim_alpha_cumprods = alpha_cumprods[self.ddim_timesteps] self.ddim_alpha_cumprods_prev = np.asarray( [alpha_cumprods[0]] + alpha_cumprods[self.ddim_timesteps[:-1]].tolist() ) # convert to torch tensors self.ddim_timesteps = torch.from_numpy(self.ddim_timesteps).long() self.ddim_alpha_cumprods = torch.from_numpy(self.ddim_alpha_cumprods) self.ddim_alpha_cumprods_prev = torch.from_numpy(self.ddim_alpha_cumprods_prev) def to(self, device): self.ddim_timesteps = self.ddim_timesteps.to(device) self.ddim_alpha_cumprods = self.ddim_alpha_cumprods.to(device) self.ddim_alpha_cumprods_prev = self.ddim_alpha_cumprods_prev.to(device) return self def ddim_step(self, pred_x0, pred_noise, timestep_index): alpha_cumprod_prev = extract_into_tensor(self.ddim_alpha_cumprods_prev, timestep_index, pred_x0.shape) dir_xt = (1.0 - alpha_cumprod_prev).sqrt() * pred_noise x_prev = alpha_cumprod_prev.sqrt() * pred_x0 + dir_xt return x_prev @torch.no_grad() def update_ema(target_params, source_params, rate=0.99): """ Update target parameters to be closer to those of source parameters using an exponential moving average. :param target_params: the target parameter sequence. :param source_params: the source parameter sequence. :param rate: the EMA rate (closer to 1 means slower). """ for targ, src in zip(target_params, source_params): # if src.requires_grad == True: targ.detach().mul_(rate).add_(src, alpha=1 - rate) def import_model_class_from_model_name_or_path( pretrained_model_name_or_path: str, revision: str, subfolder: str = "text_encoder" ): text_encoder_config = PretrainedConfig.from_pretrained( pretrained_model_name_or_path, subfolder=subfolder, revision=revision ) model_class = text_encoder_config.architectures[0] if model_class == "CLIPTextModel": from transformers import CLIPTextModel return CLIPTextModel elif model_class == "CLIPTextModelWithProjection": from transformers import CLIPTextModelWithProjection return CLIPTextModelWithProjection else: raise ValueError(f"{model_class} is not supported.") def parse_args(): parser = argparse.ArgumentParser(description="Simple example of a training script.") # ----------Model Checkpoint Loading Arguments---------- parser.add_argument( "--pretrained_teacher_model", type=str, default=None, required=True, help="Path to pretrained LDM teacher model or model identifier from huggingface.co/models.", ) parser.add_argument( "--pretrained_vae_model_name_or_path", type=str, default=None, help="Path to pretrained VAE model with better numerical stability. More details: https://github.com/huggingface/diffusers/pull/4038.", ) parser.add_argument( "--teacher_revision", type=str, default=None, required=False, help="Revision of pretrained LDM teacher model identifier from huggingface.co/models.", ) parser.add_argument( "--revision", type=str, default=None, required=False, help="Revision of pretrained LDM model identifier from huggingface.co/models.", ) # ----------Training Arguments---------- # ----General Training Arguments---- parser.add_argument( "--output_dir", type=str, default="lcm-xl-distilled", help="The output directory where the model predictions and checkpoints will be written.", ) parser.add_argument( "--cache_dir", type=str, default=None, help="The directory where the downloaded models and datasets will be stored.", ) parser.add_argument("--seed", type=int, default=None, help="A seed for reproducible training.") # ----Logging---- parser.add_argument( "--logging_dir", type=str, default="logs", help=( "[TensorBoard](https://www.tensorflow.org/tensorboard) log directory. Will default to" " *output_dir/runs/**CURRENT_DATETIME_HOSTNAME***." ), ) parser.add_argument( "--report_to", type=str, default="tensorboard", help=( 'The integration to report the results and logs to. Supported platforms are `"tensorboard"`' ' (default), `"wandb"` and `"comet_ml"`. Use `"all"` to report to all integrations.' ), ) # ----Checkpointing---- parser.add_argument( "--checkpointing_steps", type=int, default=500, help=( "Save a checkpoint of the training state every X updates. These checkpoints are only suitable for resuming" " training using `--resume_from_checkpoint`." ), ) parser.add_argument( "--checkpoints_total_limit", type=int, default=None, help=("Max number of checkpoints to store."), ) parser.add_argument( "--resume_from_checkpoint", type=str, default=None, help=( "Whether training should be resumed from a previous checkpoint. Use a path saved by" ' `--checkpointing_steps`, or `"latest"` to automatically select the last available checkpoint.' ), ) # ----Image Processing---- parser.add_argument( "--train_shards_path_or_url", type=str, default=None, help=( "The name of the Dataset (from the HuggingFace hub) to train on (could be your own, possibly private," " dataset). It can also be a path pointing to a local copy of a dataset in your filesystem," " or to a folder containing files that 🤗 Datasets can understand." ), ) parser.add_argument( "--resolution", type=int, default=512, help=( "The resolution for input images, all the images in the train/validation dataset will be resized to this" " resolution" ), ) parser.add_argument( "--interpolation_type", type=str, default="bilinear", help=( "The interpolation function used when resizing images to the desired resolution. Choose between `bilinear`," " `bicubic`, `box`, `nearest`, `nearest_exact`, `hamming`, and `lanczos`." ), ) parser.add_argument( "--center_crop", default=False, action="store_true", help=( "Whether to center crop the input images to the resolution. If not set, the images will be randomly" " cropped. The images will be resized to the resolution first before cropping." ), ) parser.add_argument( "--random_flip", action="store_true", help="whether to randomly flip images horizontally", ) # ----Dataloader---- parser.add_argument( "--dataloader_num_workers", type=int, default=0, help=( "Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process." ), ) # ----Batch Size and Training Steps---- parser.add_argument( "--train_batch_size", type=int, default=16, help="Batch size (per device) for the training dataloader." ) parser.add_argument("--num_train_epochs", type=int, default=100) parser.add_argument( "--max_train_steps", type=int, default=None, help="Total number of training steps to perform. If provided, overrides num_train_epochs.", ) parser.add_argument( "--max_train_samples", type=int, default=None, help=( "For debugging purposes or quicker training, truncate the number of training examples to this value if set." ), ) # ----Learning Rate---- parser.add_argument( "--learning_rate", type=float, default=1e-4, help="Initial learning rate (after the potential warmup period) to use.", ) parser.add_argument( "--scale_lr", action="store_true", default=False, help="Scale the learning rate by the number of GPUs, gradient accumulation steps, and batch size.", ) parser.add_argument( "--lr_scheduler", type=str, default="constant", help=( 'The scheduler type to use. Choose between ["linear", "cosine", "cosine_with_restarts", "polynomial",' ' "constant", "constant_with_warmup"]' ), ) parser.add_argument( "--lr_warmup_steps", type=int, default=500, help="Number of steps for the warmup in the lr scheduler." ) parser.add_argument( "--gradient_accumulation_steps", type=int, default=1, help="Number of updates steps to accumulate before performing a backward/update pass.", ) # ----Optimizer (Adam)---- parser.add_argument( "--use_8bit_adam", action="store_true", help="Whether or not to use 8-bit Adam from bitsandbytes." ) parser.add_argument("--adam_beta1", type=float, default=0.9, help="The beta1 parameter for the Adam optimizer.") parser.add_argument("--adam_beta2", type=float, default=0.999, help="The beta2 parameter for the Adam optimizer.") parser.add_argument("--adam_weight_decay", type=float, default=1e-2, help="Weight decay to use.") parser.add_argument("--adam_epsilon", type=float, default=1e-08, help="Epsilon value for the Adam optimizer") parser.add_argument("--max_grad_norm", default=1.0, type=float, help="Max gradient norm.") # ----Diffusion Training Arguments---- parser.add_argument( "--proportion_empty_prompts", type=float, default=0, help="Proportion of image prompts to be replaced with empty strings. Defaults to 0 (no prompt replacement).", ) # ----Latent Consistency Distillation (LCD) Specific Arguments---- parser.add_argument( "--w_min", type=float, default=5.0, required=False, help=( "The minimum guidance scale value for guidance scale sampling. Note that we are using the Imagen CFG" " formulation rather than the LCM formulation, which means all guidance scales have 1 added to them as" " compared to the original paper." ), ) parser.add_argument( "--w_max", type=float, default=15.0, required=False, help=( "The maximum guidance scale value for guidance scale sampling. Note that we are using the Imagen CFG" " formulation rather than the LCM formulation, which means all guidance scales have 1 added to them as" " compared to the original paper." ), ) parser.add_argument( "--num_ddim_timesteps", type=int, default=50, help="The number of timesteps to use for DDIM sampling.", ) parser.add_argument( "--loss_type", type=str, default="l2", choices=["l2", "huber"], help="The type of loss to use for the LCD loss.", ) parser.add_argument( "--huber_c", type=float, default=0.001, help="The huber loss parameter. Only used if `--loss_type=huber`.", ) parser.add_argument( "--unet_time_cond_proj_dim", type=int, default=256, help=( "The dimension of the guidance scale embedding in the U-Net, which will be used if the teacher U-Net" " does not have `time_cond_proj_dim` set." ), ) parser.add_argument( "--vae_encode_batch_size", type=int, default=32, required=False, help=( "The batch size used when encoding (and decoding) images to latents (and vice versa) using the VAE." " Encoding or decoding the whole batch at once may run into OOM issues." ), ) parser.add_argument( "--timestep_scaling_factor", type=float, default=10.0, help=( "The multiplicative timestep scaling factor used when calculating the boundary scalings for LCM. The" " higher the scaling is, the lower the approximation error, but the default value of 10.0 should typically" " suffice." ), ) # ----Exponential Moving Average (EMA)---- parser.add_argument( "--ema_decay", type=float, default=0.95, required=False, help="The exponential moving average (EMA) rate or decay factor.", ) # ----Mixed Precision---- parser.add_argument( "--mixed_precision", type=str, default=None, choices=["no", "fp16", "bf16"], help=( "Whether to use mixed precision. Choose between fp16 and bf16 (bfloat16). Bf16 requires PyTorch >=" " 1.10.and an Nvidia Ampere GPU. Default to the value of accelerate config of the current system or the" " flag passed with the `accelerate.launch` command. Use this argument to override the accelerate config." ), ) parser.add_argument( "--allow_tf32", action="store_true", help=( "Whether or not to allow TF32 on Ampere GPUs. Can be used to speed up training. For more information, see" " https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices" ), ) parser.add_argument( "--cast_teacher_unet", action="store_true", help="Whether to cast the teacher U-Net to the precision specified by `--mixed_precision`.", ) # ----Training Optimizations---- parser.add_argument( "--enable_xformers_memory_efficient_attention", action="store_true", help="Whether or not to use xformers." ) parser.add_argument( "--gradient_checkpointing", action="store_true", help="Whether or not to use gradient checkpointing to save memory at the expense of slower backward pass.", ) # ----Distributed Training---- parser.add_argument("--local_rank", type=int, default=-1, help="For distributed training: local_rank") # ----------Validation Arguments---------- parser.add_argument( "--validation_steps", type=int, default=200, help="Run validation every X steps.", ) # ----------Huggingface Hub Arguments----------- parser.add_argument("--push_to_hub", action="store_true", help="Whether or not to push the model to the Hub.") parser.add_argument("--hub_token", type=str, default=None, help="The token to use to push to the Model Hub.") parser.add_argument( "--hub_model_id", type=str, default=None, help="The name of the repository to keep in sync with the local `output_dir`.", ) # ----------Accelerate Arguments---------- parser.add_argument( "--tracker_project_name", type=str, default="text2image-fine-tune", help=( "The `project_name` argument passed to Accelerator.init_trackers for" " more information see https://huggingface.co/docs/accelerate/v0.17.0/en/package_reference/accelerator#accelerate.Accelerator" ), ) args = parser.parse_args() env_local_rank = int(os.environ.get("LOCAL_RANK", -1)) if env_local_rank != -1 and env_local_rank != args.local_rank: args.local_rank = env_local_rank if args.proportion_empty_prompts < 0 or args.proportion_empty_prompts > 1: raise ValueError("`--proportion_empty_prompts` must be in the range [0, 1].") return args # Adapted from pipelines.StableDiffusionPipeline.encode_prompt def encode_prompt(prompt_batch, text_encoder, tokenizer, proportion_empty_prompts, is_train=True): captions = [] for caption in prompt_batch: if random.random() < proportion_empty_prompts: captions.append("") elif isinstance(caption, str): captions.append(caption) elif isinstance(caption, (list, np.ndarray)): # take a random caption if there are multiple captions.append(random.choice(caption) if is_train else caption[0]) with torch.no_grad(): text_inputs = tokenizer( captions, padding="max_length", max_length=tokenizer.model_max_length, truncation=True, return_tensors="pt", ) text_input_ids = text_inputs.input_ids prompt_embeds = text_encoder(text_input_ids.to(text_encoder.device))[0] return prompt_embeds def main(args): if args.report_to == "wandb" and args.hub_token is not None: raise ValueError( "You cannot use both --report_to=wandb and --hub_token due to a security risk of exposing your token." " Please use `huggingface-cli login` to authenticate with the Hub." ) logging_dir = Path(args.output_dir, args.logging_dir) accelerator_project_config = ProjectConfiguration(project_dir=args.output_dir, logging_dir=logging_dir) from accelerate import DistributedDataParallelKwargs ddp_kwargs = DistributedDataParallelKwargs(find_unused_parameters=True) accelerator = Accelerator( gradient_accumulation_steps=args.gradient_accumulation_steps, mixed_precision=args.mixed_precision, log_with=args.report_to, project_config=accelerator_project_config, kwargs_handlers=[ddp_kwargs], split_batches=True, ) # It's important to set `split_batches=True` when using webdataset to get the right number # of steps for lr scheduling. If set to False, the number of steps will be devide by the number of # processes assuming batches are multiplied by the number of processes # Make one log on every process with the configuration for debugging. logging.basicConfig( format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%m/%d/%Y %H:%M:%S", level=logging.INFO, ) logger.info(accelerator.state, main_process_only=False) if accelerator.is_local_main_process: transformers.utils.logging.set_verbosity_warning() diffusers.utils.logging.set_verbosity_info() else: transformers.utils.logging.set_verbosity_error() diffusers.utils.logging.set_verbosity_error() # If passed along, set the training seed now. if args.seed is not None: set_seed(args.seed) # Handle the repository creation if accelerator.is_main_process: if args.output_dir is not None: os.makedirs(args.output_dir, exist_ok=True) if args.push_to_hub: repo_id = create_repo( repo_id=args.hub_model_id or Path(args.output_dir).name, exist_ok=True, token=args.hub_token, private=True, ).repo_id # 1. Create the noise scheduler and the desired noise schedule. noise_scheduler = DDPMScheduler.from_pretrained( args.pretrained_teacher_model, subfolder="scheduler", revision=args.teacher_revision ) # DDPMScheduler calculates the alpha and sigma noise schedules (based on the alpha bars) for us alpha_schedule = torch.sqrt(noise_scheduler.alphas_cumprod) sigma_schedule = torch.sqrt(1 - noise_scheduler.alphas_cumprod) # Initialize the DDIM ODE solver for distillation. solver = DDIMSolver( noise_scheduler.alphas_cumprod.numpy(), timesteps=noise_scheduler.config.num_train_timesteps, ddim_timesteps=args.num_ddim_timesteps, ) # 2. Load tokenizers from SD 1.X/2.X checkpoint. tokenizer = AutoTokenizer.from_pretrained( args.pretrained_teacher_model, subfolder="tokenizer", revision=args.teacher_revision, use_fast=False ) # 3. Load text encoders from SD 1.X/2.X checkpoint. # import correct text encoder classes text_encoder = CLIPTextModel.from_pretrained( args.pretrained_teacher_model, subfolder="text_encoder", revision=args.teacher_revision ) # 4. Load VAE from SD 1.X/2.X checkpoint vae = AutoencoderKL.from_pretrained( args.pretrained_teacher_model, subfolder="vae", revision=args.teacher_revision, ) # 5. Load teacher U-Net from SD 1.X/2.X checkpoint teacher_unet = UNet2DConditionModel.from_pretrained( args.pretrained_teacher_model, subfolder="unet", revision=args.teacher_revision ) # 6. Freeze teacher vae, text_encoder, and teacher_unet vae.requires_grad_(False) text_encoder.requires_grad_(False) teacher_unet.requires_grad_(False) # 7. Create online student U-Net. This will be updated by the optimizer (e.g. via backpropagation.) # Add `time_cond_proj_dim` to the student U-Net if `teacher_unet.config.time_cond_proj_dim` is None time_cond_proj_dim = ( teacher_unet.config.time_cond_proj_dim if teacher_unet.config.time_cond_proj_dim is not None else args.unet_time_cond_proj_dim ) unet = UNet2DConditionModel.from_config(teacher_unet.config, time_cond_proj_dim=time_cond_proj_dim) # load teacher_unet weights into unet unet.load_state_dict(teacher_unet.state_dict(), strict=False) unet.train() # 8. Create target student U-Net. This will be updated via EMA updates (polyak averaging). # Initialize from (online) unet target_unet = UNet2DConditionModel.from_config(teacher_unet.config, time_cond_proj_dim=time_cond_proj_dim) # load teacher_unet weights into unet target_unet.load_state_dict(teacher_unet.state_dict(), strict=False) target_unet.train() target_unet.requires_grad_(False) # Check that all trainable models are in full precision low_precision_error_string = ( " Please make sure to always have all model weights in full float32 precision when starting training - even if" " doing mixed precision training, copy of the weights should still be float32." ) if accelerator.unwrap_model(unet).dtype != torch.float32: raise ValueError( f"Controlnet loaded as datatype {accelerator.unwrap_model(unet).dtype}. {low_precision_error_string}" ) # 9. Handle mixed precision and device placement # For mixed precision training we cast all non-trainable weigths to half-precision # as these weights are only used for inference, keeping weights in full precision is not required. weight_dtype = torch.float32 if accelerator.mixed_precision == "fp16": weight_dtype = torch.float16 elif accelerator.mixed_precision == "bf16": weight_dtype = torch.bfloat16 # Move unet, vae and text_encoder to device and cast to weight_dtype # The VAE is in float32 to avoid NaN losses. vae.to(accelerator.device) if args.pretrained_vae_model_name_or_path is not None: vae.to(dtype=torch.float32) text_encoder.to(accelerator.device, dtype=torch.float32) # Move teacher_unet to device, optionally cast to weight_dtype target_unet.to(accelerator.device) teacher_unet.to(accelerator.device) target_unet.to(torch.float32) teacher_unet.to(torch.float32) # Also move the alpha and sigma noise schedules to accelerator.device. alpha_schedule = alpha_schedule.to(accelerator.device) sigma_schedule = sigma_schedule.to(accelerator.device) solver = solver.to(accelerator.device) # 10. Handle saving and loading of checkpoints # `accelerate` 0.16.0 will have better support for customized saving if version.parse(accelerate.__version__) >= version.parse("0.16.0"): # create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format def save_model_hook(models, weights, output_dir): if accelerator.is_main_process: target_unet.save_pretrained(os.path.join(output_dir, "unet_target")) for i, model in enumerate(models): model.save_pretrained(os.path.join(output_dir, "unet")) # make sure to pop weight so that corresponding model is not saved again weights.pop() def load_model_hook(models, input_dir): load_model = UNet2DConditionModel.from_pretrained(os.path.join(input_dir, "unet_target")) target_unet.load_state_dict(load_model.state_dict()) target_unet.to(accelerator.device) del load_model for i in range(len(models)): # pop models so that they are not loaded again model = models.pop() # load diffusers style into model load_model = UNet2DConditionModel.from_pretrained(input_dir, subfolder="unet") model.register_to_config(**load_model.config) model.load_state_dict(load_model.state_dict()) del load_model accelerator.register_save_state_pre_hook(save_model_hook) accelerator.register_load_state_pre_hook(load_model_hook) # 11. Enable optimizations if args.enable_xformers_memory_efficient_attention: if is_xformers_available(): import xformers xformers_version = version.parse(xformers.__version__) if xformers_version == version.parse("0.0.16"): logger.warning( "xFormers 0.0.16 cannot be used for training in some GPUs. If you observe problems during " "training, please update xFormers to at least 0.0.17. " "See https://huggingface.co/docs/diffusers/main/en/optimization/xformers for more details." ) unet.enable_xformers_memory_efficient_attention() teacher_unet.enable_xformers_memory_efficient_attention() target_unet.enable_xformers_memory_efficient_attention() else: raise ValueError("xformers is not available. Make sure it is installed correctly") # Enable TF32 for faster training on Ampere GPUs, # cf https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices if args.allow_tf32: torch.backends.cuda.matmul.allow_tf32 = True if args.gradient_checkpointing: unet.enable_gradient_checkpointing() # Use 8-bit Adam for lower memory usage or to fine-tune the model in 16GB GPUs if args.use_8bit_adam: try: import bitsandbytes as bnb except ImportError: raise ImportError( "To use 8-bit Adam, please install the bitsandbytes library: `pip install bitsandbytes`." ) from None optimizer_class = bnb.optim.AdamW8bit else: optimizer_class = torch.optim.AdamW optimizer_dict = dict() scheduler_dict = dict() param_number = len(list(unet.parameters())) print(param_number) lisa_p = 0.25 # 128 / param_number # 32 / param_number lisa(model=unet, p=lisa_p) for p in unet.parameters(): if p.requires_grad: optimizer_dict[p] = optimizer_class( [{"params": p}], lr=args.learning_rate, betas=(args.adam_beta1, args.adam_beta2), weight_decay=args.adam_weight_decay, eps=args.adam_epsilon, ) optimizer_dict[p] = accelerator.prepare_optimizer(optimizer_dict[p]) dataset = SDText2ImageDataset( train_shards_path_or_url=args.train_shards_path_or_url, num_train_examples=args.max_train_samples, per_gpu_batch_size=args.train_batch_size, global_batch_size=args.train_batch_size * accelerator.num_processes, num_workers=args.dataloader_num_workers, resolution=args.resolution, interpolation_type=args.interpolation_type, shuffle_buffer_size=1000, pin_memory=True, persistent_workers=True, ) train_dataloader = dataset.train_dataloader def compute_embeddings(prompt_batch, proportion_empty_prompts, text_encoder, tokenizer, is_train=True): prompt_embeds = encode_prompt(prompt_batch, text_encoder, tokenizer, proportion_empty_prompts, is_train) return {"prompt_embeds": prompt_embeds} compute_embeddings_fn = functools.partial( compute_embeddings, proportion_empty_prompts=0, text_encoder=text_encoder, tokenizer=tokenizer, ) # 14. LR Scheduler creation # Scheduler and math around the number of training steps. overrode_max_train_steps = False num_update_steps_per_epoch = math.ceil(train_dataloader.num_batches / args.gradient_accumulation_steps) if args.max_train_steps is None: args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch overrode_max_train_steps = True for p in unet.parameters(): if p.requires_grad: scheduler_dict[p] = get_scheduler( args.lr_scheduler, optimizer=optimizer_dict[p], num_warmup_steps=args.lr_warmup_steps * accelerator.num_processes, num_training_steps=args.max_train_steps * accelerator.num_processes, ) scheduler_dict[p] = accelerator.prepare_scheduler(scheduler_dict[p]) # define a hook function to update the parameter p during the backward pass def optimizer_hook(p): if p.grad is None: del scheduler_dict[p] del optimizer_dict[p] return else: if p not in optimizer_dict: optimizer_dict[p] = optimizer_class( [{"params": p}], lr=args.learning_rate, betas=(args.adam_beta1, args.adam_beta2), weight_decay=args.adam_weight_decay, eps=args.adam_epsilon, ) optimizer_dict[p] = accelerator.prepare_optimizer(optimizer_dict[p]) if p not in scheduler_dict: scheduler_dict[p] = get_scheduler( args.lr_scheduler, optimizer=optimizer_dict[p], num_warmup_steps=args.lr_warmup_steps * accelerator.num_processes, num_training_steps=args.max_train_steps * accelerator.num_processes, ) scheduler_dict[p] = accelerator.prepare_scheduler(scheduler_dict[p]) if accelerator.sync_gradients: torch.nn.utils.clip_grad_norm_(p, args.max_grad_norm) optimizer_dict[p].step() optimizer_dict[p].zero_grad(set_to_none=True) scheduler_dict[p].step() # Register the hook onto every parameter for p in unet.parameters(): if p.requires_grad: p.register_post_accumulate_grad_hook(optimizer_hook) unet = accelerator.prepare_model(unet) # 13. Dataset creation and data processing # Here, we compute not just the text embeddings but also the additional embeddings # needed for the SD XL UNet to operate. # We need to recalculate our total training steps as the size of the training dataloader may have changed. num_update_steps_per_epoch = math.ceil(train_dataloader.num_batches / args.gradient_accumulation_steps) if overrode_max_train_steps: args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch # Afterwards we recalculate our number of training epochs args.num_train_epochs = math.ceil(args.max_train_steps / num_update_steps_per_epoch) # We need to initialize the trackers we use, and also store our configuration. # The trackers initializes automatically on the main process. if accelerator.is_main_process: tracker_config = dict(vars(args)) accelerator.init_trackers(args.tracker_project_name, config=tracker_config) uncond_input_ids = tokenizer( [""] * args.train_batch_size, return_tensors="pt", padding="max_length", max_length=77 ).input_ids.to(accelerator.device) uncond_prompt_embeds = text_encoder(uncond_input_ids)[0] # 16. Train! total_batch_size = args.train_batch_size * accelerator.num_processes * args.gradient_accumulation_steps logger.info("***** Running training *****") logger.info(f" Num batches each epoch = {train_dataloader.num_batches}") logger.info(f" Num Epochs = {args.num_train_epochs}") logger.info(f" Instantaneous batch size per device = {args.train_batch_size}") logger.info(f" Total train batch size (w. parallel, distributed & accumulation) = {total_batch_size}") logger.info(f" Gradient Accumulation steps = {args.gradient_accumulation_steps}") logger.info(f" Total optimization steps = {args.max_train_steps}") global_step = 0 first_epoch = 0 # Potentially load in the weights and states from a previous save if args.resume_from_checkpoint: if args.resume_from_checkpoint != "latest": path = os.path.basename(args.resume_from_checkpoint) else: # Get the most recent checkpoint dirs = os.listdir(args.output_dir) dirs = [d for d in dirs if d.startswith("checkpoint")] dirs = sorted(dirs, key=lambda x: int(x.split("-")[1])) path = dirs[-1] if len(dirs) > 0 else None if path is None: accelerator.print( f"Checkpoint '{args.resume_from_checkpoint}' does not exist. Starting a new training run." ) args.resume_from_checkpoint = None initial_global_step = 0 else: accelerator.print(f"Resuming from checkpoint {path}") accelerator.load_state(os.path.join(args.output_dir, path)) global_step = int(path.split("-")[1]) initial_global_step = global_step first_epoch = global_step // num_update_steps_per_epoch else: initial_global_step = 0 progress_bar = tqdm( range(0, args.max_train_steps), initial=initial_global_step, desc="Steps", # Only show the progress bar once on each machine. disable=not accelerator.is_local_main_process, ) total_count = 0 for epoch in range(first_epoch, args.num_train_epochs): for step, batch in enumerate(train_dataloader): if total_count % 5 == 0 and total_count != 0: param_number = len(list(unet.parameters())) lisa(model=unet, p=lisa_p) total_count += 1 with accelerator.accumulate(unet): # 1. Load and process the image and text conditioning image, text = batch image = image.to(accelerator.device, non_blocking=True) encoded_text = compute_embeddings_fn(text) pixel_values = image.to(dtype=weight_dtype) if vae.dtype != weight_dtype: vae.to(dtype=weight_dtype) # encode pixel values with batch size of at most args.vae_encode_batch_size latents = [] for i in range(0, pixel_values.shape[0], args.vae_encode_batch_size): latents.append(vae.encode(pixel_values[i : i + args.vae_encode_batch_size]).latent_dist.sample()) latents = torch.cat(latents, dim=0) latents = latents * vae.config.scaling_factor latents = latents.to(weight_dtype) bsz = latents.shape[0] # 2. Sample a random timestep for each image t_n from the ODE solver timesteps without bias. # For the DDIM solver, the timestep schedule is [T - 1, T - k - 1, T - 2 * k - 1, ...] topk = noise_scheduler.config.num_train_timesteps // args.num_ddim_timesteps index = torch.randint(0, args.num_ddim_timesteps, (bsz,), device=latents.device).long() start_timesteps = solver.ddim_timesteps[index] timesteps = start_timesteps - topk timesteps = torch.where(timesteps < 0, torch.zeros_like(timesteps), timesteps) # 3. Get boundary scalings for start_timesteps and (end) timesteps. c_skip_start, c_out_start = scalings_for_boundary_conditions( start_timesteps, timestep_scaling=args.timestep_scaling_factor ) c_skip_start, c_out_start = [append_dims(x, latents.ndim) for x in [c_skip_start, c_out_start]] c_skip, c_out = scalings_for_boundary_conditions( timesteps, timestep_scaling=args.timestep_scaling_factor ) c_skip, c_out = [append_dims(x, latents.ndim) for x in [c_skip, c_out]] # 4. Sample noise from the prior and add it to the latents according to the noise magnitude at each # timestep (this is the forward diffusion process) [z_{t_{n + k}} in Algorithm 1] noise = torch.randn_like(latents) noisy_model_input = noise_scheduler.add_noise(latents, noise, start_timesteps) # 5. Sample a random guidance scale w from U[w_min, w_max] and embed it w = (args.w_max - args.w_min) * torch.rand((bsz,)) + args.w_min w_embedding = guidance_scale_embedding(w, embedding_dim=time_cond_proj_dim) w = w.reshape(bsz, 1, 1, 1) # Move to U-Net device and dtype w = w.to(device=latents.device, dtype=latents.dtype) w_embedding = w_embedding.to(device=latents.device, dtype=latents.dtype) # 6. Prepare prompt embeds and unet_added_conditions prompt_embeds = encoded_text.pop("prompt_embeds") # 7. Get online LCM prediction on z_{t_{n + k}} (noisy_model_input), w, c, t_{n + k} (start_timesteps) noise_pred = unet( noisy_model_input, start_timesteps, timestep_cond=w_embedding, encoder_hidden_states=prompt_embeds.float(), added_cond_kwargs=encoded_text, ).sample pred_x_0 = get_predicted_original_sample( noise_pred, start_timesteps, noisy_model_input, noise_scheduler.config.prediction_type, alpha_schedule, sigma_schedule, ) model_pred = c_skip_start * noisy_model_input + c_out_start * pred_x_0 # 8. Compute the conditional and unconditional teacher model predictions to get CFG estimates of the # predicted noise eps_0 and predicted original sample x_0, then run the ODE solver using these # estimates to predict the data point in the augmented PF-ODE trajectory corresponding to the next ODE # solver timestep. with torch.no_grad(): with torch.autocast("cuda"): # 1. Get teacher model prediction on noisy_model_input z_{t_{n + k}} and conditional embedding c cond_teacher_output = teacher_unet( noisy_model_input.to(weight_dtype), start_timesteps, encoder_hidden_states=prompt_embeds.to(weight_dtype), ).sample cond_pred_x0 = get_predicted_original_sample( cond_teacher_output, start_timesteps, noisy_model_input, noise_scheduler.config.prediction_type, alpha_schedule, sigma_schedule, ) cond_pred_noise = get_predicted_noise( cond_teacher_output, start_timesteps, noisy_model_input, noise_scheduler.config.prediction_type, alpha_schedule, sigma_schedule, ) # 2. Get teacher model prediction on noisy_model_input z_{t_{n + k}} and # unconditional embedding 0 uncond_teacher_output = teacher_unet( noisy_model_input.to(weight_dtype), start_timesteps, encoder_hidden_states=uncond_prompt_embeds.to(weight_dtype), ).sample uncond_pred_x0 = get_predicted_original_sample( uncond_teacher_output, start_timesteps, noisy_model_input, noise_scheduler.config.prediction_type, alpha_schedule, sigma_schedule, ) uncond_pred_noise = get_predicted_noise( uncond_teacher_output, start_timesteps, noisy_model_input, noise_scheduler.config.prediction_type, alpha_schedule, sigma_schedule, ) # 3. Calculate the CFG estimate of x_0 (pred_x0) and eps_0 (pred_noise) # Note that this uses the LCM paper's CFG formulation rather than the Imagen CFG formulation pred_x0 = cond_pred_x0 + w * (cond_pred_x0 - uncond_pred_x0) pred_noise = cond_pred_noise + w * (cond_pred_noise - uncond_pred_noise) # 4. Run one step of the ODE solver to estimate the next point x_prev on the # augmented PF-ODE trajectory (solving backward in time) # Note that the DDIM step depends on both the predicted x_0 and source noise eps_0. x_prev = solver.ddim_step(pred_x0, pred_noise, index) # 9. Get target LCM prediction on x_prev, w, c, t_n (timesteps) with torch.no_grad(): with torch.autocast("cuda", dtype=weight_dtype): target_noise_pred = target_unet( x_prev.float(), timesteps, timestep_cond=w_embedding, encoder_hidden_states=prompt_embeds.float(), ).sample pred_x_0 = get_predicted_original_sample( target_noise_pred, timesteps, x_prev, noise_scheduler.config.prediction_type, alpha_schedule, sigma_schedule, ) target = c_skip * x_prev + c_out * pred_x_0 # 10. Calculate loss if args.loss_type == "l2": loss = F.mse_loss(model_pred.float(), target.float(), reduction="mean") elif args.loss_type == "huber": loss = torch.mean( torch.sqrt((model_pred.float() - target.float()) ** 2 + args.huber_c**2) - args.huber_c ) # 11. Backpropagate on the online student model (`unet`) accelerator.backward(loss) # Checks if the accelerator has performed an optimization step behind the scenes if accelerator.sync_gradients: # 12. Make EMA update to target student model parameters (`target_unet`) update_ema(target_unet.parameters(), unet.parameters(), args.ema_decay) progress_bar.update(1) global_step += 1 if accelerator.is_main_process: if global_step % args.checkpointing_steps == 0: # _before_ saving state, check if this save would set us over the `checkpoints_total_limit` if args.checkpoints_total_limit is not None: checkpoints = os.listdir(args.output_dir) checkpoints = [d for d in checkpoints if d.startswith("checkpoint")] checkpoints = sorted(checkpoints, key=lambda x: int(x.split("-")[1])) # before we save the new checkpoint, we need to have at _most_ # `checkpoints_total_limit - 1` checkpoints if len(checkpoints) >= args.checkpoints_total_limit: num_to_remove = len(checkpoints) - args.checkpoints_total_limit + 1 removing_checkpoints = checkpoints[0:num_to_remove] logger.info( f"{len(checkpoints)} checkpoints already exist, removing " f"{len(removing_checkpoints)} checkpoints" ) logger.info(f"removing checkpoints: {', '.join(removing_checkpoints)}") for removing_checkpoint in removing_checkpoints: removing_checkpoint = os.path.join(args.output_dir, removing_checkpoint) shutil.rmtree(removing_checkpoint) save_path = os.path.join(args.output_dir, f"checkpoint-{global_step}") accelerator.save_state(save_path) logger.info(f"Saved state to {save_path}") if global_step % 50 == 0: log_validation(vae, target_unet, args, accelerator, weight_dtype, global_step, "target_2") log_validation(vae, unet, args, accelerator, weight_dtype, global_step, "online_2") logs = {"loss": loss.detach().item(), "lr": list(optimizer_dict.values())[0].param_groups[0]["lr"]} progress_bar.set_postfix(**logs) accelerator.log(logs, step=global_step) if global_step >= args.max_train_steps: break # Create the pipeline using using the trained modules and save it. accelerator.wait_for_everyone() if accelerator.is_main_process: unet = accelerator.unwrap_model(unet) unet.save_pretrained(os.path.join(args.output_dir, "unet")) target_unet = accelerator.unwrap_model(target_unet) target_unet.save_pretrained(os.path.join(args.output_dir, "unet_target")) if args.push_to_hub: upload_folder( repo_id=repo_id, folder_path=args.output_dir, commit_message="End of training", ignore_patterns=["step_*", "epoch_*"], ) accelerator.end_training() if __name__ == "__main__": args = parse_args() main(args) ================================================ FILE: experimental/LISA-diffusion/latent_consistency_model/train_lcm_distill_sd_wds_lora.py ================================================ #!/usr/bin/env python # Copyright 2024 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and import argparse import functools import gc import itertools import json import logging import math import os import random import shutil from pathlib import Path from typing import Union import accelerate import diffusers import numpy as np import torch import torch.nn.functional as F import torch.utils.checkpoint import torchvision.transforms.functional as TF import transformers import webdataset as wds from accelerate import Accelerator from accelerate.logging import get_logger from accelerate.utils import ProjectConfiguration, set_seed from braceexpand import braceexpand from diffusers import ( AutoencoderKL, DDPMScheduler, LCMScheduler, StableDiffusionPipeline, UNet2DConditionModel, ) from diffusers.optimization import get_scheduler from diffusers.training_utils import resolve_interpolation_mode from diffusers.utils import check_min_version, is_wandb_available from diffusers.utils.import_utils import is_xformers_available from huggingface_hub import create_repo, upload_folder from packaging import version from peft import LoraConfig, get_peft_model, get_peft_model_state_dict from torch.utils.data import default_collate from torchvision import transforms from tqdm.auto import tqdm from transformers import AutoTokenizer, CLIPTextModel, PretrainedConfig from webdataset.tariterators import ( base_plus_ext, tar_file_expander, url_opener, valid_sample, ) MAX_SEQ_LENGTH = 77 if is_wandb_available(): import wandb # Will error if the minimal version of diffusers is not installed. Remove at your own risks. check_min_version("0.28.0.dev0") logger = get_logger(__name__) def get_module_kohya_state_dict(module, prefix: str, dtype: torch.dtype, adapter_name: str = "default"): kohya_ss_state_dict = {} for peft_key, weight in get_peft_model_state_dict(module, adapter_name=adapter_name).items(): kohya_key = peft_key.replace("base_model.model", prefix) kohya_key = kohya_key.replace("lora_A", "lora_down") kohya_key = kohya_key.replace("lora_B", "lora_up") kohya_key = kohya_key.replace(".", "_", kohya_key.count(".") - 2) kohya_ss_state_dict[kohya_key] = weight.to(dtype) # Set alpha parameter if "lora_down" in kohya_key: alpha_key = f"{kohya_key.split('.')[0]}.alpha" kohya_ss_state_dict[alpha_key] = torch.tensor(module.peft_config[adapter_name].lora_alpha).to(dtype) return kohya_ss_state_dict def filter_keys(key_set): def _f(dictionary): return {k: v for k, v in dictionary.items() if k in key_set} return _f def group_by_keys_nothrow(data, keys=base_plus_ext, lcase=True, suffixes=None, handler=None): """Return function over iterator that groups key, value pairs into samples. :param keys: function that splits the key into key and extension (base_plus_ext) :param lcase: convert suffixes to lower case (Default value = True) """ current_sample = None for filesample in data: assert isinstance(filesample, dict) fname, value = filesample["fname"], filesample["data"] prefix, suffix = keys(fname) if prefix is None: continue if lcase: suffix = suffix.lower() # FIXME webdataset version throws if suffix in current_sample, but we have a potential for # this happening in the current LAION400m dataset if a tar ends with same prefix as the next # begins, rare, but can happen since prefix aren't unique across tar files in that dataset if current_sample is None or prefix != current_sample["__key__"] or suffix in current_sample: if valid_sample(current_sample): yield current_sample current_sample = {"__key__": prefix, "__url__": filesample["__url__"]} if suffixes is None or suffix in suffixes: current_sample[suffix] = value if valid_sample(current_sample): yield current_sample def tarfile_to_samples_nothrow(src, handler=wds.warn_and_continue): # NOTE this is a re-impl of the webdataset impl with group_by_keys that doesn't throw streams = url_opener(src, handler=handler) files = tar_file_expander(streams, handler=handler) samples = group_by_keys_nothrow(files, handler=handler) return samples class WebdatasetFilter: def __init__(self, min_size=1024, max_pwatermark=0.5): self.min_size = min_size self.max_pwatermark = max_pwatermark def __call__(self, x): try: if "json" in x: x_json = json.loads(x["json"]) filter_size = (x_json.get("original_width", 0.0) or 0.0) >= self.min_size and x_json.get( "original_height", 0 ) >= self.min_size filter_watermark = (x_json.get("pwatermark", 1.0) or 1.0) <= self.max_pwatermark return filter_size and filter_watermark else: return False except Exception: return False class SDText2ImageDataset: def __init__( self, train_shards_path_or_url: Union[str, list[str]], num_train_examples: int, per_gpu_batch_size: int, global_batch_size: int, num_workers: int, resolution: int = 512, interpolation_type: str = "bilinear", shuffle_buffer_size: int = 1000, pin_memory: bool = False, persistent_workers: bool = False, ): if not isinstance(train_shards_path_or_url, str): train_shards_path_or_url = [list(braceexpand(urls)) for urls in train_shards_path_or_url] # flatten list using itertools train_shards_path_or_url = list(itertools.chain.from_iterable(train_shards_path_or_url)) interpolation_mode = resolve_interpolation_mode(interpolation_type) def transform(example): # resize image image = example["image"] image = TF.resize(image, resolution, interpolation=interpolation_mode) # get crop coordinates and crop image c_top, c_left, _, _ = transforms.RandomCrop.get_params(image, output_size=(resolution, resolution)) image = TF.crop(image, c_top, c_left, resolution, resolution) image = TF.to_tensor(image) image = TF.normalize(image, [0.5], [0.5]) example["image"] = image return example processing_pipeline = [ wds.decode("pil", handler=wds.ignore_and_continue), wds.rename(image="jpg;png;jpeg;webp", text="text;txt;caption", handler=wds.warn_and_continue), wds.map(filter_keys({"image", "text"})), wds.map(transform), wds.to_tuple("image", "text"), ] # Create train dataset and loader pipeline = [ wds.ResampledShards(train_shards_path_or_url), tarfile_to_samples_nothrow, wds.shuffle(shuffle_buffer_size), *processing_pipeline, wds.batched(per_gpu_batch_size, partial=False, collation_fn=default_collate), ] num_worker_batches = math.ceil(num_train_examples / (global_batch_size * num_workers)) # per dataloader worker num_batches = num_worker_batches * num_workers num_samples = num_batches * global_batch_size # each worker is iterating over this self._train_dataset = wds.DataPipeline(*pipeline).with_epoch(num_worker_batches) self._train_dataloader = wds.WebLoader( self._train_dataset, batch_size=None, shuffle=False, num_workers=num_workers, pin_memory=pin_memory, persistent_workers=persistent_workers, ) # add meta-data to dataloader instance for convenience self._train_dataloader.num_batches = num_batches self._train_dataloader.num_samples = num_samples @property def train_dataset(self): return self._train_dataset @property def train_dataloader(self): return self._train_dataloader def log_validation(vae, unet, args, accelerator, weight_dtype, step): logger.info("Running validation... ") unet = accelerator.unwrap_model(unet) pipeline = StableDiffusionPipeline.from_pretrained( args.pretrained_teacher_model, vae=vae, scheduler=LCMScheduler.from_pretrained(args.pretrained_teacher_model, subfolder="scheduler"), revision=args.revision, torch_dtype=weight_dtype, safety_checker=None, ) pipeline.set_progress_bar_config(disable=True) lora_state_dict = get_module_kohya_state_dict(unet, "lora_unet", weight_dtype) pipeline.load_lora_weights(lora_state_dict) pipeline.fuse_lora() pipeline = pipeline.to(accelerator.device, dtype=weight_dtype) if args.enable_xformers_memory_efficient_attention: pipeline.enable_xformers_memory_efficient_attention() if args.seed is None: generator = None else: generator = torch.Generator(device=accelerator.device).manual_seed(args.seed) validation_prompts = [ "portrait photo of a girl, photograph, highly detailed face, depth of field, moody light, golden hour, style by Dan Winters, Russell James, Steve McCurry, centered, extremely detailed, Nikon D850, award winning photography", # noqa: E501 "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k", "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", "A photo of beautiful mountain with realistic sunset and blue lake, highly detailed, masterpiece", ] image_logs = [] for _, prompt in enumerate(validation_prompts): images = [] with torch.autocast("cuda", dtype=weight_dtype): images = pipeline( prompt=prompt, num_inference_steps=4, num_images_per_prompt=4, generator=generator, guidance_scale=1.0, ).images image_logs.append({"validation_prompt": prompt, "images": images}) for tracker in accelerator.trackers: if tracker.name == "tensorboard": for log in image_logs: images = log["images"] validation_prompt = log["validation_prompt"] formatted_images = [] for image in images: formatted_images.append(np.asarray(image)) formatted_images = np.stack(formatted_images) tracker.writer.add_images(validation_prompt, formatted_images, step, dataformats="NHWC") elif tracker.name == "wandb": formatted_images = [] for log in image_logs: images = log["images"] validation_prompt = log["validation_prompt"] for image in images: image = wandb.Image(image, caption=validation_prompt) formatted_images.append(image) tracker.log({"validation": formatted_images}) else: logger.warning(f"image logging not implemented for {tracker.name}") del pipeline gc.collect() torch.cuda.empty_cache() return image_logs # From LatentConsistencyModel.get_guidance_scale_embedding def guidance_scale_embedding(w, embedding_dim=512, dtype=torch.float32): """ See https://github.com/google-research/vdm/blob/dc27b98a554f65cdc654b800da5aa1846545d41b/model_vdm.py#L298 Args: timesteps (`torch.Tensor`): generate embedding vectors at these timesteps embedding_dim (`int`, *optional*, defaults to 512): dimension of the embeddings to generate dtype: data type of the generated embeddings Returns: `torch.FloatTensor`: Embedding vectors with shape `(len(timesteps), embedding_dim)` """ assert len(w.shape) == 1 w = w * 1000.0 half_dim = embedding_dim // 2 emb = torch.log(torch.tensor(10000.0)) / (half_dim - 1) emb = torch.exp(torch.arange(half_dim, dtype=dtype) * -emb) emb = w.to(dtype)[:, None] * emb[None, :] emb = torch.cat([torch.sin(emb), torch.cos(emb)], dim=1) if embedding_dim % 2 == 1: # zero pad emb = torch.nn.functional.pad(emb, (0, 1)) assert emb.shape == (w.shape[0], embedding_dim) return emb def append_dims(x, target_dims): """Appends dimensions to the end of a tensor until it has target_dims dimensions.""" dims_to_append = target_dims - x.ndim if dims_to_append < 0: raise ValueError(f"input has {x.ndim} dims but target_dims is {target_dims}, which is less") return x[(...,) + (None,) * dims_to_append] # From LCMScheduler.get_scalings_for_boundary_condition_discrete def scalings_for_boundary_conditions(timestep, sigma_data=0.5, timestep_scaling=10.0): scaled_timestep = timestep_scaling * timestep c_skip = sigma_data**2 / (scaled_timestep**2 + sigma_data**2) c_out = scaled_timestep / (scaled_timestep**2 + sigma_data**2) ** 0.5 return c_skip, c_out # Compare LCMScheduler.step, Step 4 def get_predicted_original_sample(model_output, timesteps, sample, prediction_type, alphas, sigmas): alphas = extract_into_tensor(alphas, timesteps, sample.shape) sigmas = extract_into_tensor(sigmas, timesteps, sample.shape) if prediction_type == "epsilon": pred_x_0 = (sample - sigmas * model_output) / alphas elif prediction_type == "sample": pred_x_0 = model_output elif prediction_type == "v_prediction": pred_x_0 = alphas * sample - sigmas * model_output else: raise ValueError( f"Prediction type {prediction_type} is not supported; currently, `epsilon`, `sample`, and `v_prediction`" f" are supported." ) return pred_x_0 # Based on step 4 in DDIMScheduler.step def get_predicted_noise(model_output, timesteps, sample, prediction_type, alphas, sigmas): alphas = extract_into_tensor(alphas, timesteps, sample.shape) sigmas = extract_into_tensor(sigmas, timesteps, sample.shape) if prediction_type == "epsilon": pred_epsilon = model_output elif prediction_type == "sample": pred_epsilon = (sample - alphas * model_output) / sigmas elif prediction_type == "v_prediction": pred_epsilon = alphas * model_output + sigmas * sample else: raise ValueError( f"Prediction type {prediction_type} is not supported; currently, `epsilon`, `sample`, and `v_prediction`" f" are supported." ) return pred_epsilon def extract_into_tensor(a, t, x_shape): b, *_ = t.shape out = a.gather(-1, t) return out.reshape(b, *((1,) * (len(x_shape) - 1))) class DDIMSolver: def __init__(self, alpha_cumprods, timesteps=1000, ddim_timesteps=50): # DDIM sampling parameters step_ratio = timesteps // ddim_timesteps self.ddim_timesteps = (np.arange(1, ddim_timesteps + 1) * step_ratio).round().astype(np.int64) - 1 self.ddim_alpha_cumprods = alpha_cumprods[self.ddim_timesteps] self.ddim_alpha_cumprods_prev = np.asarray( [alpha_cumprods[0]] + alpha_cumprods[self.ddim_timesteps[:-1]].tolist() ) # convert to torch tensors self.ddim_timesteps = torch.from_numpy(self.ddim_timesteps).long() self.ddim_alpha_cumprods = torch.from_numpy(self.ddim_alpha_cumprods) self.ddim_alpha_cumprods_prev = torch.from_numpy(self.ddim_alpha_cumprods_prev) def to(self, device): self.ddim_timesteps = self.ddim_timesteps.to(device) self.ddim_alpha_cumprods = self.ddim_alpha_cumprods.to(device) self.ddim_alpha_cumprods_prev = self.ddim_alpha_cumprods_prev.to(device) return self def ddim_step(self, pred_x0, pred_noise, timestep_index): alpha_cumprod_prev = extract_into_tensor(self.ddim_alpha_cumprods_prev, timestep_index, pred_x0.shape) dir_xt = (1.0 - alpha_cumprod_prev).sqrt() * pred_noise x_prev = alpha_cumprod_prev.sqrt() * pred_x0 + dir_xt return x_prev @torch.no_grad() def update_ema(target_params, source_params, rate=0.99): """ Update target parameters to be closer to those of source parameters using an exponential moving average. :param target_params: the target parameter sequence. :param source_params: the source parameter sequence. :param rate: the EMA rate (closer to 1 means slower). """ for targ, src in zip(target_params, source_params): targ.detach().mul_(rate).add_(src, alpha=1 - rate) def import_model_class_from_model_name_or_path( pretrained_model_name_or_path: str, revision: str, subfolder: str = "text_encoder" ): text_encoder_config = PretrainedConfig.from_pretrained( pretrained_model_name_or_path, subfolder=subfolder, revision=revision ) model_class = text_encoder_config.architectures[0] if model_class == "CLIPTextModel": from transformers import CLIPTextModel return CLIPTextModel elif model_class == "CLIPTextModelWithProjection": from transformers import CLIPTextModelWithProjection return CLIPTextModelWithProjection else: raise ValueError(f"{model_class} is not supported.") def parse_args(): parser = argparse.ArgumentParser(description="Simple example of a training script.") # ----------Model Checkpoint Loading Arguments---------- parser.add_argument( "--pretrained_teacher_model", type=str, default=None, required=True, help="Path to pretrained LDM teacher model or model identifier from huggingface.co/models.", ) parser.add_argument( "--pretrained_vae_model_name_or_path", type=str, default=None, help="Path to pretrained VAE model with better numerical stability. More details: https://github.com/huggingface/diffusers/pull/4038.", ) parser.add_argument( "--teacher_revision", type=str, default=None, required=False, help="Revision of pretrained LDM teacher model identifier from huggingface.co/models.", ) parser.add_argument( "--revision", type=str, default=None, required=False, help="Revision of pretrained LDM model identifier from huggingface.co/models.", ) # ----------Training Arguments---------- # ----General Training Arguments---- parser.add_argument( "--output_dir", type=str, default="lcm-xl-distilled", help="The output directory where the model predictions and checkpoints will be written.", ) parser.add_argument( "--cache_dir", type=str, default=None, help="The directory where the downloaded models and datasets will be stored.", ) parser.add_argument("--seed", type=int, default=None, help="A seed for reproducible training.") # ----Logging---- parser.add_argument( "--logging_dir", type=str, default="logs", help=( "[TensorBoard](https://www.tensorflow.org/tensorboard) log directory. Will default to" " *output_dir/runs/**CURRENT_DATETIME_HOSTNAME***." ), ) parser.add_argument( "--report_to", type=str, default="tensorboard", help=( 'The integration to report the results and logs to. Supported platforms are `"tensorboard"`' ' (default), `"wandb"` and `"comet_ml"`. Use `"all"` to report to all integrations.' ), ) # ----Checkpointing---- parser.add_argument( "--checkpointing_steps", type=int, default=500, help=( "Save a checkpoint of the training state every X updates. These checkpoints are only suitable for resuming" " training using `--resume_from_checkpoint`." ), ) parser.add_argument( "--checkpoints_total_limit", type=int, default=None, help=("Max number of checkpoints to store."), ) parser.add_argument( "--resume_from_checkpoint", type=str, default=None, help=( "Whether training should be resumed from a previous checkpoint. Use a path saved by" ' `--checkpointing_steps`, or `"latest"` to automatically select the last available checkpoint.' ), ) # ----Image Processing---- parser.add_argument( "--train_shards_path_or_url", type=str, default=None, help=( "The name of the Dataset (from the HuggingFace hub) to train on (could be your own, possibly private," " dataset). It can also be a path pointing to a local copy of a dataset in your filesystem," " or to a folder containing files that 🤗 Datasets can understand." ), ) parser.add_argument( "--resolution", type=int, default=512, help=( "The resolution for input images, all the images in the train/validation dataset will be resized to this" " resolution" ), ) parser.add_argument( "--interpolation_type", type=str, default="bilinear", help=( "The interpolation function used when resizing images to the desired resolution. Choose between `bilinear`," " `bicubic`, `box`, `nearest`, `nearest_exact`, `hamming`, and `lanczos`." ), ) parser.add_argument( "--center_crop", default=False, action="store_true", help=( "Whether to center crop the input images to the resolution. If not set, the images will be randomly" " cropped. The images will be resized to the resolution first before cropping." ), ) parser.add_argument( "--random_flip", action="store_true", help="whether to randomly flip images horizontally", ) # ----Dataloader---- parser.add_argument( "--dataloader_num_workers", type=int, default=0, help=( "Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process." ), ) # ----Batch Size and Training Steps---- parser.add_argument( "--train_batch_size", type=int, default=16, help="Batch size (per device) for the training dataloader." ) parser.add_argument("--num_train_epochs", type=int, default=100) parser.add_argument( "--max_train_steps", type=int, default=None, help="Total number of training steps to perform. If provided, overrides num_train_epochs.", ) parser.add_argument( "--max_train_samples", type=int, default=None, help=( "For debugging purposes or quicker training, truncate the number of training examples to this value if set." ), ) # ----Learning Rate---- parser.add_argument( "--learning_rate", type=float, default=1e-4, help="Initial learning rate (after the potential warmup period) to use.", ) parser.add_argument( "--scale_lr", action="store_true", default=False, help="Scale the learning rate by the number of GPUs, gradient accumulation steps, and batch size.", ) parser.add_argument( "--lr_scheduler", type=str, default="constant", help=( 'The scheduler type to use. Choose between ["linear", "cosine", "cosine_with_restarts", "polynomial",' ' "constant", "constant_with_warmup"]' ), ) parser.add_argument( "--lr_warmup_steps", type=int, default=500, help="Number of steps for the warmup in the lr scheduler." ) parser.add_argument( "--gradient_accumulation_steps", type=int, default=1, help="Number of updates steps to accumulate before performing a backward/update pass.", ) # ----Optimizer (Adam)---- parser.add_argument( "--use_8bit_adam", action="store_true", help="Whether or not to use 8-bit Adam from bitsandbytes." ) parser.add_argument("--adam_beta1", type=float, default=0.9, help="The beta1 parameter for the Adam optimizer.") parser.add_argument("--adam_beta2", type=float, default=0.999, help="The beta2 parameter for the Adam optimizer.") parser.add_argument("--adam_weight_decay", type=float, default=1e-2, help="Weight decay to use.") parser.add_argument("--adam_epsilon", type=float, default=1e-08, help="Epsilon value for the Adam optimizer") parser.add_argument("--max_grad_norm", default=1.0, type=float, help="Max gradient norm.") # ----Diffusion Training Arguments---- parser.add_argument( "--proportion_empty_prompts", type=float, default=0, help="Proportion of image prompts to be replaced with empty strings. Defaults to 0 (no prompt replacement).", ) # ----Latent Consistency Distillation (LCD) Specific Arguments---- parser.add_argument( "--w_min", type=float, default=5.0, required=False, help=( "The minimum guidance scale value for guidance scale sampling. Note that we are using the Imagen CFG" " formulation rather than the LCM formulation, which means all guidance scales have 1 added to them as" " compared to the original paper." ), ) parser.add_argument( "--w_max", type=float, default=15.0, required=False, help=( "The maximum guidance scale value for guidance scale sampling. Note that we are using the Imagen CFG" " formulation rather than the LCM formulation, which means all guidance scales have 1 added to them as" " compared to the original paper." ), ) parser.add_argument( "--num_ddim_timesteps", type=int, default=50, help="The number of timesteps to use for DDIM sampling.", ) parser.add_argument( "--loss_type", type=str, default="l2", choices=["l2", "huber"], help="The type of loss to use for the LCD loss.", ) parser.add_argument( "--huber_c", type=float, default=0.001, help="The huber loss parameter. Only used if `--loss_type=huber`.", ) parser.add_argument( "--lora_r", type=int, default=64, help="The rank of the LoRA projection matrix.", ) parser.add_argument( "--lora_alpha", type=int, default=64, help=( "The value of the LoRA alpha parameter, which controls the scaling factor in front of the LoRA weight" " update delta_W. No scaling will be performed if this value is equal to `lora_r`." ), ) parser.add_argument( "--lora_dropout", type=float, default=0.0, help="The dropout probability for the dropout layer added before applying the LoRA to each layer input.", ) parser.add_argument( "--lora_target_modules", type=str, default=None, help=( "A comma-separated string of target module keys to add LoRA to. If not set, a default list of modules will" " be used. By default, LoRA will be applied to all conv and linear layers." ), ) parser.add_argument( "--vae_encode_batch_size", type=int, default=32, required=False, help=( "The batch size used when encoding (and decoding) images to latents (and vice versa) using the VAE." " Encoding or decoding the whole batch at once may run into OOM issues." ), ) parser.add_argument( "--timestep_scaling_factor", type=float, default=10.0, help=( "The multiplicative timestep scaling factor used when calculating the boundary scalings for LCM. The" " higher the scaling is, the lower the approximation error, but the default value of 10.0 should typically" " suffice." ), ) # ----Mixed Precision---- parser.add_argument( "--mixed_precision", type=str, default=None, choices=["no", "fp16", "bf16"], help=( "Whether to use mixed precision. Choose between fp16 and bf16 (bfloat16). Bf16 requires PyTorch >=" " 1.10.and an Nvidia Ampere GPU. Default to the value of accelerate config of the current system or the" " flag passed with the `accelerate.launch` command. Use this argument to override the accelerate config." ), ) parser.add_argument( "--allow_tf32", action="store_true", help=( "Whether or not to allow TF32 on Ampere GPUs. Can be used to speed up training. For more information, see" " https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices" ), ) parser.add_argument( "--cast_teacher_unet", action="store_true", help="Whether to cast the teacher U-Net to the precision specified by `--mixed_precision`.", ) # ----Training Optimizations---- parser.add_argument( "--enable_xformers_memory_efficient_attention", action="store_true", help="Whether or not to use xformers." ) parser.add_argument( "--gradient_checkpointing", action="store_true", help="Whether or not to use gradient checkpointing to save memory at the expense of slower backward pass.", ) # ----Distributed Training---- parser.add_argument("--local_rank", type=int, default=-1, help="For distributed training: local_rank") # ----------Validation Arguments---------- parser.add_argument( "--validation_steps", type=int, default=200, help="Run validation every X steps.", ) # ----------Huggingface Hub Arguments----------- parser.add_argument("--push_to_hub", action="store_true", help="Whether or not to push the model to the Hub.") parser.add_argument("--hub_token", type=str, default=None, help="The token to use to push to the Model Hub.") parser.add_argument( "--hub_model_id", type=str, default=None, help="The name of the repository to keep in sync with the local `output_dir`.", ) # ----------Accelerate Arguments---------- parser.add_argument( "--tracker_project_name", type=str, default="text2image-fine-tune", help=( "The `project_name` argument passed to Accelerator.init_trackers for" " more information see https://huggingface.co/docs/accelerate/v0.17.0/en/package_reference/accelerator#accelerate.Accelerator" ), ) args = parser.parse_args() env_local_rank = int(os.environ.get("LOCAL_RANK", -1)) if env_local_rank != -1 and env_local_rank != args.local_rank: args.local_rank = env_local_rank if args.proportion_empty_prompts < 0 or args.proportion_empty_prompts > 1: raise ValueError("`--proportion_empty_prompts` must be in the range [0, 1].") return args # Adapted from pipelines.StableDiffusionPipeline.encode_prompt def encode_prompt(prompt_batch, text_encoder, tokenizer, proportion_empty_prompts, is_train=True): captions = [] for caption in prompt_batch: if random.random() < proportion_empty_prompts: captions.append("") elif isinstance(caption, str): captions.append(caption) elif isinstance(caption, (list, np.ndarray)): # take a random caption if there are multiple captions.append(random.choice(caption) if is_train else caption[0]) with torch.no_grad(): text_inputs = tokenizer( captions, padding="max_length", max_length=tokenizer.model_max_length, truncation=True, return_tensors="pt", ) text_input_ids = text_inputs.input_ids prompt_embeds = text_encoder(text_input_ids.to(text_encoder.device))[0] return prompt_embeds def main(args): if args.report_to == "wandb" and args.hub_token is not None: raise ValueError( "You cannot use both --report_to=wandb and --hub_token due to a security risk of exposing your token." " Please use `huggingface-cli login` to authenticate with the Hub." ) logging_dir = Path(args.output_dir, args.logging_dir) accelerator_project_config = ProjectConfiguration(project_dir=args.output_dir, logging_dir=logging_dir) accelerator = Accelerator( gradient_accumulation_steps=args.gradient_accumulation_steps, mixed_precision=args.mixed_precision, log_with=args.report_to, project_config=accelerator_project_config, split_batches=True, ) # It's important to set `split_batches=True` when using webdataset to get the right number # of steps for lr scheduling. If set to False, the number of steps will be devide by the number of # processes assuming batches are multiplied by the number of processes # Make one log on every process with the configuration for debugging. logging.basicConfig( format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%m/%d/%Y %H:%M:%S", level=logging.INFO, ) logger.info(accelerator.state, main_process_only=False) if accelerator.is_local_main_process: transformers.utils.logging.set_verbosity_warning() diffusers.utils.logging.set_verbosity_info() else: transformers.utils.logging.set_verbosity_error() diffusers.utils.logging.set_verbosity_error() # If passed along, set the training seed now. if args.seed is not None: set_seed(args.seed) # Handle the repository creation if accelerator.is_main_process: if args.output_dir is not None: os.makedirs(args.output_dir, exist_ok=True) if args.push_to_hub: repo_id = create_repo( repo_id=args.hub_model_id or Path(args.output_dir).name, exist_ok=True, token=args.hub_token, private=True, ).repo_id # 1. Create the noise scheduler and the desired noise schedule. noise_scheduler = DDPMScheduler.from_pretrained( args.pretrained_teacher_model, subfolder="scheduler", revision=args.teacher_revision ) # DDPMScheduler calculates the alpha and sigma noise schedules (based on the alpha bars) for us alpha_schedule = torch.sqrt(noise_scheduler.alphas_cumprod) sigma_schedule = torch.sqrt(1 - noise_scheduler.alphas_cumprod) # Initialize the DDIM ODE solver for distillation. solver = DDIMSolver( noise_scheduler.alphas_cumprod.numpy(), timesteps=noise_scheduler.config.num_train_timesteps, ddim_timesteps=args.num_ddim_timesteps, ) # 2. Load tokenizers from SD 1.X/2.X checkpoint. tokenizer = AutoTokenizer.from_pretrained( args.pretrained_teacher_model, subfolder="tokenizer", revision=args.teacher_revision, use_fast=False ) # 3. Load text encoders from SD 1.X/2.X checkpoint. # import correct text encoder classes text_encoder = CLIPTextModel.from_pretrained( args.pretrained_teacher_model, subfolder="text_encoder", revision=args.teacher_revision ) # 4. Load VAE from SD 1.X/2.X checkpoint vae = AutoencoderKL.from_pretrained( args.pretrained_teacher_model, subfolder="vae", revision=args.teacher_revision, ) # 5. Load teacher U-Net from SD 1.X/2.X checkpoint teacher_unet = UNet2DConditionModel.from_pretrained( args.pretrained_teacher_model, subfolder="unet", revision=args.teacher_revision ) # 6. Freeze teacher vae, text_encoder, and teacher_unet vae.requires_grad_(False) text_encoder.requires_grad_(False) teacher_unet.requires_grad_(False) # 7. Create online student U-Net. unet = UNet2DConditionModel.from_pretrained( args.pretrained_teacher_model, subfolder="unet", revision=args.teacher_revision ) unet.train() # Check that all trainable models are in full precision low_precision_error_string = ( " Please make sure to always have all model weights in full float32 precision when starting training - even if" " doing mixed precision training, copy of the weights should still be float32." ) if accelerator.unwrap_model(unet).dtype != torch.float32: raise ValueError( f"Controlnet loaded as datatype {accelerator.unwrap_model(unet).dtype}. {low_precision_error_string}" ) # 8. Add LoRA to the student U-Net, only the LoRA projection matrix will be updated by the optimizer. if args.lora_target_modules is not None: lora_target_modules = [module_key.strip() for module_key in args.lora_target_modules.split(",")] else: lora_target_modules = [ "to_q", "to_k", "to_v", "to_out.0", "proj_in", "proj_out", "ff.net.0.proj", "ff.net.2", "conv1", "conv2", "conv_shortcut", "downsamplers.0.conv", "upsamplers.0.conv", "time_emb_proj", ] lora_config = LoraConfig( r=args.lora_r, target_modules=lora_target_modules, lora_alpha=args.lora_alpha, lora_dropout=args.lora_dropout, ) unet = get_peft_model(unet, lora_config) # 9. Handle mixed precision and device placement # For mixed precision training we cast all non-trainable weigths to half-precision # as these weights are only used for inference, keeping weights in full precision is not required. weight_dtype = torch.float32 if accelerator.mixed_precision == "fp16": weight_dtype = torch.float16 elif accelerator.mixed_precision == "bf16": weight_dtype = torch.bfloat16 # Move unet, vae and text_encoder to device and cast to weight_dtype # The VAE is in float32 to avoid NaN losses. vae.to(accelerator.device) if args.pretrained_vae_model_name_or_path is not None: vae.to(dtype=weight_dtype) text_encoder.to(accelerator.device, dtype=weight_dtype) # Move teacher_unet to device, optionally cast to weight_dtype teacher_unet.to(accelerator.device) if args.cast_teacher_unet: teacher_unet.to(dtype=weight_dtype) # Also move the alpha and sigma noise schedules to accelerator.device. alpha_schedule = alpha_schedule.to(accelerator.device) sigma_schedule = sigma_schedule.to(accelerator.device) # Move the ODE solver to accelerator.device. solver = solver.to(accelerator.device) # 10. Handle saving and loading of checkpoints # `accelerate` 0.16.0 will have better support for customized saving if version.parse(accelerate.__version__) >= version.parse("0.16.0"): # create custom saving & loading hooks so that `accelerator.save_state(...)` serializes in a nice format def save_model_hook(models, weights, output_dir): if accelerator.is_main_process: unet_ = accelerator.unwrap_model(unet) lora_state_dict = get_peft_model_state_dict(unet_, adapter_name="default") StableDiffusionPipeline.save_lora_weights(os.path.join(output_dir, "unet_lora"), lora_state_dict) # save weights in peft format to be able to load them back unet_.save_pretrained(output_dir) for _, model in enumerate(models): # make sure to pop weight so that corresponding model is not saved again weights.pop() def load_model_hook(models, input_dir): # load the LoRA into the model unet_ = accelerator.unwrap_model(unet) unet_.load_adapter(input_dir, "default", is_trainable=True) for _ in range(len(models)): # pop models so that they are not loaded again models.pop() accelerator.register_save_state_pre_hook(save_model_hook) accelerator.register_load_state_pre_hook(load_model_hook) # 11. Enable optimizations if args.enable_xformers_memory_efficient_attention: if is_xformers_available(): import xformers xformers_version = version.parse(xformers.__version__) if xformers_version == version.parse("0.0.16"): logger.warning( "xFormers 0.0.16 cannot be used for training in some GPUs. If you observe problems during " "training, please update xFormers to at least 0.0.17. " "See https://huggingface.co/docs/diffusers/main/en/optimization/xformers for more details." ) unet.enable_xformers_memory_efficient_attention() teacher_unet.enable_xformers_memory_efficient_attention() # target_unet.enable_xformers_memory_efficient_attention() else: raise ValueError("xformers is not available. Make sure it is installed correctly") # Enable TF32 for faster training on Ampere GPUs, # cf https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices if args.allow_tf32: torch.backends.cuda.matmul.allow_tf32 = True if args.gradient_checkpointing: unet.enable_gradient_checkpointing() # Use 8-bit Adam for lower memory usage or to fine-tune the model in 16GB GPUs if args.use_8bit_adam: try: import bitsandbytes as bnb except ImportError: raise ImportError( "To use 8-bit Adam, please install the bitsandbytes library: `pip install bitsandbytes`." ) from None optimizer_class = bnb.optim.AdamW8bit else: optimizer_class = torch.optim.AdamW # 12. Optimizer creation optimizer = optimizer_class( unet.parameters(), lr=args.learning_rate, betas=(args.adam_beta1, args.adam_beta2), weight_decay=args.adam_weight_decay, eps=args.adam_epsilon, ) # 13. Dataset creation and data processing # Here, we compute not just the text embeddings but also the additional embeddings # needed for the SD XL UNet to operate. def compute_embeddings(prompt_batch, proportion_empty_prompts, text_encoder, tokenizer, is_train=True): prompt_embeds = encode_prompt(prompt_batch, text_encoder, tokenizer, proportion_empty_prompts, is_train) return {"prompt_embeds": prompt_embeds} dataset = SDText2ImageDataset( train_shards_path_or_url=args.train_shards_path_or_url, num_train_examples=args.max_train_samples, per_gpu_batch_size=args.train_batch_size, global_batch_size=args.train_batch_size * accelerator.num_processes, num_workers=args.dataloader_num_workers, resolution=args.resolution, interpolation_type=args.interpolation_type, shuffle_buffer_size=1000, pin_memory=True, persistent_workers=True, ) train_dataloader = dataset.train_dataloader compute_embeddings_fn = functools.partial( compute_embeddings, proportion_empty_prompts=0, text_encoder=text_encoder, tokenizer=tokenizer, ) # 14. LR Scheduler creation # Scheduler and math around the number of training steps. overrode_max_train_steps = False num_update_steps_per_epoch = math.ceil(train_dataloader.num_batches / args.gradient_accumulation_steps) if args.max_train_steps is None: args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch overrode_max_train_steps = True lr_scheduler = get_scheduler( args.lr_scheduler, optimizer=optimizer, num_warmup_steps=args.lr_warmup_steps, num_training_steps=args.max_train_steps, ) # 15. Prepare for training # Prepare everything with our `accelerator`. unet, optimizer, lr_scheduler = accelerator.prepare(unet, optimizer, lr_scheduler) # We need to recalculate our total training steps as the size of the training dataloader may have changed. num_update_steps_per_epoch = math.ceil(train_dataloader.num_batches / args.gradient_accumulation_steps) if overrode_max_train_steps: args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch # Afterwards we recalculate our number of training epochs args.num_train_epochs = math.ceil(args.max_train_steps / num_update_steps_per_epoch) # We need to initialize the trackers we use, and also store our configuration. # The trackers initializes automatically on the main process. if accelerator.is_main_process: tracker_config = dict(vars(args)) accelerator.init_trackers(args.tracker_project_name, config=tracker_config) uncond_input_ids = tokenizer( [""] * args.train_batch_size, return_tensors="pt", padding="max_length", max_length=77 ).input_ids.to(accelerator.device) uncond_prompt_embeds = text_encoder(uncond_input_ids)[0] # 16. Train! total_batch_size = args.train_batch_size * accelerator.num_processes * args.gradient_accumulation_steps logger.info("***** Running training *****") logger.info(f" Num batches each epoch = {train_dataloader.num_batches}") logger.info(f" Num Epochs = {args.num_train_epochs}") logger.info(f" Instantaneous batch size per device = {args.train_batch_size}") logger.info(f" Total train batch size (w. parallel, distributed & accumulation) = {total_batch_size}") logger.info(f" Gradient Accumulation steps = {args.gradient_accumulation_steps}") logger.info(f" Total optimization steps = {args.max_train_steps}") global_step = 0 first_epoch = 0 # Potentially load in the weights and states from a previous save if args.resume_from_checkpoint: if args.resume_from_checkpoint != "latest": path = os.path.basename(args.resume_from_checkpoint) else: # Get the most recent checkpoint dirs = os.listdir(args.output_dir) dirs = [d for d in dirs if d.startswith("checkpoint")] dirs = sorted(dirs, key=lambda x: int(x.split("-")[1])) path = dirs[-1] if len(dirs) > 0 else None if path is None: accelerator.print( f"Checkpoint '{args.resume_from_checkpoint}' does not exist. Starting a new training run." ) args.resume_from_checkpoint = None initial_global_step = 0 else: accelerator.print(f"Resuming from checkpoint {path}") accelerator.load_state(os.path.join(args.output_dir, path)) global_step = int(path.split("-")[1]) initial_global_step = global_step first_epoch = global_step // num_update_steps_per_epoch else: initial_global_step = 0 progress_bar = tqdm( range(0, args.max_train_steps), initial=initial_global_step, desc="Steps", # Only show the progress bar once on each machine. disable=not accelerator.is_local_main_process, ) for epoch in range(first_epoch, args.num_train_epochs): for step, batch in enumerate(train_dataloader): with accelerator.accumulate(unet): # 1. Load and process the image and text conditioning image, text = batch image = image.to(accelerator.device, non_blocking=True) encoded_text = compute_embeddings_fn(text) pixel_values = image.to(dtype=weight_dtype) if vae.dtype != weight_dtype: vae.to(dtype=weight_dtype) # encode pixel values with batch size of at most args.vae_encode_batch_size latents = [] for i in range(0, pixel_values.shape[0], args.vae_encode_batch_size): latents.append(vae.encode(pixel_values[i : i + args.vae_encode_batch_size]).latent_dist.sample()) latents = torch.cat(latents, dim=0) latents = latents * vae.config.scaling_factor latents = latents.to(weight_dtype) bsz = latents.shape[0] # 2. Sample a random timestep for each image t_n from the ODE solver timesteps without bias. # For the DDIM solver, the timestep schedule is [T - 1, T - k - 1, T - 2 * k - 1, ...] topk = noise_scheduler.config.num_train_timesteps // args.num_ddim_timesteps index = torch.randint(0, args.num_ddim_timesteps, (bsz,), device=latents.device).long() start_timesteps = solver.ddim_timesteps[index] timesteps = start_timesteps - topk timesteps = torch.where(timesteps < 0, torch.zeros_like(timesteps), timesteps) # 3. Get boundary scalings for start_timesteps and (end) timesteps. c_skip_start, c_out_start = scalings_for_boundary_conditions( start_timesteps, timestep_scaling=args.timestep_scaling_factor ) c_skip_start, c_out_start = [append_dims(x, latents.ndim) for x in [c_skip_start, c_out_start]] c_skip, c_out = scalings_for_boundary_conditions( timesteps, timestep_scaling=args.timestep_scaling_factor ) c_skip, c_out = [append_dims(x, latents.ndim) for x in [c_skip, c_out]] # 4. Sample noise from the prior and add it to the latents according to the noise magnitude at each # timestep (this is the forward diffusion process) [z_{t_{n + k}} in Algorithm 1] noise = torch.randn_like(latents) noisy_model_input = noise_scheduler.add_noise(latents, noise, start_timesteps) # 5. Sample a random guidance scale w from U[w_min, w_max] # Note that for LCM-LoRA distillation it is not necessary to use a guidance scale embedding w = (args.w_max - args.w_min) * torch.rand((bsz,)) + args.w_min w = w.reshape(bsz, 1, 1, 1) w = w.to(device=latents.device, dtype=latents.dtype) # 6. Prepare prompt embeds and unet_added_conditions prompt_embeds = encoded_text.pop("prompt_embeds") # 7. Get online LCM prediction on z_{t_{n + k}} (noisy_model_input), w, c, t_{n + k} (start_timesteps) noise_pred = unet( noisy_model_input, start_timesteps, timestep_cond=None, encoder_hidden_states=prompt_embeds.float(), added_cond_kwargs=encoded_text, ).sample pred_x_0 = get_predicted_original_sample( noise_pred, start_timesteps, noisy_model_input, noise_scheduler.config.prediction_type, alpha_schedule, sigma_schedule, ) model_pred = c_skip_start * noisy_model_input + c_out_start * pred_x_0 # 8. Compute the conditional and unconditional teacher model predictions to get CFG estimates of the # predicted noise eps_0 and predicted original sample x_0, then run the ODE solver using these # estimates to predict the data point in the augmented PF-ODE trajectory corresponding to the next ODE # solver timestep. with torch.no_grad(): with torch.autocast("cuda"): # 1. Get teacher model prediction on noisy_model_input z_{t_{n + k}} and conditional embedding c cond_teacher_output = teacher_unet( noisy_model_input.to(weight_dtype), start_timesteps, encoder_hidden_states=prompt_embeds.to(weight_dtype), ).sample cond_pred_x0 = get_predicted_original_sample( cond_teacher_output, start_timesteps, noisy_model_input, noise_scheduler.config.prediction_type, alpha_schedule, sigma_schedule, ) cond_pred_noise = get_predicted_noise( cond_teacher_output, start_timesteps, noisy_model_input, noise_scheduler.config.prediction_type, alpha_schedule, sigma_schedule, ) # 2. Get teacher model prediction on noisy_model_input z_{t_{n + k}} and # unconditional embedding 0 uncond_teacher_output = teacher_unet( noisy_model_input.to(weight_dtype), start_timesteps, encoder_hidden_states=uncond_prompt_embeds.to(weight_dtype), ).sample uncond_pred_x0 = get_predicted_original_sample( uncond_teacher_output, start_timesteps, noisy_model_input, noise_scheduler.config.prediction_type, alpha_schedule, sigma_schedule, ) uncond_pred_noise = get_predicted_noise( uncond_teacher_output, start_timesteps, noisy_model_input, noise_scheduler.config.prediction_type, alpha_schedule, sigma_schedule, ) # 3. Calculate the CFG estimate of x_0 (pred_x0) and eps_0 (pred_noise) # Note that this uses the LCM paper's CFG formulation rather than the Imagen CFG formulation pred_x0 = cond_pred_x0 + w * (cond_pred_x0 - uncond_pred_x0) pred_noise = cond_pred_noise + w * (cond_pred_noise - uncond_pred_noise) # 4. Run one step of the ODE solver to estimate the next point x_prev on the # augmented PF-ODE trajectory (solving backward in time) # Note that the DDIM step depends on both the predicted x_0 and source noise eps_0. x_prev = solver.ddim_step(pred_x0, pred_noise, index) # 9. Get target LCM prediction on x_prev, w, c, t_n (timesteps) # Note that we do not use a separate target network for LCM-LoRA distillation. with torch.no_grad(): with torch.autocast("cuda", dtype=weight_dtype): target_noise_pred = unet( x_prev.float(), timesteps, timestep_cond=None, encoder_hidden_states=prompt_embeds.float(), ).sample pred_x_0 = get_predicted_original_sample( target_noise_pred, timesteps, x_prev, noise_scheduler.config.prediction_type, alpha_schedule, sigma_schedule, ) target = c_skip * x_prev + c_out * pred_x_0 # 10. Calculate loss if args.loss_type == "l2": loss = F.mse_loss(model_pred.float(), target.float(), reduction="mean") elif args.loss_type == "huber": loss = torch.mean( torch.sqrt((model_pred.float() - target.float()) ** 2 + args.huber_c**2) - args.huber_c ) # 11. Backpropagate on the online student model (`unet`) accelerator.backward(loss) if accelerator.sync_gradients: accelerator.clip_grad_norm_(unet.parameters(), args.max_grad_norm) optimizer.step() lr_scheduler.step() optimizer.zero_grad(set_to_none=True) # Checks if the accelerator has performed an optimization step behind the scenes if accelerator.sync_gradients: progress_bar.update(1) global_step += 1 if accelerator.is_main_process: if global_step % args.checkpointing_steps == 0: # _before_ saving state, check if this save would set us over the `checkpoints_total_limit` if args.checkpoints_total_limit is not None: checkpoints = os.listdir(args.output_dir) checkpoints = [d for d in checkpoints if d.startswith("checkpoint")] checkpoints = sorted(checkpoints, key=lambda x: int(x.split("-")[1])) # before we save the new checkpoint, we need to have at _most_ # `checkpoints_total_limit - 1` checkpoints if len(checkpoints) >= args.checkpoints_total_limit: num_to_remove = len(checkpoints) - args.checkpoints_total_limit + 1 removing_checkpoints = checkpoints[0:num_to_remove] logger.info( f"{len(checkpoints)} checkpoints already exist, removing " f"{len(removing_checkpoints)} checkpoints" ) logger.info(f"removing checkpoints: {', '.join(removing_checkpoints)}") for removing_checkpoint in removing_checkpoints: removing_checkpoint = os.path.join(args.output_dir, removing_checkpoint) shutil.rmtree(removing_checkpoint) save_path = os.path.join(args.output_dir, f"checkpoint-{global_step}") accelerator.save_state(save_path) logger.info(f"Saved state to {save_path}") if global_step % args.validation_steps == 0: log_validation(vae, unet, args, accelerator, weight_dtype, global_step) logs = {"loss": loss.detach().item(), "lr": lr_scheduler.get_last_lr()[0]} progress_bar.set_postfix(**logs) accelerator.log(logs, step=global_step) if global_step >= args.max_train_steps: break # Create the pipeline using using the trained modules and save it. accelerator.wait_for_everyone() if accelerator.is_main_process: unet = accelerator.unwrap_model(unet) unet.save_pretrained(args.output_dir) lora_state_dict = get_peft_model_state_dict(unet, adapter_name="default") StableDiffusionPipeline.save_lora_weights(os.path.join(args.output_dir, "unet_lora"), lora_state_dict) if args.push_to_hub: upload_folder( repo_id=repo_id, folder_path=args.output_dir, commit_message="End of training", ignore_patterns=["step_*", "epoch_*"], ) accelerator.end_training() if __name__ == "__main__": args = parse_args() main(args) ================================================ FILE: experimental/LISA-diffusion/requirement.txt ================================================ accelerate>=0.16.0 torchvision transformers>=4.25.1 ftfy peft wandb tensorboard Jinja2 webdataset datasets ================================================ FILE: experimental/LISA-diffusion/single_lisa.py ================================================ import numpy as np import torch class LISADiffusion: def __init__(self, model, rate=None): self.model = model self.rate = rate self.initialize() def freeze_all_layers(self, model): for param in model.parameters(): param.requires_grad = False def random_activate_layers(self, model, p): activate_number = int((len(list(model.parameters())) - 2) * p) index = np.random.choice(range(0, len(list(model.parameters())) - 1, 1), activate_number, replace=False) count = 0 for param in model.parameters(): if count == 0 or count == len(list(model.parameters())) - 1: param.requires_grad = True elif count in index: param.requires_grad = True count += 1 def lisa(self, model, p=0.25): self.freeze_all_layers(model) self.random_activate_layers(model, p) def lisa_recall(self): param_number = len(list(self.model.parameters())) lisa_p = 8 / param_number if self.rate is None else self.rate self.lisa(model=self.model, p=lisa_p) def initialize(self): self.optimizer_dict = dict() self.scheduler_dict = dict() self.lisa_recall() def register( self, optimizer_class=None, get_scheduler=None, accelerator=None, optim_kwargs=None, sched_kwargs=None, ): if optim_kwargs is None: optim_kwargs = {} if sched_kwargs is None: sched_kwargs = {} for p in self.model.parameters(): if p.requires_grad: self.optimizer_dict[p] = optimizer_class([{"params": p}], **optim_kwargs) if accelerator is not None: self.optimizer_dict[p] = accelerator.prepare_optimizer(self.optimizer_dict[p]) for p in self.model.parameters(): if p.requires_grad: self.scheduler_dict[p] = get_scheduler(optimizer=self.optimizer_dict[p], **sched_kwargs) if accelerator is not None: self.scheduler_dict[p] = accelerator.prepare_scheduler(self.scheduler_dict[p]) def insert_hook( self, optimizer_class=None, get_scheduler=None, accelerator=None, optim_kwargs=None, sched_kwargs=None, ): if optim_kwargs is None: optim_kwargs = {} if sched_kwargs is None: sched_kwargs = {} def optimizer_hook(p): if p.grad is None: del self.scheduler_dict[p] del self.optimizer_dict[p] return else: if p not in self.optimizer_dict: self.optimizer_dict[p] = optimizer_class([{"params": p}], **optim_kwargs) if accelerator is not None: self.optimizer_dict[p] = accelerator.prepare_optimizer(self.optimizer_dict[p]) if p not in self.scheduler_dict: self.scheduler_dict[p] = get_scheduler(optimizer=self.optimizer_dict[p], **sched_kwargs) if accelerator is not None: self.scheduler_dict[p] = accelerator.prepare_scheduler(self.scheduler_dict[p]) if accelerator is not None and accelerator.sync_gradients: torch.nn.utils.clip_grad_norm_(p, 10.0) self.optimizer_dict[p].step() self.optimizer_dict[p].zero_grad(set_to_none=True) self.scheduler_dict[p].step() # Register the hook onto every parameter for p in self.model.parameters(): if p.requires_grad: p.register_post_accumulate_grad_hook(optimizer_hook) ================================================ FILE: experimental/RAFT-diffusion/README.md ================================================ # RAFT-Diffusion In this folder, we provide an example to show that how does RAFT work on diffusion models. We will also include these script into LMFlow framework into the LMFlow APIs in the future. The requirements are shown below. ``` accelerate 0.18.0 asttokens 2.2.1 backcall 0.2.0 bitsandbytes 0.37.2 certifi 2022.12.7 charset-normalizer 3.1.0 clip 1.0 cmake 3.26.1 comm 0.1.3 contourpy 1.0.7 cycler 0.11.0 debugpy 1.6.7 decorator 5.1.1 diffusers 0.14.0 executing 1.2.0 filelock 3.11.0 fonttools 4.39.3 ftfy 6.1.1 huggingface-hub 0.13.4 idna 3.4 importlib-metadata 6.2.0 importlib-resources 5.12.0 ipykernel 6.22.0 ipython 8.12.0 jedi 0.18.2 Jinja2 3.1.2 jupyter_client 8.1.0 jupyter_core 5.3.0 kiwisolver 1.4.4 lit 16.0.0 MarkupSafe 2.1.2 matplotlib 3.7.1 matplotlib-inline 0.1.6 mpmath 1.3.0 mypy-extensions 1.0.0 nest-asyncio 1.5.6 networkx 3.1 numpy 1.24.2 nvidia-cublas-cu11 11.10.3.66 nvidia-cuda-cupti-cu11 11.7.101 nvidia-cuda-nvrtc-cu11 11.7.99 nvidia-cuda-runtime-cu11 11.7.99 nvidia-cudnn-cu11 8.5.0.96 nvidia-cufft-cu11 10.9.0.58 nvidia-curand-cu11 10.2.10.91 nvidia-cusolver-cu11 11.4.0.1 nvidia-cusparse-cu11 11.7.4.91 nvidia-nccl-cu11 2.14.3 nvidia-nvtx-cu11 11.7.91 open-clip-torch 2.16.0 packaging 23.0 pandas 2.0.0 parso 0.8.3 pexpect 4.8.0 pickleshare 0.7.5 Pillow 9.5.0 pip 23.0.1 platformdirs 3.2.0 prompt-toolkit 3.0.38 protobuf 3.20.3 psutil 5.9.4 ptyprocess 0.7.0 pure-eval 0.2.2 Pygments 2.14.0 pyparsing 3.0.9 pyre-extensions 0.0.23 python-dateutil 2.8.2 pytz 2023.3 PyYAML 6.0 pyzmq 25.0.2 regex 2023.3.23 requests 2.28.2 sentencepiece 0.1.97 setuptools 65.6.3 six 1.16.0 stack-data 0.6.2 sympy 1.11.1 timm 0.6.13 tokenizers 0.13.3 torch 2.0.0 torchvision 0.15.1 tornado 6.2 tqdm 4.65.0 traitlets 5.9.0 transformers 4.27.4 triton 2.0.0 typing_extensions 4.5.0 typing-inspect 0.8.0 tzdata 2023.3 urllib3 1.26.15 wcwidth 0.2.6 wheel 0.38.4 xformers 0.0.18 zipp 3.15.0 ``` We will also add a COLAB link for convenience. ================================================ FILE: experimental/RAFT-diffusion/SD256-RAFT.ipynb ================================================ { "cells": [ { "cell_type": "markdown", "metadata": { "id": "YoURrh11fbIc" }, "source": [ "# RAFT: Reward rAnked FineTuning for Generative Foundation Model Alignment\n", "\n", "This notebook beautifully showcases how RAFT can be leveraged to fine-tune a model.\n", "\n", "\n", "\n", "\n", "\n", "Curious how this works? Read our [paper](https://arxiv.org/abs/2304.06767) to explore the intricacies of our innovative approach." ] }, { "cell_type": "markdown", "metadata": { "id": "BzmCovNKkwbi" }, "source": [ "## Initial Setup" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "n7TI5hirlzn8" }, "outputs": [], "source": [ "# @title Install the required libs\n", "%pip install -q accelerate diffusers transformers ftfy bitsandbytes gradio natsort safetensors xformers datasets\n", "%pip install -qq \"ipywidgets>=7,<8\"\n", "!wget -q https://raw.githubusercontent.com/OptimalScale/LMFlow/main/experimental/RAFT-diffusion/train_text_to_image_lora.py" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "fvCBZCnrqcX1" }, "outputs": [], "source": [ "# @title Install CLIP\n", "\n", "!pip install git+https://github.com/deepgoyal19/CLIP.git" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "guDgmswnmW-4" }, "outputs": [], "source": [ "# @title Import required libraries\n", "import argparse\n", "import itertools\n", "import math\n", "import os\n", "import shutil\n", "from os.path import expanduser # pylint: disable=import-outside-toplevel\n", "from urllib.request import urlretrieve # pylint: disable=import-outside-toplevel\n", "from contextlib import nullcontext\n", "import random\n", "import pandas as pd\n", "import numpy as np\n", "import torch\n", "import torch.nn.functional as F\n", "import torch.utils.checkpoint\n", "from torch.utils.data import Dataset\n", "import concurrent\n", "import PIL\n", "from accelerate import Accelerator\n", "from accelerate.logging import get_logger\n", "from accelerate.utils import set_seed\n", "from diffusers import (\n", " AutoencoderKL,\n", " DDPMScheduler,\n", " PNDMScheduler,\n", " StableDiffusionPipeline,\n", " UNet2DConditionModel,\n", " DPMSolverMultistepScheduler,\n", ")\n", "from diffusers.optimization import get_scheduler\n", "from diffusers.pipelines.stable_diffusion import StableDiffusionSafetyChecker\n", "from PIL import Image\n", "from torchvision import transforms\n", "from tqdm.auto import tqdm\n", "from transformers import CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer\n", "import clip\n", "import bitsandbytes as bnb\n", "from torch.utils.data import DataLoader\n", "\n", "\n", "def image_grid(imgs, rows, cols):\n", " assert len(imgs) == rows * cols\n", "\n", " w, h = imgs[0].size\n", " grid = Image.new(\"RGB\", size=(cols * w, rows * h))\n", " grid_w, grid_h = grid.size\n", "\n", " for i, img in enumerate(imgs):\n", " grid.paste(img, box=(i % cols * w, i // cols * h))\n", " return grid" ] }, { "cell_type": "markdown", "metadata": { "id": "f4D64FI9pI38" }, "source": [ "## Loading Dataset" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "7IryKE4wq0SZ" }, "outputs": [], "source": [ "# @title Creating Dataloader\n", "\n", "prompts = [\"airplane\", \"automobile\", \"bird\", \"deer\", \"dog\", \"cat\", \"frog\", \"horse\", \"ship\", \"truck\"] # CIFAR labels\n", "prompts = pd.DataFrame({\"prompts\": prompts}) # converting prompts list into a pandas dataframe\n", "\n", "\n", "class CIFAR10Dataset:\n", " def __init__(self):\n", " global prompts\n", " self.prompts = prompts.iloc[:, 0]\n", "\n", " def __len__(self):\n", " return len(self.prompts)\n", "\n", " def __getitem__(self, index):\n", " return self.prompts.iloc[index]\n", "\n", "\n", "# @markdown Please mention the batch size.\n", "batch_size = 5 # @param {type:\"integer\"}\n", "\n", "\n", "dataset = CIFAR10Dataset()\n", "finetune_dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=False)" ] }, { "cell_type": "markdown", "metadata": { "id": "BWH9vc1kvhvC" }, "source": [ "## Loading CLIP" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "lJAguhs1d89L" }, "outputs": [], "source": [ "def get_aesthetic_model(clip_model=\"vit_l_14\"):\n", " \"\"\"load the aethetic model\"\"\"\n", " home = expanduser(\"~\")\n", " cache_folder = home + \"/.cache/emb_reader\"\n", " path_to_model = cache_folder + \"/sa_0_4_\" + clip_model + \"_linear.pth\"\n", " if not os.path.exists(path_to_model):\n", " os.makedirs(cache_folder, exist_ok=True)\n", " url_model = (\n", " \"https://github.com/LAION-AI/aesthetic-predictor/blob/main/sa_0_4_\" + clip_model + \"_linear.pth?raw=true\"\n", " )\n", " urlretrieve(url_model, path_to_model)\n", " if clip_model == \"vit_l_14\":\n", " m = torch.nn.Linear(768, 1)\n", " elif clip_model == \"vit_b_32\":\n", " m = torch.nn.Linear(512, 1)\n", " else:\n", " raise ValueError()\n", " s = torch.load(path_to_model)\n", " m.load_state_dict(s)\n", " m.eval()\n", " return m\n", "\n", "\n", "device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n", "amodel = get_aesthetic_model(clip_model=\"vit_l_14\").to(device)\n", "amodel.eval()\n", "\n", "model, preprocess = clip.load(\"ViT-L/14\", device=device)" ] }, { "cell_type": "markdown", "metadata": { "id": "0RPeQGHUzUZp" }, "source": [ "## Evaluating Aesthetic Score" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "s61Ljr9Sd89M" }, "outputs": [], "source": [ "def get_image_score(image): # Evaluating Scores if images\n", " images = preprocess(image).unsqueeze(0).to(device)\n", " with torch.no_grad():\n", " image_features = model.encode_image(images).to(device)\n", " image_features /= image_features.norm(dim=-1, keepdim=True)\n", " image_features = image_features.to(torch.float32)\n", " prediction = amodel(image_features)\n", " return float(prediction)\n", "\n", "\n", "def get_max_score(\n", " image_list, index, epoch=0\n", "): # The get_max_score function will return prompt's image with the highest aesthetic score will be chosen for additional fine-tuning.\n", " score_list = []\n", " for image in image_list:\n", " score_list.append(get_image_score(image))\n", " torch.cuda.empty_cache()\n", "\n", " prompts.loc[index, f\"Epoch{epoch} Scores\"] = max(score_list)\n", " return [max(score_list), score_list.index(max(score_list))]" ] }, { "cell_type": "markdown", "metadata": { "id": "Ak1jArUL0eCi" }, "source": [ "##Parameters" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "jv6WYJos0iT5" }, "outputs": [], "source": [ "# @title Settings for the model\n", "\n", "# @markdown All settings have been configured to achieve optimal output. Changing them is not advisable.\n", "\n", "# @markdown Enter value for `resolution`.\n", "resolution = 256 # @param {type:\"integer\"}\n", "\n", "# @markdown Enter value for `num_images_per_prompt`.\n", "num_images_per_prompt = 10 # @param {type:\"integer\"}\n", "\n", "# @markdown Enter value for `epochs`.\n", "epochs = 10 # @param {type:\"integer\"} |" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "7gFbnMaLd89N" }, "outputs": [], "source": [ "# @title Setting Stable Diffusion pipeline\n", "model_id = \"runwayml/stable-diffusion-v1-5\"\n", "pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to(device)\n", "pipe.enable_xformers_memory_efficient_attention()\n", "torch.cuda.empty_cache()\n", "\n", "# @markdown Check the `set_progress_bar_config` option if you would like to hide the progress bar for image generation\n", "set_progress_bar_config = False # @param {type:\"boolean\"}\n", "pipe.set_progress_bar_config(disable=set_progress_bar_config)\n", "\n", "\n", "scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)\n", "pipe.scheduler = scheduler\n", "\n", "torch.cuda.empty_cache()" ] }, { "cell_type": "markdown", "metadata": { "id": "9U2P_PUN-5xX" }, "source": [ "##Finetuning" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "F-m6S9Sg-yS_" }, "outputs": [], "source": [ "# @title Generating images on the pretrained model\n", "\n", "# @markdown Check the box to generate images using the pretrained model.\n", "generate_pretrained_model_images = True # @param {type:\"boolean\"}\n", "\n", "if generate_pretrained_model_images:\n", " image_list = []\n", " for step, prompt_list in enumerate(finetune_dataloader):\n", " image = pipe(\n", " prompt_list, num_images_per_prompt=num_images_per_prompt, width=resolution, height=resolution\n", " ).images\n", " image_list += image\n", " torch.cuda.empty_cache()\n", "\n", " grid = image_grid(image_list, len(prompts), num_images_per_prompt)\n", " grid.save(\"pretrained.png\")\n", " grid" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "kPfHR4HQd89N" }, "outputs": [], "source": [ "# @title Run training\n", "\n", "os.environ[\"MODEL_NAME\"] = model_id\n", "os.environ[\"OUTPUT_DIR\"] = f\"./CustomModel/\"\n", "topk = 8\n", "training_steps_per_epoch = topk * 10\n", "os.environ[\"CHECKPOINTING_STEPS\"] = str(training_steps_per_epoch)\n", "os.environ[\"RESOLUTION\"] = str(resolution)\n", "os.environ[\"LEARNING_RATE\"] = str(9e-6)\n", "\n", "# remove old account directory\n", "try:\n", " shutil.rmtree(\"./CustomModel\")\n", "except:\n", " pass\n", "try:\n", " shutil.rmtree(\"./trainingdataset/imagefolder/\")\n", "except:\n", " pass\n", "\n", "model_id = \"runwayml/stable-diffusion-v1-5\"\n", "\n", "\n", "for epoch in range(epochs + 1):\n", " print(\"Epoch: \", epoch)\n", " epoch = epoch\n", " training_steps = str(training_steps_per_epoch * (epoch + 1))\n", " os.environ[\"TRAINING_STEPS\"] = training_steps\n", " os.environ[\"TRAINING_DIR\"] = f\"./trainingdataset/imagefolder/{epoch}\"\n", "\n", " training_prompts = []\n", " prompts[f\"Epoch{epoch} Scores\"] = np.nan\n", "\n", " for step, prompt_list in enumerate(finetune_dataloader):\n", " image = pipe(\n", " prompt_list, num_images_per_prompt=num_images_per_prompt, width=resolution, height=resolution\n", " ).images\n", " image_list = []\n", "\n", " for i in range(int(len(image) / num_images_per_prompt)):\n", " image_list.append(image[i * num_images_per_prompt : (i + 1) * num_images_per_prompt])\n", " torch.cuda.empty_cache()\n", "\n", " with concurrent.futures.ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:\n", " step_list = [i for i in range(step * batch_size, (step + 1) * batch_size)]\n", " score_index = executor.map(get_max_score, image_list, step_list, [epoch for i in range(len(step_list))])\n", "\n", " iterator = 0\n", " for max_scores in score_index:\n", " training_prompts.append([max_scores[0], image_list[iterator][max_scores[1]], prompt_list[iterator]])\n", " iterator += 1\n", "\n", " training_prompts = [row[1:3] for row in sorted(training_prompts, key=lambda x: (x[0]), reverse=True)[:topk]]\n", " training_prompts = pd.DataFrame(training_prompts)\n", "\n", " if not os.path.exists(f\"./trainingdataset/imagefolder/{epoch}/train/\"):\n", " os.makedirs(f\"./trainingdataset/imagefolder/{epoch}/train/\")\n", " if not os.path.exists(f\"./CustomModel/\"):\n", " os.makedirs(f\"./CustomModel/\")\n", " for i in range(len(training_prompts)):\n", " training_prompts.iloc[i, 0].save(f\"./trainingdataset/imagefolder/{epoch}/train/{i}.png\")\n", "\n", " training_prompts[\"file_name\"] = [f\"{i}.png\" for i in range(len(training_prompts))]\n", " training_prompts.columns = [\"0\", \"text\", \"file_name\"]\n", " training_prompts.drop(\"0\", axis=1, inplace=True)\n", " training_prompts.to_csv(f\"./trainingdataset/imagefolder/{epoch}/train/metadata.csv\", index=False)\n", " torch.cuda.empty_cache()\n", "\n", " if epoch < epochs:\n", " !accelerate launch --num_processes=1 --mixed_precision='fp16' --dynamo_backend='no' --num_machines=1 train_text_to_image_lora.py \\\n", " --pretrained_model_name_or_path=$MODEL_NAME \\\n", " --train_data_dir=$TRAINING_DIR \\\n", " --resolution=$RESOLUTION \\\n", " --train_batch_size=8 \\\n", " --gradient_accumulation_steps=1 \\\n", " --gradient_checkpointing \\\n", " --max_grad_norm=1 \\\n", " --mixed_precision=\"fp16\" \\\n", " --max_train_steps=$TRAINING_STEPS \\\n", " --learning_rate=$LEARNING_RATE \\\n", " --lr_warmup_steps=0 \\\n", " --enable_xformers_memory_efficient_attention \\\n", " --dataloader_num_workers=1 \\\n", " --output_dir=$OUTPUT_DIR \\\n", " --lr_warmup_steps=0 \\\n", " --seed=1234 \\\n", " --checkpointing_steps=$CHECKPOINTING_STEPS \\\n", " --resume_from_checkpoint=\"latest\" \\\n", " --lr_scheduler='constant' \n", "\n", " pipe.unet.load_attn_procs(f\"./CustomModel/\")\n", " torch.cuda.empty_cache()" ] }, { "cell_type": "markdown", "metadata": { "id": "rglR5r5gahMv" }, "source": [ "##Results\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cellView": "form", "id": "kcf9aY6od89O" }, "outputs": [], "source": [ "# @title Generating results on the fine-tuned model\n", "\n", "# @markdown Check the box to generate images using the fine-tuned model.\n", "generate_finetuned_model_images = True # @param {type:\"boolean\"}\n", "\n", "if generate_finetuned_model_images:\n", " image_list = []\n", " pipe.unet.load_attn_procs(\"./CustomModel\")\n", " for step, prompt_list in enumerate(finetune_dataloader):\n", " image = pipe(\n", " prompt_list, num_images_per_prompt=num_images_per_prompt, width=resolution, height=resolution\n", " ).images\n", " image_list += image\n", " torch.cuda.empty_cache()\n", "\n", " grid = image_grid(image_list, len(prompts), num_images_per_prompt)\n", " grid.save(\"trained.png\")\n", " grid.show()" ] } ], "metadata": { "accelerator": "GPU", "colab": { "collapsed_sections": [ "BzmCovNKkwbi", "f4D64FI9pI38", "BWH9vc1kvhvC", "0RPeQGHUzUZp", "Ak1jArUL0eCi", "9U2P_PUN-5xX", "rglR5r5gahMv" ], "provenance": [] }, "gpuClass": "premium", "kernelspec": { "display_name": "deepanshu", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" }, "vscode": { "interpreter": { "hash": "cd95ac8400f934ca97b7c7125945f5f2a4616fc88b7668f808354bfbb29c51b3" } } }, "nbformat": 4, "nbformat_minor": 0 } ================================================ FILE: experimental/RAFT-diffusion/requirements.txt ================================================ accelerate==0.18.0 asttokens==2.2.1 backcall==0.2.0 bitsandbytes==0.37.2 certifi==2022.12.7 charset-normalizer==3.1.0 clip==1.0== cmake==3.26.1 comm==0.1.3 contourpy==1.0.7 cycler==0.11.0 debugpy==1.6.7 decorator==5.1.1 diffusers==0.14.0 executing==1.2.0 filelock==3.11.0 fonttools==4.39.3 ftfy==6.1.1 huggingface-hub==0.13.4 idna==3.4 importlib-metadata==6.2.0 importlib-resources==5.12.0 ipykernel==6.22.0 ipython==8.12.0 jedi==0.18.2 Jinja2==3.1.2 jupyter_client==8.1.0 jupyter_core==5.3.0 kiwisolver==1.4.4 lit==16.0.0 MarkupSafe==2.1.2 matplotlib==3.7.1 matplotlib-inline==0.1.6 mpmath==1.3.0 mypy-extensions==1.0.0 nest-asyncio==1.5.6 networkx==3.1 numpy==1.24.2 nvidia-cublas-cu11==11.10.3.66 nvidia-cuda-cupti-cu11==11.7.101 nvidia-cuda-nvrtc-cu11==11.7.99 nvidia-cuda-runtime-cu11==11.7.99 nvidia-cudnn-cu11==8.5.0.96 nvidia-cufft-cu11==10.9.0.58 nvidia-curand-cu11==10.2.10.91 nvidia-cusolver-cu11==11.4.0.1 nvidia-cusparse-cu11==11.7.4.91 nvidia-nccl-cu11==2.14.3 nvidia-nvtx-cu11==11.7.91 open-clip-torch==2.16.0 packaging==23.0 pandas==2.0.0 parso==0.8.3 pexpect==4.8.0 pickleshare==0.7.5 Pillow==9.5.0 pip==23.0.1 platformdirs==3.2.0 prompt-toolkit==3.0.38 protobuf==3.20.3 psutil==5.9.4 ptyprocess==0.7.0 pure-eval==0.2.2 Pygments==2.14.0 pyparsing==3.0.9 pyre-extensions==0.0.23 python-dateutil==2.8.2 pytz==2023.3 PyYAML==6.0 pyzmq==25.0.2 regex==2023.3.23 requests==2.28.2 sentencepiece==0.1.97 setuptools==65.6.3 six==1.16.0 stack-data==0.6.2 sympy==1.11.1 timm==0.6.13 tokenizers==0.13.3 torch==2.0.0 torchvision==0.15.1 tornado==6.2 tqdm==4.65.0 traitlets==5.9.0 transformers==4.27.4 triton==2.0.0 typing_extensions==4.5.0 typing-inspect==0.8.0 tzdata==2023.3 urllib3==1.26.15 wcwidth==0.2.6 wheel==0.38.4 xformers==0.0.18 zipp==3.15.0 ================================================ FILE: experimental/RAFT-diffusion/train_text_to_image_lora.py ================================================ # Copyright 2023 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Fine-tuning script for Stable Diffusion for text2image with support for LoRA.""" import argparse import logging import math import os import random from pathlib import Path from typing import Optional import datasets import diffusers import numpy as np import torch import torch.nn.functional as F import torch.utils.checkpoint import transformers from accelerate import Accelerator from accelerate.logging import get_logger from accelerate.utils import ProjectConfiguration, set_seed from datasets import load_dataset from diffusers import AutoencoderKL, DDPMScheduler, DiffusionPipeline, UNet2DConditionModel from diffusers.loaders import AttnProcsLayers from diffusers.models.attention_processor import LoRAAttnProcessor from diffusers.optimization import get_scheduler from diffusers.utils import check_min_version, is_wandb_available from diffusers.utils.import_utils import is_xformers_available from huggingface_hub import HfFolder, create_repo, upload_folder, whoami from packaging import version from torchvision import transforms from tqdm.auto import tqdm from transformers import CLIPTextModel, CLIPTokenizer # Will error if the minimal version of diffusers is not installed. Remove at your own risks. check_min_version("0.15.0.dev0") logger = get_logger(__name__, log_level="INFO") def save_model_card(repo_name, images=None, base_model=str, dataset_name=str, repo_folder=None): img_str = "" # for i, image in enumerate(images): # image.save(os.path.join(repo_folder, f"image_{i}.png")) # img_str += f"![img_{i}](./image_{i}.png)\n" yaml = f""" --- license: creativeml-openrail-m base_model: {base_model} tags: - stable-diffusion - stable-diffusion-diffusers - text-to-image - diffusers - lora inference: true --- """ model_card = f""" # LoRA text2image fine-tuning - {repo_name} These are LoRA adaption weights for {base_model}. The weights were fine-tuned on the {dataset_name} dataset. You can find some example images in the following. \n\n {img_str} """ with open(os.path.join(repo_folder, "README.md"), "w") as f: f.write(yaml + model_card) def parse_args(): parser = argparse.ArgumentParser(description="Simple example of a training script.") parser.add_argument( "--pretrained_model_name_or_path", type=str, default=None, required=True, help="Path to pretrained model or model identifier from huggingface.co/models.", ) parser.add_argument( "--revision", type=str, default=None, required=False, help="Revision of pretrained model identifier from huggingface.co/models.", ) parser.add_argument( "--dataset_name", type=str, default=None, help=( "The name of the Dataset (from the HuggingFace hub) to train on (could be your own, possibly private," " dataset). It can also be a path pointing to a local copy of a dataset in your filesystem," " or to a folder containing files that 🤗 Datasets can understand." ), ) parser.add_argument( "--dataset_config_name", type=str, default=None, help="The config of the Dataset, leave as None if there's only one config.", ) parser.add_argument( "--train_data_dir", type=str, default=None, help=( "A folder containing the training data. Folder contents must follow the structure described in" " https://huggingface.co/docs/datasets/image_dataset#imagefolder. In particular, a `metadata.jsonl` file" " must exist to provide the captions for the images. Ignored if `dataset_name` is specified." ), ) parser.add_argument( "--image_column", type=str, default="image", help="The column of the dataset containing an image." ) parser.add_argument( "--caption_column", type=str, default="text", help="The column of the dataset containing a caption or a list of captions.", ) parser.add_argument( "--validation_prompt", type=str, default=None, help="A prompt that is sampled during training for inference." ) parser.add_argument( "--num_validation_images", type=int, default=4, help="Number of images that should be generated during validation with `validation_prompt`.", ) parser.add_argument( "--validation_epochs", type=int, default=1, help=( "Run fine-tuning validation every X epochs. The validation process consists of running the prompt" " `args.validation_prompt` multiple times: `args.num_validation_images`." ), ) parser.add_argument( "--max_train_samples", type=int, default=None, help=( "For debugging purposes or quicker training, truncate the number of training examples to this value if set." ), ) parser.add_argument( "--output_dir", type=str, default="sd-model-finetuned-lora", help="The output directory where the model predictions and checkpoints will be written.", ) parser.add_argument( "--cache_dir", type=str, default=None, help="The directory where the downloaded models and datasets will be stored.", ) parser.add_argument("--seed", type=int, default=None, help="A seed for reproducible training.") parser.add_argument( "--resolution", type=int, default=512, help=( "The resolution for input images, all the images in the train/validation dataset will be resized to this" " resolution" ), ) parser.add_argument( "--center_crop", default=False, action="store_true", help=( "Whether to center crop the input images to the resolution. If not set, the images will be randomly" " cropped. The images will be resized to the resolution first before cropping." ), ) parser.add_argument( "--random_flip", action="store_true", help="whether to randomly flip images horizontally", ) parser.add_argument( "--train_batch_size", type=int, default=16, help="Batch size (per device) for the training dataloader." ) parser.add_argument("--num_train_epochs", type=int, default=100) parser.add_argument( "--max_train_steps", type=int, default=None, help="Total number of training steps to perform. If provided, overrides num_train_epochs.", ) parser.add_argument( "--gradient_accumulation_steps", type=int, default=1, help="Number of updates steps to accumulate before performing a backward/update pass.", ) parser.add_argument( "--gradient_checkpointing", action="store_true", help="Whether or not to use gradient checkpointing to save memory at the expense of slower backward pass.", ) parser.add_argument( "--learning_rate", type=float, default=1e-4, help="Initial learning rate (after the potential warmup period) to use.", ) parser.add_argument( "--scale_lr", action="store_true", default=False, help="Scale the learning rate by the number of GPUs, gradient accumulation steps, and batch size.", ) parser.add_argument( "--lr_scheduler", type=str, default="constant", help=( 'The scheduler type to use. Choose between ["linear", "cosine", "cosine_with_restarts", "polynomial",' ' "constant", "constant_with_warmup"]' ), ) parser.add_argument( "--lr_warmup_steps", type=int, default=500, help="Number of steps for the warmup in the lr scheduler." ) parser.add_argument( "--use_8bit_adam", action="store_true", help="Whether or not to use 8-bit Adam from bitsandbytes." ) parser.add_argument( "--allow_tf32", action="store_true", help=( "Whether or not to allow TF32 on Ampere GPUs. Can be used to speed up training. For more information, see" " https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices" ), ) parser.add_argument( "--dataloader_num_workers", type=int, default=0, help=( "Number of subprocesses to use for data loading. 0 means that the data will be loaded in the main process." ), ) parser.add_argument("--adam_beta1", type=float, default=0.9, help="The beta1 parameter for the Adam optimizer.") parser.add_argument("--adam_beta2", type=float, default=0.999, help="The beta2 parameter for the Adam optimizer.") parser.add_argument("--adam_weight_decay", type=float, default=1e-2, help="Weight decay to use.") parser.add_argument("--adam_epsilon", type=float, default=1e-08, help="Epsilon value for the Adam optimizer") parser.add_argument("--max_grad_norm", default=1.0, type=float, help="Max gradient norm.") parser.add_argument("--push_to_hub", action="store_true", help="Whether or not to push the model to the Hub.") parser.add_argument("--hub_token", type=str, default=None, help="The token to use to push to the Model Hub.") parser.add_argument( "--hub_model_id", type=str, default=None, help="The name of the repository to keep in sync with the local `output_dir`.", ) parser.add_argument( "--project_dir", type=str, default="logs", help=( "[TensorBoard](https://www.tensorflow.org/tensorboard) log directory. Will default to" " *output_dir/runs/**CURRENT_DATETIME_HOSTNAME***." ), ) parser.add_argument( "--mixed_precision", type=str, default=None, choices=["no", "fp16", "bf16"], help=( "Whether to use mixed precision. Choose between fp16 and bf16 (bfloat16). Bf16 requires PyTorch >=" " 1.10.and an Nvidia Ampere GPU. Default to the value of accelerate config of the current system or the" " flag passed with the `accelerate.launch` command. Use this argument to override the accelerate config." ), ) parser.add_argument( "--report_to", type=str, default="tensorboard", help=( 'The integration to report the results and logs to. Supported platforms are `"tensorboard"`' ' (default), `"wandb"` and `"comet_ml"`. Use `"all"` to report to all integrations.' ), ) parser.add_argument("--local_rank", type=int, default=-1, help="For distributed training: local_rank") parser.add_argument( "--checkpointing_steps", type=int, default=500, help=( "Save a checkpoint of the training state every X updates. These checkpoints are only suitable for resuming" " training using `--resume_from_checkpoint`." ), ) parser.add_argument( "--checkpoints_total_limit", type=int, default=None, help=( "Max number of checkpoints to store. Passed as `total_limit` to the `Accelerator` `ProjectConfiguration`." " See Accelerator::save_state https://huggingface.co/docs/accelerate/package_reference/accelerator#accelerate.Accelerator.save_state" " for more docs" ), ) parser.add_argument( "--resume_from_checkpoint", type=str, default=None, help=( "Whether training should be resumed from a previous checkpoint. Use a path saved by" ' `--checkpointing_steps`, or `"latest"` to automatically select the last available checkpoint.' ), ) parser.add_argument( "--enable_xformers_memory_efficient_attention", action="store_true", help="Whether or not to use xformers." ) args = parser.parse_args() env_local_rank = int(os.environ.get("LOCAL_RANK", -1)) if env_local_rank != -1 and env_local_rank != args.local_rank: args.local_rank = env_local_rank # Sanity checks if args.dataset_name is None and args.train_data_dir is None: raise ValueError("Need either a dataset name or a training folder.") return args def get_full_repo_name(model_id: str, organization: Optional[str] = None, token: Optional[str] = None): if token is None: token = HfFolder.get_token() if organization is None: username = whoami(token)["name"] return f"{username}/{model_id}" else: return f"{organization}/{model_id}" DATASET_NAME_MAPPING = { "lambdalabs/pokemon-blip-captions": ("image", "text"), } def main(): args = parse_args() project_dir = os.path.join(args.output_dir, args.project_dir) accelerator_project_config = ProjectConfiguration(total_limit=args.checkpoints_total_limit) accelerator = Accelerator( gradient_accumulation_steps=args.gradient_accumulation_steps, mixed_precision=args.mixed_precision, log_with=args.report_to, project_dir=project_dir, project_config=accelerator_project_config, ) if args.report_to == "wandb": if not is_wandb_available(): raise ImportError("Make sure to install wandb if you want to use it for logging during training.") import wandb # Make one log on every process with the configuration for debugging. logging.basicConfig( format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%m/%d/%Y %H:%M:%S", level=logging.INFO, ) logger.info(accelerator.state, main_process_only=False) if accelerator.is_local_main_process: datasets.utils.logging.set_verbosity_warning() transformers.utils.logging.set_verbosity_warning() diffusers.utils.logging.set_verbosity_info() else: datasets.utils.logging.set_verbosity_error() transformers.utils.logging.set_verbosity_error() diffusers.utils.logging.set_verbosity_error() # If passed along, set the training seed now. if args.seed is not None: set_seed(args.seed) # Handle the repository creation if accelerator.is_main_process: if args.output_dir is not None: os.makedirs(args.output_dir, exist_ok=True) if args.push_to_hub: repo_id = create_repo( repo_id=args.hub_model_id or Path(args.output_dir).name, exist_ok=True, token=args.hub_token ).repo_id # Load scheduler, tokenizer and models. noise_scheduler = DDPMScheduler.from_pretrained(args.pretrained_model_name_or_path, subfolder="scheduler") tokenizer = CLIPTokenizer.from_pretrained( args.pretrained_model_name_or_path, subfolder="tokenizer", revision=args.revision ) text_encoder = CLIPTextModel.from_pretrained( args.pretrained_model_name_or_path, subfolder="text_encoder", revision=args.revision ) vae = AutoencoderKL.from_pretrained(args.pretrained_model_name_or_path, subfolder="vae", revision=args.revision) unet = UNet2DConditionModel.from_pretrained( args.pretrained_model_name_or_path, subfolder="unet", revision=args.revision ) # freeze parameters of models to save more memory unet.requires_grad_(False) vae.requires_grad_(False) text_encoder.requires_grad_(False) # For mixed precision training we cast the text_encoder and vae weights to half-precision # as these models are only used for inference, keeping weights in full precision is not required. weight_dtype = torch.float32 if accelerator.mixed_precision == "fp16": weight_dtype = torch.float16 elif accelerator.mixed_precision == "bf16": weight_dtype = torch.bfloat16 # Move unet, vae and text_encoder to device and cast to weight_dtype unet.to(accelerator.device, dtype=weight_dtype) vae.to(accelerator.device, dtype=weight_dtype) text_encoder.to(accelerator.device, dtype=weight_dtype) # now we will add new LoRA weights to the attention layers # It's important to realize here how many attention weights will be added and of which sizes # The sizes of the attention layers consist only of two different variables: # 1) - the "hidden_size", which is increased according to `unet.config.block_out_channels`. # 2) - the "cross attention size", which is set to `unet.config.cross_attention_dim`. # Let's first see how many attention processors we will have to set. # For Stable Diffusion, it should be equal to: # - down blocks (2x attention layers) * (2x transformer layers) * (3x down blocks) = 12 # - mid blocks (2x attention layers) * (1x transformer layers) * (1x mid blocks) = 2 # - up blocks (2x attention layers) * (3x transformer layers) * (3x down blocks) = 18 # => 32 layers # Set correct lora layers lora_attn_procs = {} for name in unet.attn_processors.keys(): cross_attention_dim = None if name.endswith("attn1.processor") else unet.config.cross_attention_dim if name.startswith("mid_block"): hidden_size = unet.config.block_out_channels[-1] elif name.startswith("up_blocks"): block_id = int(name[len("up_blocks.")]) hidden_size = list(reversed(unet.config.block_out_channels))[block_id] elif name.startswith("down_blocks"): block_id = int(name[len("down_blocks.")]) hidden_size = unet.config.block_out_channels[block_id] lora_attn_procs[name] = LoRAAttnProcessor(hidden_size=hidden_size, cross_attention_dim=cross_attention_dim) unet.set_attn_processor(lora_attn_procs) if args.enable_xformers_memory_efficient_attention: if is_xformers_available(): import xformers xformers_version = version.parse(xformers.__version__) if xformers_version == version.parse("0.0.16"): logger.warning( "xFormers 0.0.16 cannot be used for training in some GPUs. If you observe problems during " "training, please update xFormers to at least 0.0.17. " "See https://huggingface.co/docs/diffusers/main/en/optimization/xformers for more details." ) unet.enable_xformers_memory_efficient_attention() else: raise ValueError("xformers is not available. Make sure it is installed correctly") lora_layers = AttnProcsLayers(unet.attn_processors) # Enable TF32 for faster training on Ampere GPUs, # cf https://pytorch.org/docs/stable/notes/cuda.html#tensorfloat-32-tf32-on-ampere-devices if args.allow_tf32: torch.backends.cuda.matmul.allow_tf32 = True if args.scale_lr: args.learning_rate = ( args.learning_rate * args.gradient_accumulation_steps * args.train_batch_size * accelerator.num_processes ) # Initialize the optimizer if args.use_8bit_adam: try: import bitsandbytes as bnb except ImportError as ex: raise ImportError( "Please install bitsandbytes to use 8-bit Adam. You can do so by running `pip install bitsandbytes`" ) from ex optimizer_cls = bnb.optim.AdamW8bit else: optimizer_cls = torch.optim.AdamW optimizer = optimizer_cls( lora_layers.parameters(), lr=args.learning_rate, betas=(args.adam_beta1, args.adam_beta2), weight_decay=args.adam_weight_decay, eps=args.adam_epsilon, ) # Get the datasets: you can either provide your own training and evaluation files (see below) # or specify a Dataset from the hub (the dataset will be downloaded automatically from the datasets Hub). # In distributed training, the load_dataset function guarantees that only one local process can concurrently # download the dataset. if args.dataset_name is not None: # Downloading and loading a dataset from the hub. dataset = load_dataset( args.dataset_name, args.dataset_config_name, cache_dir=args.cache_dir, ) else: data_files = {} if args.train_data_dir is not None: data_files["train"] = os.path.join(args.train_data_dir, "**") dataset = load_dataset( "imagefolder", data_files=data_files, cache_dir=args.cache_dir, ) # See more about loading custom images at # https://huggingface.co/docs/datasets/v2.4.0/en/image_load#imagefolder # Preprocessing the datasets. # We need to tokenize inputs and targets. column_names = dataset["train"].column_names # 6. Get the column names for input/target. dataset_columns = DATASET_NAME_MAPPING.get(args.dataset_name, None) if args.image_column is None: image_column = dataset_columns[0] if dataset_columns is not None else column_names[0] else: image_column = args.image_column if image_column not in column_names: raise ValueError( f"--image_column' value '{args.image_column}' needs to be one of: {', '.join(column_names)}" ) if args.caption_column is None: caption_column = dataset_columns[1] if dataset_columns is not None else column_names[1] else: caption_column = args.caption_column if caption_column not in column_names: raise ValueError( f"--caption_column' value '{args.caption_column}' needs to be one of: {', '.join(column_names)}" ) # Preprocessing the datasets. # We need to tokenize input captions and transform the images. def tokenize_captions(examples, is_train=True): captions = [] for caption in examples[caption_column]: if isinstance(caption, str): captions.append(caption) elif isinstance(caption, (list, np.ndarray)): # take a random caption if there are multiple captions.append(random.choice(caption) if is_train else caption[0]) else: raise ValueError( f"Caption column `{caption_column}` should contain either strings or lists of strings." ) inputs = tokenizer( captions, max_length=tokenizer.model_max_length, padding="max_length", truncation=True, return_tensors="pt" ) return inputs.input_ids # Preprocessing the datasets. train_transforms = transforms.Compose( [ transforms.Resize(args.resolution, interpolation=transforms.InterpolationMode.BILINEAR), transforms.CenterCrop(args.resolution) if args.center_crop else transforms.RandomCrop(args.resolution), transforms.RandomHorizontalFlip() if args.random_flip else transforms.Lambda(lambda x: x), transforms.ToTensor(), transforms.Normalize([0.5], [0.5]), ] ) def preprocess_train(examples): images = [image.convert("RGB") for image in examples[image_column]] examples["pixel_values"] = [train_transforms(image) for image in images] examples["input_ids"] = tokenize_captions(examples) return examples with accelerator.main_process_first(): if args.max_train_samples is not None: dataset["train"] = dataset["train"].shuffle(seed=args.seed).select(range(args.max_train_samples)) # Set the training transforms train_dataset = dataset["train"].with_transform(preprocess_train) def collate_fn(examples): pixel_values = torch.stack([example["pixel_values"] for example in examples]) pixel_values = pixel_values.to(memory_format=torch.contiguous_format).float() input_ids = torch.stack([example["input_ids"] for example in examples]) return {"pixel_values": pixel_values, "input_ids": input_ids} # DataLoaders creation: train_dataloader = torch.utils.data.DataLoader( train_dataset, shuffle=False, collate_fn=collate_fn, batch_size=args.train_batch_size, num_workers=args.dataloader_num_workers, ) # Scheduler and math around the number of training steps. overrode_max_train_steps = False num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps) if args.max_train_steps is None: args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch overrode_max_train_steps = True lr_scheduler = get_scheduler( args.lr_scheduler, optimizer=optimizer, num_warmup_steps=args.lr_warmup_steps * args.gradient_accumulation_steps, num_training_steps=args.max_train_steps * args.gradient_accumulation_steps, ) # Prepare everything with our `accelerator`. lora_layers, optimizer, train_dataloader, lr_scheduler = accelerator.prepare( lora_layers, optimizer, train_dataloader, lr_scheduler ) # We need to recalculate our total training steps as the size of the training dataloader may have changed. num_update_steps_per_epoch = math.ceil(len(train_dataloader) / args.gradient_accumulation_steps) if overrode_max_train_steps: args.max_train_steps = args.num_train_epochs * num_update_steps_per_epoch # Afterwards we recalculate our number of training epochs args.num_train_epochs = math.ceil(args.max_train_steps / num_update_steps_per_epoch) # We need to initialize the trackers we use, and also store our configuration. # The trackers initializes automatically on the main process. if accelerator.is_main_process: accelerator.init_trackers("text2image-fine-tune", config=vars(args)) # Train! total_batch_size = args.train_batch_size * accelerator.num_processes * args.gradient_accumulation_steps logger.info("***** Running training *****") logger.info(f" Num examples = {len(train_dataset)}") logger.info(f" Num Epochs = {args.num_train_epochs}") logger.info(f" Instantaneous batch size per device = {args.train_batch_size}") logger.info(f" Total train batch size (w. parallel, distributed & accumulation) = {total_batch_size}") logger.info(f" Gradient Accumulation steps = {args.gradient_accumulation_steps}") logger.info(f" Total optimization steps = {args.max_train_steps}") global_step = 0 first_epoch = 0 # Potentially load in the weights and states from a previous save if args.resume_from_checkpoint: if args.resume_from_checkpoint != "latest": path = os.path.basename(args.resume_from_checkpoint) else: # Get the most recent checkpoint dirs = os.listdir(args.output_dir) dirs = [d for d in dirs if d.startswith("checkpoint")] dirs = sorted(dirs, key=lambda x: int(x.split("-")[1])) path = dirs[-1] if len(dirs) > 0 else None if path is None: accelerator.print( f"Checkpoint '{args.resume_from_checkpoint}' does not exist. Starting a new training run." ) args.resume_from_checkpoint = None else: accelerator.print(f"Resuming from checkpoint {path}") accelerator.load_state(os.path.join(args.output_dir, path)) global_step = int(path.split("-")[1]) resume_global_step = global_step * args.gradient_accumulation_steps first_epoch = global_step // num_update_steps_per_epoch resume_step = resume_global_step % (num_update_steps_per_epoch * args.gradient_accumulation_steps) # Only show the progress bar once on each machine. progress_bar = tqdm(range(global_step, args.max_train_steps), disable=not accelerator.is_local_main_process) progress_bar.set_description("Steps") for epoch in range(first_epoch, args.num_train_epochs): unet.train() train_loss = 0.0 for step, batch in enumerate(train_dataloader): # Skip steps until we reach the resumed step if args.resume_from_checkpoint and epoch == first_epoch and step < resume_step: if step % args.gradient_accumulation_steps == 0: progress_bar.update(1) continue with accelerator.accumulate(unet): # Convert images to latent space latents = vae.encode(batch["pixel_values"].to(dtype=weight_dtype)).latent_dist.sample() latents = latents * vae.config.scaling_factor # Sample noise that we'll add to the latents noise = torch.randn_like(latents) bsz = latents.shape[0] # Sample a random timestep for each image timesteps = torch.randint(0, noise_scheduler.num_train_timesteps, (bsz,), device=latents.device) timesteps = timesteps.long() # Add noise to the latents according to the noise magnitude at each timestep # (this is the forward diffusion process) noisy_latents = noise_scheduler.add_noise(latents, noise, timesteps) # Get the text embedding for conditioning encoder_hidden_states = text_encoder(batch["input_ids"])[0] # Get the target for loss depending on the prediction type if noise_scheduler.config.prediction_type == "epsilon": target = noise elif noise_scheduler.config.prediction_type == "v_prediction": target = noise_scheduler.get_velocity(latents, noise, timesteps) else: raise ValueError(f"Unknown prediction type {noise_scheduler.config.prediction_type}") # Predict the noise residual and compute loss model_pred = unet(noisy_latents, timesteps, encoder_hidden_states).sample loss = F.mse_loss(model_pred.float(), target.float(), reduction="mean") # Gather the losses across all processes for logging (if we use distributed training). avg_loss = accelerator.gather(loss.repeat(args.train_batch_size)).mean() train_loss += avg_loss.item() / args.gradient_accumulation_steps # logger.info(loss) # Backpropagate accelerator.backward(loss) if accelerator.sync_gradients: params_to_clip = lora_layers.parameters() accelerator.clip_grad_norm_(params_to_clip, args.max_grad_norm) optimizer.step() lr_scheduler.step() optimizer.zero_grad() # Checks if the accelerator has performed an optimization step behind the scenes if accelerator.sync_gradients: progress_bar.update(1) global_step += 1 accelerator.log({"train_loss": train_loss}, step=global_step) train_loss = 0.0 if global_step % args.checkpointing_steps == 0: if accelerator.is_main_process: save_path = os.path.join(args.output_dir, f"checkpoint-{global_step}") accelerator.save_state(save_path) logger.info(f"Saved state to {save_path}") logs = {"step_loss": loss.detach().item(), "lr": lr_scheduler.get_last_lr()[0]} progress_bar.set_postfix(**logs) if global_step >= args.max_train_steps: break if accelerator.is_main_process: if args.validation_prompt is not None and epoch % args.validation_epochs == 0: logger.info( f"Running validation... \n Generating {args.num_validation_images} images with prompt:" f" {args.validation_prompt}." ) # create pipeline pipeline = DiffusionPipeline.from_pretrained( args.pretrained_model_name_or_path, unet=accelerator.unwrap_model(unet), revision=args.revision, torch_dtype=weight_dtype, ) pipeline = pipeline.to(accelerator.device) pipeline.set_progress_bar_config(disable=True) # run inference generator = torch.Generator(device=accelerator.device).manual_seed(args.seed) images = [] for _ in range(args.num_validation_images): images.append( pipeline(args.validation_prompt, num_inference_steps=50, generator=generator).images[0] ) for tracker in accelerator.trackers: if tracker.name == "tensorboard": np_images = np.stack([np.asarray(img) for img in images]) tracker.writer.add_images("validation", np_images, epoch, dataformats="NHWC") if tracker.name == "wandb": tracker.log( { "validation": [ wandb.Image(image, caption=f"{i}: {args.validation_prompt}") for i, image in enumerate(images) ] } ) del pipeline torch.cuda.empty_cache() # Save the lora layers accelerator.wait_for_everyone() if accelerator.is_main_process: unet = unet.to(torch.float32) unet.save_attn_procs(args.output_dir) if args.push_to_hub: save_model_card( repo_id, base_model=args.pretrained_model_name_or_path, dataset_name=args.dataset_name, repo_folder=args.output_dir, ) upload_folder( repo_id=repo_id, folder_path=args.output_dir, commit_message="End of training", ignore_patterns=["step_*", "epoch_*"], ) # # Final inference # Load previous pipeline # pipeline = DiffusionPipeline.from_pretrained( # args.pretrained_model_name_or_path, revision=args.revision, torch_dtype=weight_dtype # ) # pipeline = pipeline.to(accelerator.device) # # load attention processors # pipeline.unet.load_attn_procs(args.output_dir) # run inference # generator = torch.Generator(device=accelerator.device).manual_seed(args.seed) # images = [] # for _ in range(args.num_validation_images): # images.append(pipeline(args.validation_prompt, num_inference_steps=30, generator=generator).images[0]) # for _ in range(1): # images.append(pipeline('a photo of cat').images[0]) # images[0].save('/root/autodl-tmp/deepanshu/output.png') # if accelerator.is_main_process: # for tracker in accelerator.trackers: # if tracker.name == "tensorboard": # np_images = np.stack([np.asarray(img) for img in images]) # tracker.writer.add_images("test", np_images, epoch, dataformats="NHWC") # if tracker.name == "wandb": # tracker.log( # { # "test": [ # wandb.Image(image, caption=f"{i}: {args.validation_prompt}") # for i, image in enumerate(images) # ] # } # ) accelerator.end_training() if __name__ == "__main__": main() ================================================ FILE: pyproject.toml ================================================ [build-system] requires = ["setuptools >= 64"] build-backend = "setuptools.build_meta" # ------------------------------- # tool.ruff - Linting configuration # ------------------------------- [tool.ruff] # Note: While the formatter will attempt to format lines such that they remain within the line-length, # it isn't a hard upper bound, and formatted lines may exceed the line-length. target-version = "py39" line-length = 120 exclude = [ "tests/utils/test_data_utils.py", "tests/pipeline/test_memory_safe_vllm_inferencer.py", "tests/models/test_hf_decoder_model.py", "src/lmflow/pipeline/utils/raft_trainer.py", "src/lmflow/pipeline/raft_aligner.py", "examples/chatbot_gradio.py", ] [tool.ruff.lint] isort = {known-first-party = ["lmflow"]} select = [ # pycodestyle "E", # Pyflakes "F", # pyupgrade "UP", # flake8-bugbear "B", # isort "I", "G", ] ignore = [ # star imports "F405", "F403", # lambda expression assignment "E731", # Loop control variable not used within loop body "B007", # f-string format "UP032", # Can remove once 3.10+ is the minimum Python version "UP007", # `.log()` statement uses f-string "G004", ] [tool.ruff.lint.per-file-ignores] "tests/**/*.py" = ["F841"] "src/lmflow/utils/conversation_template/*.py" = ["E501"] "src/lmflow/utils/llava_conversation_lib.py" = ["E501"] "src/lmflow/utils/constants.py" = ["E501"] ================================================ FILE: requirements.txt ================================================ packaging numpy datasets==3.6.0 tokenizers>=0.13.3 peft>=0.10.0 torch>=2.0.1 wandb sentencepiece transformers>=4.31.0 cpm_kernels==1.0.11 evaluate==0.4.0 bitsandbytes>=0.40.0 pydantic accelerate>=0.27.2 einops>=0.6.1 tensordict ================================================ FILE: scripts/archive/bash.sh ================================================ #!/bin/bash # # Shell and python scripts goes here ================================================ FILE: scripts/archive/convert_llama_weights_to_hf.py ================================================ # Copyright 2022 EleutherAI and The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import argparse import gc import json import math import os import shutil import torch from transformers import LlamaConfig, LlamaForCausalLM """ Sample usage: ``` python src/transformers/models/llama/convert_llama_weights_to_hf.py \ --input_dir /path/to/downloaded/llama/weights --model_size 7B --output_dir /output/path ``` Thereafter, models can be loaded via: ```py from transformers import LlamaForCausalLM, LlamaForTokenizer model = LlamaForCausalLM.from_pretrained("/output/path") tokenizer = LlamaTokenizer.from_pretrained("/output/path") ``` Important note: you need to be able to host the whole model in RAM to execute this script (even if the biggest versions come in several checkpoints they each contain a part of each weight of the model, so we need to load them all in RAM). """ INTERMEDIATE_SIZE_MAP = { "7B": 11008, "13B": 13824, "33B": 17920, "65B": 22016, } NUM_SHARDS = { "7B": 1, "13B": 2, "33B": 4, "65B": 8, } def compute_intermediate_size(n): return int(math.ceil(n * 8 / 3) + 255) // 256 * 256 def read_json(path): with open(path) as f: return json.load(f) def write_json(text, path): with open(path, "w") as f: json.dump(text, f) def write_model(model_path, input_base_path, model_size): os.makedirs(model_path, exist_ok=True) tmp_model_path = os.path.join(model_path, "tmp") os.makedirs(tmp_model_path, exist_ok=True) params = read_json(os.path.join(input_base_path, "params.json")) num_shards = NUM_SHARDS[model_size] n_layers = params["n_layers"] n_heads = params["n_heads"] n_heads_per_shard = n_heads // num_shards dim = params["dim"] dims_per_head = dim // n_heads base = 10000.0 inv_freq = 1.0 / (base ** (torch.arange(0, dims_per_head, 2).float() / dims_per_head)) # permute for sliced rotary def permute(w): return w.view(n_heads, dim // n_heads // 2, 2, dim).transpose(1, 2).reshape(dim, dim) print(f"Fetching all parameters from the checkpoint at {input_base_path}.") # Load weights if model_size == "7B": # Not shared # (The sharded implementation would also work, but this is simpler.) loaded = torch.load(os.path.join(input_base_path, "consolidated.00.pth"), map_location="cpu") else: # Sharded loaded = [ torch.load(os.path.join(input_base_path, f"consolidated.{i:02d}.pth"), map_location="cpu") for i in range(num_shards) ] param_count = 0 index_dict = {"weight_map": {}} for layer_i in range(n_layers): filename = f"pytorch_model-{layer_i + 1}-of-{n_layers + 1}.bin" if model_size == "7B": # Unsharded state_dict = { f"model.layers.{layer_i}.self_attn.q_proj.weight": permute( loaded[f"layers.{layer_i}.attention.wq.weight"] ), f"model.layers.{layer_i}.self_attn.k_proj.weight": permute( loaded[f"layers.{layer_i}.attention.wk.weight"] ), f"model.layers.{layer_i}.self_attn.v_proj.weight": loaded[f"layers.{layer_i}.attention.wv.weight"], f"model.layers.{layer_i}.self_attn.o_proj.weight": loaded[f"layers.{layer_i}.attention.wo.weight"], f"model.layers.{layer_i}.mlp.gate_proj.weight": loaded[f"layers.{layer_i}.feed_forward.w1.weight"], f"model.layers.{layer_i}.mlp.down_proj.weight": loaded[f"layers.{layer_i}.feed_forward.w2.weight"], f"model.layers.{layer_i}.mlp.up_proj.weight": loaded[f"layers.{layer_i}.feed_forward.w3.weight"], f"model.layers.{layer_i}.input_layernorm.weight": loaded[f"layers.{layer_i}.attention_norm.weight"], f"model.layers.{layer_i}.post_attention_layernorm.weight": loaded[f"layers.{layer_i}.ffn_norm.weight"], } else: # Sharded # Note that in the 13B checkpoint, not cloning the two following weights will result in the checkpoint # becoming 37GB instead of 26GB for some reason. state_dict = { f"model.layers.{layer_i}.input_layernorm.weight": loaded[0][ f"layers.{layer_i}.attention_norm.weight" ].clone(), f"model.layers.{layer_i}.post_attention_layernorm.weight": loaded[0][ f"layers.{layer_i}.ffn_norm.weight" ].clone(), } state_dict[f"model.layers.{layer_i}.self_attn.q_proj.weight"] = permute( torch.cat( [ loaded[i][f"layers.{layer_i}.attention.wq.weight"].view(n_heads_per_shard, dims_per_head, dim) for i in range(num_shards) ], dim=0, ).reshape(dim, dim) ) state_dict[f"model.layers.{layer_i}.self_attn.k_proj.weight"] = permute( torch.cat( [ loaded[i][f"layers.{layer_i}.attention.wk.weight"].view(n_heads_per_shard, dims_per_head, dim) for i in range(num_shards) ], dim=0, ).reshape(dim, dim) ) state_dict[f"model.layers.{layer_i}.self_attn.v_proj.weight"] = torch.cat( [ loaded[i][f"layers.{layer_i}.attention.wv.weight"].view(n_heads_per_shard, dims_per_head, dim) for i in range(num_shards) ], dim=0, ).reshape(dim, dim) state_dict[f"model.layers.{layer_i}.self_attn.o_proj.weight"] = torch.cat( [loaded[i][f"layers.{layer_i}.attention.wo.weight"] for i in range(num_shards)], dim=1 ) state_dict[f"model.layers.{layer_i}.mlp.gate_proj.weight"] = torch.cat( [loaded[i][f"layers.{layer_i}.feed_forward.w1.weight"] for i in range(num_shards)], dim=0 ) state_dict[f"model.layers.{layer_i}.mlp.down_proj.weight"] = torch.cat( [loaded[i][f"layers.{layer_i}.feed_forward.w2.weight"] for i in range(num_shards)], dim=1 ) state_dict[f"model.layers.{layer_i}.mlp.up_proj.weight"] = torch.cat( [loaded[i][f"layers.{layer_i}.feed_forward.w3.weight"] for i in range(num_shards)], dim=0 ) state_dict[f"model.layers.{layer_i}.self_attn.rotary_emb.inv_freq"] = inv_freq for k, v in state_dict.items(): index_dict["weight_map"][k] = filename param_count += v.numel() torch.save(state_dict, os.path.join(tmp_model_path, filename)) filename = f"pytorch_model-{n_layers + 1}-of-{n_layers + 1}.bin" if model_size == "7B": # Unsharded state_dict = { "model.embed_tokens.weight": loaded["tok_embeddings.weight"], "model.norm.weight": loaded["norm.weight"], "lm_head.weight": loaded["output.weight"], } else: state_dict = { "model.norm.weight": loaded[0]["norm.weight"], "model.embed_tokens.weight": torch.cat( [loaded[i]["tok_embeddings.weight"] for i in range(num_shards)], dim=1 ), "lm_head.weight": torch.cat([loaded[i]["output.weight"] for i in range(num_shards)], dim=0), } for k, v in state_dict.items(): index_dict["weight_map"][k] = filename param_count += v.numel() torch.save(state_dict, os.path.join(tmp_model_path, filename)) # Write configs index_dict["metadata"] = {"total_size": param_count * 2} write_json(index_dict, os.path.join(tmp_model_path, "pytorch_model.bin.index.json")) config = LlamaConfig( hidden_size=dim, intermediate_size=compute_intermediate_size(dim), num_attention_heads=params["n_heads"], num_hidden_layers=params["n_layers"], rms_norm_eps=params["norm_eps"], ) config.save_pretrained(tmp_model_path) # Make space so we can load the model properly now. del state_dict del loaded gc.collect() print("Loading the checkpoint in a Llama model.") model = LlamaForCausalLM.from_pretrained(tmp_model_path, torch_dtype=torch.float16, low_cpu_mem_usage=True) # Avoid saving this as part of the config. del model.config._name_or_path print("Saving in the Transformers format.") model.save_pretrained(model_path) shutil.rmtree(tmp_model_path) def write_tokenizer(tokenizer_path, input_tokenizer_path): print(f"Fetching the tokenizer from {input_tokenizer_path}.") os.makedirs(tokenizer_path, exist_ok=True) write_json({}, os.path.join(tokenizer_path, "special_tokens_map.json")) write_json( { "bos_token": "", "eos_token": "", "model_max_length": int(1e30), "tokenizer_class": "LlamaTokenizer", "unk_token": "", }, os.path.join(tokenizer_path, "tokenizer_config.json"), ) shutil.copyfile(input_tokenizer_path, os.path.join(tokenizer_path, "tokenizer.model")) def main(): parser = argparse.ArgumentParser() parser.add_argument( "--input_dir", help="Location of LLaMA weights, which contains tokenizer.model and model folders", ) parser.add_argument( "--model_size", choices=["7B", "13B", "33B", "65B", "tokenizer_only"], ) parser.add_argument( "--output_dir", help="Location to write HF model and tokenizer", ) args = parser.parse_args() if args.model_size != "tokenizer_only": write_model( model_path=args.output_dir, input_base_path=os.path.join(args.input_dir, args.model_size), model_size=args.model_size, ) write_tokenizer( tokenizer_path=args.output_dir, input_tokenizer_path=os.path.join(args.input_dir, "tokenizer.model"), ) if __name__ == "__main__": main() ================================================ FILE: scripts/archive/download_model.sh ================================================ #!/bin/bash function main() { public_server="http://lmflow.org:5000" if [ $# -lt 1 -o "$1" = "-h" -o "$1" = "--help" ]; then echo "Usage: bash $(basename $0) model_name" echo "Example: bash $(basename $0) instruction_ckpt" echo "Example: bash $(basename $0) all" fi if [ "$1" = "llama7b-lora-medical" -o "$1" = "medical_ckpt" -o "$1" = "all" ]; then echo "downloading llama7b-lora-medical.tar.gz" filename='llama7b-lora-medical.tar.gz' wget ${public_server}/${filename} tar zxvf ${filename} rm ${filename} fi if [ "$1" = "llama13b-lora-medical" -o "$1" = "medical_ckpt" -o "$1" = "all" ]; then echo "downloading llama13b-lora-medical.tar.gz" filename='llama13b-lora-medical.tar.gz' wget ${public_server}/${filename} tar zxvf ${filename} rm ${filename} fi if [ "$1" = "llama30b-lora-medical" -o "$1" = "medical_ckpt" -o "$1" = "all" ]; then echo "downloading llama30b-lora-medical.tar.gz" filename='llama30b-lora-medical.tar.gz' wget ${public_server}/${filename} tar zxvf ${filename} rm ${filename} fi if [ "$1" = "llama7b-lora-170k" -o "$1" = "instruction_ckpt" -o "$1" = "all" ]; then echo "downloading llama7b-lora-170k.tar.gz" filename='llama7b-lora-170k.tar.gz' wget ${public_server}/${filename} tar zxvf ${filename} rm ${filename} fi if [ "$1" = "llama7b-lora-380k" -o "$1" = "instruction_ckpt" -o "$1" = "all" ]; then echo "downloading llama7b-lora-380k.tar.gz" filename='llama7b-lora-380k.tar.gz' wget ${public_server}/${filename} tar zxvf ${filename} rm ${filename} fi if [ "$1" = "llama13b-lora-170k" -o "$1" = "instruction_ckpt" -o "$1" = "all" ]; then echo "downloading llama13b-lora-170k.tar.gz" filename='llama13b-lora-170k.tar.gz' wget ${public_server}/${filename} tar zxvf ${filename} rm ${filename} fi if [ "$1" = "llama13b-lora-380k" -o "$1" = "instruction_ckpt" -o "$1" = "all" ]; then echo "downloading llama13b-lora-380k.tar.gz" filename='llama13b-lora-380k.tar.gz' wget ${public_server}/${filename} tar zxvf ${filename} rm ${filename} fi if [ "$1" = "llama30b-lora-170k" -o "$1" = "instruction_ckpt" -o "$1" = "all" ]; then echo "downloading llama30b-lora-170k.tar.gz" filename='llama30b-lora-170k.tar.gz' wget ${public_server}/${filename} tar zxvf ${filename} rm ${filename} fi if [ "$1" = "llama7b-lora-movie-reviewer" -o "$1" = "raft_ckpt" -o "$1" = "all" ]; then echo "downloading llama7b-lora-movie-reviewer" filename='llama7b-lora-movie-reviewer.tar.gz' wget ${public_server}/${filename} tar zxvf ${filename} rm ${filename} fi if [ "$1" = "cockatoo-7b" -o "$1" = "all" ]; then echo "downloading cockatoo-7b" filename='cockatoo-7b.tar.gz' wget ${public_server}/${filename} tar zxvf ${filename} rm ${filename} fi if [ "$1" = "parakeets-2.7b" -o "$1" = "all" ]; then echo "downloading parakeets-2.7b" filename='parakeets-2.7b.tar.gz' wget ${public_server}/${filename} tar zxvf ${filename} rm ${filename} fi if [ "$1" = "robin-7b" -o "$1" = "all" ]; then echo "downloading robin-7b" filename='robin-7b-v2-delta.tar.gz' wget ${public_server}/${filename} tar zxvf ${filename} rm ${filename} fi if [ "$1" = "minigpt4_7b" -o "$1" = "all" ]; then echo "downloading minigpt4_7b" filename='pretrained_minigpt4_7b.pth' wget ${public_server}/${filename} fi if [ "$1" = "minigpt4_13b" -o "$1" = "all" ]; then echo "downloading minigpt4_13b" filename='pretrained_minigpt4_13b.pth' wget ${public_server}/${filename} fi if [ "$1" = "llava_vicuna7b_language_projection" -o "$1" = "all" ]; then echo "downloading llava vicuna7b language_projection" filename="multimodal/llava-336px-pretrain-vicuna-7b-v1.3_language_projection.pth" wget ${public_server}/${filename} fi if [ "$1" = "llava_vicuna13b_model_01" -o "$1" = "all" ]; then echo "downloading llava vicunda13 b trained model 01 checkpoint " filepath="llava-v1-0719-336px-lora-merge-vicuna-13b-v1.3" filename="pytorch_model-00001-of-00003.bin" python ../utils/download_hf_file.py \ --repo_id liuhaotian/llava-v1-0719-336px-lora-merge-vicuna-13b-v1.3 \ --filename ${filename} \ --target_path ${filepath} \ --repo_type "model" fi if [ "$1" = "llava_vicuna13b_model_02" -o "$1" = "all" ]; then echo "downloading llava vicunda13 b trained model 01 checkpoint " filepath="llava-v1-0719-336px-lora-merge-vicuna-13b-v1.3" filename="pytorch_model-00002-of-00003.bin" python ../utils/download_hf_file.py \ --repo_id liuhaotian/llava-v1-0719-336px-lora-merge-vicuna-13b-v1.3 \ --filename ${filename} \ --target_path ${filepath} \ --repo_type "model" fi if [ "$1" = "llava_vicuna13b_model_03" -o "$1" = "all" ]; then echo "downloading llava vicunda13 b trained model 01 checkpoint " filepath="llava-v1-0719-336px-lora-merge-vicuna-13b-v1.3" filename="pytorch_model-00003-of-00003.bin" python ../utils/download_hf_file.py \ --repo_id liuhaotian/llava-v1-0719-336px-lora-merge-vicuna-13b-v1.3 \ --filename ${filename} \ --target_path ${filepath} \ --repo_type "model" fi } main "$@" ================================================ FILE: scripts/archive/export_llama_state_dict_checkpoint.py ================================================ # Export state dict for downstream inference, such as llama.cpp import json import os import torch from peft import PeftModel from transformers import LlamaForCausalLM, LlamaTokenizer # noqa: E402 def permute(w): return w.view(n_heads, dim // n_heads // 2, 2, dim).transpose(1, 2).reshape(dim, dim) def unpermute(w): return w.view(n_heads, 2, dim // n_heads // 2, dim).transpose(1, 2).reshape(dim, dim) def translate_state_dict_key(k): # noqa: C901 k = k.replace("base_model.model.", "") if k == "model.embed_tokens.weight": return "tok_embeddings.weight" elif k == "model.norm.weight": return "norm.weight" elif k == "lm_head.weight": return "output.weight" elif k.startswith("model.layers."): layer = k.split(".")[2] if k.endswith(".self_attn.q_proj.weight"): return f"layers.{layer}.attention.wq.weight" elif k.endswith(".self_attn.k_proj.weight"): return f"layers.{layer}.attention.wk.weight" elif k.endswith(".self_attn.v_proj.weight"): return f"layers.{layer}.attention.wv.weight" elif k.endswith(".self_attn.o_proj.weight"): return f"layers.{layer}.attention.wo.weight" elif k.endswith(".mlp.gate_proj.weight"): return f"layers.{layer}.feed_forward.w1.weight" elif k.endswith(".mlp.down_proj.weight"): return f"layers.{layer}.feed_forward.w2.weight" elif k.endswith(".mlp.up_proj.weight"): return f"layers.{layer}.feed_forward.w3.weight" elif k.endswith(".input_layernorm.weight"): return f"layers.{layer}.attention_norm.weight" elif k.endswith(".post_attention_layernorm.weight"): return f"layers.{layer}.ffn_norm.weight" elif k.endswith("rotary_emb.inv_freq") or "lora" in k: return None else: print(layer, k) raise NotImplementedError else: print(k) raise NotImplementedError PARAM_LIST = { 7: { "dim": 4096, "multiple_of": 256, "n_heads": 32, "n_layers": 32, "norm_eps": 1e-06, "vocab_size": -1, }, 13: { "dim": 5120, "multiple_of": 256, "n_heads": 40, "n_layers": 40, "norm_eps": 1e-06, "vocab_size": -1, }, 33: { "dim": 6656, "multiple_of": 256, "n_heads": 52, "n_layers": 60, "norm_eps": 1e-06, "vocab_size": -1, }, } BASE_MODEL = os.environ.get("BASE_MODEL", None) assert BASE_MODEL, ( "Please specify a value for BASE_MODEL environment variable, e.g. " "`export BASE_MODEL=decapoda-research/llama-30b-hf`" ) # noqa: E501 LORA_MODEL = os.environ.get("LORA_MODEL", None) MODEL_SIZE = int(os.environ.get("MODEL_SIZE", None)) assert MODEL_SIZE, "Please specify a value for MODEL_SIZE environment variable, e.g. " "`export MODEL_SIZE=33`" # noqa: E501 tokenizer = LlamaTokenizer.from_pretrained(BASE_MODEL) base_model = LlamaForCausalLM.from_pretrained( BASE_MODEL, load_in_8bit=False, torch_dtype=torch.float16, device_map={"": "cpu"}, ) params = PARAM_LIST[MODEL_SIZE] n_layers = params["n_layers"] n_heads = params["n_heads"] dim = params["dim"] dims_per_head = dim // n_heads base = 10000.0 inv_freq = 1.0 / (base ** (torch.arange(0, dims_per_head, 2).float() / dims_per_head)) if LORA_MODEL is not None: lora_model = PeftModel.from_pretrained( base_model, LORA_MODEL, device_map={"": "cpu"}, torch_dtype=torch.float16, ) # merge weights for layer in lora_model.base_model.model.model.layers: layer.self_attn.q_proj.merge_weights = True layer.self_attn.v_proj.merge_weights = True lora_model.train(False) lora_model_sd = lora_model.state_dict() new_state_dict = {} for k, v in lora_model_sd.items(): new_k = translate_state_dict_key(k) if new_k is not None: if "wq" in new_k or "wk" in new_k: new_state_dict[new_k] = unpermute(v) else: new_state_dict[new_k] = v else: base_model.eval() new_state_dict = {} state_dicts = base_model.state_dict() for k, v in state_dicts.items(): new_k = translate_state_dict_key(k) if new_k is not None: if "wq" in new_k or "wk" in new_k: new_state_dict[new_k] = unpermute(v) else: new_state_dict[new_k] = v os.makedirs("./ckpt", exist_ok=True) torch.save(new_state_dict, "./ckpt/consolidated.00.pth") with open("./ckpt/params.json", "w") as f: json.dump(params, f) ================================================ FILE: scripts/archive/run_all_benchmark.sh ================================================ #!/bin/bash help_message="./$(basename $0)" help_message+=" --model_name_or_path MODEL_NAME_OR_PATH" if [ $# -ge 1 ]; then extra_args="$@" fi model_name_or_path="" while [[ $# -ge 1 ]]; do key="$1" case ${key} in -h|--help) printf "${help_message}" 1>&2 return 0 ;; --model_name_or_path) model_name_or_path="$2" shift ;; *) # Ignores unknown options esac shift done model_name=$(echo "${model_name_or_path}" | sed "s/\//--/g") echo ${model_name} if [[ "${model_name}" = "" ]]; then echo "no model name specified" 1>&2 exit 1 fi log_dir=output_dir/${model_name}_lmflow_chat_nll_eval mkdir -p ${log_dir} echo "[Evaluating] Evaluate on LMFlow_chat" ./scripts/archive/run_benchmark.sh ${extra_args} --dataset_name lmflow_chat_nll_eval | tee ${log_dir}/benchmark.log 2> ${log_dir}/benchmark.err log_dir=output_dir/${model_name}_all_nll_eval mkdir -p ${log_dir} echo "[Evaluating] Evaluate on [commonsense, wiki, instruction_following (gpt4) ] nll evaluation" ./scripts/archive/run_benchmark.sh ${extra_args} --dataset_name all_nll_eval | tee ${log_dir}/benchmark.log 2> ${log_dir}/benchmark.err log_dir=output_dir/${model_name}_commonsense_qa_eval mkdir -p ${log_dir} echo "[Evaluating] Evaluate on commonsense QA Accuracy evaluation" ./scripts/archive/run_benchmark.sh ${extra_args} --dataset_name commonsense_qa_eval | tee ${log_dir}/benchmark.log 2> ${log_dir}/benchmark.err ================================================ FILE: scripts/archive/run_app.sh ================================================ #!/bin/bash CUDA_VISIBLE_DEVICES=0 accelerate launch --config_file configs/archive/accelerate_singlegpu_config.yaml service/app.py \ --model_name_or_path gpt2 \ --torch_dtype bfloat16 \ --max_new_tokens 200 ================================================ FILE: scripts/archive/run_benchmark.sh ================================================ #!/bin/bash if [ "$1" == "-h" -o "$1" == "--help" ]; then help_message="./$(basename $0)" help_message+=" --dataset_name DATASET_NAME" help_message+=" --model_name_or_path MODEL_NAME_OR_PATH" echo ${help_message} 1>&2 exit 1 fi extra_args="--dataset_name gpt4_en_eval --model_name_or_path gpt2" if [ $# -ge 1 ]; then extra_args="$@" fi CUDA_VISIBLE_DEVICES=0 \ deepspeed --master_port 11001 examples/benchmarking.py \ --use_ram_optimized_load 0 \ --deepspeed examples/ds_config.json \ --metric nll \ --prompt_structure "###Human: {input}###Assistant:" \ ${extra_args} ================================================ FILE: scripts/archive/run_chatbot.sh ================================================ #!/bin/bash # A simple chatbot script, the memory of the chatbot has a length of maximum # model length, e.g. 4k for llama-2. model=gpt2 lora_args="" if [ $# -ge 1 ]; then model=$1 fi if [ $# -ge 2 ]; then lora_args="--lora_model_path $2" fi # --temperature 0.7 \ accelerate launch --config_file configs/archive/accelerate_multigpu_config.yaml \ examples/chatbot.py \ --deepspeed configs/archive/ds_config_chatbot.json \ --model_name_or_path ${model} \ --max_new_tokens 256 \ --temperature 1.0 \ --end_string "#" \ ${lora_args} ================================================ FILE: scripts/archive/run_chatbot_chatglm.sh ================================================ #!/bin/bash model=THUDM/chatglm-6b lora_args="" if [ $# -ge 1 ]; then model=$1 fi if [ $# -ge 2 ]; then lora_args="--lora_model_path $2" fi CUDA_VISIBLE_DEVICES=0 \ deepspeed examples/chatbot.py \ --arch_type encoder_decoder \ --deepspeed configs/archive/ds_config_chatbot.json \ --model_name_or_path ${model} \ ${lora_args} ================================================ FILE: scripts/archive/run_chatbot_cpu.sh ================================================ #!/bin/bash model=gpt2 lora_args="" if [ $# -ge 1 ]; then model=$1 fi if [ $# -ge 2 ]; then lora_args="--lora_model_path $2" fi CUDA_VISIBLE_DEVICES="" \ python examples/chatbot.py \ --deepspeed configs/archive/ds_config_chatbot.json \ --model_name_or_path ${model} \ --device "cpu" \ ${lora_args} ================================================ FILE: scripts/archive/run_detail_gpu_memory.sh ================================================ python ./examples/detail_memory.py meta-llama/Llama-2-7b-hf 10 0 0 128 # base python ./examples/detail_memory.py meta-llama/Llama-2-7b-hf 10 0 1 128 # Lora python ./examples/detail_memory.py meta-llama/Llama-2-7b-hf 10 0 1 256 # Lora python ./examples/detail_memory.py meta-llama/Llama-2-7b-hf 10 1 0 128 # LISA python ./examples/detail_memory.py meta-llama/Llama-2-7b-hf 512 0 0 128 # base python ./examples/detail_memory.py meta-llama/Llama-2-7b-hf 512 0 1 128 # Lora python ./examples/detail_memory.py meta-llama/Llama-2-7b-hf 512 0 1 256 # Lora python ./examples/detail_memory.py meta-llama/Llama-2-7b-hf 512 1 0 128 # LISA python ./examples/detail_memory.py meta-llama/Llama-2-7b-hf 1024 0 0 128 # base python ./examples/detail_memory.py meta-llama/Llama-2-7b-hf 1024 0 1 128 # Lora python ./examples/detail_memory.py meta-llama/Llama-2-7b-hf 1024 0 1 256 # Lora python ./examples/detail_memory.py meta-llama/Llama-2-7b-hf 1024 1 0 128 # LISA ================================================ FILE: scripts/archive/run_dpo_align.sh ================================================ #!/bin/bash # Please run this script under ${project_id} in project directory of # Parses arguments model_name_or_path=meta-llama/Llama-2-7b-hf dataset_path=data/dpo-mix-7k output_dir=output_models/dpo deepspeed_args="--master_port=11000" # specify gpus/single gpu here by # `--include localhost:0,1` or `--include localhost:0` while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; -o|--output_dir) output_dir="$2" shift ;; --deepspeed_args) deepspeed_args="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done exp_id=dpo project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} deepspeed ${deepspeed_args} \ examples/dpo_train.py \ --model_name_or_path ${model_name_or_path} \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} \ --run_name dpo \ --max_steps 200 \ --learning_rate 1e-6 \ --use_lora 1 \ --lora_r 8 \ --sanity_check True \ --save_aggregated_lora 0\ --logging_steps 20 \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ================================================ FILE: scripts/archive/run_dpov2_align.sh ================================================ #!/bin/bash model_name_or_path=meta-llama/Meta-Llama-3-8B-Instruct dataset_path=data/iterative-prompt/train output_dir=output_models/dpov2_align # DPO related arguments reference_model_name_or_path=meta-llama/Meta-Llama-3-8B-Instruct eval_dataset_path=data/iterative-prompt/eval margin_scale=1.0 max_prompt_length=1000 loss_type=sigmoid sampling_paired_method=max_min mask_prompt=True length_penalty=0 # Align exp_id=dpov2_align project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} accelerate launch --config_file configs/accelerate_fsdp_config.yaml \ examples/dpov2_train.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code 0 \ --reference_model_name_or_path ${reference_model_name_or_path} \ --do_train True \ --dataset_path ${dataset_path} \ --eval_dataset_path ${eval_dataset_path} \ --margin_scale ${margin_scale} \ --max_prompt_length ${max_prompt_length} \ --loss_type ${loss_type} \ --sampling_paired_method ${sampling_paired_method} \ --mask_prompt ${mask_prompt} \ --length_penalty ${length_penalty} \ --bf16 True \ --torch_dtype bfloat16 \ --learning_rate 5e-7 \ --lr_scheduler_type cosine \ --warmup_steps 100 \ --optim paged_adamw_32bit \ --per_device_train_batch_size 1 \ --per_device_eval_batch_size 1 \ --gradient_accumulation_steps 16 \ --gradient_checkpointing True \ --num_train_epochs 2 \ --logging_steps 2 \ --save_strategy epoch \ --save_steps 5000 \ --evaluation_strategy steps \ --eval_steps 100 \ --output_dir ${output_dir} \ --run_name ${exp_id} \ --report_to wandb \ --seed 42 \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ================================================ FILE: scripts/archive/run_evaluation.sh ================================================ #!/bin/bash if [ ! -d data/MedQA-USMLE ]; then cd data && ./download.sh MedQA-USMLE && cd - fi CUDA_VISIBLE_DEVICES=0 \ deepspeed examples/evaluation.py \ --answer_type medmcqa \ --model_name_or_path gpt2-large \ --dataset_path data/MedQA-USMLE/validation \ --deepspeed examples/ds_config.json \ --inference_batch_size_per_device 1 \ --metric accuracy ================================================ FILE: scripts/archive/run_evaluation_accelerator.sh ================================================ #!/bin/bash if [ ! -d data/MedQA-USMLE ]; then cd data && ./download.sh MedQA-USMLE && cd - fi CUDA_VISIBLE_DEVICES=0 accelerate launch --config_file configs/archive/accelerate_singlegpu_config.yaml examples/evaluation.py \ --answer_type usmle \ --model_name_or_path gpt2-large \ --dataset_path data/MedQA-USMLE/validation \ --use_ram_optimized_load True \ --deepspeed examples/ds_config.json \ --metric accuracy \ --output_dir output_dir/accelerator_1_card \ --inference_batch_size_per_device 1 \ --torch_dtype bfloat16 ================================================ FILE: scripts/archive/run_evaluation_with_lora.sh ================================================ #!/bin/bash # --model_name_or_path specifies the original huggingface model # --lora_model_path specifies the model difference introduced by finetuning, # i.e. the one saved by ./scripts/run_finetune_with_lora.sh if [ ! -d data/alpaca ]; then cd data && ./download.sh alpaca && cd - fi CUDA_VISIBLE_DEVICES=0 \ deepspeed examples/evaluation.py \ --answer_type text \ --model_name_or_path facebook/galactica-1.3b \ --lora_model_path output_models/finetune_with_lora \ --dataset_path data/alpaca/test \ --prompt_structure "Input: {input}" \ --deepspeed examples/ds_config.json \ --inference_batch_size_per_device 1 \ --metric accuracy ================================================ FILE: scripts/archive/run_finetune.sh ================================================ #!/bin/bash # Please run this script under ${project_id} in project directory of # https://github.com/shizhediao/llm-ft # COMMIT: d5fecf30ba8011067b10cf51fede53a5ab6574e4 # Parses arguments model_name_or_path=gpt2 dataset_path=data/alpaca/train_conversation output_dir=output_models/finetune deepspeed_args="--master_port=11000" conversation_template=llama2 # Safety related arguments trust_remote_code=0 while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; -o|--output_model_path) output_dir="$2" shift ;; --conversation_template) conversation_template="$2" shift ;; --deepspeed_args) deepspeed_args="$2" shift ;; --trust_remote_code) trust_remote_code="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done # Finetune exp_id=finetune project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} deepspeed ${deepspeed_args} \ examples/finetune.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code ${trust_remote_code} \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --conversation_template ${conversation_template} \ --num_train_epochs 0.01 \ --learning_rate 2e-5 \ --disable_group_texts 1 \ --block_size 256 \ --per_device_train_batch_size 1 \ --deepspeed configs/archive/ds_config_zero3.json \ --fp16 \ --run_name finetune \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --dataloader_num_workers 1 \ > >(tee ${log_dir}/train.log) \ 2> >(tee ${log_dir}/train.err >&2) ================================================ FILE: scripts/archive/run_finetune_with_custom_optim.sh ================================================ #!/bin/bash # Please run this script under ${project_id} in project directory of # https://github.com/shizhediao/llm-ft # COMMIT: d5fecf30ba8011067b10cf51fede53a5ab6574e4 # Parses arguments model_name_or_path=gpt2 dataset_path=data/alpaca/train_conversation # Other optional arguments that can improve memory saving gradient_checkpointing=True use_flash_attention=0 gradient_accumulation_steps=1 batch_size=1 block_size=256 per_device_train_batch_size=1 conversation_template=llama2 optim=dummy # Select an optimizer from the following options: # - 'adamw_torch' # - 'adafactor' # - 'sgd' # - 'lion_8bit' # - 'lion_32bit' # - 'rmsprop' # Additional optimizers are shown below learning_rate=1e-5 lr_schedule=cosine beta1=0.9 beta2=0.999 beta3=0.99 weight_decay=0 momentum=0 num_epoch=0.01 use_deepspeed=1 seed=42 # Safety related arguments trust_remote_code=0 # Enable model parallelism for multiple gpus, modify this if you prefer # customized deepspeed zero-redundancy optimization settings num_gpu=$(python -c "import torch; print(torch.cuda.device_count())") ds_config_file=configs/archive/ds_config_zero0_no_offload.json if [[ ${num_gpu} -ge 2 ]]; then ds_config_file=configs/archive/ds_config_zero2_no_offload.json fi while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; -o|--output_model_path) output_dir="$2" shift ;; --lisa_activated_layers) lisa_activated_layers="$2" shift ;; --lisa_interval_steps) lisa_interval_steps="$2" shift ;; --gradient_checkpointing) gradient_checkpointing="$2" shift ;; --deepspeed) ds_config_file="$2" shift ;; --use_flash_attention) use_flash_attention="$2" shift ;; --gradient_accumulation_steps) gradient_accumulation_steps="$2" shift ;; --block_size) block_size="$2" shift ;; --conversation_template) conversation_template="$2" shift ;; --per_device_train_batch_size|--batch_size) per_device_train_batch_size="$2" batch_size="$2" shift ;; --trust_remote_code) trust_remote_code="$2" shift ;; --run_name) run_name="$2" shift ;; --optim) optim="$2" shift ;; --lr) learning_rate="$2" shift ;; --beta1) beta1="$2" shift ;; --beta2) beta2="$2" shift ;; --beta3) beta3="$2" shift ;; --weight_decay) weight_decay="$2" shift ;; --momentum) momentum="$2" shift ;; -n|--num_epoch) num_epoch="$2" shift ;; --lr_schedule) lr_schedule="$2" shift ;; --use_deepspeed) use_deepspeed="$2" shift ;; --seed) seed="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done deepspeed_args="--master_port=1103" optim_suffix_args="" if [ "${optim}" == "dummy" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_dummy_beta1 ${beta1}" optim_suffix_args+=" --optim_dummy_beta2 ${beta2}" elif [ "${optim}" == "adabelief" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "adabound" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "lars" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_momentum ${momentum}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "lamb" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "adamax" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "nadam" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "radam" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "adamp" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "sgdp" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_momentum ${momentum}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "yogi" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "sophia" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "adan" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_beta3 ${beta3}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "adam" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" elif [ "${optim}" == "novograd" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "adadelta" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" elif [ "${optim}" == "adagrad" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" elif [ "${optim}" == "adamw_schedule_free" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "sgd_schedule_free" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_momentum ${momentum}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" else optim_suffix_args="--optim ${optim}" optim_suffix_args+=" --adam_beta1 ${beta1}" optim_suffix_args+=" --adam_beta2 ${beta2}" fi # Finetune exp_id=alpaca_${optim}_lr-${learning_rate}_beta1-${beta1}_beta2-${beta2}_lr-sched-${lr_schedule}_model-$(basename ${model_name_or_path})_batch-size-${batch_size}x${gradient_accumulation_steps}_seed-${seed} echo "$(date): ${exp_id}..." tmp_dir=tmp mkdir -p ${tmp_dir} prefix=${exp_id} if [ -f ${tmp_dir}/${prefix}.mark ]; then exit 0 fi trap "rm -f ${tmp_dir}/${prefix}.mark" SIGINT SIGTERM SIGKILL touch ${tmp_dir}/${prefix}.mark project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} output_dir=output_models/${exp_id} mkdir -p ${output_dir} ${log_dir} exe="deepspeed ${deepspeed_args}" if [[ ${use_deepspeed} -eq 0 ]]; then exe=python fi ${exe} examples/finetune.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code ${trust_remote_code} \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --conversation_template ${conversation_template} \ --num_train_epochs ${num_epoch} \ --learning_rate ${learning_rate} \ --lr_scheduler_type ${lr_schedule} \ --disable_group_texts 1 \ --block_size ${block_size} \ --per_device_train_batch_size ${per_device_train_batch_size} \ --bf16 \ --deepspeed configs/archive/ds_config_zero2_no_offload.json \ --torch_dtype bfloat16 \ --run_name ${exp_id} \ --validation_split_percentage 0 \ --logging_steps 1 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --dataloader_num_workers 1 \ --gradient_checkpointing ${gradient_checkpointing} \ --use_flash_attention ${use_flash_attention} \ --gradient_accumulation_steps ${gradient_accumulation_steps} \ --seed ${seed} \ ${optim_suffix_args} \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err if [[ $? -ne 0 ]]; then echo "$(date): failed" rm -f ${tmp_dir}/${prefix}.mark fi ================================================ FILE: scripts/archive/run_finetune_with_lisa.sh ================================================ #!/bin/bash # Please run this script under ${project_id} in project directory of # https://github.com/shizhediao/llm-ft # COMMIT: d5fecf30ba8011067b10cf51fede53a5ab6574e4 # Parses arguments model_name_or_path=meta-llama/Llama-2-7b-hf dataset_path=data/alpaca/train_conversation output_dir=output_models/finetune_lisa lisa_activated_layers=1 lisa_interval_steps=20 # Other optional arguments that can improve memory saving gradient_checkpointing=True use_flash_attention=0 gradient_accumulation_steps=1 block_size=256 per_device_train_batch_size=1 conversation_template=llama2 # Safety related arguments trust_remote_code=0 # Enable model parallelism for multiple gpus, modify this if you prefer # customized deepspeed zero-redundancy optimization settings num_gpu=$(python -c "import torch; print(torch.cuda.device_count())") ds_config_file=configs/archive/ds_config_zero0_no_offload.json if [ ${num_gpu} -ge 2 ]; then ds_config_file=configs/archive/ds_config_zero2_no_offload.json fi while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; -o|--output_model_path) output_dir="$2" shift ;; --lisa_activated_layers) lisa_activated_layers="$2" shift ;; --lisa_interval_steps) lisa_interval_steps="$2" shift ;; --gradient_checkpointing) gradient_checkpointing="$2" shift ;; --deepspeed) ds_config_file="$2" shift ;; --use_flash_attention) use_flash_attention="$2" shift ;; --gradient_accumulation_steps) gradient_accumulation_steps="$2" shift ;; --block_size) block_size="$2" shift ;; --conversation_template) conversation_template="$2" shift ;; --per_device_train_batch_size|--batch_size) per_device_train_batch_size="$2" shift ;; --trust_remote_code) trust_remote_code="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done # Finetune exp_id=finetune project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} python examples/finetune.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code ${trust_remote_code} \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --conversation_template ${conversation_template} \ --num_train_epochs 1 \ --learning_rate 1e-5 \ --disable_group_texts 1 \ --block_size ${block_size} \ --per_device_train_batch_size ${per_device_train_batch_size} \ --bf16 \ --torch_dtype bfloat16 \ --run_name finetune \ --optim paged_adamw_32bit \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --dataloader_num_workers 1 \ --gradient_checkpointing ${gradient_checkpointing} \ --use_flash_attention ${use_flash_attention} \ --gradient_accumulation_steps ${gradient_accumulation_steps} \ --use_lisa 1 \ --lisa_activated_layers ${lisa_activated_layers} \ --lisa_interval_steps ${lisa_interval_steps} \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ================================================ FILE: scripts/archive/run_finetune_with_lora.sh ================================================ #!/bin/bash # Please run this script under ${project_id} in project directory of # Parses arguments model_name_or_path=gpt2 dataset_path=data/alpaca/train_conversation conversation_template=llama2 output_dir=output_models/finetune deepspeed_args="--master_port=11000" # Safety related arguments trust_remote_code=0 while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; --conversation_template) conversation_template="$2" shift ;; -o|--output_lora_path) output_dir="$2" shift ;; --deepspeed_args) deepspeed_args="$2" shift ;; --trust_remote_code) trust_remote_code="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done # Finetune exp_id=finetune_with_lora project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} deepspeed ${deepspeed_args} \ examples/finetune.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code ${trust_remote_code} \ --dataset_path ${dataset_path} \ --conversation_template ${conversation_template} \ --output_dir ${output_dir} --overwrite_output_dir \ --num_train_epochs 0.01 \ --learning_rate 1e-4 \ --block_size 512 \ --per_device_train_batch_size 1 \ --use_lora 1 \ --lora_r 8 \ --save_aggregated_lora 0\ --deepspeed configs/archive/ds_config_zero2.json \ --fp16 \ --run_name ${exp_id} \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --dataloader_num_workers 1 \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ================================================ FILE: scripts/archive/run_finetune_with_qlora.sh ================================================ #!/bin/bash # Please run this script under ${project_id} in project directory of # Parses arguments model_name_or_path=meta-llama/Llama-2-13b-hf dataset_path=data/alpaca/train_conversation conversation_template=llama2 output_dir=output_models/finetune deepspeed_args="--master_port=11000" # Safety related arguments trust_remote_code=0 while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; --conversation_template) conversation_template="$2" shift ;; -o|--output_model_path) output_dir="$2" shift ;; --deepspeed_args) deepspeed_args="$2" shift ;; --trust_remote_code) trust_remote_code="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done # Finetune exp_id=finetune_with_lora project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} deepspeed ${deepspeed_args} \ examples/finetune.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code ${trust_remote_code} \ --dataset_path ${dataset_path} \ --conversation_template ${conversation_template} \ --output_dir ${output_dir} --overwrite_output_dir \ --num_train_epochs 0.01 \ --learning_rate 1e-4 \ --block_size 512 \ --per_device_train_batch_size 1 \ --use_qlora 1 \ --save_aggregated_lora 0 \ --deepspeed configs/archive/ds_config_zero2.json \ --fp16 \ --run_name ${exp_id} \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --dataloader_num_workers 1 \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ================================================ FILE: scripts/archive/run_inference.sh ================================================ #!/bin/bash # An interactive inference script without context history, i.e. the chatbot # won't have conversation memory. model=gpt2 lora_args="" if [ $# -ge 1 ]; then model=$1 fi if [ $# -ge 2 ]; then lora_args="--lora_model_path $2" fi accelerate launch --config_file configs/accelerate_fsdp_config.yaml \ examples/inference.py \ --model_name_or_path ${model} \ --max_new_tokens 256 \ --temperature 1.0 \ ${lora_args} ================================================ FILE: scripts/archive/run_inference_multimodal_model.sh ================================================ #!/bin/bash model="Salesforce/blip-image-captioning-base" lora_args="" if [ $# -ge 1 ]; then model=$1 fi if [ $# -ge 2 ]; then lora_args="--lora_model_path $2" fi CUDA_VISIBLE_DEVICES=0 \ deepspeed examples/inference.py \ --deepspeed configs/archive/ds_config_multimodal.json \ --model_name_or_path ${model} \ --arch_type vision_encoder_decoder \ ${lora_args} ================================================ FILE: scripts/archive/run_iterative_dpo.sh ================================================ python examples/iterative_dpo_train.py configs/iterative_dpo.yaml ================================================ FILE: scripts/archive/run_multistage_finetune.sh ================================================ #!/bin/bash # Please run this script under ${project_id} in project directory of deepspeed_args="--master_port=11000" # Default argument if [ $# -ge 1 ]; then deepspeed_args="$1" fi exp_id=multistage_finetune project_dir=$(cd "$(dirname $0)"/..; pwd) output_dir=${project_dir}/output_models/${exp_id} log_dir=${project_dir}/log/${exp_id} dataset_path="${project_dir}/data/example_dataset/train" if [ ! -d ${dataset_path} ]; then cd data && ./download.sh example_dataset && cd - fi mkdir -p ${output_dir} ${log_dir} deepspeed ${deepspeed_args} \ examples/multistage_finetune.py \ --num_stages_per_epoch 1 \ --run_name ${exp_id} \ --model_name_or_path facebook/galactica-1.3b \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --num_train_epochs 3 \ --learning_rate 1e-3 \ --block_size 512 \ --per_device_train_batch_size 2 \ --use_lora 1 \ --lora_r 8 \ --save_aggregated_lora 1 \ --deepspeed configs/archive/ds_config_zero2.json \ --bf16 \ --run_name finetune_with_lora \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --dataloader_num_workers 1 \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ================================================ FILE: scripts/archive/run_raft_align.sh ================================================ #!/bin/bash # Please run this script under project directory. deepspeed_args="--master_port=11110" # Default argument if [ $# -ge 1 ]; then deepspeed_args="$1" fi exp_id=raft_align project_dir=$(cd "$(dirname $0)"/..; pwd) output_dir=${project_dir}/output_models/${exp_id} log_dir=${project_dir}/log/${exp_id} if [ ! -d data/hh_rlhf ]; then cd data && ./download.sh hh_rlhf && cd - fi mkdir -p ${output_dir} ${log_dir} export PYTHONPATH=. deepspeed ${deepspeed_args} \ examples/raft_align.py \ --model_name_or_path gpt2 \ --num_raft_iteration 20 \ --learning_rate 2e-5 \ --lr_scheduler_type "constant" \ --bf16 \ --deepspeed configs/archive/ds_config_zero2.json \ --dataset_path ${project_dir}/data/hh_rlhf/rlhf_prompt \ --output_reward_path ${project_dir}/tmp/raft_aligner/reward.txt \ --output_dir ${output_dir} --overwrite_output_dir \ --run_name ${exp_id} \ --num_train_epochs 4 \ --per_device_train_batch_size 1 \ --per_device_eval_batch_size 1 \ --validation_split_percentage 0 \ --logging_steps 1 \ --do_train \ --ddp_timeout 72000 \ --save_steps 7777 \ --dataloader_num_workers 1 \ --preprocessing_num_workers 12 \ --inference_batch_size_per_device 1 \ --collection_strategy "local" \ --raft_batch_size 1024 \ --output_min_length 96 \ --top_reward_percentage 0.125 \ | tee ${log_dir}/raft_align.log \ 2> ${log_dir}/raft_align.err ================================================ FILE: scripts/archive/run_reward_modeling.sh ================================================ #!/bin/bash # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. # Parses arguments model_name_or_path=google/gemma-2b-it train_dataset_path=data/ultrafeedback-binarized-preferences-cleaned/train eval_dataset_path=data/ultrafeedback-binarized-preferences-cleaned/train output_dir=output_models/reward_modeling conversation_template=gemma # Safety related arguments trust_remote_code=0 while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; --train_dataset_path) train_dataset_path="$2" shift ;; --eval_dataset_path) eval_dataset_path="$2" shift ;; -o|--output_model_path) output_dir="$2" shift ;; --conversation_template) conversation_template="$2" shift ;; --trust_remote_code) trust_remote_code="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done # Finetune exp_id=reward_modeling project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} accelerate launch --config_file configs/accelerate_fsdp_config.yaml \ examples/reward_modeling.py \ --model_name_or_path ${model_name_or_path} \ --arch_type "text_regression" \ --do_train True \ --dataset_path ${train_dataset_path} \ --conversation_template ${conversation_template} \ --output_dir ${output_dir} --overwrite_output_dir \ --use_flash_attention True \ --block_size 4096 \ --learning_rate 1e-5 \ --per_device_train_batch_size 1 \ --per_device_eval_batch_size 1 \ --num_train_epochs 0.001 \ --weight_decay 0.001 \ --evaluation_strategy "steps" \ --save_strategy "steps" \ --save_steps 999999 \ --gradient_accumulation_steps 32 \ --gradient_checkpointing True \ --remove_unused_columns False \ --bf16 True \ --torch_dtype bfloat16 \ --logging_strategy "steps" \ --logging_steps 10 \ --optim "paged_adamw_32bit" \ --lr_scheduler_type "cosine" \ --warmup_ratio 0.03 \ --report_to 'wandb' \ --run_name ${exp_id} \ --do_eval True \ --eval_dataset_path ${eval_dataset_path} \ --eval_steps 999999 \ --preprocessing_num_workers 4 \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ================================================ FILE: scripts/archive/run_reward_modeling_with_lisa.sh ================================================ #!/bin/bash # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. # Parses arguments model_name_or_path=google/gemma-2b-it train_dataset_path=data/ultrafeedback-binarized-preferences-cleaned/train eval_dataset_path=data/ultrafeedback-binarized-preferences-cleaned/train output_dir=output_models/reward_modeling_lisa conversation_template=gemma lisa_activated_layers=1 lisa_interval_steps=20 # Safety related arguments trust_remote_code=0 while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; --train_dataset_path) train_dataset_path="$2" shift ;; --eval_dataset_path) eval_dataset_path="$2" shift ;; --lisa_activated_layers) lisa_activated_layers="$2" shift ;; --lisa_interval_steps) lisa_interval_steps="$2" shift ;; -o|--output_model_path) output_dir="$2" shift ;; --conversation_template) conversation_template="$2" shift ;; --trust_remote_code) trust_remote_code="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done # Finetune exp_id=reward_modeling_lisa project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} accelerate launch --config_file configs/accelerate_fsdp_config.yaml \ examples/reward_modeling.py \ --model_name_or_path ${model_name_or_path} \ --arch_type "text_regression" \ --do_train True \ --dataset_path ${train_dataset_path} \ --conversation_template ${conversation_template} \ --output_dir ${output_dir} --overwrite_output_dir \ --use_flash_attention True \ --block_size 4096 \ --learning_rate 1e-5 \ --per_device_train_batch_size 1 \ --per_device_eval_batch_size 1 \ --num_train_epochs 2 \ --weight_decay 0.001 \ --evaluation_strategy "steps" \ --save_strategy "steps" \ --save_steps 999999 \ --gradient_accumulation_steps 32 \ --gradient_checkpointing True \ --remove_unused_columns False \ --bf16 True \ --torch_dtype bfloat16 \ --logging_strategy "steps" \ --logging_steps 10 \ --optim "paged_adamw_32bit" \ --lr_scheduler_type "cosine" \ --warmup_ratio 0.03 \ --report_to 'wandb' \ --run_name ${exp_id} \ --do_eval True \ --eval_dataset_path ${eval_dataset_path} \ --eval_steps 999999 \ --use_lisa True \ --lisa_activated_layers ${lisa_activated_layers} \ --lisa_interval_steps ${lisa_interval_steps} \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ================================================ FILE: scripts/archive/run_reward_modeling_with_lora.sh ================================================ #!/bin/bash # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. # Parses arguments model_name_or_path=google/gemma-2b-it train_dataset_path=data/ultrafeedback-binarized-preferences-cleaned/train eval_dataset_path=data/ultrafeedback-binarized-preferences-cleaned/train output_dir=output_models/reward_modeling_lora conversation_template=gemma # Safety related arguments trust_remote_code=0 while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; --train_dataset_path) train_dataset_path="$2" shift ;; --eval_dataset_path) eval_dataset_path="$2" shift ;; -o|--output_model_path) output_dir="$2" shift ;; --conversation_template) conversation_template="$2" shift ;; --trust_remote_code) trust_remote_code="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done # Finetune exp_id=reward_modeling_lora project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} accelerate launch --config_file configs/accelerate_fsdp_config.yaml \ examples/reward_modeling.py \ --model_name_or_path ${model_name_or_path} \ --arch_type "text_regression" \ --do_train True \ --dataset_path ${train_dataset_path} \ --conversation_template ${conversation_template} \ --output_dir ${output_dir} --overwrite_output_dir \ --use_flash_attention True \ --block_size 4096 \ --learning_rate 1e-5 \ --per_device_train_batch_size 1 \ --per_device_eval_batch_size 1 \ --num_train_epochs 2 \ --weight_decay 0.001 \ --evaluation_strategy "steps" \ --save_strategy "steps" \ --save_steps 999999 \ --gradient_accumulation_steps 32 \ --gradient_checkpointing True \ --remove_unused_columns False \ --bf16 True \ --torch_dtype bfloat16 \ --logging_strategy "steps" \ --logging_steps 10 \ --optim "paged_adamw_32bit" \ --lr_scheduler_type "cosine" \ --warmup_ratio 0.03 \ --report_to 'wandb' \ --run_name ${exp_id} \ --do_eval True \ --eval_dataset_path ${eval_dataset_path} \ --eval_steps 999999 \ --use_lora True \ --lora_r 8 \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ================================================ FILE: scripts/archive/run_rm_inference.sh ================================================ #!/bin/bash # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. # Parses arguments run_name=rm_inference model_name_or_path=sfairXC/FsfairX-LLaMA3-RM-v0.1 dataset_path=data/alpaca/test output_dir=data/rm_inference_results output_file_name=results.json conversation_template=llama3 # Safety related arguments trust_remote_code=0 while [[ $# -ge 1 ]]; do key="$1" case ${key} in -r|--run_name) run_name="$2" shift ;; -m|--model_name_or_path) model_name_or_path="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; --conversation_template) conversation_template="$2" shift ;; --output_dir) output_dir="$2" shift ;; --output_file_name) output_file_name="$2" shift ;; --trust_remote_code) trust_remote_code="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done # inference project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${run_name} output_file_path=${output_dir}/${run_name}/${output_file_name} mkdir -p ${output_dir}/${run_name} ${log_dir} accelerate launch --config_file configs/accelerator_multigpu_config.yaml \ examples/rm_inference.py \ --trust_remote_code ${trust_remote_code} \ --model_name_or_path ${model_name_or_path} \ --arch_type text_regression \ --block_size 4096 \ --inference_batch_size 16 \ --dataset_path ${dataset_path} \ --overwrite_cache True \ --conversation_template ${conversation_template} \ --preprocessing_num_workers 16 \ --save_inference_results True \ --inference_results_path ${output_file_path} \ 2>&1 | tee ${log_dir}/rm_inference.log ================================================ FILE: scripts/archive/run_tool.sh ================================================ model="gorilla-llm/gorilla-7b-hf-delta-v1" python examples/tool_inference.py \ --model ${model} \ ================================================ FILE: scripts/archive/run_vllm_inference.sh ================================================ #!/bin/bash # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. # Parses arguments run_name=vllm_inference model_name_or_path='Qwen/Qwen2-0.5B' dataset_path=data/alpaca/test_conversation output_dir=data/inference_results output_file_name=results.json apply_chat_template=True # Safety related arguments trust_remote_code=0 while [[ $# -ge 1 ]]; do key="$1" case ${key} in -r|--run_name) run_name="$2" shift ;; -m|--model_name_or_path) model_name_or_path="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; --output_dir) output_dir="$2" shift ;; --output_file_name) output_file_name="$2" shift ;; --apply_chat_template) apply_chat_template="$2" shift ;; --trust_remote_code) trust_remote_code="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done # inference project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${run_name} output_file_path=${output_dir}/${run_name}/${output_file_name} mkdir -p ${output_dir}/${run_name} ${log_dir} python examples/vllm_inference.py \ --use_vllm True \ --trust_remote_code ${trust_remote_code} \ --model_name_or_path ${model_name_or_path} \ --dataset_path ${dataset_path} \ --preprocessing_num_workers 16 \ --random_seed 42 \ --apply_chat_template ${apply_chat_template} \ --num_output_sequences 2 \ --use_beam_search False \ --temperature 1.0 \ --top_p 0.9 \ --max_new_tokens 1024 \ --save_inference_results True \ --inference_results_path ${output_file_path} \ --enable_decode_inference_result False \ --vllm_gpu_memory_utilization 0.95 \ --vllm_tensor_parallel_size 2 \ --enable_distributed_vllm_inference False \ 2>&1 | tee ${log_dir}/vllm_inference.log ================================================ FILE: scripts/multimodal/README.md ================================================ # MultiModal Conversation ## Download dataset We use the dataset from LLava to present the example of multi-modaltiy training. Please first download the [pretrain dataset](https://huggingface.co/datasets/liuhaotian/LLaVA-CC3M-Pretrain-595K) for pre-training. Then download the [coco 2017](https://cocodataset.org/) and the [conversation file](https://huggingface.co/datasets/liuhaotian/LLaVA-Instruct-150K/blob/main/llava_instruct_80k.json) for finetuning. After downloading, modify the data path in the training script to your own path. ## Pretrain Run the following script for pretraining: ``` bash scripts/multimodal/run_finetune_multi_modal_stage1.sh ``` ## Finetune Modify the path of the dataset and the pretrain language projection model and run the following script: ``` bash script/multimodal/run_finetune_multi_modal_stage2.sh ``` ## Inference on CLI Run the following script for LLava: ``` bash script/multimodal/run_vis_chatbot_llava.sh ``` Run the following script for mini gpt-4: ``` bash script/multimodal/run_vis_chatbot_minigpt4.sh ``` ## Inference on gradio: Run the following script for mini gpt-4: ``` bash script/multimodal/run_vis_chatbot_gradio_minigpt4.sh ``` ================================================ FILE: scripts/multimodal/run_finetune_multi_modal_stage1.sh ================================================ #!/bin/bash # Please run this script under ${project_id} in project directory of # https://github.com/shizhediao/llm-ft # COMMIT: d5fecf30ba8011067b10cf51fede53a5ab6574e4 # Parses argumen model_name_or_path=Salesforce/blip2-flan-t5-xxl # please download the dataset from # https://huggingface.co/datasets/liuhaotian/LLaVA-CC3M-Pretrain-595K dataset_path=./data/llava_cc3m_pretrain_595k/chat.json image_folder=./data/llava_cc3m_pretrain_595k/images output_dir=output_models/finetune_llava-336px-vicuna-7b-v1.3_stage1 deepspeed_args="--master_port=12000" while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; -o|--output_model_path) output_dir="$2" shift ;; --deepspeed_args) deepspeed_args="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done if [ ! -d data/llava_cc3m_pretrain_595k ]; then cd data && ./download.sh llava_cc3m_pretrain_595k && cd - fi # Finetune exp_id=finetune project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} deepspeed ${deepspeed_args} \ examples/finetune_multi_modal.py \ --deepspeed configs/archive/ds_config_multimodal.json \ --arch_type vision_encoder_decoder \ --llava_loading True \ --model_name_or_path ${model_name_or_path} \ --image_encoder_name_or_path openai/clip-vit-large-patch14 \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --image_folder ${image_folder} \ --custom_vision_model True \ --llm_model_name_or_path lmsys/vicuna-7b-v1.5 \ --image_aspect_ratio None \ --fp16 True \ --gradient_accumulation_steps 4 \ --per_device_train_batch_size 8 \ --learning_rate 2e-3 \ --weight_decay 0. \ --warmup_ratio 0.03 \ --lr_scheduler_type "cosine" \ --run_name finetune \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --dataloader_num_workers 1 \ --num_train_epochs 1 \ --save_language_projection True \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ================================================ FILE: scripts/multimodal/run_finetune_multi_modal_stage2.sh ================================================ #!/bin/bash # Please run this script under ${project_id} in project directory of # https://github.com/shizhediao/llm-ft # COMMIT: d5fecf30ba8011067b10cf51fede53a5ab6574e4 # Parses argumen # FIXME upload the projector into lmflow. model_name_or_path=Salesforce/blip2-flan-t5-xxl # Please download the coco dataset and the conversation file from # https://huggingface.co/datasets/liuhaotian/LLaVA-Instruct-150K/blob/main/llava_instruct_80k.json dataset_path=./data/llava_instruct_80k_truncated.json image_folder=./data/coco2017/train2017 output_dir=output_models/finetune_llava-336px-vicuna-7b-v1.3_stage2 deepspeed_args="--master_port=12000" while [[ $# -ge 1 ]]; do key="$1" case ${key} in -m|--model_name_or_path) model_name_or_path="$2" shift ;; -d|--dataset_path) dataset_path="$2" shift ;; -o|--output_model_path) output_dir="$2" shift ;; --deepspeed_args) deepspeed_args="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done if [ ! -f output_models/llava-336px-pretrain-vicuna-7b-v1.3_language_projection.pth ]; then cd output_models && ./download.sh llava_vicuna7b_language_projection && cd - fi if [ ! -d data/coco2017 ]; then cd data && ./download.sh coco2017 && cd - fi if [ ! -f data/llava_instruct_80k.json ]; then cd data && ./download.sh llava_instruction_finetune_80k && cd - fi if [ ! -f data/llava_instruct_80k_truncated.json ]; then python utils/preprocess_multimodal_data.py \ --data_path data/llava_instruct_80k.json \ --save_path data/llava_instruct_80k_truncated.json fi # Finetune exp_id=finetune project_dir=$(cd "$(dirname $0)"/..; pwd) log_dir=${project_dir}/log/${exp_id} mkdir -p ${output_dir} ${log_dir} # train batch size is set as 4 # default in llava is 16 deepspeed ${deepspeed_args} \ examples/finetune_multi_modal.py \ --deepspeed configs/archive/ds_config_zero2.json \ --arch_type vision_encoder_decoder \ --llava_loading True \ --model_name_or_path ${model_name_or_path} \ --image_encoder_name_or_path openai/clip-vit-large-patch14-336 \ --pretrained_language_projection_path output_models/llava-336px-pretrain-vicuna-7b-v1.3_language_projection.pth \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --image_folder ${image_folder} \ --custom_vision_model True \ --llm_model_name_or_path lmsys/vicuna-7b-v1.3 \ --image_aspect_ratio None \ --fp16 True \ --learning_rate 2e-5 \ --gradient_accumulation_steps 8 \ --per_device_train_batch_size 1 \ --per_device_eval_batch_size 4 \ --weight_decay 0. \ --warmup_ratio 0.03 \ --lr_scheduler_type "cosine" \ --run_name finetune \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --dataloader_num_workers 1 \ --sep_style "v1" \ --num_train_epochs 1 \ | tee ${log_dir}/train.log \ 2> ${log_dir}/train.err ================================================ FILE: scripts/multimodal/run_vis_chatbot_blip2.sh ================================================ model=Salesforce/blip2-opt-2.7b deepspeed examples/vis_chatbot.py --model_name_or_path ${model} \ --deepspeed configs/archive/ds_config_vis_chatbot.json \ --arch_type vision_encoder_decoder \ --task vqa \ ${@:1} ================================================ FILE: scripts/multimodal/run_vis_chatbot_gradio_minigpt4.sh ================================================ #!/bin/bash model=Salesforce/blip2-flan-t5-xxl # if [ ! -f output_models/pretrained_minigpt4_7b.pth ]; then # cd output_models && ./download.sh minigpt4_7b && cd - # fi # # if [ ! -f output_models/pretrained_minigpt4_7b_converted.pth ]; then # python utils/convert_minigpt4_checkpoints.py \ # --model_path output_models/pretrained_minigpt4_7b.pth \ # --save_path output_models/pretrained_minigpt4_7b_converted.pth # fi # # deepspeed --master_port=11005 examples/vis_chatbot_gradio.py \ # --model_name_or_path ${model} \ # --deepspeed configs/archive/ds_config_multimodal.json \ # --arch_type vision_encoder_decoder \ # --task vqa \ # --custom_model \ # --chatbot_format mini_gpt \ # --prompt_structure "###Human: {input_text}###Assistant:" \ # --llm_model_name_or_path LMFlow/Full-Robin-7b-v2 \ # --checkpoint_path output_models/pretrained_minigpt4_7b_converted.pth \ # --low_resource True \ # --max_new_tokens 1024 if [ ! -f output_models/pretrained_minigpt4_13b.pth ]; then cd output_models && ./download.sh minigpt4_13b && cd - fi if [ ! -f output_models/pretrained_minigpt4_13b_converted.pth ]; then python utils/convert_minigpt4_checkpoints.py \ --model_path output_models/pretrained_minigpt4_13b.pth \ --save_path output_models/pretrained_minigpt4_13b_converted.pth fi deepspeed --master_port=11005 examples/vis_chatbot_gradio.py \ --model_name_or_path ${model} \ --deepspeed configs/archive/ds_config_vis_chatbot.json \ --arch_type vision_encoder_decoder \ --task vqa \ --custom_model \ --chatbot_type mini_gpt \ --prompt_structure "###Human: {input_text}###Assistant:" \ --llm_model_name_or_path LMFlow/Full-Robin-13b-v2 \ --pretrained_language_projection_path output_models/pretrained_minigpt4_13b_converted.pth \ --low_resource True \ --max_new_tokens 1024 ================================================ FILE: scripts/multimodal/run_vis_chatbot_llava.sh ================================================ # only work for gpu mem > 25G; fail to do 4 bit and 8 bit inference. model_name_or_path=Salesforce/blip2-flan-t5-xxl llava_pretrain_model_path="output_models/llava-v1-0719-336px-lora-merge-vicuna-13b-v1.3/" deepspeed_args="--master_port=12000" if [ ! -f ${llava_pretrain_model_path}"pytorch_model-00001-of-00003.bin" ]; then cd output_models && ./download.sh llava_vicuna13b_model_01 && cd - fi if [ ! -f ${llava_pretrain_model_path}"pytorch_model-00002-of-00003.bin" ]; then cd output_models && ./download.sh llava_vicuna13b_model_02 && cd - fi if [ ! -f ${llava_pretrain_model_path}"pytorch_model-00003-of-00003.bin" ]; then cd output_models && ./download.sh llava_vicuna13b_model_03 && cd - fi deepspeed ${deepspeed_args} \ examples/vis_chatbot.py \ --deepspeed configs/archive/ds_config_vis_chatbot.json \ --arch_type vision_encoder_decoder \ --task vqa \ --custom_model True \ --chatbot_type llava \ --prompt_structure '{input_text} ASSISTANT:' \ --llava_loading True \ --model_name_or_path ${model_name_or_path} \ --image_encoder_name_or_path openai/clip-vit-large-patch14-336 \ --custom_vision_model True \ --llm_model_name_or_path lmsys/vicuna-13b-v1.5 \ --llava_pretrain_model_path ${llava_pretrain_model_path}"*.bin" \ --with_deepspeed False \ --save_pretrain_model_path "output_models/lmflow_llava-v1-0719-336px-lora-merge-vicuna-13b-v1.3" \ ${@:1} ================================================ FILE: scripts/multimodal/run_vis_chatbot_minigpt4.sh ================================================ model=Salesforce/blip2-flan-t5-xxl llm_model_name_or_path=lmsys/vicuna-7b-v1.3 deepspeed_args="--master_port=12000 --num_gpus=1" if [ ! -f output_models/pretrained_minigpt4_7b.pth ]; then cd output_models && ./download.sh minigpt4_7b && cd - fi if [ ! -f output_models/pretrained_minigpt4_7b_converted.pth ]; then python utils/convert_minigpt4_checkpoints.py \ --model_path output_models/pretrained_minigpt4_7b.pth \ --save_path output_models/pretrained_minigpt4_7b_converted.pth fi deepspeed ${deepspeed_args} examples/vis_chatbot.py --model_name_or_path ${model} --deepspeed configs/archive/ds_config_vis_chatbot.json --arch_type vision_encoder_decoder --task vqa --custom_model \ --chatbot_type mini_gpt \ --prompt_structure "{input_text}###Assistant:" \ --pretrained_language_projection_path output_models/pretrained_minigpt4_7b_converted.pth \ --llm_model_name_or_path ${llm_model_name_or_path} \ --low_resource True \ ${@:1} ================================================ FILE: scripts/run_finetune.sh ================================================ #!/bin/bash model_name_or_path=meta-llama/Llama-3.2-3B-Instruct dataset_path=data/alpaca/train_conversation conversation_template=llama3 output_dir=output_models/finetune # Finetune exp_id=finetune log_dir=${output_dir}/log/ mkdir -p ${output_dir} ${log_dir} accelerate launch --config_file configs/accelerate_fsdp_config.yaml \ examples/finetune.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code 0 \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --conversation_template ${conversation_template} \ --disable_group_texts 1 \ --num_train_epochs 1 \ --block_size 512 \ --per_device_train_batch_size 1 \ --gradient_accumulation_steps 1 \ --learning_rate 2e-5 \ --lr_scheduler_type cosine \ --bf16 \ --torch_dtype bfloat16 \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --use_flash_attention 0 \ --gradient_checkpointing 0 \ --dataloader_num_workers 8 \ --report_to wandb \ --run_name ${exp_id} \ --seed 42 \ > >(tee ${log_dir}/train.log) \ 2> >(tee ${log_dir}/train.err >&2) ================================================ FILE: scripts/run_finetune_with_custom_optim.sh ================================================ #!/bin/bash model_name_or_path=meta-llama/Llama-3.2-3B-Instruct dataset_path=data/alpaca/train_conversation conversation_template=llama3 output_dir=output_models/finetune_custom_optim # Select an optimizer from the following options: # - 'adamw_torch' # - 'adafactor' # - 'sgd' # - 'lion_8bit' # - 'lion_32bit' # - 'rmsprop' # Additional optimizers are shown below optim=dummy beta1=0.9 beta2=0.999 beta3=0.99 weight_decay=0 momentum=0 # Finetune exp_id=finetune_custom_optim log_dir=${output_dir}/log/ mkdir -p ${output_dir} ${log_dir} optim_suffix_args="" if [ "${optim}" == "dummy" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_dummy_beta1 ${beta1}" optim_suffix_args+=" --optim_dummy_beta2 ${beta2}" elif [ "${optim}" == "adabelief" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "adabound" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "lars" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_momentum ${momentum}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "lamb" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "adamax" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "nadam" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "radam" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "adamp" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "sgdp" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_momentum ${momentum}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "yogi" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "sophia" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "adan" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_beta3 ${beta3}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "adam" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" elif [ "${optim}" == "novograd" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "adadelta" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" elif [ "${optim}" == "adagrad" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" elif [ "${optim}" == "muon" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" optim_suffix_args+=" --customized_optim ${optim}" elif [ "${optim}" == "adamw_schedule_free" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_beta1 ${beta1}" optim_suffix_args+=" --optim_beta2 ${beta2}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" elif [ "${optim}" == "sgd_schedule_free" ]; then optim_suffix_args="--use_customized_optim 1" optim_suffix_args+=" --customized_optim ${optim}" optim_suffix_args+=" --optim_momentum ${momentum}" optim_suffix_args+=" --optim_weight_decay ${weight_decay}" else optim_suffix_args="--optim ${optim}" optim_suffix_args+=" --adam_beta1 ${beta1}" optim_suffix_args+=" --adam_beta2 ${beta2}" fi accelerate launch --config_file configs/accelerate_fsdp_config.yaml \ examples/finetune.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code 0 \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --conversation_template ${conversation_template} \ ${optim_suffix_args} \ --disable_group_texts 1 \ --num_train_epochs 1 \ --block_size 512 \ --per_device_train_batch_size 1 \ --gradient_accumulation_steps 1 \ --learning_rate 2e-5 \ --lr_scheduler_type cosine \ --bf16 \ --torch_dtype bfloat16 \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --use_flash_attention 0 \ --gradient_checkpointing 0 \ --dataloader_num_workers 8 \ --report_to wandb \ --run_name ${exp_id} \ --seed 42 \ > >(tee ${log_dir}/train.log) \ 2> >(tee ${log_dir}/train.err >&2) ================================================ FILE: scripts/run_finetune_with_lisa.sh ================================================ #!/bin/bash model_name_or_path=meta-llama/Llama-3.2-3B-Instruct dataset_path=data/alpaca/train_conversation conversation_template=llama3 output_dir=output_models/finetune_lisa # LISA related arguments lisa_activated_layers=1 lisa_interval_steps=20 # Finetune exp_id=finetune_lisa log_dir=${output_dir}/log/ mkdir -p ${output_dir} ${log_dir} accelerate launch --config_file configs/accelerate_fsdp_config.yaml \ examples/finetune.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code 0 \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --conversation_template ${conversation_template} \ --use_lisa 1 \ --lisa_activated_layers ${lisa_activated_layers} \ --lisa_interval_steps ${lisa_interval_steps} \ --disable_group_texts 1 \ --num_train_epochs 1 \ --block_size 512 \ --per_device_train_batch_size 1 \ --gradient_accumulation_steps 1 \ --learning_rate 2e-5 \ --lr_scheduler_type cosine \ --bf16 \ --torch_dtype bfloat16 \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --use_flash_attention 0 \ --gradient_checkpointing 0 \ --dataloader_num_workers 8 \ --report_to wandb \ --run_name ${exp_id} \ --seed 42 \ > >(tee ${log_dir}/train.log) \ 2> >(tee ${log_dir}/train.err >&2) ================================================ FILE: scripts/run_finetune_with_lora.sh ================================================ #!/bin/bash model_name_or_path=meta-llama/Llama-3.2-3B-Instruct dataset_path=data/alpaca/train_conversation conversation_template=llama3 output_dir=output_models/finetune_lora # LoRA related arguments lora_r=8 lora_alpha=32 lora_dropout=0.1 # Finetune exp_id=finetune_with_lora log_dir=${output_dir}/log/ mkdir -p ${output_dir} ${log_dir} accelerate launch --config_file configs/accelerate_fsdp_config.yaml \ examples/finetune.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code 0 \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --conversation_template ${conversation_template} \ --use_lora 1 \ --lora_r ${lora_r} \ --lora_alpha ${lora_alpha} \ --lora_dropout ${lora_dropout} \ --disable_group_texts 1 \ --num_train_epochs 1 \ --block_size 512 \ --per_device_train_batch_size 1 \ --gradient_accumulation_steps 1 \ --learning_rate 2e-5 \ --lr_scheduler_type cosine \ --bf16 \ --torch_dtype bfloat16 \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --use_flash_attention 0 \ --gradient_checkpointing 0 \ --dataloader_num_workers 8 \ --report_to wandb \ --run_name ${exp_id} \ --seed 42 \ > >(tee ${log_dir}/train.log) \ 2> >(tee ${log_dir}/train.err >&2) ================================================ FILE: scripts/run_finetune_with_qlora.sh ================================================ #!/bin/bash model_name_or_path=meta-llama/Llama-3.2-3B-Instruct dataset_path=data/alpaca/train_conversation conversation_template=llama3 output_dir=output_models/finetune_qlora # QLoRA related arguments quant_bit=4 lora_r=8 lora_alpha=32 lora_dropout=0.1 # Finetune exp_id=finetune_with_qlora log_dir=${output_dir}/log/ mkdir -p ${output_dir} ${log_dir} accelerate launch --config_file configs/accelerate_fsdp_config.yaml \ examples/finetune.py \ --model_name_or_path ${model_name_or_path} \ --trust_remote_code 0 \ --dataset_path ${dataset_path} \ --output_dir ${output_dir} --overwrite_output_dir \ --conversation_template ${conversation_template} \ --use_qlora 1 \ --quant_bit ${quant_bit} \ --lora_r ${lora_r} \ --lora_alpha ${lora_alpha} \ --lora_dropout ${lora_dropout} \ --disable_group_texts 1 \ --num_train_epochs 1 \ --block_size 512 \ --per_device_train_batch_size 1 \ --gradient_accumulation_steps 1 \ --learning_rate 2e-5 \ --lr_scheduler_type cosine \ --bf16 \ --torch_dtype bfloat16 \ --validation_split_percentage 0 \ --logging_steps 20 \ --do_train \ --ddp_timeout 72000 \ --save_steps 5000 \ --use_flash_attention 0 \ --gradient_checkpointing 0 \ --dataloader_num_workers 8 \ --report_to wandb \ --run_name ${exp_id} \ --seed 42 \ > >(tee ${log_dir}/train.log) \ 2> >(tee ${log_dir}/train.err >&2) ================================================ FILE: scripts/run_merge_lora.sh ================================================ #!/bin/bash # Parses arguments model_name_or_path=gpt2 lora_model_path=output_models/lora output_model_path=output_models/merge_lora device=cpu while [[ $# -ge 1 ]]; do key="$1" case ${key} in --model_name_or_path) model_name_or_path="$2" shift ;; --lora_model_path) lora_model_path="$2" shift ;; --output_model_path) output_model_path="$2" shift ;; --device) device="$2" shift ;; *) echo "error: unknown option \"${key}\"" 1>&2 exit 1 esac shift done if [ ${device} == "cpu" ]; then python examples/merge_lora.py \ --model_name_or_path ${model_name_or_path} \ --lora_model_path ${lora_model_path} \ --output_model_path ${output_model_path} \ --device ${device} \ elif [ ${device} == "gpu" ]; then echo "Error: Merging LoRA weights using gpu not supported yet. Please use cpu." else echo "Error: Unknown device \"${device}\"" 1>&2 exit 1 fi ================================================ FILE: scripts/run_sglang_inference.sh ================================================ python examples/sglang_inference.py \ --model_name_or_path Qwen/Qwen3-4B-Instruct-2507 \ --dataset_path data/alpaca/prompt_only \ --inference_engine sglang \ --inference_gpu_memory_utilization 0.8 \ --num_output_sequences 2 \ --temperature 1.0 \ --max_new_tokens 2048 \ --top_p 0.95 \ --random_seed 42 \ --save_inference_results True \ --inference_results_path output_data/sglang_inference_results/results.json ================================================ FILE: scripts/run_unittest.sh ================================================ #!/bin/bash python -m unittest discover ================================================ FILE: setup.py ================================================ import os from setuptools import find_packages, setup folder = os.path.dirname(__file__) version_path = os.path.join(folder, "src", "lmflow", "version.py") __version__ = None with open(version_path) as f: exec(f.read(), globals()) req_path = os.path.join(folder, "requirements.txt") install_requires = [] if os.path.exists(req_path): with open(req_path) as fp: install_requires = [line.strip() for line in fp] extra_require = { "multimodal": ["Pillow"], "vllm": ["vllm>=0.4.3"], "sglang": ["sglang"], "ray": ["ray>=2.22.0"], "gradio": ["gradio"], "flask": ["flask", "flask_cors"], "flash_attn": ["flash-attn>=2.0.2"], "trl": ["trl==0.8.0"], "deepspeed": ["deepspeed>=0.14.4"], "develop": ["pytest"], "dev": ["ruff", "pytest", "pre-commit"], } readme_path = os.path.join(folder, "README.md") readme_contents = "" if os.path.exists(readme_path): with open(readme_path, encoding="utf-8") as fp: readme_contents = fp.read().strip() setup( name="lmflow", version=__version__, description="LMFlow: Large Model Flow.", author="The LMFlow Team", long_description=readme_contents, long_description_content_type="text/markdown", package_dir={"": "src"}, packages=find_packages("src"), package_data={}, install_requires=install_requires, extras_require=extra_require, classifiers=[ "Intended Audience :: Science/Research/Engineering", "Topic :: Scientific/Engineering :: Artificial Intelligence", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", ], requires_python=">=3.9", ) # optionals # lm-eval==0.3.0 ================================================ FILE: src/lmflow/__init__.py ================================================ from .version import __version__ as internal_version __version__ = internal_version from transformers.utils import check_min_version from transformers.utils.versions import require_version from lmflow import args, datasets, models, pipeline, utils # Will error if the minimal version of Transformers is not installed. Remove at your own risks. check_min_version("4.27.0.dev0") require_version("datasets>=1.8.0", "To fix: pip install -r examples/pytorch/language-modeling/requirements.txt") __all__ = ["args", "datasets", "models", "pipeline", "utils"] ================================================ FILE: src/lmflow/args.py ================================================ #!/usr/bin/env python """This script defines dataclasses: ModelArguments and DatasetArguments, that contain the arguments for the model and dataset used in training. It imports several modules, including dataclasses, field from typing, Optional from typing, require_version from transformers.utils.versions, MODEL_FOR_CAUSAL_LM_MAPPING, and TrainingArguments from transformers. MODEL_CONFIG_CLASSES is assigned a list of the model config classes from MODEL_FOR_CAUSAL_LM_MAPPING. MODEL_TYPES is assigned a tuple of the model types extracted from the MODEL_CONFIG_CLASSES. """ import logging from dataclasses import dataclass, field from pathlib import Path from typing import Optional from transformers import ( MODEL_FOR_CAUSAL_LM_MAPPING, TrainingArguments, ) from transformers.utils.versions import require_version from lmflow.utils.versioning import is_flash_attn_available MODEL_CONFIG_CLASSES = list(MODEL_FOR_CAUSAL_LM_MAPPING.keys()) MODEL_TYPES = tuple(conf.model_type for conf in MODEL_CONFIG_CLASSES) logger = logging.getLogger(__name__) class OptimizerNames: DUMMY = "dummy" ADABELIEF = "adabelief" ADABOUND = "adabound" LARS = "lars" LAMB = "lamb" ADAMAX = "adamax" NADAM = "nadam" RADAM = "radam" ADAMP = "adamp" SGDP = "sgdp" YOGI = "yogi" SOPHIA = "sophia" ADAN = "adan" ADAM = "adam" NOVOGRAD = "novograd" ADADELTA = "adadelta" ADAGRAD = "adagrad" MUON = "muon" ADAMW_SCHEDULE_FREE = "adamw_schedule_free" SGD_SCHEDULE_FREE = "sgd_schedule_free" @dataclass class ModelArguments: """ Define a class ModelArguments using the dataclass decorator. The class contains several optional parameters that can be used to configure a model. model_name_or_path : str a string representing the path or name of a pretrained model checkpoint for weights initialization. If None, a model will be trained from scratch. model_type : str a string representing the type of model to use if training from scratch. If not provided, a pretrained model will be used. config_overrides : str a string representing the default config settings to override when training a model from scratch. config_name : str a string representing the name or path of the pretrained config to use, if different from the model_name_or_path. tokenizer_name : str a string representing the name or path of the pretrained tokenizer to use, if different from the model_name_or_path. cache_dir : str a string representing the path to the directory where pretrained models downloaded from huggingface.co will be stored. use_fast_tokenizer : bool a boolean indicating whether to use a fast tokenizer (backed by the tokenizers library) or not. model_revision : str a string representing the specific model version to use (can be a branch name, tag name, or commit id). token : Optional[str] Necessary when accessing a private model/dataset. torch_dtype : str a string representing the dtype to load the model under. If auto is passed, the dtype will be automatically derived from the model's weights. use_ram_optimized_load : bool a boolean indicating whether to use disk mapping when memory is not enough. use_int8 : bool a boolean indicating whether to load int8 quantization for inference. load_in_4bit : bool whether to load the model in 4bit model_max_length : int The maximum length of the model. truncation_side : str The side on which the model should have truncation applied. arch_type : str Model architecture type. padding_side : str The side on which the tokenizer should have padding applied. eos_padding : bool whether to pad with eos token instead of pad token. ignore_bias_buffers : bool fix for DDP issues with LM bias/mask buffers - invalid scalar type,`inplace operation. """ model_name_or_path: Optional[str] = field( default=None, metadata={ "help": ( "The model checkpoint for weights initialization.Don't set if you want to train a model from scratch." ) }, ) lora_model_path: Optional[str] = field( default=None, metadata={ "help": ( "The incremental model diff introduced by LoRA finetuning." " Along with the original non-finetuned model forms the whole" " finetuned model." ) }, ) model_type: Optional[str] = field( default=None, metadata={"help": "If training from scratch, pass a model type from the list: " + ", ".join(MODEL_TYPES)}, ) config_overrides: Optional[str] = field( default=None, metadata={ "help": ( "Override some existing default config settings when a model is trained from scratch. Example: " "n_embd=10,resid_pdrop=0.2,scale_attn_weights=false,summary_type=cls_index" ) }, ) arch_type: Optional[str] = field( default="decoder_only", metadata={ "help": ("Model architecture type."), "choices": ["decoder_only", "encoder_decoder", "text_regression", "vision_encoder_decoder"], }, ) config_name: Optional[str] = field( default=None, metadata={"help": "Pretrained config name or path if not the same as model_name"} ) tokenizer_name: Optional[str] = field( default=None, metadata={"help": "Pretrained tokenizer name or path if not the same as model_name"} ) cache_dir: Optional[str] = field( default=None, metadata={"help": "Where do you want to store the pretrained models downloaded from huggingface.co"}, ) use_fast_tokenizer: bool = field( default=True, metadata={"help": "Whether to use one of the fast tokenizer (backed by the tokenizers library) or not."}, ) model_revision: str = field( default="main", metadata={"help": "The specific model version to use (can be a branch name, tag name or commit id)."}, ) token: Optional[str] = field( default=None, metadata={"help": ("Necessary to specify when accessing a private model/dataset.")}, ) trust_remote_code: bool = field( default=False, metadata={"help": ("Whether to trust remote code when loading model.")}, ) torch_dtype: Optional[str] = field( default=None, metadata={ "help": ( "Override the default `torch.dtype` and load the model under this dtype. If `auto` is passed, the " "dtype will be automatically derived from the model's weights." ), "choices": ["auto", "bfloat16", "float16", "float32"], }, ) use_dora: bool = field( default=False, metadata={"help": "Whether to dora, https://github.com/NVlabs/DoRA."}, ) use_lora: bool = field( default=False, metadata={"help": "Whether to lora."}, ) use_qlora: bool = field( default=False, metadata={"help": "Whether to use qlora."}, ) bits: Optional[int] = field( default=None, metadata={ "help": "[deprecated] The number of bits for quantization.", "choices": [4, 8], }, ) quant_bit: int = field( default=4, metadata={ "help": "The number of bits for quantization.", "choices": [4, 8], }, ) quant_type: str = field( default="nf4", metadata={ "help": "The quantization type for quantization.", "choices": ["nf4", "fp4"], }, ) double_quant: bool = field( default=True, metadata={"help": "Whether to use double quantization."}, ) lora_r: int = field( default=8, metadata={"help": "the rank of the lora parameters. The smaller lora_r is , the fewer parameters lora has."}, ) lora_alpha: int = field( default=32, metadata={ "help": "Merging ratio between the fine-tuned model and the original. This is controlled by a parameter " "called alpha in the paper." }, ) lora_target_modules: str = field( default=None, metadata={"help": "Model modules to apply LoRA to. Use comma to separate multiple modules."} ) lora_dropout: float = field( default=0.1, metadata={"help": "The dropout rate in lora.linear."}, ) save_aggregated_lora: bool = field( default=False, metadata={"help": "Whether to save aggregated lora."}, ) use_ram_optimized_load: bool = field( default=True, metadata={"help": "Whether use disk mapping when memory is not enough."} ) use_flash_attention: bool = field( default=False, metadata={"help": ("whether use flash attention layer to reduce GPU memory with higher time cost.")}, ) truncate_to_model_max_length: bool = field( default=True, metadata={"help": ("whether truncate the dataset to model max length.")} ) do_rope_scaling: bool = field( default=False, metadata={ "help": ( "whether do ROPE scaling for llama model." "Linear_scaling credits to the Reddit user /u/kaiokendev." "https://arxiv.org/abs/2306.15595" "NTK_scaling credits to the Reddit users /u/bloc97 and /u/emozilla." "https://www.reddit.com/r/LocalLLaMA/comments/14lz7j5/ntkaware_scaled_rope_allows_llama_models_to_have/" ) }, ) rope_pi_ratio: int = field(default=1, metadata={"help": ("the ratio of pi in RoPE scaling.")}) rope_ntk_ratio: int = field(default=1, metadata={"help": ("the ratio of NTK in RoPE scaling.")}) use_int8: bool = field(default=False, metadata={"help": "whether to load int8 quantization for inference"}) load_in_4bit: Optional[bool] = field( default=True, metadata={"help": "whether to load the model in 4bit"}, ) model_max_length: Optional[int] = field( default=None, metadata={ "help": ( "The maximum length of the model. When not specified, " "will follow the model's default max length. (i.e., tokenizer.model_max_length)" ) }, ) truncation_side: str = field( default=None, metadata={ "help": ( "The side on which the tokenizer should have truncation applied. " "When not specified, will follow the tokenizer's default truncation strategy. " "(i.e., tokenizer.truncation_side)" ), "choices": [None, "left", "right"], }, ) padding_side: str = field( default="right", metadata={ "help": ( "The side on which the tokenizer should have padding applied. " "LMFlow uses right padding by default. When set to `auto`, will " "use padding_side from tokenizer.padding_side." ), "choices": ["right", "left", "auto"], }, ) eos_padding: Optional[bool] = field(default=False, metadata={"help": "whether to pad with eos token"}) ignore_bias_buffers: Optional[bool] = field( default=False, metadata={ # debug argument for distributed training "help": "fix for DDP issues with LM bias/mask buffers - invalid scalar type,`inplace operation. See" "https://github.com/huggingface/transformers/issues/22482#issuecomment-1595790992" }, ) def __post_init__(self): if self.config_overrides is not None and (self.config_name is not None or self.model_name_or_path is not None): raise ValueError( "--config_overrides can't be used in combination with --config_name or --model_name_or_path" ) if self.use_qlora: if not self.use_lora: logger.warning("use_qlora is set to True, but use_lora is not set to True. Setting use_lora to True.") self.use_lora = True if self.use_flash_attention: if not is_flash_attn_available(): self.use_flash_attention = False logger.warning( "Flash attention is not available in the current environment. Disabling " "flash attention. If you want to use flash attention, please install by " "`pip install -e '.[flash_attn]'`." ) else: logger.warning( "Flash attention is not enabled. We recommend enabling flash attention by " "`--use_flash_attention 1` for better performance." ) if self.lora_target_modules is not None: self.lora_target_modules: list[str] = split_args(self.lora_target_modules) if "encoder_decoder" in self.arch_type: raise NotImplementedError("The encoder-decoder model is not fully implemented yet.") if self.bits is not None: logger.warning("The argument `bits` is deprecated. Please use `quant_bit` instead.") self.quant_bit = self.bits @dataclass class VisModelArguments(ModelArguments): low_resource: Optional[bool] = field(default=False, metadata={"help": "Use 8 bit and float16 when loading llm"}) custom_model: bool = field(default=False, metadata={"help": "flag for the model from huggingface or not"}) pretrained_language_projection_path: str = field( default=None, metadata={"help": "path for model pretrained_language_projection_path"} ) custom_vision_model: bool = field(default=False, metadata={"help": "flag for the model from huggingface or not"}) image_encoder_name_or_path: Optional[str] = field( default=None, metadata={"help": ("The name or path of the image encoder to use.")}, ) qformer_name_or_path: Optional[str] = field( default=None, metadata={"help": ("llm model in multi-modality model")}, ) llm_model_name_or_path: Optional[str] = field( default=None, metadata={"help": ("llm model in multi-modality model")}, ) use_prompt_cache: bool = field( default=False, metadata={"help": "Whether to use prompt cache."}, ) prompt_cache_path: Optional[str] = field( default=None, metadata={"help": "Path to prompt cache."}, ) llava_loading: Optional[bool] = field( default=False, metadata={"help": "Whether to load module by module from pretrained model."}, ) with_qformer: Optional[bool] = field( default=False, metadata={"help": "Whether to use qformer."}, ) vision_select_layer: Optional[int] = field( default=-2, metadata={"help": "Which layer to select in vision model."}, ) llava_pretrain_model_path: Optional[str] = field( default=None, metadata={"help": "Path to llava pretrained model."}, ) save_pretrain_model_path: Optional[str] = field( default=None, metadata={"help": "Path to pretrained model."}, ) @dataclass class DatasetArguments: """ Define a class DatasetArguments using the dataclass decorator. The class contains several optional parameters that can be used to configure a dataset for a language model. dataset_path : str a string representing the path of the dataset to use. dataset_name : str a string representing the name of the dataset to use. The default value is "customized". is_custom_dataset : bool a boolean indicating whether to use custom data. The default value is False. customized_cache_dir : str a string representing the path to the directory where customized dataset caches will be stored. dataset_config_name : str a string representing the configuration name of the dataset to use (via the datasets library). train_file : str a string representing the path to the input training data file (a text file). validation_file : str a string representing the path to the input evaluation data file to evaluate the perplexity on (a text file). max_train_samples : int an integer indicating the maximum number of training examples to use for debugging or quicker training. If set, the training dataset will be truncated to this number. max_eval_samples: int an integer indicating the maximum number of evaluation examples to use for debugging or quicker training. If set, the evaluation dataset will be truncated to this number. streaming : bool a boolean indicating whether to enable streaming mode. block_size: int an integer indicating the optional input sequence length after tokenization. The training dataset will be truncated in blocks of this size for training. train_on_prompt: bool a boolean indicating whether to train on prompt for conversation datasets such as ShareGPT. conversation_template: str a string representing the template for conversation datasets. dataset_cache_dir: str a string representing the path to the dataset cache directory. Useful when the default cache dir (`~/.cache/huggingface/datasets`) has limited space. The class also includes some additional parameters that can be used to configure the dataset further, such as `overwrite_cache`, `validation_split_percentage`, `preprocessing_num_workers`, `disable_group_texts`, `demo_example_in_prompt`, `explanation_in_prompt`, `keep_linebreaks`, and `prompt_structure`. The field function is used to set default values and provide help messages for each parameter. The Optional type hint is used to indicate that a parameter is optional. The metadata argument is used to provide additional information about each parameter, such as a help message. """ dataset_path: Optional[str] = field(default=None, metadata={"help": "The path of the dataset to use."}) dataset_name: Optional[str] = field(default="customized", metadata={"help": 'Should be "customized"'}) is_custom_dataset: Optional[bool] = field(default=False, metadata={"help": "whether to use custom data"}) customized_cache_dir: Optional[str] = field( default=".cache/llm-ft/datasets", metadata={"help": "Where do you want to store the customized dataset caches"}, ) dataset_config_name: Optional[str] = field( default=None, metadata={"help": "The configuration name of the dataset to use (via the datasets library)."} ) train_file: Optional[str] = field(default=None, metadata={"help": "The input training data file (a text file)."}) validation_file: Optional[str] = field( default=None, metadata={"help": "An optional input evaluation data file to evaluate the perplexity on (a text file)."}, ) max_train_samples: Optional[int] = field( default=None, metadata={ "help": ( "For debugging purposes or quicker training, truncate the number of training examples to this " "value if set." ) }, ) max_eval_samples: Optional[int] = field( default=1e10, metadata={ "help": ( "For debugging purposes or quicker training, truncate the number of evaluation examples to this " "value if set." ) }, ) streaming: bool = field(default=False, metadata={"help": "Enable streaming mode"}) block_size: Optional[int] = field( default=None, metadata={ "help": ( "Optional input sequence length after tokenization. " "The training dataset will be truncated in block of this size for training. " "Default to the model max input length for single sentence inputs (take into account special tokens)." ) }, ) overwrite_cache: bool = field(default=False, metadata={"help": "Overwrite the cached training and evaluation sets"}) validation_split_percentage: Optional[int] = field( default=5, metadata={"help": "The percentage of the train set used as validation set in case there's no validation split"}, ) preprocessing_num_workers: Optional[int] = field( default=None, metadata={"help": "The number of processes to use for the preprocessing."}, ) group_texts_batch_size: int = field( default=1000, metadata={ "help": ( "Number of samples that will be grouped together to go though" " `group_texts` operation. See `--disable_group_texts` for" " detailed explanation of this operation." ) }, ) disable_group_texts: bool = field( default=True, metadata={ "help": ( "Whether we disable group of original samples together to" " generate sample sequences of length `block_size`" " By Default, it is True, which means the long samples" " are truncated to `block_size` tokens" " and short samples are padded to `block_size` tokens." " If set to False, we group every 1000 tokenized" " sequences together, divide them into" " [{total_num_tokens} / {block_size}] sequences," " each with `block_size` tokens" " (the remaining tokens are ommited." " This group text behavior is useful" " for continual pretrain or pretrain." ) }, ) keep_linebreaks: bool = field( default=True, metadata={"help": "Whether to keep line breaks when using TXT files or not."} ) test_file: Optional[str] = field( default=None, metadata={"help": "Evaluation File Path"}, ) train_on_prompt: bool = field( default=False, metadata={"help": "Whether to train on prompt for conversation datasets such as ShareGPT."} ) conversation_template: Optional[str] = field( default=None, metadata={ "help": ( "The template for conversation datasets. Supports LMFlow preset names " "(e.g. llama3, qwen2_5, deepseek_v3) and special values " "`tokenizer` / `hf_auto` to use tokenizer.chat_template " "(`tokenizer` is strict; `hf_auto` falls back to LMFlow default when unavailable)." ) }, ) dataset_cache_dir: Optional[str] = field( default=None, metadata={ "help": ( "The path to the dataset cache directory. Useful when the " "default cache dir (`~/.cache/huggingface/datasets`) has limited space." ) }, ) calculate_dataset_stats: bool = field( default=False, metadata={ "help": ( "Whether to calculate the dataset statistics, including the number of samples, " "the average length of samples, total tokens, etc." ) }, ) def __post_init__(self): if self.streaming: require_version("datasets>=2.0.0", "The streaming feature requires `datasets>=2.0.0`") if self.dataset_name is None and self.train_file is None and self.validation_file is None: raise ValueError("Need either a dataset name or a training/validation file.") else: if self.train_file is not None: extension = self.train_file.split(".")[-1] assert extension in ["csv", "json", "txt"], "`train_file` should be a csv, a json or a txt file." if self.validation_file is not None: extension = self.validation_file.split(".")[-1] assert extension in ["csv", "json", "txt"], "`validation_file` should be a csv, a json or a txt file." @dataclass class MultiModalDatasetArguments(DatasetArguments): image_folder: Optional[str] = field(default=None, metadata={"help": "The folder of the image file."}) image_aspect_ratio: Optional[str] = field(default="pad", metadata={"help": "The ratio type"}) is_multimodal: Optional[bool] = field(default=True, metadata={"help": "Flag for the modality type."}) use_image_start_end: Optional[bool] = field(default=True, metadata={"help": "Flag for the modality type."}) sep_style: Optional[str] = field(default="plain", metadata={"help": "Sep style in multi_modality dataset."}) @dataclass class FinetunerArguments(TrainingArguments): """ Adapt transformers.TrainingArguments """ eval_dataset_path: Optional[str] = field(default=None, metadata={"help": "The path of the eval dataset to use."}) remove_unused_columns: Optional[bool] = field( default=False, metadata={"help": "whether to remove the unused columns in collate fn"} ) finetune_part: Optional[str] = field(default="language_projection", metadata={"help": "the module to finetune."}) save_language_projection: Optional[str] = field( default=False, metadata={"help": "whether to save language projection layer in multi-modal models."} ) use_lisa: bool = field(default=False, metadata={"help": "whether to use LISA training strategy."}) lisa_activated_layers: int = field(default=2, metadata={"help": "the number of activated layers in LISA."}) lisa_interval_steps: int = field( default=20, metadata={ "help": "the number of steps in each freezing interval of LISA, i.e. the selected unfreezed layers " "are randomly switched every {lisa_interval_steps} steps." }, ) lisa_layers_attribute: str = field( default="model.model.layers", metadata={"help": "where the layer attribute stores, e.g. model.model.layers"} ) use_customized_optim: bool = field(default=False, metadata={"help": "whether to use customized optimizers."}) customized_optim: str = field(default="sign_sgd", metadata={"help": "name of the customized optimizer."}) customized_optim_args: str = field(default=None, metadata={"help": "optional arguments that are supplied."}) optim_dummy_beta1: float = field( default=0.9, metadata={"help": "A useless argument for dummy optimizer, just for tutorial"} ) optim_dummy_beta2: float = field( default=0.999, metadata={"help": "A useless argument for dummy optimizer, just for tutorial"} ) optim_adam_beta1: float = field( default=0.9, metadata={"help": "Coefficient used for computing running averages of gradient"} ) optim_adam_beta2: float = field( default=0.999, metadata={"help": "Coefficient used for computing running averages of squared gradient"} ) optim_beta1: float = field( default=0.9, metadata={"help": "Coefficient used for computing running averages of gradient"} ) optim_beta2: float = field( default=0.999, metadata={"help": "Coefficient used for computing running averages of squared gradient"} ) optim_beta3: float = field( default=0.9, metadata={"help": "Coefficient used for computing running averages of gradient"} ) optim_momentum: float = field( default=0.999, metadata={"help": "Coefficient used for the momentum term in optimizers like SGD with momentum"} ) optim_weight_decay: float = field( default=0, metadata={"help": "Weight decay (L2 penalty) added to the loss to prevent overfitting"} ) @dataclass class RewardModelTunerArguments(FinetunerArguments): """ Arguments for reward modeling. """ pass @dataclass class EvaluatorArguments: """ Define a class EvaluatorArguments using the dataclass decorator. The class contains several optional parameters that can be used to configure a evaluator. local_rank : str For distributed training: local_rank random_shuffle : bool use_wandb : bool random_seed : int, default = 1 output_dir : str, default = './output_dir', mixed_precision : str, choice from ["bf16","fp16"]. mixed precision mode, whether to use bf16 or fp16 deepspeed : Enable deepspeed and pass the path to deepspeed json config file (e.g. ds_config.json) or an already loaded json file as a dict temperature : float An argument of model.generate in huggingface to control the diversity of generation. repetition_penalty : float An argument of model.generate in huggingface to penalize repetitions. """ local_rank: int = field(default=-1, metadata={"help": "For distributed training: local_rank"}) random_shuffle: Optional[bool] = field(default=False, metadata={"help": ""}) use_wandb: Optional[bool] = field( default=False, metadata={"help": ("When this flag is True, wandb will be enabled")}, ) random_seed: Optional[int] = field( default=1, metadata={"help": ("used to set random seed")}, ) output_dir: Optional[str] = field( default="./output_dir", metadata={"help": "Output path for the inferenced results"}, ) mixed_precision: Optional[str] = field( default="bf16", metadata={ "help": ("mixed precision mode, whether to use bf16 or fp16"), "choices": ["bf16", "fp16"], }, ) deepspeed: Optional[str] = field( default=None, metadata={ "help": ( "Enable deepspeed and pass the path to deepspeed json config file (e.g. ds_config.json) or an already" " loaded json file as a dict" ) }, ) answer_type: Optional[str] = field( default="text", metadata={ "help": ( "Question type for answer extraction from the decoder output." " Supported types: \n" ' 1) "multiple_choice", e.g. A, B, C, D, ...\n' ' 2) "binary_choice", e.g. yes, no, maybe\n' ' 3) "math", e.g. 1.0, -3.52\n' ' 4) "text", e.g. "I think that it is okay"\n' " 5) Special treatment for several datasets\n" ' - "gsm8k"\n' ' - "svamp"\n' ' - "asdiv"\n' ' - "addsub"\n' ' - "singleeq"\n' ' - "multiarith"\n' ' - "aqua"\n' ' - "csqa"\n' ' - "strategyqa"\n' ' - "pubmedqa"\n' ' - "medmcqa"\n' ' - "usmle"\n' ) }, ) prompt_structure: Optional[str] = field( default="{input}", metadata={ "help": ( "Prompt structure to facilitate prompt engineering during" " inference. The model will receive" " `prompt_structure.format(input=input)` as its input." ) }, ) evaluate_block_size: Optional[int] = field( default=512, metadata={ "help": ( "the model will have at least block_size tokens for context when calculating the " "conditional likelihood of any one token (provided there are block_size preceding " "tokens available to condition on)" ) }, ) metric: Optional[str] = field( default="accuracy", metadata={ "help": "the metric the model will be evaluated on", "choices": ["ppl", "perplexity", "acc", "accuracy", "nll", "neg_log_likelihood"], }, ) inference_batch_size_per_device: Optional[int] = field( default=1, metadata={ "help": ( "every device will infer {inference_batch_size_per_device}" " samples in parallel. The inferred results will be concatenaed" " with inputs and attach a reward." ), }, ) use_accelerator_for_evaluator: Optional[bool] = field( default=None, metadata={"help": "[Deprecated] Whether to use Huggingface Accelerator instead of Deepspeed"}, ) temperature: float = field( default=0, metadata={"help": "Temperature during inference."}, ) repetition_penalty: float = field( default=1, metadata={"help": "Repetition_penalty during inference."}, ) max_new_tokens: int = field( default=100, metadata={"help": "Maximum length during inference."}, ) minibatch_size: int = field( default=1, metadata={"help": "Mini batch size during evaluation."}, ) def __post_init__(self): if self.use_accelerator_for_evaluator is not None: logger.warning( "You've specified `use_accelerator_for_evaluator`. This argument is deprecated. " "It will not take effect and will be removed in a future version, " "since LMFlow now can automatically detect whether is in Accelerate or Deepspeed environment." ) @dataclass class InferencerArguments: """ Define a class InferencerArguments using the dataclass decorator. The class contains several optional parameters that can be used to configure a inferencer. local_rank : str For distributed training: local_rank random_seed : int, default = 1 inference_batch_size : int, default = 1 deepspeed : Enable deepspeed and pass the path to deepspeed json config file (e.g. ds_config.json) or an already loaded json file as a dict mixed_precision : str, choice from ["bf16","fp16"]. mixed precision mode, whether to use bf16 or fp16 temperature : float An argument of model.generate in huggingface to control the diversity of generation. repetition_penalty : float An argument of model.generate in huggingface to penalize repetitions. use_beam_search : Optional[bool] Whether to use beam search during inference, By default False. num_output_sequences : Optional[int] Number of output sequences to return for the given prompt, currently only used in vllm inference, By default 8. top_p : Optional[float] top_p for sampling, By default 1.0. top_k : Optional[int] top_k for sampling, By default -1 (no top_k). additional_stop_token_ids : Optional[list[int]] the ids of the end of sentence tokens, By default []. apply_chat_template : Optional[bool] Whether to apply chat template, By default True. save_results : Optional[bool] Whether to save inference results, By default False. results_path : Optional[str] The **json file** path of inference results, By default None. enable_decode_inference_result : Optional[bool] Whether to detokenize the inference results. NOTE: For iterative align pipelines, whether to detokenize depends on the homogeneity of the policy model and the reward model (i.e., if they have the same tokenizer). use_vllm: bool, optional Whether to use VLLM for inference, By default False. vllm_tensor_parallel_size: int, optional The tensor parallel size for VLLM inference. vllm_gpu_memory_utilization: float, optional The GPU memory utilization for VLLM inference. The proportion of GPU memory (per GPU) to use for VLLM inference. """ device: str = field( default="gpu", metadata={ "help": "device of chatbot", "choices": ["gpu", "cpu"], }, ) local_rank: int = field( default=-1, metadata={"help": "For distributed training: local_rank"}, ) inference_batch_size: int = field( default=1, metadata={"help": "batch size for inference"}, ) vllm_inference_batch_size: int = field(default=1, metadata={"help": "The batch size for VLLM inference."}) temperature: float = field( default=0.0, metadata={"help": "Temperature during inference."}, ) repetition_penalty: float = field( default=1, metadata={"help": "Repetition_penalty during inference."}, ) max_new_tokens: int = field( default=100, metadata={"help": "Maximum length during inference."}, ) random_seed: Optional[int] = field( default=1, metadata={"help": ("used to set random seed")}, ) deepspeed: Optional[str] = field( default=None, metadata={ "help": ( "Enable deepspeed and pass the path to deepspeed json config file (e.g. ds_config.json) or an already" " loaded json file as a dict" ) }, ) mixed_precision: Optional[str] = field( default="bf16", metadata={ "help": ("mixed precision mode, whether to use bf16 or fp16"), "choices": ["bf16", "fp16"], }, ) do_sample: Optional[bool] = field( default=False, metadata={"help": "whether turn on true random sampling during inference."}, ) return_logprob: Optional[bool] = field( default=False, metadata={"help": "whether to return log probability during inference."}, ) use_accelerator: Optional[bool] = field( default=None, metadata={"help": "[Deprecated] Whether to use Huggingface Accelerator instead of Deepspeed"}, ) use_beam_search: Optional[bool] = field( default=False, metadata={"help": "whether to use beam search during inference."}, ) num_output_sequences: Optional[int] = field( default=8, metadata={ "help": ( "number of output sequences to return for the given prompt, currently only used in vllm inference." ) }, ) top_p: Optional[float] = field( default=1.0, metadata={"help": "top_p for sampling."}, ) top_k: Optional[int] = field( default=-1, metadata={"help": "top_k for sampling."}, ) additional_stop_token_ids: Optional[list[int]] = field( default_factory=lambda: [], metadata={"help": "the ids of the end of sentence tokens"}, ) apply_chat_template: Optional[bool] = field( default=True, metadata={"help": "whether to apply chat template"}, ) enable_decode_inference_result: Optional[bool] = field( default=False, metadata={"help": "Whether to decode the inference results."}, ) tensor_parallel_size: Optional[int] = field( default=1, metadata={"help": "The tp size for distributed (multi-instance) inference."} ) enable_distributed_inference: Optional[bool] = field( default=False, metadata={"help": "Whether to use multi-instance VLLM inference."} ) distributed_inference_num_instances: Optional[int] = field( default=1, metadata={"help": "The number of instances for multi-instance VLLM inference."} ) # vllm inference args use_vllm: Optional[bool] = field( default=None, metadata={ "help": "Whether to use VLLM for inference, By default None. Deprecated, use inference_engine instead." }, ) vllm_tensor_parallel_size: Optional[int] = field( default=None, metadata={ "help": ( "The tensor parallel size for VLLM inference. Deprecated, use inference_tensor_parallel_size instead." ) }, ) vllm_gpu_memory_utilization: Optional[float] = field( default=None, metadata={ "help": ( "The GPU memory utilization for VLLM inference. " "Deprecated, use inference_gpu_memory_utilization instead." ) }, ) # inference engine args inference_engine: Optional[str] = field( default="huggingface", metadata={ "help": "The inference engine to use, by default huggingface.", "choices": ["huggingface", "vllm", "sglang"], }, ) inference_tensor_parallel_size: Optional[int] = field( default=1, metadata={"help": "The tensor parallel size for inference."} ) inference_gpu_memory_utilization: Optional[float] = field( default=0.95, metadata={"help": "The GPU memory utilization for inference."} ) enable_deterministic_inference: bool = field( default=False, metadata={ "help": "Whether to enable deterministic inference. Only supported for SGLang inference engine currently." }, ) attention_backend: Optional[str] = field( default=None, metadata={ "help": ( "The attention backend to use. Only supported for SGLang inference engine currently. " "Please leave it as None to let SGLang automatically choose if you're not sure." ) }, ) # Args for result saving save_results: Optional[bool] = field(default=None, metadata={"help": "Whether to save results."}) results_path: Optional[str] = field(default=None, metadata={"help": "The path of results."}) save_inference_results: Optional[bool] = field(default=False, metadata={"help": "Whether to save inference results."}) inference_results_path: Optional[str] = field(default=None, metadata={"help": "The path of inference results."}) def __post_init__(self): if self.use_accelerator is not None: logger.warning( "You've specified `use_accelerator`. This argument is deprecated. " "It will not take effect and will be removed in a future version, " "since LMFlow now can automatically detect whether is in Accelerate or Deepspeed environment." ) if self.save_results: logger.warning("`save_results` is deprecated and will be removed in a future version. Please use `save_inference_results` instead.") self.save_inference_results = self.save_results if self.results_path: logger.warning("`results_path` is deprecated and will be removed in a future version. Please use `inference_results_path` instead.") self.inference_results_path = self.results_path if self.save_inference_results: if self.inference_results_path is None: raise ValueError("Need to specify inference_results_path when save_inference_results is True.") else: if not self.inference_results_path.endswith(".json"): raise ValueError("The inference_results_path must be a json file.") else: Path(self.inference_results_path).parent.mkdir(parents=True, exist_ok=True) if self.use_vllm is True: logger.warning( "Inference engine is set to vllm. You've specified `use_vllm`. This argument is deprecated and " "will be removed in a future version. Please use `inference_engine` instead." ) self.inference_engine = "vllm" if self.vllm_tensor_parallel_size is not None: logger.warning( "You've specified `vllm_tensor_parallel_size`. This argument is deprecated and " "will be removed in a future version. Please use `inference_tensor_parallel_size` instead." ) self.inference_tensor_parallel_size = self.vllm_tensor_parallel_size if self.vllm_gpu_memory_utilization is not None: logger.warning( "You've specified `vllm_gpu_memory_utilization`. This argument is deprecated and " "will be removed in a future version. Please use `inference_gpu_memory_utilization` instead." ) self.inference_gpu_memory_utilization = self.vllm_gpu_memory_utilization if self.inference_engine != "sglang": if self.return_logprob: logger.warning("`return_logprob` is only supported for SGLang inference engine currently. ") if self.inference_engine == "sglang": if self.enable_deterministic_inference: if self.attention_backend is None: self.attention_backend = "fa3" logger.warning( "`enable_deterministic_inference` is enabled, but `attention_backend` is not specified. " "Using `fa3` as the attention backend by default." ) else: assert self.attention_backend in ["fa3", "flashinfer", "triton"], ( "Invalid attention backend. Please choose from 'fa3', 'flashinfer', or 'triton'." ) @dataclass class RaftAlignerArguments(TrainingArguments): """ Define a class RaftAlignerArguments to configure raft aligner. """ output_reward_path: Optional[str] = field( default="tmp/raft_aligner/", metadata={"help": "The path of output rewards."} ) output_min_length: Optional[int] = field( default=64, metadata={ "help": ("minimum length of the output token sequence generated from model given an input."), }, ) output_max_length: Optional[int] = field( default=128, metadata={ "help": ("maximum length of the output token sequence generated from model given an output."), }, ) num_raft_iteration: Optional[int] = field( default=20, metadata={"help": "number of iterations of the raft aligner."}, ) raft_batch_size: Optional[int] = field( default=1024, metadata={"help": ("only select {raft_batch_size} samples each time for STF training.")}, ) top_reward_percentage: Optional[float] = field( default=0.2, metadata={ "help": ( "only top {top_reward_percentage} samples in the raft batch," " (in terms of rewards), will be used for SFT the model." ), }, ) inference_batch_size_per_device: Optional[int] = field( default=1, metadata={ "help": ( "every device will infer {inference_batch_size_per_device}" " samples in parallel. The inferred results will be concatenaed" " with inputs and attach a reward." ), }, ) collection_strategy: Optional[str] = field( default="top", metadata={ "help": ( "{collection_strategy} is either top or local" " top means that we rank the samples globally regardless of the prompts" " local means that we only rank the samples with the same prompt" ), }, ) @dataclass class BenchmarkingArguments: dataset_name: Optional[str] = field( default=None, metadata={"help": "benchmark dataset name provided by lmflow"}, ) lm_evaluation_metric: Optional[str] = field( default="accuracy", metadata={ "help": "the metric the model will be evaluated on", "choices": [ "acc", "acc_norm", "bleu", "chrf", "em", "f1", "ppl", "ter", "r@1", "r@2", "mrr", "mc1", "mc2", "word_perplexity", "byte_perplexity", "bits_per_byte", ], }, ) @dataclass class DPOAlignerArguments: """ The arguments for the DPO training script. """ local_rank: int = field( default=-1, metadata={"help": "For distributed training: local_rank"}, ) # data parameters beta: Optional[float] = field(default=0.1, metadata={"help": "the beta parameter for DPO loss"}) # # training parameters learning_rate: Optional[float] = field(default=5e-4, metadata={"help": "optimizer learning rate"}) lr_scheduler_type: Optional[str] = field(default="cosine", metadata={"help": "the lr scheduler type"}) warmup_steps: Optional[int] = field(default=100, metadata={"help": "the number of warmup steps"}) weight_decay: Optional[float] = field(default=0.05, metadata={"help": "the weight decay"}) optimizer_type: Optional[str] = field(default="paged_adamw_32bit", metadata={"help": "the optimizer type"}) per_device_train_batch_size: Optional[int] = field(default=4, metadata={"help": "train batch size per device"}) per_device_eval_batch_size: Optional[int] = field(default=1, metadata={"help": "eval batch size per device"}) gradient_accumulation_steps: Optional[int] = field( default=4, metadata={"help": "the number of gradient accumulation steps"}, ) gradient_checkpointing: Optional[bool] = field( default=True, metadata={"help": "whether to use gradient checkpointing"}, ) gradient_checkpointing_use_reentrant: Optional[bool] = field( default=False, metadata={"help": "whether to use reentrant for gradient checkpointing"}, ) max_prompt_length: Optional[int] = field( default=512, metadata={"help": "the maximum prompt length"}, ) max_length: Optional[int] = field( default=1024, metadata={"help": "the maximum sequence length"}, ) max_steps: Optional[int] = field( default=1000, metadata={"help": "max number of training steps"}, ) logging_steps: Optional[int] = field( default=10, metadata={"help": "the logging frequency"}, ) save_steps: Optional[int] = field( default=100, metadata={"help": "the saving frequency"}, ) eval_steps: Optional[int] = field( default=100, metadata={"help": "the evaluation frequency"}, ) output_dir: Optional[str] = field( default="./results", metadata={"help": "the output directory"}, ) log_freq: Optional[int] = field( default=1, metadata={"help": "the logging frequency"}, ) sanity_check: Optional[bool] = field(default=False, metadata={"help": "only train on 1000 samples"}) report_to: Optional[str] = field( default="wandb", metadata={ "help": 'The list of integrations to report the results and logs to. Supported platforms are `"azure_ml"`,' '`"comet_ml"`, `"mlflow"`, `"neptune"`, `"tensorboard"`,`"clearml"` and `"wandb"`. ' 'Use `"all"` to report to all integrations installed, `"none"` for no integrations.' }, ) seed: Optional[int] = field( default=0, metadata={"help": "Random seed that will be set at the beginning of training."} ) run_name: Optional[str] = field(default="dpo", metadata={"help": "The name of the run."}) eval_dataset_path: Optional[str] = field(default=None, metadata={"help": "The path of the eval dataset."}) @dataclass class DPOv2AlignerArguments(FinetunerArguments): """ The arguments for the DPOv2 training script. """ # general args random_seed: Optional[int] = field(default=42, metadata={"help": "the random seed"}) accelerate_config_file: Optional[str] = field( default=None, metadata={"help": "file path for accelerate config file, only used in memory safe dpov2 align."} ) # pair sampling args margin_scale: Optional[float] = field(default=1.0, metadata={"help": "the margin scale"}) sampling_paired_method: Optional[str] = field(default="max_random", metadata={"help": "the choose type"}) length_penalty: Optional[float] = field(default=0, metadata={"help": "the length penalty"}) # data collator args max_length: Optional[int] = field(default=2048, metadata={"help": "the maximum sequence length, prompt + output"}) max_prompt_length: Optional[int] = field(default=1000, metadata={"help": "the maximum prompt length"}) mask_prompt: Optional[bool] = field(default=False, metadata={"help": "mask prompt"}) # dpov2 aligner args beta: Optional[float] = field(default=0.1, metadata={"help": "the beta parameter for DPO loss"}) loss_type: Optional[str] = field(default="sigmoid", metadata={"help": "the loss type"}) @dataclass class IterativeAlignerArguments(InferencerArguments): """ Arguments for iterative aligners. """ dataset_path_list: list[str] = field( default_factory=list, metadata={"help": "The list of dataset paths for iterative aligners."} ) initial_iter_idx: int = field( default=0, metadata={"help": "The initial iteration index, 0 refers to the first dataset in dataset_path_list."} ) @dataclass class IterativeDPOAlignerArguments(IterativeAlignerArguments, DPOv2AlignerArguments): """ Arguments for iterative DPO aligners. """ output_dir: Optional[str] = field( default="./runs", metadata={"help": "Output path for the inferenced results"}, ) reward_model_inference_batch_size: int = field( default=1, metadata={"help": "The batch size for reward model inference."} ) reward_model_inference_block_size: int = field( default=2048, metadata={"help": "The block size for reward model inference."} ) do_response_generation: bool = field( default=True, metadata={"help": "Whether to generate responses using the model."} ) do_scoring: bool = field(default=True, metadata={"help": "Whether to score the responses using the reward model."}) do_dpo_align: bool = field(default=True, metadata={"help": "Whether to perform DPO alignment."}) PIPELINE_ARGUMENT_MAPPING = { "finetuner": FinetunerArguments, "evaluator": EvaluatorArguments, "inferencer": InferencerArguments, "vllm_inferencer": InferencerArguments, "sglang_inferencer": InferencerArguments, "rm_inferencer": InferencerArguments, "raft_aligner": RaftAlignerArguments, "dpo_aligner": DPOAlignerArguments, "rm_tuner": RewardModelTunerArguments, "dpov2_aligner": DPOv2AlignerArguments, "iterative_dpo_aligner": IterativeDPOAlignerArguments, } class AutoArguments: """ Automatically choose arguments from FinetunerArguments or EvaluatorArguments. """ def get_pipeline_args_class(pipeline_name: str): return PIPELINE_ARGUMENT_MAPPING[pipeline_name] def split_args(args): return [elem.strip() for elem in args.split(",")] if isinstance(args, str) else args ================================================ FILE: src/lmflow/datasets/__init__.py ================================================ """This Python code defines a class Dataset with methods for initializing, loading, and manipulating datasets from different backends such as Hugging Face and JSON. The `Dataset` class includes methods for loading datasets from a dictionary and a Hugging Face dataset, mapping datasets, and retrieving the backend dataset and arguments. """ from lmflow.datasets.dataset import Dataset from lmflow.utils.versioning import is_multimodal_available if is_multimodal_available(): from lmflow.datasets.multi_modal_dataset import CustomMultiModalDataset __all__ = ["Dataset", "CustomMultiModalDataset"] else: __all__ = ["Dataset"] ================================================ FILE: src/lmflow/datasets/dataset.py ================================================ #!/usr/bin/env python """This Python code defines a class Dataset with methods for initializing, loading, and manipulating datasets from different backends such as Hugging Face and JSON. The `Dataset` class includes methods for loading datasets from a dictionary and a Hugging Face dataset, mapping datasets, and retrieving the backend dataset and arguments. """ # Importing necessary libraries and modules import copy import json import logging from pathlib import Path from typing import Optional from datasets import Dataset as HFDataset from datasets import load_dataset from tqdm import tqdm from lmflow.args import DatasetArguments from lmflow.utils.constants import ( DATASET_DESCRIPTION_MAP, INSTANCE_FIELDS_MAP, TEXT_ONLY_DATASET_DESCRIPTION, ) from lmflow.utils.data_utils import check_dataset_instances_key_fast, get_dataset_type_fast from lmflow.utils.versioning import is_multimodal_available if is_multimodal_available(): from .multi_modal_dataset import CustomMultiModalDataset logger = logging.getLogger(__name__) DATASET_TYPES = [ "text_only", "text2text", "float_only", "image_text", "conversation", "paired_conversation", "paired_text_to_text", "text_to_textlist", "text_to_scored_textlist", ] KEY_TYPE = "type" KEY_INSTANCES = "instances" KEY_SCORE = "score" class Dataset: r""" Initializes the Dataset object with the given parameters. Parameters ------------ data_args : DatasetArguments object. Contains the arguments required to load the dataset. backend : str, default="huggingface" A string representing the dataset backend. Defaults to "huggingface". args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. """ def __init__(self, data_args: DatasetArguments = None, backend: str = "huggingface", *args, **kwargs): self.data_args = data_args self.backend = backend self.backend_dataset = None self.type = None # Original type of the dataset self.dataset_path = data_args.dataset_path if data_args.dataset_path is None: return if backend == "huggingface": data_files = [x.absolute().as_posix() for x in Path(self.dataset_path).glob("*.json")] logger.info(f"Data files: \n{data_files}") # check if the dataset is in the correct format and get the dataset type (text_only, text2text, etc.) self._check_hf_json_format(data_files) # Load the dataset using the HuggingFace dataset library logger.info("Loading datasets") extensions = "json" raw_dataset = load_dataset( extensions, data_files=data_files, field=KEY_INSTANCES, split="train", cache_dir=data_args.dataset_cache_dir, ) self.backend_dataset = raw_dataset self._check_instance_format() elif backend == "json": # TODO (@Jiachun) pass elif backend == "custom_multi_modal": # FIXME refactor the backend name if not is_multimodal_available(): raise ValueError('Multimodal not available. Please install via `pip install -e ".[multimodal]"`') raw_dataset = CustomMultiModalDataset(self.dataset_path, data_args) self.backend_dataset = raw_dataset else: raise NotImplementedError(f'Unsupported dataset backend "{backend}"') def __len__(self): return len(self.backend_dataset) def _check_instance_format(self): """ Checks if data (instances) have required fields. Raises messages with hints if not matched. """ fields = self.backend_dataset.features correct_fields = INSTANCE_FIELDS_MAP[self.type] if not set(correct_fields).issubset(set(fields)): raise ValueError(f"data instance fields incorrect {list(correct_fields)} are required.") def _check_hf_json_format(self, data_files: list[str]): for single_file in tqdm(data_files, desc="Checking dataset keys"): # get type and check if it is consistent json_data_type = get_dataset_type_fast(single_file) if not json_data_type: raise ValueError( f'"{KEY_TYPE}" must be provided to initialize a dataset, e.g.\n {TEXT_ONLY_DATASET_DESCRIPTION}' ) if self.type is None: self.type = json_data_type elif self.type != json_data_type: raise ValueError( "All task files must have same data types. Previous" f' files have type "{self.type}", but in file' f' {single_file}, it has type "{self.type}".' ) # check if instances key is provided key_instances_exists_flag = check_dataset_instances_key_fast(single_file, KEY_INSTANCES) if not key_instances_exists_flag: raise ValueError( f'"{KEY_INSTANCES}" must be provided to initialize a' f" dataset, e.g.\n" f" {TEXT_ONLY_DATASET_DESCRIPTION}" ) def from_dict(self, dict_obj: dict, *args, **kwargs): r""" Create a Dataset object from a dictionary. Return a Dataset given a dict with format: { "type": TYPE, "instances": [ { "key_1": VALUE_1.1, "key_2": VALUE_1.2, ... }, { "key_1": VALUE_2.1, "key_2": VALUE_2.2, ... }, ... ] } Parameters ----------- dict_obj : dict. A dictionary containing the dataset information. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. Returns --------- self : Dataset object. """ if self.backend == "huggingface": if KEY_TYPE not in dict_obj: raise ValueError( f'"{KEY_TYPE}" must be provided to initialize a dataset, e.g.\n {TEXT_ONLY_DATASET_DESCRIPTION}' ) if KEY_INSTANCES not in dict_obj: raise ValueError( f'"{KEY_INSTANCES}" must be provided to initialize a' f" dataset, e.g.\n" f" {TEXT_ONLY_DATASET_DESCRIPTION}" ) self.type = dict_obj[KEY_TYPE] if self.type not in INSTANCE_FIELDS_MAP: raise ValueError(f'type "{self.type}" is not supported') correct_fields = INSTANCE_FIELDS_MAP[self.type] for i, instance in enumerate(dict_obj[KEY_INSTANCES]): fields = instance.keys() if not set(correct_fields).issubset(set(fields)): raise ValueError(f"data instance fields incorrect {list(correct_fields)} are required.") try: hf_dict = {} if len(dict_obj[KEY_INSTANCES]) > 0: for key in dict_obj[KEY_INSTANCES][0].keys(): hf_dict[key] = [instance[key] for instance in dict_obj[KEY_INSTANCES]] self.backend_dataset = HFDataset.from_dict(hf_dict, *args, **kwargs) except AttributeError as ex: raise ValueError( f"Error occurs: {ex}. Failed to convert dict to" f' "{self.type}" dataset,' f" the standard format is as" f" follows:\n" f" {DATASET_DESCRIPTION_MAP[self.type]}" ) from ex self._check_instance_format() return self elif self.backend == "dict": self.backend_dataset = dict_obj self.type = dict_obj[KEY_TYPE] return self else: raise NotImplementedError(f'Currently .from_dict is not supported for backend "{self.backend}"') @classmethod def create_from_dict(cls, dict_obj, *args, **kwargs): r""" Returns -------- Returns a Dataset object given a dict. """ empty_data_args = DatasetArguments(dataset_path=None) dataset = Dataset(empty_data_args) return dataset.from_dict(dict_obj) def to_dict(self): r""" Returns --------- Return a dict represents the dataset: { "type": TYPE, "instances": [ { "key_1": VALUE_1.1, "key_2": VALUE_1.2, ... }, { "key_1": VALUE_2.1, "key_2": VALUE_2.2, ... }, ... ] } A python dict object represents the content of this dataset. """ if self.backend == "huggingface": dict_obj = {} dict_obj[KEY_TYPE] = self.get_type() hf_dict = self.backend_dataset.to_dict() dict_obj[KEY_INSTANCES] = [] first_key = None for key in hf_dict.keys(): first_key = key break if first_key is not None: num_instances = len(hf_dict[first_key]) dict_obj[KEY_INSTANCES] = [ {key: hf_dict[key][i] for key in hf_dict.keys()} for i in range(num_instances) ] return dict_obj elif self.backend == "dict": dict_obj = self.backend_dataset return dict_obj else: raise NotImplementedError(f'Current .to_dict is not supported for backend "{self.backend}"') def to_list(self): """Returns a list of instances.""" if self.backend == "huggingface": instance_list = [self.backend_dataset.__getitem__(idx) for idx in range(len(self.backend_dataset))] return instance_list elif self.backend == "dict": instance_list = copy.deepcopy(self.backend_dataset[KEY_INSTANCES]) # TODO: should be a list of instances, instance should be huggingface datasets row format return instance_list else: raise NotImplementedError(f'Current .to_list is not supported for backend "{self.backend}"') def map(self, *args, **kwargs): r""" Parameters ------------ args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. Returns --------- self : Dataset object. """ # If the dataset uses Hugging Face as the backend, # call the `map()` function of the Hugging Face backend dataset if self.backend == "huggingface": # Set the mapped dataset as the backend dataset of the current dataset mapped_backend_dataset = self.backend_dataset.map(*args, **kwargs) self.backend_dataset = mapped_backend_dataset return self else: # If the backend is not Hugging Face, raise a NotImplementedError raise NotImplementedError(f'Currently .map is not supported for backend "{self.backend}"') def get_backend(self) -> Optional[str]: r""" Returns --------- self.backend """ return self.backend def get_backend_dataset(self): r""" Returns --------- self.backend_dataset """ return self.backend_dataset def get_fingerprint(self): r""" Returns --------- Fingerprint of the backend_dataset which controls the cache """ return self.backend_dataset._fingerprint def get_data_args(self): r""" Returns --------- self.data_args """ return self.data_args def get_type(self) -> str: r""" Returns --------- self.type """ return self.type def save(self, file_path: str, format: str = "json"): r""" Save the dataset to a json file. Parameters ------------ file_path : str. The path to the file where the dataset will be saved. """ if format == "json": assert Path(file_path).suffix == ".json", "The file path must have a .json extension." with open(file_path, "w", encoding="utf-8") as fout: json.dump(self.to_dict(), fout, indent=4, ensure_ascii=False) else: logger.error(f"Unsupported format when saving the dataset: {format}.") def sample(self, n: int, seed: int = 42): r""" Sample n instances from the dataset. Parameters ------------ n : int. The number of instances to sample from the dataset. Returns --------- sample_dataset : Dataset object. A new dataset object containing the sampled instances. """ if self.backend == "huggingface": sampled_dataset = self.backend_dataset.shuffle(seed=seed).select(range(n)) output_dataset = self.create_from_dict( { "type": self.get_type(), "instances": [ {col_name: sampled_dataset[col_name][i] for col_name in sampled_dataset.column_names} for i in range(n) ], } ) return output_dataset else: raise NotImplementedError(f'Currently .sample is not supported for backend "{self.backend}"') def train_test_split(self, test_size: float = 0.2, shuffle: bool = True, seed: int = 42): r""" Split the dataset into training and testing sets. Parameters ------------ test_size : float, default=0.2. The proportion of the dataset that will be used for testing. Returns --------- train_dataset : Dataset object. A new dataset object containing the training instances. test_dataset : Dataset object. A new dataset object containing the testing instances. """ if self.backend == "huggingface": splited = self.backend_dataset.train_test_split(test_size=test_size, shuffle=shuffle, seed=seed) train_dataset = self.create_from_dict( { "type": self.get_type(), "instances": [ {col_name: splited["train"][col_name][i] for col_name in splited["train"].column_names} for i in range(len(splited["train"])) ], } ) test_dataset = self.create_from_dict( { "type": self.get_type(), "instances": [ {col_name: splited["test"][col_name][i] for col_name in splited["test"].column_names} for i in range(len(splited["test"])) ], } ) return train_dataset, test_dataset else: raise NotImplementedError(f'Currently .train_test_split is not supported for backend "{self.backend}"') def drop_instances(self, indices: list): r""" Drop instances from the dataset. Parameters ------------ indices : list. A list of indices of the instances to drop from the dataset. """ if self.backend == "huggingface": self.backend_dataset = self.backend_dataset.remove_indices(indices) else: raise NotImplementedError(f'Currently .drop_instances is not supported for backend "{self.backend}"') def sanity_check( self, drop_invalid: bool = True, ): r""" Perform a sanity check on the dataset. """ if self.backend == "huggingface": self.hf_dataset_sanity_check(drop_invalid) else: raise NotImplementedError(f'Currently .sanity_check is not supported for backend "{self.backend}"') def hf_dataset_sanity_check( self, drop_invalid: bool = True, ): r""" Perform a sanity check on the HuggingFace dataset. """ if self.backend_dataset is None or len(self.backend_dataset) == 0: raise ValueError("Dataset is empty.") if self.type == "text_to_textlist": num_output_per_instance = len(self.backend_dataset["output"][0]) dataset_cache = self.backend_dataset.filter(lambda x: len(x["input"]) != 0) dataset_cache = self.backend_dataset.filter(lambda x: len(x["output"]) == num_output_per_instance) dataset_cache = self.backend_dataset.filter(lambda x: not all([len(output) == 0 for output in x["output"]])) if len(dataset_cache) != len(self.backend_dataset): warning_info = ( f"Found {len(self.backend_dataset) - len(dataset_cache)} invalid instances " "during hf_dataset_sanity_check, please check:\n" " 1. length of input strings should not be empty\n" " 2. length of output strings should not be all empty\n" " 3. number of output strings should be consistent\n" # since we will use tensor reshape later ) if drop_invalid: self.backend_dataset = dataset_cache logger.warning(warning_info) logger.warning("Invalid instances are dropped.") else: raise ValueError(warning_info) else: logger.warning(f"No sanity check for {self.type} dataset.") ================================================ FILE: src/lmflow/datasets/multi_modal_dataset.py ================================================ #!/usr/bin/env python # FIXME update the doc string. """This Python code defines a class Multi Modal Dataset.""" import copy import json import os.path as osp from dataclasses import dataclass import torch import transformers from PIL import Image from torch.utils.data import Dataset from lmflow.args import DatasetArguments from lmflow.utils import llava_conversation_lib as conversation_lib from lmflow.utils.constants import ( DEFAULT_IM_END_TOKEN, DEFAULT_IM_START_TOKEN, DEFAULT_IMAGE_TOKEN, IGNORE_INDEX, IMAGE_TOKEN_INDEX, ) class CustomMultiModalDataset(Dataset): """Dataset for Multi Modal data""" def __init__(self, dataset_path: str, data_args: DatasetArguments): super().__init__() data_dict = json.load(open(dataset_path)) self.data_dict = data_dict print("Finish loading json file in dataset.") self.data_args = data_args self.image_folder = data_args.image_folder def __len__(self): return len(self.data_dict) def register_tokenizer(self, tokenizer, image_processor=None): self.tokenizer = tokenizer self.image_processor = getattr(tokenizer, "image_processor", image_processor) def __getitem__(self, i): data = self.data_dict[i] if isinstance(i, int): data = [data] assert len(data) == 1 processor = self.image_processor if "image" in data[0]: image_file = data[0]["image"] image = Image.open(osp.join(self.image_folder, image_file)).convert("RGB") if self.data_args.image_aspect_ratio == "pad": def expand2square(pil_img, background_color): width, height = pil_img.size if width == height: return pil_img elif width > height: result = Image.new(pil_img.mode, (width, width), background_color) result.paste(pil_img, (0, (width - height) // 2)) return result else: result = Image.new(pil_img.mode, (height, height), background_color) result.paste(pil_img, ((height - width) // 2, 0)) return result image = expand2square(image, tuple(int(x * 255) for x in processor.image_mean)) image = processor.preprocess(image, return_tensors="pt")["pixel_values"][0] else: image = processor.preprocess(image, return_tensors="pt")["pixel_values"][0] data = preprocess_multimodal_llava(copy.deepcopy([e["conversations"] for e in data]), self.data_args) else: data = copy.deepcopy([e["conversations"] for e in data]) if self.data_args.sep_style == "plain": data_dict = preprocess_llama_from_llava_plain( data, self.tokenizer, has_image=("image" in self.data_dict[i]) ) else: data_dict = preprocess_llama_from_llava_v1(data, self.tokenizer, has_image=("image" in self.data_dict[i])) if isinstance(i, int): data_dict = dict(input_ids=data_dict["input_ids"][0], labels=data_dict["labels"][0]) # image exist in the data if "image" in self.data_dict[i]: data_dict["image"] = image else: # image does not exist in the data, but the model is multimodal crop_size = self.image_processor.crop_size data_dict["image"] = torch.zeros(3, crop_size["height"], crop_size["width"]) return data_dict def preprocess_multimodal_llava(sources, data_args): is_multimodal = data_args.is_multimodal if not is_multimodal: return sources for source in sources: for sentence in source: if DEFAULT_IMAGE_TOKEN in sentence["value"]: sentence["value"] = sentence["value"].replace(DEFAULT_IMAGE_TOKEN, "").strip() sentence["value"] = DEFAULT_IMAGE_TOKEN + "\n" + sentence["value"] sentence["value"] = sentence["value"].strip() if "mmtag" in conversation_lib.default_conversation.version: sentence["value"] = sentence["value"].replace( DEFAULT_IMAGE_TOKEN, "" + DEFAULT_IMAGE_TOKEN + "" ) replace_token = DEFAULT_IMAGE_TOKEN if data_args.use_image_start_end: replace_token = DEFAULT_IM_START_TOKEN + replace_token + DEFAULT_IM_END_TOKEN sentence["value"] = sentence["value"].replace(DEFAULT_IMAGE_TOKEN, replace_token) return sources def tokenizer_image_token(prompt, tokenizer, image_token_index=IMAGE_TOKEN_INDEX, return_tensors=None): prompt_chunks = [tokenizer(chunk).input_ids for chunk in prompt.split("")] def insert_separator(X, sep): return [ele for sublist in zip(X, [sep] * len(X)) for ele in sublist][:-1] input_ids = [] offset = 0 if len(prompt_chunks) > 0 and len(prompt_chunks[0]) > 0 and prompt_chunks[0][0] == tokenizer.bos_token_id: offset = 1 input_ids.append(prompt_chunks[0][0]) for x in insert_separator(prompt_chunks, [image_token_index] * (offset + 1)): input_ids.extend(x[offset:]) if return_tensors is not None: if return_tensors == "pt": return torch.tensor(input_ids, dtype=torch.long) raise ValueError(f"Unsupported tensor type: {return_tensors}") return input_ids def preprocess_llama_from_llava_plain(sources, tokenizer: transformers.PreTrainedTokenizer, has_image: bool = False): """ This function just add the image in the front of text. And don't add any prompt. Args: sources: The input data with text and image. tokenizer: The tokenizer to process text. has_image: Whether the input data has image. Returns: The input_ids and labels for the model. """ conversations = [] for source in sources: assert len(source) == 2 assert DEFAULT_IMAGE_TOKEN in source[0]["value"] source[0]["value"] = DEFAULT_IMAGE_TOKEN conversation = source[0]["value"] + source[1]["value"] + conversation_lib.default_conversation.sep conversations.append(conversation) # tokenize conversations input_ids = [tokenizer_image_token(prompt, tokenizer, return_tensors="pt") for prompt in conversations] targets = copy.deepcopy(input_ids) for target, source in zip(targets, sources): tokenized_len = len(tokenizer_image_token(source[0]["value"], tokenizer)) target[:tokenized_len] = IGNORE_INDEX return dict(input_ids=input_ids, labels=targets) def preprocess_llama_from_llava_v1(sources, tokenizer: transformers.PreTrainedTokenizer, has_image: bool = False): """ This function add the prompt and then put the image after the prompt. So it needs additional code to generate the target label. Args: sources: The input data with text and image. tokenizer: The tokenizer to process text. has_image: Whether the input data has image. Returns: The input_ids and labels for the model. """ conv = conversation_lib.default_conversation.copy() roles = {"human": conv.roles[0], "gpt": conv.roles[1]} # Apply prompt templates conversations = [] for i, source in enumerate(sources): if roles[source[0]["from"]] != conv.roles[0]: # Skip the first one if it is not from human source = source[1:] conv.messages = [] for j, sentence in enumerate(source): role = roles[sentence["from"]] assert role == conv.roles[j % 2], f"{i}" conv.append_message(role, sentence["value"]) conversations.append(conv.get_prompt()) # Tokenize conversations if has_image: input_ids = torch.stack( [tokenizer_image_token(prompt, tokenizer, return_tensors="pt") for prompt in conversations], dim=0 ) else: input_ids = tokenizer( conversations, return_tensors="pt", padding="longest", max_length=tokenizer.model_max_length, truncation=True, ).input_ids targets = input_ids.clone() assert conv.sep_style == conversation_lib.SeparatorStyle.TWO # Mask targets sep = conv.sep + conv.roles[1] + ": " for conversation, target in zip(conversations, targets): total_len = int(target.ne(tokenizer.pad_token_id).sum()) rounds = conversation.split(conv.sep2) cur_len = 1 target[:cur_len] = IGNORE_INDEX for i, rou in enumerate(rounds): if rou == "": break parts = rou.split(sep) if len(parts) != 2: break parts[0] += sep if has_image: round_len = len(tokenizer_image_token(rou, tokenizer)) instruction_len = len(tokenizer_image_token(parts[0], tokenizer)) - 2 else: round_len = len(tokenizer(rou).input_ids) instruction_len = len(tokenizer(parts[0]).input_ids) - 2 target[cur_len : cur_len + instruction_len] = IGNORE_INDEX cur_len += round_len target[cur_len:] = IGNORE_INDEX if cur_len < tokenizer.model_max_length: if cur_len != total_len: target[:] = IGNORE_INDEX print(f"WARNING: tokenization mismatch: {cur_len} vs. {total_len}. (ignored)") return dict( input_ids=input_ids, labels=targets, ) @dataclass class DataCollatorForSupervisedDataset: """Collate examples for supervised fine-tuning.""" tokenizer: transformers.PreTrainedTokenizer def __call__(self, instances): input_ids, labels = tuple([instance[key] for instance in instances] for key in ("input_ids", "labels")) input_ids = torch.nn.utils.rnn.pad_sequence( input_ids, batch_first=True, padding_value=self.tokenizer.pad_token_id ) labels = torch.nn.utils.rnn.pad_sequence(labels, batch_first=True, padding_value=IGNORE_INDEX) input_ids = input_ids[:, : self.tokenizer.model_max_length] labels = labels[:, : self.tokenizer.model_max_length] batch = dict( input_ids=input_ids, labels=labels, attention_mask=input_ids.ne(self.tokenizer.pad_token_id), ) if "image" in instances[0]: images = [instance["image"] for instance in instances] if all(x is not None and x.shape == images[0].shape for x in images): batch["images"] = torch.stack(images) else: batch["images"] = images return batch ================================================ FILE: src/lmflow/models/__init__.py ================================================ ================================================ FILE: src/lmflow/models/auto_model.py ================================================ #!/usr/bin/env python """Automatically get correct model type.""" from lmflow.models.hf_decoder_model import HFDecoderModel from lmflow.models.hf_text_regression_model import HFTextRegressionModel # from lmflow.models.hf_encoder_decoder_model import HFEncoderDecoderModel class AutoModel: @classmethod def get_model(self, model_args, *args, **kwargs): arch_type = model_args.arch_type if arch_type == "decoder_only": return HFDecoderModel(model_args, *args, **kwargs) elif arch_type == "text_regression": return HFTextRegressionModel(model_args, *args, **kwargs) # elif arch_type == "encoder_decoder" or \ # arch_type == "vision_encoder_decoder": # return HFEncoderDecoderModel(model_args, *args, **kwargs) else: raise NotImplementedError(f'model architecture type "{arch_type}" is not supported') ================================================ FILE: src/lmflow/models/base_model.py ================================================ #!/usr/bin/env python """Base model class.""" class BaseModel: pass ================================================ FILE: src/lmflow/models/decoder_model.py ================================================ #!/usr/bin/env python """A one-line summary of the module or program, terminated by a period. Leave one blank line. The rest of this docstring should contain an overall description of the module or program. Optionally, it may also contain a brief description of exported classes and functions and/or usage examples. Typical usage example: foo = ClassFoo() bar = foo.FunctionBar() """ from lmflow.models.base_model import BaseModel class DecoderModel(BaseModel): def __init__(self, *args, **kwargs): pass ================================================ FILE: src/lmflow/models/encoder_decoder_model.py ================================================ #!/usr/bin/env python """A one-line summary of the module or program, terminated by a period. Leave one blank line. The rest of this docstring should contain an overall description of the module or program. Optionally, it may also contain a brief description of exported classes and functions and/or usage examples. Typical usage example: foo = ClassFoo() bar = foo.FunctionBar() """ from lmflow.models.base_model import BaseModel class EncoderDecoderModel(BaseModel): def __init__(self, *args, **kwargs): pass ================================================ FILE: src/lmflow/models/hf_decoder_model.py ================================================ #!/usr/bin/env python """This is a class called HFDecoderModel which is a wrapper around transformers model and tokenizer classes. It has several methods such as __init__, tokenize, and train that are used for training and fine-tuning the model. The __init__ method takes in several arguments such as model_args which are used to load the pretrained model and tokenizer, and initialize the training settings. The tokenize method is used to tokenize the input text and return the input IDs and attention masks that can be fed to the model for training or inference. Overall, this class provides a convenient interface for loading and fine-tuning transformer models and can be used for various NLP tasks such as language modeling, text classification, and question answering. """ import hashlib import logging import os from typing import Literal, Optional, Union import numpy as np import torch from peft import PeftModel from transformers import ( AutoConfig, AutoModelForCausalLM, ) from lmflow.datasets.dataset import Dataset from lmflow.models.decoder_model import DecoderModel from lmflow.models.hf_model_mixin import HFModelMixin from lmflow.models.interfaces.tunable import Tunable from lmflow.tokenization.hf_decoder_model import conversation_tokenize_function, tokenize_function from lmflow.utils.constants import ( CONVERSATION_DATASET_DESCRIPTION, TEXT2TEXT_DATASET_DESCRIPTION, TEXT_ONLY_DATASET_DESCRIPTION, ) from lmflow.utils.conversation_template import PRESET_TEMPLATES from lmflow.utils.data_utils import VLLMInferenceResultWithInput from lmflow.utils.deprecated import deprecated_args from lmflow.utils.envs import is_accelerate_env from lmflow.utils.versioning import is_flash_attn_available, is_ray_available, is_vllm_available from lmflow.utils.protocol import DataProto logger = logging.getLogger(__name__) if is_flash_attn_available(): pass else: logger.warning("Consider install flash_attn for better performance.") if is_vllm_available(): from vllm import SamplingParams if is_ray_available(): import ray import ray.data class HFDecoderModel(DecoderModel, HFModelMixin, Tunable): r""" Initializes a HFDecoderModel instance. Parameters ------------ model_args : Model arguments such as model name, path, revision, etc. do_train : bool, default True Determines whether to prepare the model for training, including distribtued env, model placement, quantization, lora, etc. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. """ def __init__(self, model_args, do_train=True, device="gpu", **kwargs): HFModelMixin.__init__(self, model_args=model_args, do_train=do_train, device=device, **kwargs) def tokenize(self, dataset: Dataset, add_special_tokens=True, *args, **kwargs) -> Dataset: """ Tokenize the full dataset. Parameters ------------ dataset : lmflow.datasets.Dataset. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. Returns ------------ tokenized_datasets : The tokenized dataset, without any leading or trailing special tokens (normally they are Begin-Of-Sentence or End-Of-Sentence tokens). """ # Preprocessing the datasets. # First we tokenize all the texts. if dataset.get_backend() != "huggingface": raise NotImplementedError("tokenization of datasets with non-huggingface backend are not supported yet") dataset_type = dataset.get_type() model_args = self.model_args raw_datasets = dataset hf_raw_datasets = dataset.get_backend_dataset() column_names = list(hf_raw_datasets.features) data_args = raw_datasets.get_data_args() if data_args.block_size is None: data_args.block_size = self.tokenizer.model_max_length logger.warning( f"`block_size` is not provided. Using tokenizer.model_max_length={self.tokenizer.model_max_length}." ) # Requires three types of information for tokenizing different datasets # 1) Which fields require tokenization, e.g. # "text2float": "text", but not "float" # "text2text": both "input" and "output" # 2) How will there tokenized sequence concatenated together, e.g. # "text_only": "text" -> "text" # "text2text": "input", "output" -> "input" + "output" # 3) Which fields require loss in final computation, e.g. # "text_only": "text" # "text2text": "output" only tokenized_column_order = None # Handles 1) and 2) label_columns = None # Handles 3) if dataset_type == "text_only": tokenized_column_order = ["text"] label_columns = ["text"] elif dataset_type == "text2text": tokenized_column_order = ["input", "output"] label_columns = ["output"] add_special_tokens = False elif dataset_type == "conversation": if data_args.conversation_template: if data_args.conversation_template == "tokenizer": if getattr(self.tokenizer, "chat_template", None): conversation_template = self.tokenizer.chat_template else: raise NotImplementedError( "Requested tokenizer chat template, but tokenizer.chat_template is not available." ) elif data_args.conversation_template == "hf_auto": if getattr(self.tokenizer, "chat_template", None): conversation_template = self.tokenizer.chat_template else: logger.warning( "Requested `hf_auto`, but tokenizer.chat_template is unavailable. " "Falling back to LMFlow default template." ) conversation_template = PRESET_TEMPLATES["empty"] elif data_args.conversation_template in PRESET_TEMPLATES.keys(): conversation_template = PRESET_TEMPLATES[data_args.conversation_template] else: raise NotImplementedError( f"Conversation template {data_args.conversation_template} is not supported yet." ) else: if getattr(self.tokenizer, "chat_template", None): logger.warning("No conversation template provided. Using tokenizer.chat_template.") conversation_template = self.tokenizer.chat_template else: logger.warning("No conversation template provided. Using default template.") conversation_template = PRESET_TEMPLATES["empty"] logger.warning(f"Conversation template: {conversation_template}") else: raise NotImplementedError( f'dataset type "{dataset_type}" is not supported, currently' " only support following data types:\n" f" 1) {TEXT_ONLY_DATASET_DESCRIPTION}\n" f" 2) {TEXT2TEXT_DATASET_DESCRIPTION}\n" f" 3) {CONVERSATION_DATASET_DESCRIPTION}\n" ) # Whether to truncate long sequences to fit into max_length use_truncation = False if model_args.use_lora or data_args.disable_group_texts: use_truncation = True tokenize_fn = conversation_tokenize_function if "conversation" in dataset_type else tokenize_function tokenize_fn_kwargs = { "data_args": data_args, "tokenizer": self.tokenizer, "column_names": column_names, } if "conversation" in dataset_type: tokenize_fn_kwargs["conversation_template"] = conversation_template else: tokenize_fn_kwargs["label_columns"] = label_columns tokenize_fn_kwargs["tokenized_column_order"] = tokenized_column_order tokenize_fn_kwargs["add_special_tokens"] = add_special_tokens tokenize_fn_kwargs["use_truncation"] = use_truncation tokenize_kwargs = {} if not data_args.streaming: fingerprint = hashlib.md5( ( raw_datasets.get_fingerprint() + str(self.tokenizer) + f"###padding_side={self.tokenizer.padding_side}" + ( "###conversation_template=" + str(conversation_template) if "conversation" in dataset_type else "" ) + f"###disable_group_texts={data_args.disable_group_texts}" + f"###block_size={data_args.block_size}" ).encode("utf-8") ).hexdigest() tokenize_kwargs = { "num_proc": data_args.preprocessing_num_workers, "load_from_cache_file": not data_args.overwrite_cache, "desc": "Running tokenizer on dataset", "new_fingerprint": fingerprint, } if data_args.block_size < self.tokenizer.model_max_length: logger.warning( f"block_size {data_args.block_size} < model_max_length {self.tokenizer.model_max_length}, " "use block_size for maximum tokenized sequence length." ) tokenized_datasets = raw_datasets.map( tokenize_fn, batched=True, remove_columns=column_names, fn_kwargs=tokenize_fn_kwargs, **tokenize_kwargs ) return tokenized_datasets def encode(self, input: Union[str, list[str]], *args, **kwargs) -> Union[list[int], list[list[int]]]: """ Perform encoding process of the tokenizer. Parameters ------------ inputs : str or list. The text sequence. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. Returns ------------ outputs : if string input,return the tokenized inputs. "Hello,world!"-> [101, 7592, 1010, 2088, 102] if batch input,return {input_ids,attention_mask,token_type_ids} ["Hello,world!","Hello!"] -> { 'input_ids': tensor([[ 101, 7592, 1010, 2088, 102],...), 'attention_mask': tensor([[1, 1, 1, 1, 1],[0,0,1,1,1]]) } """ if isinstance(input, list): return self.tokenizer(text=input, **kwargs) # batch encode,will automatically do left padding elif isinstance(input, str): return self.tokenizer.encode(text=input, **kwargs) else: raise NotImplementedError(f'type "{type(input)}" cannot be encoded') def decode(self, input, **kwargs) -> Union[str, list[str]]: """ Perform decoding process of the tokenizer. Parameters ------------ inputs : list or tensor. The token sequence. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. Returns ------------ outputs : The text decoded from the token inputs. if batch input,return the list of text [[101, 7592, 1010, 2088, 102],[101, 7592, 1010, 2088, 102]]-> ["Hello,world!","Hello,world!" if single input,return the text [101, 7592, 1010, 2088, 102]-> "Hello,world!" """ if isinstance(input, list): input = torch.tensor(input) if input.dim() == 2: return self.tokenizer.batch_decode(input, **kwargs) # batch_decode else: # Can be list of ints or a Tensor return self.tokenizer.decode(input, **kwargs) @deprecated_args( use_vllm={ "replacement": "inference_engine", "mapper": lambda x: "vllm" if x is True else "huggingface", "message": ( "use_vllm is deprecated and will be removed in a future version. " "Please use `inference_engine='vllm'` instead." ), } ) def inference( self, inputs: Union[str, list[str], torch.Tensor, DataProto], sampling_params: Optional[Union[dict, "SamplingParams"]] = None, return_logprob: bool = False, release_gpu: bool = False, inference_engine: Literal["huggingface", "vllm", "sglang"] = "huggingface", gpu_memory_utilization: Optional[float] = None, tensor_parallel_size: Optional[int] = None, enable_deterministic_inference: bool = False, attention_backend: Optional[str] = None, **kwargs, ) -> Union[list[VLLMInferenceResultWithInput] | DataProto]: """ Perform generation process of the model. Parameters ------------ inputs : Union[str, list[str], torch.Tensor, DataProto] The sequence used as a prompt for the generation or as model inputs to the model. When the inference engine is "vllm", this should be a string or a list of strings. When the inference engine is "huggingface", this should be a tensor. When the inference engine is "sglang", this should be a DataProto. sampling_params : Optional[Union[dict, "SamplingParams"]], optional The sampling parameters to use, by default None. return_logprob : bool, optional Whether to return log probability during inference, by default False. release_gpu : bool, optional Whether to release the GPU resource after inference, by default False. inference_engine : Literal["huggingface", "vllm", "sglang"], optional The inference engine to use, by default "huggingface". gpu_memory_utilization : float, optional The GPU memory utilization to use, by default None. tensor_parallel_size : int, optional The tensor parallel size to use, by default None. enable_deterministic_inference : bool, optional Whether to enable deterministic inference, by default False. attention_backend : Optional[str], optional The attention backend to use, by default None. Returns ------------ outputs : The generated sequence output """ if isinstance(inputs, str): inputs = [inputs] if not self._activated: self.activate_model_for_inference( inference_engine=inference_engine, gpu_memory_utilization=gpu_memory_utilization, tensor_parallel_size=tensor_parallel_size, enable_deterministic_inference=enable_deterministic_inference, attention_backend=attention_backend, ) if inference_engine == "vllm": res = self.__vllm_inference(inputs=inputs, sampling_params=sampling_params) elif inference_engine == "sglang": res = self.__sglang_inference( inputs=inputs, return_logprob=return_logprob, ) else: res = self.__inference(inputs=inputs, **kwargs) if release_gpu: self.deactivate_model_for_inference(inference_engine=inference_engine) return res def __inference(self, inputs, *args, **kwargs): """ Perform generation process of the model. Parameters ------------ inputs : The **tokenized** sequence used as a prompt for the generation or as model inputs to the model. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. Returns ------------ outputs : The generated sequence output """ with torch.no_grad(): if is_accelerate_env(): outputs = self.backend_model.generate( input_ids=inputs, pad_token_id=self.tokenizer.pad_token_id, **kwargs ) else: if self.device == "gpu": outputs = self.ds_engine.module.generate( input_ids=inputs, synced_gpus=True, pad_token_id=self.tokenizer.pad_token_id, **kwargs ) elif self.device == "cpu": outputs = self.backend_model.generate( input_ids=inputs, synced_gpus=True, pad_token_id=self.tokenizer.pad_token_id, **kwargs ) else: raise NotImplementedError(f'device "{self.device}" is not supported') return outputs def __vllm_inference( self, inputs: list[str], sampling_params: Optional["SamplingParams"] = None, ) -> list[VLLMInferenceResultWithInput]: """Perform VLLM inference process of the model. Parameters ---------- inputs : list[str] Prompt(s), string or a list of strings. sampling_params : Optional[SamplingParams], optional vllm SamplingParams object, by default None. Returns ------- list[VLLMInferenceResultWithInput] Return a list of VLLMInferenceResultWithInput, where each element contains the input prompt and the corresponding output. When `sampling_params.detokenize = True`, the output would be a list of strings, contains sampling_params.n samples for the corresponding prompt. When `sampling_params.detokenize = False`, return a list of list of ints (token ids, no decoding after generation). """ vllm_outputs = self.backend_model_for_inference.generate( inputs, sampling_params=sampling_params, use_tqdm=True, ) # TODO: unified lmflow sample format final_output = [] for output in vllm_outputs: if sampling_params.detokenize: output_list = [sentence.text for sentence in output.outputs] else: output_list = [sentence.token_ids for sentence in output.outputs] final_output.append({"input": output.prompt, "output": output_list}) return final_output def __sglang_inference( self, inputs: DataProto, return_logprob: bool = False, ) -> DataProto: """Perform SGLang inference process of the model.""" sglang_outputs = self.backend_model_for_inference.generate( prompt=inputs.non_tensor_batch["inputs"].tolist(), # use tensor instead of str later sampling_params=inputs.meta_info["sampling_params"], return_logprob=return_logprob, ) inputs.non_tensor_batch["outputs"] = [output["text"] for output in sglang_outputs] # TODO: padding for batching the output ids; generatin details return inputs @deprecated_args( use_vllm={ "replacement": "inference_engine", "mapper": lambda x: "vllm" if x is True else "huggingface", "message": ( "use_vllm is deprecated and will be removed in a future version. " "Please use `inference_engine='vllm'` instead." ), } ) def prepare_inputs_for_inference( self, dataset: Dataset, apply_chat_template: bool = True, inference_engine: Literal["huggingface", "vllm", "sglang"] = "huggingface", enable_distributed_inference: bool = False, sampling_params: Optional[dict] = None, ) -> Union[list[str], "ray.data.Dataset", DataProto]: if dataset.get_type() == "text_only": if apply_chat_template: dataset = dataset.map( lambda sample: { "templated": self.tokenizer.apply_chat_template( [{"role": "user", "content": sample["text"]}], tokenize=False, add_generation_prompt=True ) }, num_proc=dataset.data_args.preprocessing_num_workers, ) inference_inputs = dataset.get_backend_dataset()["templated"] else: inference_inputs = dataset.get_backend_dataset()["text"] elif dataset.get_type() == "text2text": logger.warning("For a text2text dataset, only `input` will be used as the model input.") if apply_chat_template: dataset = dataset.map( lambda sample: { "templated": self.tokenizer.apply_chat_template( conversation=[{"role": "user", "content": sample["input"]}], tokenize=False, add_generation_prompt=True, ) }, num_proc=dataset.data_args.preprocessing_num_workers, ) inference_inputs = dataset.get_backend_dataset()["templated"] else: inference_inputs = dataset.get_backend_dataset()["input"] elif dataset.get_type() == "conversation": if apply_chat_template: def preprocess_conversation(sample): conversation = sample["messages"][:-1] if len(sample["messages"]) % 2 == 0 else sample["messages"] if sample["messages"][-1]["role"] != "user": logger.warning( "Not a valid conversation for generation, since the conversation " "doesn't end up with an user message. Skip." ) sample_out = {"templated": ""} else: sample_out = { "templated": self.tokenizer.apply_chat_template( conversation=conversation, tokenize=False, add_generation_prompt=True, ) } return sample_out # TODO: investigate performance issue dataset = dataset.map( preprocess_conversation, num_proc=dataset.data_args.preprocessing_num_workers, ) inference_inputs = dataset.get_backend_dataset()["templated"] else: logger.warning( "Your dataset is `conversation` type but `apply_chat_template` is set to False. " "Will use the first user input in conversation as model input." ) inference_inputs = [ conversation[0]["content"] for conversation in dataset.get_backend_dataset()["messages"] ] else: raise NotImplementedError(f"Currently `{dataset.get_type()}` data are not supported for vllm inference.") inference_inputs = [sentence for sentence in inference_inputs if len(sentence) > 0] if inference_engine == "vllm" and enable_distributed_inference: inference_inputs = ray.data.from_items( inference_inputs ) # -> dict[str, np.ndarray], {"item": array(['...', '...', '...'])} if inference_engine == "sglang": if self.tokenizer.bos_token: # in consistent with sglang bench_serving.py demo inference_inputs = [sentence.replace(self.tokenizer.bos_token, "") for sentence in inference_inputs] # currently only test dataproto on sglang inference inference_inputs = np.array(inference_inputs) inference_inputs = DataProto.from_single_dict( data={"inputs": inference_inputs}, meta_info={"sampling_params": {**sampling_params, "n": 1}, "actual_n_rollouts": sampling_params["n"]} ) # handling n>1 since we don't want one-to-many mapping. Later this will be applied to all inference engines. inference_inputs = inference_inputs.repeat(sampling_params["n"]) return inference_inputs def merge_lora_weights(self): if self.model_args.use_lora and not self.model_args.use_qlora: self.get_backend_model().merge_and_unload() elif self.model_args.use_qlora: logger.warning( "Reloading base model in 16-bit precision to merge adapter weights. NOTE: Your device must have" "sufficient memory to reload the model in half-precision without quantization." ) self.get_peft_without_qlora() self.get_backend_model().merge_and_unload() else: logger.warning("LoRA training is NOT enabled. Merging LoRA weights is not applicable.") def get_peft_without_qlora(self): import tempfile with tempfile.TemporaryDirectory() as tmpdirname: print("created temporary directory", tmpdirname) self.get_backend_model().save_pretrained(tmpdirname) torch_dtype = ( self.model_args.torch_dtype if self.model_args.torch_dtype in ["auto", None] else getattr(torch, self.model_args.torch_dtype) ) config_kwargs = { "cache_dir": self.model_args.cache_dir, "revision": self.model_args.model_revision, "token": self.model_args.token, } config = AutoConfig.from_pretrained(self.model_args.model_name_or_path, **config_kwargs) device_map = "auto" if os.environ.get("LOCAL_RANK") is not None: local_rank = int(os.environ.get("LOCAL_RANK", "0")) device_map = {"": local_rank} self.backend_model_full = AutoModelForCausalLM.from_pretrained( self.model_args.model_name_or_path, from_tf=bool(".ckpt" in self.model_args.model_name_or_path), config=config, cache_dir=self.model_args.cache_dir, revision=self.model_args.model_revision, token=self.model_args.token, torch_dtype=torch_dtype, device_map=device_map, trust_remote_code=self.model_args.trust_remote_code, attn_implementation="flash_attention_2" if self.model_args.use_flash_attention else None, ) self.backend_model = PeftModel.from_pretrained(self.backend_model_full, tmpdirname) def save(self, dir, save_full_model=False, *args, **kwargs): """ Perform generation process of the model. Parameters ------------ dir : The directory to save model and tokenizer save_full_model : Optional. Whether to save full model. kwargs : Optional. Keyword arguments. Returns ------------ outputs : The generated sequence output """ self.get_tokenizer().save_pretrained(dir) if save_full_model and self.model_args.use_lora: save_dtype = ( torch.float16 if self.model_args.torch_dtype in ["auto", None] else getattr(torch, self.model_args.torch_dtype) ) self.backend_model_full.to(dtype=save_dtype).save_pretrained(dir) logger.warning(f"Save full model with dtype: {save_dtype}") else: self.get_backend_model().save_pretrained(dir) ================================================ FILE: src/lmflow/models/hf_model_mixin.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import copy import gc import logging from contextlib import nullcontext from typing import Literal, Optional, Union import torch from peft import LoraConfig, PeftModel, TaskType, get_peft_model from peft.utils.constants import TRANSFORMERS_MODELS_TO_LORA_TARGET_MODULES_MAPPING from transformers import ( CONFIG_MAPPING, AutoConfig, AutoModelForCausalLM, AutoModelForSequenceClassification, AutoTokenizer, BitsAndBytesConfig, PreTrainedTokenizer, PreTrainedTokenizerFast, ) from transformers.modeling_utils import is_fsdp_enabled from lmflow.args import ModelArguments from lmflow.models.base_model import BaseModel from lmflow.utils.constants import LMFLOW_LORA_TARGET_MODULES_MAPPING from lmflow.utils.envs import is_accelerate_env from lmflow.utils.versioning import is_deepspeed_available, is_sglang_available, is_vllm_available logger = logging.getLogger(__name__) HF_AUTOMODEL_MAPPING = {"decoder_only": AutoModelForCausalLM, "text_regression": AutoModelForSequenceClassification} HF_AUTOMODEL_TYPE = Union[AutoModelForCausalLM, AutoModelForSequenceClassification] LORA_TARGET_MODULES_MAPPING = { k: TRANSFORMERS_MODELS_TO_LORA_TARGET_MODULES_MAPPING.get(k, LMFLOW_LORA_TARGET_MODULES_MAPPING.get(k)) for k in set(TRANSFORMERS_MODELS_TO_LORA_TARGET_MODULES_MAPPING) | set(LMFLOW_LORA_TARGET_MODULES_MAPPING) } class HFModelMixin(BaseModel): def __init__( self, model_args: ModelArguments, do_train: bool, device: Optional[str] = "gpu", hf_auto_model_additional_args: Optional[dict] = None, *args, **kwargs, ): """Initializes a HFModel instance. Parameters ---------- model_args : Dictionary with model arguments such as model name, path, revision, etc. do_train : bool To prepare the model for training or inference. device : str, optional By default "gpu" """ # See more about loading any type of standard or custom dataset (from # files, python dict, pandas DataFrame, etc) at # https://huggingface.co/docs/datasets/loading_datasets.html. # Load pretrained model and tokenizer # # Distributed training: The .from_pretrained methods guarantee that # only one local process can concurrently download model & vocab. self.device = device self.model_args = model_args self.hf_auto_model = HF_AUTOMODEL_MAPPING[model_args.arch_type] self.do_train = do_train self.tokenizer = self.__prepare_tokenizer(model_args) self.torch_dtype = self.__prepare_dtype(model_args) self.hf_model_config = self.__prepare_model_config(model_args, hf_auto_model_additional_args) self.quant_config = self.__prepare_quant_config(model_args) self.peft_config = self.__prepare_peft_config(model_args) self._activated = False # for inference load and offload # Some implementations require custom modules to be injected into the model. self.__model_module_inject(model_args) if self.do_train: self.__prepare_model_for_training(model_args, self.hf_auto_model) self.__fix_special_tokens() def __prepare_tokenizer( self, model_args: ModelArguments, ) -> Union[PreTrainedTokenizer, PreTrainedTokenizerFast]: tokenizer_name = model_args.tokenizer_name or model_args.model_name_or_path if not tokenizer_name: raise ValueError( "You are instantiating a new tokenizer from scratch. This is" " not supported by this script. You can do it from another" " script, save it, and load it from here, using" " --tokenizer_name." ) tokenizer_kwargs = { "cache_dir": model_args.cache_dir, "use_fast": model_args.use_fast_tokenizer, "revision": model_args.model_revision, "token": model_args.token, "trust_remote_code": model_args.trust_remote_code, } if model_args.padding_side != "auto": tokenizer_kwargs["padding_side"] = model_args.padding_side try: tokenizer = AutoTokenizer.from_pretrained(tokenizer_name, **tokenizer_kwargs) except RecursionError: logger.warning( "The tokenizer_config.json file doesn't set the special tokens. Using default values: " ", , for unknown token, bos token and eos token respectively." ) tokenizer = AutoTokenizer.from_pretrained( tokenizer_name, unk_token="", bos_token="", eos_token="", **tokenizer_kwargs ) tokenizer.truncation_side = model_args.truncation_side or tokenizer.truncation_side tokenizer.model_max_length = model_args.model_max_length or tokenizer.model_max_length return tokenizer def __prepare_dtype( self, model_args: ModelArguments, ) -> torch.dtype: if model_args.arch_type == "text_regression": if model_args.torch_dtype in ["auto", None, "bf16", "bfloat16"]: torch_dtype = torch.bfloat16 else: torch_dtype = getattr(torch, model_args.torch_dtype) logger.warning( f"If you are doing reward modeling," f" InstructGPT uses torch.bfloat16 for reward model, but you" f" are using {torch_dtype} for your reward model init. Ignore" f" this warning if it is intended." ) else: torch_dtype = ( model_args.torch_dtype if model_args.torch_dtype in ["auto", None] else getattr(torch, model_args.torch_dtype) ) logger.debug(f"torch_dtype on init: {torch_dtype}") return torch_dtype def __prepare_model_config( self, model_args: ModelArguments, hf_auto_model_additional_args: Optional[dict] = None, ): """Prepare model configuration for hf auto register, Parameters ---------- model_args : ModelArguments LMFlow model arguments. hf_auto_model_additional_args : Optional[dict], optional Special configurations such as `num_labels` in `AutoModelForSequenceClassification` (commonly used in reward modeling) will not preset in __prepare_model_config, so it should be passed in hf_auto_model_additional_args. Returns ------- config : ModelConfig hf model config. """ config_kwargs = { "attn_implementation": "flash_attention_2" if model_args.use_flash_attention else None, "cache_dir": model_args.cache_dir, "revision": model_args.model_revision, "token": model_args.token, "trust_remote_code": model_args.trust_remote_code, "from_tf": bool(".ckpt" in model_args.model_name_or_path), } if hf_auto_model_additional_args is not None: config_kwargs.update(hf_auto_model_additional_args) if model_args.config_name: config = AutoConfig.from_pretrained(model_args.config_name, **config_kwargs) elif model_args.model_name_or_path: config = AutoConfig.from_pretrained(model_args.model_name_or_path, **config_kwargs) else: config = CONFIG_MAPPING[model_args.model_type]() logger.warning("You are instantiating a new config instance from scratch.") if model_args.config_overrides is not None: logger.info(f"Overriding config: {model_args.config_overrides}") config.update_from_string(model_args.config_overrides) logger.info(f"New config: {config}") return config def __prepare_quant_config( self, model_args: ModelArguments, ): quant_config = None if self.do_train: if model_args.use_qlora: if model_args.quant_bit == 8: if is_fsdp_enabled(): raise ValueError("FSDP + Qlora 8-bit quantization is not supported.") quant_config_kwargs = { "load_in_8bit": True, } elif model_args.quant_bit == 4: logger.warning( "For users who are using Accelerate (FSDP backend) or DeepSpeed, " "we only implement Qlora 4-bit quantization with torch.bfloat16 dtype currently. " "Carefully check the Accelerate or DeepSpeed configurations, since they may cast dtype " "and cause errors like " "(DeepSpeed) `TypeError: output tensor must have the same type as input tensor`, or " "(Accelerate FSDP) `ValueError: Must flatten tensors with uniform dtype but got " "torch.bfloat16 and torch.float32`. " "Consider using other peft methods if your device doesn't support torch.bfloat16. " "(This is just a notification and please self-check the compatibility of your device.)" ) quant_config_kwargs = { "load_in_4bit": True, "bnb_4bit_compute_dtype": torch.bfloat16, "bnb_4bit_use_double_quant": model_args.double_quant, "bnb_4bit_quant_type": model_args.quant_type, "bnb_4bit_quant_storage": torch.bfloat16, # fsdp+qlora, see https://huggingface.co/docs/bitsandbytes/v0.43.3/en/fsdp_qlora } else: raise ValueError("Qlora only supports 4-bit and 8-bit.") quant_config = BitsAndBytesConfig(**quant_config_kwargs) else: # inference if model_args.use_int8: quant_config = BitsAndBytesConfig( load_in_8bit=model_args.use_int8, ) return quant_config def __prepare_peft_config( self, model_args: ModelArguments, ): peft_config = None if model_args.use_lora: if model_args.lora_target_modules: lora_target_modules = model_args.lora_target_modules else: model_config = self.hf_model_config if hasattr(model_config, "to_dict"): model_config = model_config.to_dict() if "model_type" not in model_config or not model_config["model_type"]: logger.warning( "It seems that your base model is a custom model, since " "model_type is not found in model_config when preparing peft config. " "Setting model_type to 'custom' as a fallback." ) model_config["model_type"] = "custom" lora_target_modules = LORA_TARGET_MODULES_MAPPING.get(model_config["model_type"], None) peft_config = LoraConfig( task_type=TaskType.CAUSAL_LM, inference_mode=False, r=model_args.lora_r, lora_alpha=model_args.lora_alpha, lora_dropout=model_args.lora_dropout, target_modules=lora_target_modules, ) if model_args.use_dora: if model_args.lora_target_modules: lora_target_modules = model_args.lora_target_modules else: model_config = self.hf_model_config if hasattr(model_config, "to_dict"): model_config = model_config.to_dict() if "model_type" not in model_config or not model_config["model_type"]: logger.warning( "It seems that your base model is a custom model, since " "model_type is not found in model_config when preparing peft config. " "Setting model_type to 'custom' as a fallback." ) model_config["model_type"] = "custom" lora_target_modules = LORA_TARGET_MODULES_MAPPING.get(model_config["model_type"], None) peft_config = LoraConfig( use_dora=True, task_type=TaskType.CAUSAL_LM, inference_mode=False, r=model_args.lora_r, lora_alpha=model_args.lora_alpha, lora_dropout=model_args.lora_dropout, target_modules=lora_target_modules, ) return peft_config def __model_module_inject( self, model_args: ModelArguments, ) -> None: """Override some model modules with custom implementations. Current implementations: - Position interpolation (model_args.do_rope_scaling): replace llama embeddings with condense embeddings. """ # position interpolation if model_args.do_rope_scaling: if "LlamaForCausalLM" in self.model_config.architectures: from lmflow.utils.position_interpolation.llama_rope_scaled_monkey_patch import ( replace_llama_with_condense, ) replace_llama_with_condense(model_args.rope_pi_ratio, model_args.rope_ntk_ratio) def __prepare_model_for_training( self, model_args: ModelArguments, hf_auto_model: HF_AUTOMODEL_TYPE, ): assert self.do_train, "To prepare the model for training, please set do_train=True." # TODO: change to accelerate if "hymba" in model_args.model_name_or_path: import torch._dynamo torch._dynamo.config.suppress_errors = True torch._dynamo.config.disable = True logger.info("Preparing model for training") if model_args.model_name_or_path: model = hf_auto_model.from_pretrained( model_args.model_name_or_path, torch_dtype=self.torch_dtype, config=self.hf_model_config, quantization_config=self.quant_config, trust_remote_code=model_args.trust_remote_code, ) else: model = hf_auto_model.from_config(self.hf_model_config) n_params = sum(dict((p.data_ptr(), p.numel()) for p in model.parameters()).values()) logger.info(f"Training new model from scratch - Total size={n_params / 2**20:.2f}M params") self.backend_model_full = model if model_args.ignore_bias_buffers: # torch distributed hack # fix for DDP issues with LM bias/mask buffers - invalid scalar type, inplace operation. # See: https://github.com/huggingface/transformers/issues/22482#issuecomment-1595790992 model._ddp_params_and_buffers_to_ignore = [ name for name, buffer in model.named_buffers() if buffer.dtype == torch.bool ] if model_args.use_lora or model_args.use_dora: model.enable_input_require_grads() model = get_peft_model(model, self.peft_config) model.print_trainable_parameters() # We resize the embeddings only when necessary to avoid index errors. # If you are creating a model from scratch on a small vocab and want a # smaller embedding size, remove this test. resize_embedding_context = nullcontext() if is_deepspeed_available() and not is_accelerate_env(): import deepspeed resize_embedding_context = deepspeed.zero.GatheredParameters( model.get_input_embeddings().weight, modifier_rank=None ) with resize_embedding_context: weights = model.get_input_embeddings().weight embedding_size = weights.shape[0] if len(self.tokenizer) > embedding_size: model.resize_token_embeddings(len(self.tokenizer)) self.backend_model = model def __prepare_model_for_inference( self, model_args: ModelArguments, hf_auto_model: HF_AUTOMODEL_TYPE, ): logger.info(f"Backend model already initialized, moving to device: {self.device}") if hasattr(self, "backend_model"): if self.backend_model.device == torch.device("cpu"): self.backend_model.to(self.device) return # TODO: change to accelerate logger.info("Preparing model for inference") inference_load_kwargs = {} inference_load_kwargs_bak = copy.deepcopy(inference_load_kwargs) ram_optimized_load_kwargs = { "device_map": "auto", "offload_folder": "offload", "offload_state_dict": True, } if model_args.use_ram_optimized_load: inference_load_kwargs.update(ram_optimized_load_kwargs) try: self.backend_model = hf_auto_model.from_pretrained( model_args.model_name_or_path, torch_dtype=self.torch_dtype, config=self.hf_model_config, quantization_config=self.quant_config, **inference_load_kwargs, ) except Exception: logger.warning("Failed to use RAM optimized load. Using original load instead.") self.backend_model = hf_auto_model.from_pretrained( model_args.model_name_or_path, torch_dtype=self.torch_dtype, config=self.hf_model_config, quantization_config=self.quant_config, **inference_load_kwargs_bak, ) self.backend_model_full = self.backend_model if model_args.lora_model_path is not None: self.backend_model = PeftModel.from_pretrained( self.backend_model, model_args.lora_model_path, ) if self.device == "gpu" and not is_accelerate_env(): if is_deepspeed_available(): import deepspeed deepspeed.init_distributed() self.ds_engine = deepspeed.initialize(model=self.backend_model)[0] self.ds_engine.module.eval() else: raise ImportError("Deepspeed is not available. Please install via `pip install -e '.[deepspeed]'`.") def __prepare_model_for_vllm_inference( self, model_args: ModelArguments, gpu_memory_utilization: float, tensor_parallel_size: int, ): if not is_vllm_available(): raise ImportError('VLLM is not available. Please install via `pip install -e ".[vllm]"`.') from vllm import LLM self.backend_model_for_inference = LLM( model=model_args.model_name_or_path, tokenizer=model_args.model_name_or_path, dtype=model_args.torch_dtype if model_args.torch_dtype else "auto", load_format="auto", gpu_memory_utilization=gpu_memory_utilization, tensor_parallel_size=tensor_parallel_size, ) def __prepare_model_for_sglang_inference( self, model_args: ModelArguments, gpu_memory_utilization: Optional[float] = None, tensor_parallel_size: Optional[int] = None, enable_deterministic_inference: bool = False, attention_backend: Optional[str] = None, ): if not is_sglang_available(): raise ImportError('SGLang is not available. Please install via `pip install -e ".[sglang]"`.') from sglang.srt.entrypoints.engine import Engine from sglang.srt.server_args import ServerArgs sgl_server_args = ServerArgs( model_path=model_args.model_name_or_path, mem_fraction_static=gpu_memory_utilization, tp_size=tensor_parallel_size, enable_deterministic_inference=enable_deterministic_inference, attention_backend=attention_backend, ) self.backend_model_for_inference = Engine(server_args=sgl_server_args) def __fix_special_tokens(self): # old models/tokenizers may not have these attributes, fixing if self.tokenizer.eos_token is None: self.tokenizer.eos_token = self.hf_model_config.eos_token if self.tokenizer.eos_token_id is None: self.tokenizer.eos_token_id = self.hf_model_config.eos_token_id if self.tokenizer.pad_token is None: self.tokenizer.pad_token = self.tokenizer.eos_token if self.tokenizer.pad_token_id is None: self.tokenizer.pad_token_id = self.tokenizer.eos_token_id if self.model_args.eos_padding: self.tokenizer.pad_token = self.tokenizer.eos_token if not hasattr(self.hf_model_config, "pad_token_id"): logger.warning("pad_token_id not found in model config. Setting pad_token_id to eos_token_id.") self.hf_model_config.pad_token_id = self.hf_model_config.eos_token_id elif self.hf_model_config.pad_token_id is None: logger.warning("pad_token_id is None in model config. Setting pad_token_id to eos_token_id.") self.hf_model_config.pad_token_id = self.hf_model_config.eos_token_id def activate_model_for_inference( self, inference_engine: Literal["huggingface", "vllm", "sglang"] = "huggingface", gpu_memory_utilization: Optional[float] = None, tensor_parallel_size: Optional[int] = None, enable_deterministic_inference: bool = False, attention_backend: Optional[str] = None, ): if self._activated: logger.warning("You are trying to activate the model for inference, but it is already activated.") return if inference_engine == "vllm": self.__prepare_model_for_vllm_inference( model_args=self.model_args, gpu_memory_utilization=gpu_memory_utilization, tensor_parallel_size=tensor_parallel_size, ) elif inference_engine == "sglang": self.__prepare_model_for_sglang_inference( model_args=self.model_args, gpu_memory_utilization=gpu_memory_utilization, tensor_parallel_size=tensor_parallel_size, enable_deterministic_inference=enable_deterministic_inference, attention_backend=attention_backend, ) else: self.__prepare_model_for_inference( model_args=self.model_args, hf_auto_model=self.hf_auto_model, ) self._activated = True def deactivate_model_for_inference( self, inference_engine: Literal["huggingface", "vllm", "sglang"] = "huggingface", ): """Deactivate the model and release the resources. NOTE: Currently, VLLM doesn't have an official way to do this, and the implementation below cannot release all gpu resources by our observation. Thus this method is just a placeholder for future implementation. See: [Github issue](https://github.com/vllm-project/vllm/issues/1908) """ if not self._activated: logger.warning("You are trying to deactivate the model for inference, but it is already deactivated.") return if inference_engine == "vllm": from vllm.distributed.parallel_state import destroy_model_parallel destroy_model_parallel() del self.backend_model_for_inference.llm_engine.model_executor.driver_worker del self.backend_model_for_inference gc.collect() torch.cuda.empty_cache() elif inference_engine == "sglang": self.backend_model_for_inference.shutdown() else: self.backend_model.to("cpu") self._activated = False def get_max_length(self): """ Return max acceptable input length in terms of tokens. """ return self.tokenizer.model_max_length def get_tokenizer(self): """ Return the tokenizer of the model. """ return self.tokenizer def get_backend_model(self): """ Return the backend model. """ return self.backend_model ================================================ FILE: src/lmflow/models/hf_text_regression_model.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import copy import hashlib import logging from typing import Optional, Union import torch from transformers.modeling_outputs import SequenceClassifierOutputWithPast from lmflow.args import ModelArguments from lmflow.datasets.dataset import KEY_SCORE, Dataset from lmflow.models.hf_model_mixin import HFModelMixin from lmflow.models.interfaces.tunable import Tunable from lmflow.models.text_regression_model import TextRegressionModel from lmflow.tokenization.hf_text_regression_model import ( conversation_tokenize_function, paired_conversation_tokenize_function, text_to_textlist_tokenize_function, tokenize_function, ) from lmflow.utils.constants import ( CONVERSATION_DATASET_DESCRIPTION, PAIRED_CONVERSATION_DATASET_DESCRIPTION, TEXT2TEXT_DATASET_DESCRIPTION, TEXT_ONLY_DATASET_DESCRIPTION, TEXT_TO_TEXTLIST_DATASET_DESCRIPTION, ) from lmflow.utils.conversation_template import PRESET_TEMPLATES from lmflow.utils.data_utils import RewardModelInferenceResultWithInput from lmflow.utils.envs import is_accelerate_env from lmflow.utils.versioning import is_ray_available, is_vllm_available if is_ray_available(): import ray import ray.data if is_vllm_available(): from vllm import SamplingParams logger = logging.getLogger(__name__) class HFTextRegressionModel(TextRegressionModel, HFModelMixin, Tunable): r""" Initializes a HFTextRegressionModel instance. Parameters ------------ model_args : Model arguments such as model name, path, revision, etc. do_train : bool, default True Determines whether to prepare the model for training, including distribtued env, model placement, quantization, lora, etc. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. """ def __init__(self, model_args: ModelArguments, do_train: bool = False, device="gpu", **kwargs): assert model_args.arch_type == "text_regression", ( f"Invalid model architecture type: {model_args.arch_type}. Expected: text_regression" ) config_additional_args = {"num_labels": 1} HFModelMixin.__init__( self, model_args=model_args, do_train=do_train, device=device, hf_auto_model_additional_args=config_additional_args, **kwargs, ) def tokenize(self, dataset: Dataset, add_special_tokens=True, *args, **kwargs): """ Tokenize the full dataset. Parameters ------------ dataset : lmflow.datasets.Dataset. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. Returns ------------ tokenized_datasets : The tokenized dataset, without any leading or trailing special tokens (normally they are Begin-Of-Sentence or End-Of-Sentence tokens). """ # Preprocessing the datasets. # First we tokenize all the texts. if dataset.get_backend() != "huggingface": raise NotImplementedError("tokenization of datasets with non-huggingface backend arenot supported yet") dataset_type = dataset.get_type() model_args = self.model_args raw_datasets = dataset hf_raw_datasets = dataset.get_backend_dataset() column_names = list( hf_raw_datasets.features ) # in paired conversation, for example, would be 'chosen' and 'rejected' data_args = raw_datasets.get_data_args() # Whether to truncate long sequences to fit into max_length use_truncation = False if model_args.use_lora or data_args.disable_group_texts: use_truncation = True # Requires three types of information for tokenizing different datasets # 1) Which fields require tokenization, e.g. # "text2float": "text", but not "float" # "text2text": both "input" and "output" # 2) How will there tokenized sequence concatenated together, e.g. # "text_only": "text" -> "text" # "text2text": "input", "output" -> "input" + "output" # 3) Which fields require loss in final computation, e.g. # "text_only": "text" # "text2text": "output" only tokenize_fn = None tokenize_fn_kwargs = { "data_args": data_args, "tokenizer": self.tokenizer, "column_names": column_names, } if dataset_type == "text_only": tokenize_fn = tokenize_function text_only_tokenize_fn_kwargs = { "tokenized_column_order": ["text"], "label_columns": ["text"], "add_special_tokens": add_special_tokens, "use_truncation": use_truncation, } tokenize_fn_kwargs.update(text_only_tokenize_fn_kwargs) elif dataset_type == "text2text": tokenize_fn = tokenize_function text2text_tokenize_fn_kwargs = { "tokenized_column_order": ["input", "output"], "label_columns": ["output"], "add_special_tokens": False, "use_truncation": use_truncation, } tokenize_fn_kwargs.update(text2text_tokenize_fn_kwargs) elif dataset_type in ["conversation", "paired_conversation"]: if dataset_type == "conversation": tokenize_fn = conversation_tokenize_function elif dataset_type == "paired_conversation": tokenize_fn = paired_conversation_tokenize_function if data_args.conversation_template: if data_args.conversation_template in PRESET_TEMPLATES.keys(): conversation_template = PRESET_TEMPLATES[data_args.conversation_template] else: raise NotImplementedError( f"Conversation template {data_args.conversation_template} is not supported yet." ) else: logger.warning("No conversation template provided. Using default template.") conversation_template = PRESET_TEMPLATES["empty"] tokenize_fn_kwargs["conversation_template"] = conversation_template logger.warning(f"Conversation template: {conversation_template}") elif dataset_type == "text_to_textlist": tokenize_fn = text_to_textlist_tokenize_function text_to_textlist_tokenize_fn_kwargs = { "add_special_tokens": False, "use_truncation": use_truncation, } tokenize_fn_kwargs.update(text_to_textlist_tokenize_fn_kwargs) else: raise NotImplementedError( f'Dataset type "{dataset_type}" is not supported, currently' " only support following data types for HFTextRegressionModel:\n" f" 1) [Inference]{TEXT_ONLY_DATASET_DESCRIPTION}\n" f" 2) [Inference]{TEXT2TEXT_DATASET_DESCRIPTION}\n" f" 3) [Training]{PAIRED_CONVERSATION_DATASET_DESCRIPTION}\n" f" 4) [Inference]{CONVERSATION_DATASET_DESCRIPTION}\n" f" 5) [Inference]{TEXT_TO_TEXTLIST_DATASET_DESCRIPTION}\n" ) tokenize_kwargs = {} if not data_args.streaming: fingerprint = hashlib.md5( ( raw_datasets.get_fingerprint() + str(self.tokenizer) + f"###padding_side={self.tokenizer.padding_side}" + ( "###conversation_template=" + str(conversation_template) if "conversation" in dataset_type else "" ) + f"###disable_group_texts={data_args.disable_group_texts}" + f"###block_size={data_args.block_size}" ).encode("utf-8") ).hexdigest() tokenize_kwargs = { "num_proc": data_args.preprocessing_num_workers, "load_from_cache_file": not data_args.overwrite_cache, "desc": "Running tokenizer on dataset", "new_fingerprint": fingerprint, } tokenized_datasets = raw_datasets.map( tokenize_fn, batched=True, remove_columns=column_names, fn_kwargs=tokenize_fn_kwargs, **tokenize_kwargs ) return tokenized_datasets def inference( self, inputs, release_gpu: bool = False, use_vllm: bool = False, **kwargs ) -> Union[list[float], SequenceClassifierOutputWithPast]: """ Perform generation process of the model. Parameters ------------ inputs : The sequence used as a prompt for the generation or as model inputs to the model. When using vllm inference, this should be a string or a list of strings. When using normal inference, this should be a tensor. release_gpu : bool, optional Whether to release the GPU resource after inference, by default False. use_vllm : bool, optional Whether to use VLLM for inference, by default False. kwargs : Optional. Keyword arguments. Returns ------------ outputs : The generated sequence output """ if use_vllm: logger.warning("VLLM inference is not supported for text regression model, using normal inference instead.") use_vllm = False if not self._activated: self.activate_model_for_inference( use_vllm=use_vllm, **kwargs, ) if use_vllm: res = self.__vllm_inference(inputs, **kwargs) else: res = self.__inference(inputs, **kwargs) if release_gpu: self.deactivate_model_for_inference(use_vllm=use_vllm) return res def __inference(self, inputs, **kwargs): """ Perform generation process of the model. Parameters ------------ inputs : The **tokenized** sequence used as a prompt for the generation or as model inputs to the model. kwargs : Optional. Keyword arguments. Returns ------------ outputs : The generated sequence output """ with torch.no_grad(): if is_accelerate_env(): outputs = self.backend_model( input_ids=inputs, **kwargs, ) else: if self.device == "gpu": # for scripts that run using 'deepspeed script.py' outputs = self.ds_engine.module( input_ids=inputs, synced_gpus=True, **kwargs, ) elif self.device == "cpu": outputs = self.backend_model( input_ids=inputs, synced_gpus=True, **kwargs, ) else: raise NotImplementedError(f'device "{self.device}" is not supported') if kwargs.get("return_input", False): outputs = {"input": inputs, "output": outputs} return outputs def __vllm_inference( self, inputs: Union[str, list[str]], sampling_params: Optional["SamplingParams"] = None, **kwargs, ) -> Union[list[list[str]], list[list[list[int]]]]: """Perform VLLM inference process of the model. Parameters ---------- inputs : Union[str, list[str]] Prompt(s), string or a list of strings. sampling_params : Optional[SamplingParams], optional vllm SamplingParams object, by default None. Returns ------- """ raise NotImplementedError("VLLM inference is not supported for text regression model.") def prepare_inputs_for_inference( self, dataset: Dataset, enable_distributed_inference: bool = False, use_vllm: bool = False, **kwargs, ) -> Union[Dataset, "ray.data.Dataset"]: if use_vllm: raise NotImplementedError("VLLM inference is not supported for text regression model.") inference_inputs = self.tokenize(dataset) if enable_distributed_inference: if not is_ray_available(): raise ValueError('Ray is not available. Please install ray via `pip install -e ".[ray]"`.') inference_inputs.sanity_check(drop_invalid=True) inference_inputs = inference_inputs.get_backend_dataset() inference_inputs = ray.data.from_items(inference_inputs) # -> dict[str, np.ndarray] # Example (batch size=2): # {'input': array(['...','...'], dtype=object), # 'output': array([array(["...", "..."], dtype=object), array(['...','...'], dtype=object)], dtype=object), # 'input_ids': array( # [ # array([array([ 27, 91, 882, ..., 128256, 128256, 128256]), # array([ 27, 91, 882, ..., 128256, 128256, 128256])], # dtype=object), # array([array([ 27, 91, 882, ..., 128256, 128256, 128256]), # array([ 27, 91, 882, ..., 128256, 128256, 128256])], # dtype=object) # ], dtype=object)} return inference_inputs @staticmethod def postprocess_inference_outputs( dataset: Dataset, scores: Union[list[float], list[list[float]]], ): output_dict = {"type": "", "instances": []} if dataset.get_type() == "text_to_textlist": output_dict["type"] = "text_to_scored_textlist" for idx, instance in enumerate(dataset.get_backend_dataset()): if len(instance["output"]) < 2: logger.warning(f"Instance {idx} has less than 2 outputs, skipping.") output_dict["instances"].append( { "input": instance["input"], "output": [{"text": text} for text in instance["output"]], } ) else: raise NotImplementedError(f"Dataset type {dataset.get_type()} is not supported for reward model inference.") for i, instance_scores in enumerate(scores): for j, score in enumerate(instance_scores): output_dict["instances"][i]["output"][j][KEY_SCORE] = score output_dataset_args = copy.deepcopy(dataset.data_args) output_dataset_args.dataset_path = None output_dataset_args.dataset_name = f"{output_dataset_args.dataset_name}_scored" output_dataset = Dataset(output_dataset_args) output_dataset = output_dataset.from_dict(output_dict) return output_dataset @staticmethod def postprocess_distributed_inference_outputs( dataset: Dataset, inference_result: list[RewardModelInferenceResultWithInput], ): output_dict = {"type": "text_to_scored_textlist", "instances": inference_result} output_dataset_args = copy.deepcopy(dataset.data_args) output_dataset_args.dataset_path = None output_dataset_args.dataset_name = f"{output_dataset_args.dataset_name}_scored" output_dataset = Dataset(output_dataset_args) output_dataset = output_dataset.from_dict(output_dict) return output_dataset def save(self, dir, *args, **kwargs): """ Perform generation process of the model. Parameters ------------ dir : The directory to save model and tokenizer kwargs : Optional. Keyword arguments. """ self.get_tokenizer().save_pretrained(dir) self.get_backend_model().save_pretrained(dir) ================================================ FILE: src/lmflow/models/interfaces/__init__.py ================================================ ================================================ FILE: src/lmflow/models/interfaces/tunable.py ================================================ #!/usr/bin/env python """Tunable class""" class Tunable: pass ================================================ FILE: src/lmflow/models/regression_model.py ================================================ #!/usr/bin/env python """General regression model.""" from lmflow.models.base_model import BaseModel class RegressionModel(BaseModel): def __init__(self, *args, **kwargs): pass ================================================ FILE: src/lmflow/models/text_regression_model.py ================================================ #!/usr/bin/env python """ A model maps "text_only" data to float. """ from lmflow.datasets.dataset import Dataset from lmflow.models.regression_model import RegressionModel class TextRegressionModel(RegressionModel): r""" Initializes a TextRegressionModel instance. Parameters ------------ model_args : Model arguments such as model name, path, revision, etc. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. """ def __init__(self, model_args, *args, **kwargs): """ Initializes a TextRegressionModel instance. :param model_args: dictionary with model arguments such as model name, path, revision, etc. """ self.inference_func = None def register_inference_function(self, inference_func): """ Registers a regression function. """ self.inference_func = inference_func def inference(self, inputs: Dataset): """ Gets regression results of a given dataset. :inputs: Dataset object, only accept type "text_only". """ if self.inference_func is not None: return self.inference_func(inputs) else: pass ================================================ FILE: src/lmflow/models/vision2seq_model.py ================================================ #!/usr/bin/env python # TODO update the doc from typing import Optional, Union import torch import torch.nn as nn from torch.nn import CrossEntropyLoss from transformers import ( AutoModel, AutoModelForCausalLM, AutoModelForSeq2SeqLM, Blip2Config, Blip2ForConditionalGeneration, Blip2PreTrainedModel, Blip2QFormerModel, Blip2VisionModel, ) from transformers.modeling_outputs import CausalLMOutputWithPast from lmflow.models.base_model import BaseModel from lmflow.models.vision_encoder import build_vision_tower from lmflow.utils.versioning import is_package_version_at_least if is_package_version_at_least("transformers", "4.46.0"): from transformers.integrations.deepspeed import is_deepspeed_zero3_enabled else: from transformers.deepspeed import is_deepspeed_zero3_enabled class CustomAutoVision2SeqModel(Blip2ForConditionalGeneration, BaseModel): def __init__( self, config: Blip2Config, image_encoder_name_or_path=None, qformer_name_or_path=None, language_model_name_or_path=None, low_resource=False, ): """ TODO update the docs Args: config: # the below varaible are used to overwrite the model in config image_encoder_name_or_path: qformer_name_or_path: language_model_name_or_path: Returns: """ super(Blip2PreTrainedModel, self).__init__(config) self.custom_vision_model = getattr(config, "custom_vision_model", False) self.with_qformer = getattr(config, "with_qformer", True) # vision model if self.custom_vision_model: # custom vision model means the vit model customized from llava. # vision_model_args = getattr(config, "vision_model_args", dict()) self.vision_model = build_vision_tower(config) config.vision_config = self.vision_model.config self.image_processor = self.vision_model.image_processor elif image_encoder_name_or_path is not None: # use the model from transformers self.vision_model = AutoModel.from_pretrained(image_encoder_name_or_path) config.vision_config = self.vision_model.config else: # the default vit in Blip2 self.vision_model = Blip2VisionModel(config.vision_config) if self.with_qformer: # check if with qformer, the blip series model use qformer # and the llava based models don't use qformer. if qformer_name_or_path is not None: self.query_tokens = nn.Parameter( torch.zeros(1, config.num_query_tokens, config.qformer_config.hidden_size) ) self.qformer = AutoModel.from_pretrained(qformer_name_or_path) else: self.query_tokens = nn.Parameter( torch.zeros(1, config.num_query_tokens, config.qformer_config.hidden_size) ) self.qformer = Blip2QFormerModel(config.qformer_config) kwargs = dict() if language_model_name_or_path is not None: if low_resource: kwargs = dict(torch_dtype=torch.float16, load_in_8bit=True, device_map="auto", low_cpu_mem_usage=True) else: if not is_deepspeed_zero3_enabled: kwargs = dict(device_map="auto", torch_dtype=torch.float16) language_model = AutoModelForCausalLM.from_pretrained(language_model_name_or_path, **kwargs) config.text_config = language_model.config else: if config.use_decoder_only_language_model: language_model = AutoModelForCausalLM.from_config(config.text_config, **kwargs) else: language_model = AutoModelForSeq2SeqLM.from_config(config.text_config, **kwargs) # Update _tied_weights_keys using the base model used. if getattr(language_model, "_tied_weights_keys", None) is not None: self._tied_weights_keys = [f"language_model.{k}" for k in language_model._tied_weights_keys] self.language_model = language_model if self.with_qformer: self.language_projection = nn.Linear( self.qformer.config.hidden_size, self.language_model.config.hidden_size ) else: self.language_projection = nn.Linear(self.vision_model.hidden_size, self.language_model.config.hidden_size) if image_encoder_name_or_path is None and language_model_name_or_path is None: self.post_init() # for deepspeed self.hidden_size = self.language_model.config.hidden_size self.config.hidden_size = self.language_model.config.hidden_size def get_backend_model(self): return self def vision_model_from_pretrained(self, pretrained_path): self.vision_model = self.vision_model.from_pretrained(pretrained_path, config=self.config.vision_config) def qformer_from_pretrained(self, pretrained_path): self.qformer = self.qformer.from_pretrained(pretrained_path, config=self.config.qformer_config) def language_model_from_pretrained(self, pretrained_path, low_resource=False, use_prompt_cache=False): # TODO remove the low resource related loading in the future self.use_prompt_cache = use_prompt_cache if low_resource: kwargs = dict(torch_dtype=torch.float16, load_in_8bit=True, device_map="auto") else: kwargs = {} past_model_dim = self.language_model.model_dim self.language_model = AutoModelForCausalLM.from_pretrained( pretrained_path, config=self.config.text_config, **kwargs ) if self.config.text_config.hidden_size != past_model_dim: # should update the language projection layer in_channels = self.language_projection.in_features self.language_projection = nn.Linear(in_channels, self.config.text_config.hidden_size, bias=True) def vision_feature_select(self, image_forward_outs): image_features = image_forward_outs.hidden_states[self.vision_feature_select_layer] if self.select_vision_feature_type == "patch": image_features = image_features[:, 1:] elif self.select_vision_feature_type == "cls_patch": image_features = image_features else: raise ValueError(f"Unexpected select feature: {self.select_feature}") return image_features def register_prompt_cache(self, prompt_ids, prompt_keys_values): """ Udpate the prompt id and embedding for reuse in the future Args: prompt_ids (torch.LongTensor): The id of the prompt. prompt_keys_values (torch.FloatTensor): The embedding of the prompt. Returns: None """ self.prompt_ids = prompt_ids self.prompt_keys_values = prompt_keys_values self.with_prompt_cache = True def save_prompt_cache(self, path): """ Save prompt embedding and id. Args: path: The path to save the prompt embedding and id. Returns: None """ torch.save(dict(prompt_ids=self.prompt_ids, prompt_keys_values=self.prompt_keys_values), path) def load_prompt_cache(self, path): """ Load prompt embedding and id. Args: path: The path to load the prompt embedding and id. Returns: None """ prompt_cache = torch.load(path) self.register_prompt_cache(prompt_cache["prompt_ids"], prompt_cache["prompt_keys_values"]) def get_tokenizer(self): return self.tokenizer def forward( self, input_ids: torch.LongTensor = None, pixel_values: Optional[torch.FloatTensor] = None, images: Optional[torch.FloatTensor] = None, attention_mask: Optional[torch.Tensor] = None, past_key_values: Optional[list[torch.FloatTensor]] = None, inputs_embeds: Optional[torch.FloatTensor] = None, labels: Optional[torch.LongTensor] = None, use_cache: Optional[bool] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, image_token_indexes: Optional[list] = None, one_sample_multiple_images: bool = False, ) -> Union[tuple, CausalLMOutputWithPast]: if not image_token_indexes: image_token_indexes = [0] if pixel_values is None and images is not None: pixel_values = images if not one_sample_multiple_images: batch_size = pixel_values.shape[0] else: batch_size = 1 output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions output_hidden_states = ( output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states ) return_dict = return_dict if return_dict is not None else self.config.use_return_dict if not self.custom_vision_model: # do the processing as blip2 and mini gpt-4; if past_key_values is not None and input_ids.shape[1] == 1: # no need to recompute the key values attention_mask = torch.ones( (attention_mask.shape[0], past_key_values[-1][-1].shape[-2] + 1), dtype=attention_mask.dtype, device=attention_mask.device, ) else: image_embeds = self.vision_model(pixel_values, return_dict=True).last_hidden_state image_attention_mask = torch.ones( image_embeds.size()[:-1], dtype=torch.long, device=image_embeds.device ) if self.with_qformer: query_tokens = self.query_tokens.expand(image_embeds.shape[0], -1, -1) query_outputs = self.qformer( query_embeds=query_tokens, encoder_hidden_states=image_embeds, encoder_attention_mask=image_attention_mask, return_dict=True, ) else: query_outputs = image_embeds query_output = query_outputs.last_hidden_state language_model_inputs = self.language_projection(query_output) inputs_embeds, attention_mask = self.processor_image_token_in_minigpt4( input_ids, language_model_inputs, attention_mask, image_token_indexes, pixel_values, batch_size ) input_ids = None else: # do the processing in the vision model # language is the causallm model. # so use language model.model to do the embed_tokens input_ids, attention_mask, past_key_values, inputs_embeds, labels = ( self.vision_model.prepare_inputs_labels_for_multimodal( input_ids, attention_mask, past_key_values, labels, pixel_values, self.language_projection, self.language_model.model, ) ) # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn) # TODO check how to generate the labels with image embeddings # print(input_ids, attention_mask) # if inputs_embeds is not None: # print("input_embeds", inputs_embeds.shape) # attention_mask.shape, inputs_embeds.shape) # TODO remove this code by fixing the ddp training issue inputs_embeds = inputs_embeds.to(self.language_model.lm_head.weight.dtype) outputs = self.language_model( input_ids=input_ids, attention_mask=attention_mask, past_key_values=past_key_values, inputs_embeds=inputs_embeds, use_cache=use_cache, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict, ) if labels is not None: logits = outputs[0] shift_logits = logits[..., :-1, :].contiguous() shift_labels = labels[..., 1:].contiguous() # Flatten the tokens loss_fct = CrossEntropyLoss() shift_logits = shift_logits.view(-1, self.config.text_config.vocab_size) shift_labels = shift_labels.view(-1) # Enable model/pipeline parallelism shift_labels = shift_labels.to(shift_logits.device) loss = loss_fct(shift_logits, shift_labels) if not return_dict: output = (shift_logits,) + outputs[1:] return ((loss,) + output) if loss is not None else output return CausalLMOutputWithPast( loss=loss, logits=logits, past_key_values=outputs.past_key_values, hidden_states=outputs.hidden_states, attentions=outputs.attentions, ) def processor_image_token_in_minigpt4( self, input_ids, language_model_inputs, attention_mask, image_token_indexes, pixel_values, batch_size=1 ): language_attention_mask = torch.ones( language_model_inputs.size()[:-1], dtype=torch.long, device=language_model_inputs.device ) if input_ids is None: input_ids = ( torch.LongTensor([[self.config.text_config.bos_token_id]]) .repeat(batch_size, 1) .to(language_model_inputs.device) ) if attention_mask is None: attention_mask = torch.ones_like(input_ids) attention_mask = attention_mask.to(language_attention_mask.device) # concatenate query embeddings with prompt embeddings inputs_embeds = self.get_input_embeddings()(input_ids) inputs_embeds = inputs_embeds.to(device=language_model_inputs.device) # concatenate the text embeddings with image embeddings inputs_embeds_with_images = [] attention_mask_with_images = [] # currently we only support with one image start_index, end_index = 0, 0 assert len(image_token_indexes) == pixel_values.shape[0] # token format: (# text, # image)xN, # text for idx, image_token_index in enumerate(image_token_indexes): end_index += image_token_index inputs_embeds_with_images.append(inputs_embeds[:, start_index:end_index]) inputs_embeds_with_images.append(language_model_inputs[idx][None]) attention_mask_with_images.append(attention_mask[:, start_index:end_index]) attention_mask_with_images.append(language_attention_mask[idx][None]) start_index = end_index inputs_embeds_with_images.append(inputs_embeds[:, image_token_indexes[-1] :]) inputs_embeds = torch.cat(inputs_embeds_with_images, dim=1) attention_mask_with_images.append(attention_mask[:, image_token_indexes[-1] :]) attention_mask = torch.cat(attention_mask_with_images, dim=1) # comebine the embeds inputs_embeds = inputs_embeds.to(self.language_model.lm_head.weight.dtype) attention_mask = attention_mask.to(self.language_model.lm_head.weight.dtype) return inputs_embeds, attention_mask @torch.no_grad() def generate( self, pixel_values: torch.FloatTensor, input_ids: Optional[torch.LongTensor] = None, attention_mask: Optional[torch.LongTensor] = None, image_token_indexes: Optional[list] = None, one_sample_multiple_images: Optional[bool] = False, images: Optional[torch.LongTensor] = None, **generate_kwargs, ) -> torch.LongTensor: """ Overrides `generate` function to be able to use the model as a conditional generator. Args: pixel_values (`torch.FloatTensor` of shape (batch_size, num_channels, height, width)): Input images to be processed. input_ids (`torch.LongTensor` of shape (batch_size, sequence_length), *optional*): The sequence used as a prompt for the generation. attention_mask (`torch.LongTensor` of shape (batch_size, sequence_length), *optional*): Mask to avoid performing attention on padding token indices image_token_indexes (bool, *optional*): The index for inserting the image tokens. one_sample_multiple_images: (bool, *optional*): The flag for inference that the input batch size is 1 and contain multiple images. Returns: captions (list): A list of strings of length batch_size * num_captions. """ if not image_token_indexes: image_token_indexes = [0] if pixel_values is None and images is not None: pixel_values = images if not one_sample_multiple_images: batch_size = pixel_values.shape[0] else: batch_size = 1 if not self.custom_vision_model: # do the processing as blip2 and mini gpt-4; image_embeds = self.vision_model(pixel_values, return_dict=True).last_hidden_state image_attention_mask = torch.ones(image_embeds.size()[:-1], dtype=torch.long, device=image_embeds.device) if self.with_qformer: query_tokens = self.query_tokens.expand(image_embeds.shape[0], -1, -1) query_outputs = self.qformer( query_embeds=query_tokens, encoder_hidden_states=image_embeds, encoder_attention_mask=image_attention_mask, return_dict=True, ) else: query_outputs = image_embeds query_output = query_outputs.last_hidden_state language_model_inputs = self.language_projection(query_output) inputs_embeds, attention_mask = self.processor_image_token_in_minigpt4( input_ids, language_model_inputs, attention_mask, image_token_indexes, pixel_values, batch_size ) input_ids = None else: # do the processing in the vision model # language is the causallm model. # so use language model.model to do the embed_tokens if pixel_values.dim() == 3: # the batch dim is missing; pixel_values = pixel_values[None] input_ids, attention_mask, past_key_values, inputs_embeds, labels = ( self.vision_model.prepare_inputs_labels_for_multimodal( input_ids, attention_mask, None, None, pixel_values, self.language_projection, self.language_model.model, ) ) # convert the dtype. # FIXME check when need to do this inputs_embeds = inputs_embeds.to(device=self.language_model.lm_head.weight.device) inputs_embeds = inputs_embeds.to(self.language_model.lm_head.weight.dtype) outputs = self.language_model.generate( inputs_embeds=inputs_embeds, attention_mask=attention_mask, **generate_kwargs, ) return outputs ================================================ FILE: src/lmflow/models/vision_encoder/__init__.py ================================================ from .clip_encoder import build_vision_tower __all__ = ["build_vision_tower"] ================================================ FILE: src/lmflow/models/vision_encoder/clip_encoder.py ================================================ import torch import torch.nn as nn from transformers import CLIPImageProcessor, CLIPVisionConfig, CLIPVisionModel from lmflow.utils.constants import IGNORE_INDEX, IMAGE_TOKEN_INDEX def build_vision_tower(vision_tower_cfg, **kwargs): vision_tower = getattr(vision_tower_cfg, "image_encoder_name_or_path", "openai/clip-vit-large-patch14") if vision_tower.startswith("openai") or vision_tower.startswith("laion"): return CLIPVisionTower(vision_tower, args=vision_tower_cfg, **kwargs) raise ValueError(f"Unknown vision tower: {vision_tower}") # FIXME check if can directly use the BlipVisionEncoder class CLIPVisionTower(nn.Module): def __init__(self, vision_tower, args, delay_load=False): super().__init__() self.is_loaded = False self.vision_tower_name = vision_tower self.select_layer = args.vision_select_layer self.select_feature = getattr(args, "vision_select_feature", "patch") if not delay_load: self.load_model() else: self.cfg_only = CLIPVisionConfig.from_pretrained(self.vision_tower_name) def load_model(self): self.image_processor = CLIPImageProcessor.from_pretrained(self.vision_tower_name) self.vision_tower = CLIPVisionModel.from_pretrained(self.vision_tower_name) self.vision_tower.requires_grad_(False) self.is_loaded = True def encode_images(self, images, language_projection): image_features = self(images) # FIXME the language projection is register in the CustomAutoVision2SeqModel # check how to move this code to improve the readability if language_projection is not None: image_features = language_projection(image_features) return image_features def feature_select(self, image_forward_outs): image_features = image_forward_outs.hidden_states[self.select_layer] if self.select_feature == "patch": image_features = image_features[:, 1:] elif self.select_feature == "cls_patch": image_features = image_features else: raise ValueError(f"Unexpected select feature: {self.select_feature}") return image_features @torch.no_grad() def forward(self, images): if type(images) is list: image_features = [] for image in images: image_forward_out = self.vision_tower( image.to(device=self.device, dtype=self.dtype).unsqueeze(0), output_hidden_states=True ) image_feature = self.feature_select(image_forward_out).to(image.dtype) image_features.append(image_feature) else: image_forward_outs = self.vision_tower( images.to(device=self.device, dtype=self.dtype), output_hidden_states=True ) image_features = self.feature_select(image_forward_outs).to(images.dtype) return image_features @property def dummy_feature(self): return torch.zeros(1, self.hidden_size, device=self.device, dtype=self.dtype) @property def dtype(self): return self.vision_tower.dtype @property def device(self): return self.vision_tower.device @property def config(self): if self.is_loaded: return self.vision_tower.config else: return self.cfg_only @property def hidden_size(self): return self.config.hidden_size @property def num_patches(self): return (self.config.image_size // self.config.patch_size) ** 2 def prepare_inputs_labels_for_multimodal( self, input_ids, attention_mask, past_key_values, labels, images, language_projection=None, language_model=None, **kwargs, ): """ Copy from the LLAVA code base. Should be polished. """ vision_tower = self.vision_tower # commonly used in model.generate (past_key_values is not None) # to avoid forward the image multiple time if vision_tower is None or images is None or input_ids.shape[1] == 1: if ( past_key_values is not None and vision_tower is not None and images is not None and input_ids.shape[1] == 1 ): attention_mask = torch.ones( (attention_mask.shape[0], past_key_values[-1][-1].shape[-2] + 1), dtype=attention_mask.dtype, device=attention_mask.device, ) return input_ids, attention_mask, past_key_values, None, labels if type(images) is list or images.ndim == 5: concat_images = torch.cat([image for image in images], dim=0) image_features = self.encode_images(concat_images, language_projection) split_sizes = [image.shape[0] for image in images] image_features = torch.split(image_features, split_sizes, dim=0) image_features = [x.flatten(0, 1) for x in image_features] else: image_features = self.encode_images(images, language_projection) new_input_embeds = [] new_labels = [] if labels is not None else None cur_image_idx = 0 for batch_idx, cur_input_ids in enumerate(input_ids): if (cur_input_ids == IMAGE_TOKEN_INDEX).sum() == 0: # multimodal LLM, but the current sample is not multimodal cur_input_embeds = language_model.embed_tokens(cur_input_ids) cur_input_embeds = cur_input_embeds + (0.0 * language_projection(vision_tower.dummy_feature)).sum() new_input_embeds.append(cur_input_embeds) if labels is not None: new_labels.append(labels[batch_idx]) cur_image_idx += 1 continue image_token_indices = torch.where(cur_input_ids == IMAGE_TOKEN_INDEX)[0] cur_new_input_embeds = [] if labels is not None: cur_labels = labels[batch_idx] cur_new_labels = [] assert cur_labels.shape == cur_input_ids.shape while image_token_indices.numel() > 0: cur_image_features = image_features[cur_image_idx] image_token_start = image_token_indices[0] # print("image token_start", image_token_start, # "curr_input_ids", cur_input_ids.shape) if getattr(self.config, "tune_mm_mlp_adapter", False) and getattr( self.config, "mm_use_im_start_end", False ): cur_new_input_embeds.append( language_model.embed_tokens(cur_input_ids[: image_token_start - 1]).detach() ) cur_new_input_embeds.append( language_model.embed_tokens(cur_input_ids[image_token_start - 1 : image_token_start]) ) cur_new_input_embeds.append(cur_image_features) cur_new_input_embeds.append( language_model.embed_tokens(cur_input_ids[image_token_start + 1 : image_token_start + 2]) ) if labels is not None: cur_new_labels.append(cur_labels[:image_token_start]) cur_new_labels.append( torch.full( (cur_image_features.shape[0],), IGNORE_INDEX, device=labels.device, dtype=labels.dtype ) ) cur_new_labels.append(cur_labels[image_token_start : image_token_start + 1]) cur_labels = cur_labels[image_token_start + 2 :] else: cur_input_ids = cur_input_ids.to(device=language_model.device) cur_new_input_embeds.append(language_model.embed_tokens(cur_input_ids[:image_token_start])) cur_new_input_embeds.append(cur_image_features) if labels is not None: cur_new_labels.append(cur_labels[:image_token_start]) cur_new_labels.append( torch.full( (cur_image_features.shape[0],), IGNORE_INDEX, device=labels.device, dtype=labels.dtype ) ) cur_labels = cur_labels[image_token_start + 1 :] cur_image_idx += 1 if getattr(self.config, "tune_mm_mlp_adapter", False) and getattr( self.config, "mm_use_im_start_end", False ): cur_input_ids = cur_input_ids[image_token_start + 2 :] else: cur_input_ids = cur_input_ids[image_token_start + 1 :] image_token_indices = torch.where(cur_input_ids == IMAGE_TOKEN_INDEX)[0] if cur_input_ids.numel() > 0: if getattr(self.config, "tune_mm_mlp_adapter", False) and getattr( self.config, "mm_use_im_start_end", False ): cur_new_input_embeds.append(language_model.embed_tokens(cur_input_ids).detach()) else: cur_new_input_embeds.append(language_model.embed_tokens(cur_input_ids)) if labels is not None: cur_new_labels.append(cur_labels) cur_new_input_embeds = [x.to(device=self.device) for x in cur_new_input_embeds] cur_new_input_embeds = torch.cat(cur_new_input_embeds, dim=0) new_input_embeds.append(cur_new_input_embeds) if labels is not None: cur_new_labels = torch.cat(cur_new_labels, dim=0) new_labels.append(cur_new_labels) if any(x.shape != new_input_embeds[0].shape for x in new_input_embeds): max_len = max(x.shape[0] for x in new_input_embeds) new_input_embeds_align = [] for cur_new_embed in new_input_embeds: cur_new_embed = torch.cat( ( cur_new_embed, torch.zeros( (max_len - cur_new_embed.shape[0], cur_new_embed.shape[1]), dtype=cur_new_embed.dtype, device=cur_new_embed.device, ), ), dim=0, ) new_input_embeds_align.append(cur_new_embed) new_input_embeds = torch.stack(new_input_embeds_align, dim=0) if labels is not None: new_labels_align = [] _new_labels = new_labels for cur_new_label in new_labels: cur_new_label = torch.cat( ( cur_new_label, torch.full( (max_len - cur_new_label.shape[0],), IGNORE_INDEX, dtype=cur_new_label.dtype, device=cur_new_label.device, ), ), dim=0, ) new_labels_align.append(cur_new_label) new_labels = torch.stack(new_labels_align, dim=0) if attention_mask is not None: new_attention_mask = [] for cur_attention_mask, cur_new_labels, cur_new_labels_align in zip( attention_mask, _new_labels, new_labels ): new_attn_mask_pad_left = torch.full( (cur_new_labels.shape[0] - labels.shape[1],), True, dtype=attention_mask.dtype, device=attention_mask.device, ) new_attn_mask_pad_right = torch.full( (cur_new_labels_align.shape[0] - cur_new_labels.shape[0],), False, dtype=attention_mask.dtype, device=attention_mask.device, ) cur_new_attention_mask = torch.cat( (new_attn_mask_pad_left, cur_attention_mask, new_attn_mask_pad_right), dim=0 ) new_attention_mask.append(cur_new_attention_mask) attention_mask = torch.stack(new_attention_mask, dim=0) assert attention_mask.shape == new_labels.shape else: new_input_embeds = torch.stack(new_input_embeds, dim=0) if labels is not None: new_labels = torch.stack(new_labels, dim=0) if attention_mask is not None: new_attn_mask_pad_left = torch.full( (attention_mask.shape[0], new_input_embeds.shape[1] - input_ids.shape[1]), True, dtype=attention_mask.dtype, device=attention_mask.device, ) attention_mask = torch.cat((new_attn_mask_pad_left, attention_mask), dim=1) assert attention_mask.shape == new_input_embeds.shape[:2] return None, attention_mask, past_key_values, new_input_embeds, new_labels ================================================ FILE: src/lmflow/optim/__init__.py ================================================ from .utils import create_customized_optimizer __all__ = ["create_customized_optimizer"] ================================================ FILE: src/lmflow/optim/adabelief.py ================================================ #!/usr/bin/env python import math import torch from torch.optim.optimizer import Optimizer class AdaBelief(Optimizer): r"""Implements AdaBelief algorithm. Modified from Adam in PyTorch reference: AdaBelief Optimizer, adapting stepsizes by the belief in observed gradients, NeurIPS 2020 """ def __init__( self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-16, weight_decay=0, amsgrad=False, weight_decouple=True, fixed_decay=False, rectify=True, degenerated_to_sgd=True, print_change_log=True, ): if not 0.0 <= lr: raise ValueError("Invalid learning rate: {}".format(lr)) if not 0.0 <= eps: raise ValueError("Invalid epsilon value: {}".format(eps)) if not 0.0 <= betas[0] < 1.0: raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) if not 0.0 <= betas[1] < 1.0: raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) self.degenerated_to_sgd = degenerated_to_sgd if isinstance(params, (list, tuple)) and len(params) > 0 and isinstance(params[0], dict): for param in params: if "betas" in param and (param["betas"][0] != betas[0] or param["betas"][1] != betas[1]): param["buffer"] = [[None, None, None] for _ in range(10)] defaults = dict( lr=lr, betas=betas, eps=eps, weight_decay=weight_decay, amsgrad=amsgrad, buffer=[[None, None, None] for _ in range(10)], ) super().__init__(params, defaults) self.degenerated_to_sgd = degenerated_to_sgd self.weight_decouple = weight_decouple self.rectify = rectify self.fixed_decay = fixed_decay if self.weight_decouple: print("Weight decoupling enabled in AdaBelief") if self.fixed_decay: print("Weight decay fixed") if self.rectify: print("Rectification enabled in AdaBelief") if amsgrad: print("AMSGrad enabled in AdaBelief") def __setstate__(self, state): super().__setstate__(state) for group in self.param_groups: group.setdefault("amsgrad", False) def reset(self): for group in self.param_groups: for p in group["params"]: state = self.state[p] amsgrad = group["amsgrad"] # State initialization state["step"] = 0 # Exponential moving average of gradient values state["exp_avg"] = torch.zeros_like(p.data) # Exponential moving average of squared gradient values state["exp_avg_var"] = torch.zeros_like(p.data) if amsgrad: # Maintains max of all exp. moving avg. of sq. grad. values state["max_exp_avg_var"] = torch.zeros_like(p.data) def step(self, closure=None): """Performs a single optimization step. Arguments: closure (callable, optional): A closure that reevaluates the model and returns the loss. """ loss = None if closure is not None: loss = closure() for group in self.param_groups: for p in group["params"]: if p.grad is None: continue # cast data type half_precision = False if p.data.dtype == torch.float16: half_precision = True p.data = p.data.float() p.grad = p.grad.float() grad = p.grad.data if grad.is_sparse: raise RuntimeError( "AdaBelief does not support sparse gradients, please consider SparseAdam instead" ) amsgrad = group["amsgrad"] state = self.state[p] beta1, beta2 = group["betas"] # State initialization if len(state) == 0: state["step"] = 0 # Exponential moving average of gradient values state["exp_avg"] = torch.zeros_like(p.data) # Exponential moving average of squared gradient values state["exp_avg_var"] = torch.zeros_like(p.data) if amsgrad: # Maintains max of all exp. moving avg. of sq. grad. values state["max_exp_avg_var"] = torch.zeros_like(p.data) # perform weight decay, check if decoupled weight decay if self.weight_decouple: if not self.fixed_decay: p.data.mul_(1.0 - group["lr"] * group["weight_decay"]) else: p.data.mul_(1.0 - group["weight_decay"]) else: if group["weight_decay"] != 0: grad.add_(p.data, alpha=group["weight_decay"]) # get current state variable exp_avg, exp_avg_var = state["exp_avg"], state["exp_avg_var"] state["step"] += 1 bias_correction1 = 1 - beta1 ** state["step"] bias_correction2 = 1 - beta2 ** state["step"] # Update first and second moment running average exp_avg.mul_(beta1).add_(grad, alpha=1 - beta1) grad_residual = grad - exp_avg exp_avg_var.mul_(beta2).addcmul_(grad_residual, grad_residual, value=1 - beta2) if amsgrad: max_exp_avg_var = state["max_exp_avg_var"] # Maintains the maximum of all 2nd moment running avg. till now torch.max(max_exp_avg_var, exp_avg_var.add_(group["eps"]), out=max_exp_avg_var) # Use the max. for normalizing running avg. of gradient denom = (max_exp_avg_var.sqrt() / math.sqrt(bias_correction2)).add_(group["eps"]) else: denom = (exp_avg_var.add_(group["eps"]).sqrt() / math.sqrt(bias_correction2)).add_(group["eps"]) # update if not self.rectify: # Default update step_size = group["lr"] / bias_correction1 p.data.addcdiv_(exp_avg, denom, value=-step_size) else: # Rectified update, forked from RAdam buffered = group["buffer"][int(state["step"] % 10)] if state["step"] == buffered[0]: N_sma, step_size = buffered[1], buffered[2] else: buffered[0] = state["step"] beta2_t = beta2 ** state["step"] N_sma_max = 2 / (1 - beta2) - 1 N_sma = N_sma_max - 2 * state["step"] * beta2_t / (1 - beta2_t) buffered[1] = N_sma # more conservative since it's an approximated value if N_sma >= 5: step_size = math.sqrt( (1 - beta2_t) * (N_sma - 4) / (N_sma_max - 4) * (N_sma - 2) / N_sma * N_sma_max / (N_sma_max - 2) ) / (1 - beta1 ** state["step"]) elif self.degenerated_to_sgd: step_size = 1.0 / (1 - beta1 ** state["step"]) else: step_size = -1 buffered[2] = step_size if N_sma >= 5: denom = exp_avg_var.sqrt().add_(group["eps"]) p.data.addcdiv_(exp_avg, denom, value=-step_size * group["lr"]) elif step_size > 0: p.data.add_(exp_avg, alpha=-step_size * group["lr"]) if half_precision: p.data = p.data.half() p.grad = p.grad.half() return loss ================================================ FILE: src/lmflow/optim/adabound.py ================================================ #!/usr/bin/env python import math import torch from torch.optim.optimizer import Optimizer class AdaBound(Optimizer): r"""Implements AdaBound algorithm. It has been proposed in `Adaptive Gradient Methods with Dynamic Bound of Learning Rate https://arxiv.org/abs/1902.09843 Note: Reference code: https://github.com/Luolc/AdaBound """ def __init__( self, params, lr: float = 1e-3, betas=(0.9, 0.999), final_lr: float = 0.1, gamma: float = 1e-3, eps: float = 1e-8, weight_decay: float = 0, amsbound: bool = False, ) -> None: if lr <= 0.0: raise ValueError("Invalid learning rate: {}".format(lr)) if eps < 0.0: raise ValueError("Invalid epsilon value: {}".format(eps)) if not 0.0 <= betas[0] < 1.0: raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) if not 0.0 <= betas[1] < 1.0: raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) if final_lr < 0.0: raise ValueError("Invalid final learning rate: {}".format(final_lr)) if not 0.0 <= gamma < 1.0: raise ValueError("Invalid gamma parameter: {}".format(gamma)) if weight_decay < 0: raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) defaults = dict( lr=lr, betas=betas, final_lr=final_lr, gamma=gamma, eps=eps, weight_decay=weight_decay, amsbound=amsbound, ) super().__init__(params, defaults) self.base_lrs = [group["lr"] for group in self.param_groups] def __setstate__(self, state) -> None: super().__setstate__(state) for group in self.param_groups: group.setdefault("amsbound", False) def step(self, closure=None): r"""Performs a single optimization step. Arguments: closure: A closure that reevaluates the model and returns the loss. """ loss = None if closure is not None: loss = closure() for group, base_lr in zip(self.param_groups, self.base_lrs): for p in group["params"]: if p.grad is None: continue grad = p.grad.data if grad.is_sparse: msg = "AdaBound does not support sparse gradients, please consider SparseAdam instead" raise RuntimeError(msg) amsbound = group["amsbound"] state = self.state[p] # State initialization if len(state) == 0: state["step"] = 0 # Exponential moving average of gradient values state["exp_avg"] = torch.zeros_like(p, memory_format=torch.preserve_format) # Exponential moving average of squared gradient values state["exp_avg_sq"] = torch.zeros_like(p, memory_format=torch.preserve_format) if amsbound: # Maintains max of all exp. moving avg. of # sq. grad. values state["max_exp_avg_sq"] = torch.zeros_like(p, memory_format=torch.preserve_format) exp_avg, exp_avg_sq = state["exp_avg"], state["exp_avg_sq"] if amsbound: max_exp_avg_sq = state["max_exp_avg_sq"] beta1, beta2 = group["betas"] state["step"] += 1 if group["weight_decay"] != 0: grad = grad.add(p.data, alpha=group["weight_decay"]) # Decay the first and second moment running average coefficient exp_avg.mul_(beta1).add_(grad, alpha=1 - beta1) exp_avg_sq.mul_(beta2).addcmul_(grad, grad, value=1 - beta2) if amsbound: # Maintains the maximum of all 2nd moment running # avg. till now torch.max(max_exp_avg_sq, exp_avg_sq, out=max_exp_avg_sq) # Use the max. for normalizing running avg. of gradient denom = max_exp_avg_sq.sqrt().add_(group["eps"]) else: denom = exp_avg_sq.sqrt().add_(group["eps"]) bias_correction1 = 1 - beta1 ** state["step"] bias_correction2 = 1 - beta2 ** state["step"] step_size = group["lr"] * math.sqrt(bias_correction2) / bias_correction1 # Applies bounds on actual learning rate # lr_scheduler cannot affect final_lr, this is a workaround # to apply lr decay final_lr = group["final_lr"] * group["lr"] / base_lr lower_bound = final_lr * (1 - 1 / (group["gamma"] * state["step"] + 1)) upper_bound = final_lr * (1 + 1 / (group["gamma"] * state["step"])) step_size = torch.full_like(denom, step_size) step_size.div_(denom).clamp_(lower_bound, upper_bound).mul_(exp_avg) p.data.add_(-step_size) return loss ================================================ FILE: src/lmflow/optim/adadelta.py ================================================ #!/usr/bin/env python import torch from torch.optim.optimizer import Optimizer class Adadelta(Optimizer): def __init__(self, params, lr=1.0, rho=0.95, eps=1e-6): defaults = dict(lr=lr, rho=rho, eps=eps) super().__init__(params, defaults) def step(self, closure=None): loss = None if closure is not None: loss = closure() for group in self.param_groups: for p in group["params"]: if p.grad is None: continue grad = p.grad.data state = self.state[p] if len(state) == 0: state["step"] = 0 state["square_avg"] = torch.zeros_like(p.data) state["acc_delta"] = torch.zeros_like(p.data) square_avg, acc_delta = state["square_avg"], state["acc_delta"] rho, eps = group["rho"], group["eps"] state["step"] += 1 square_avg.mul_(rho).addcmul_(1 - rho, grad, grad) std = square_avg.add(eps).sqrt_() delta = acc_delta.add(eps).sqrt_().div_(std).mul_(grad) p.data.add_(-delta) acc_delta.mul_(rho).addcmul_(1 - rho, delta, delta) return loss ================================================ FILE: src/lmflow/optim/adagrad.py ================================================ #!/usr/bin/env python import torch class AdaGrad(torch.optim.Optimizer): def __init__(self, params, lr=0.001, eps=1e-8, weight_decay=0): defaults = dict(lr=lr, eps=eps, weight_decay=weight_decay) super().__init__(params, defaults) def step(self, closure=None): loss = None if closure is not None: loss = closure() for group in self.param_groups: for p in group["params"]: if p.grad is None: continue grad = p.grad.data if group["weight_decay"] != 0: grad = grad.add(group["weight_decay"], p.data) state = self.state[p] if len(state) == 0: state["sum"] = torch.zeros_like(p.data) sum = state["sum"] sum.addcmul_(1, grad, grad) std = sum.sqrt().add_(group["eps"]) p.data.addcdiv_(-group["lr"], grad, std) return loss ================================================ FILE: src/lmflow/optim/adam.py ================================================ #!/usr/bin/env python import torch from torch.optim.optimizer import Optimizer class Adam(Optimizer): def __init__(self, params, lr=0.001, betas=(0.9, 0.999), eps=1e-8): defaults = dict(lr=lr, betas=betas, eps=eps) super().__init__(params, defaults) def step(self, closure=None): loss = None if closure is not None: loss = closure() for group in self.param_groups: for p in group["params"]: if p.grad is None: continue grad = p.grad.data state = self.state[p] if len(state) == 0: state["step"] = 0 state["exp_avg"] = torch.zeros_like(p.data) state["exp_avg_sq"] = torch.zeros_like(p.data) exp_avg, exp_avg_sq = state["exp_avg"], state["exp_avg_sq"] beta1, beta2 = group["betas"] state["step"] += 1 exp_avg.mul_(beta1).add_(1 - beta1, grad) exp_avg_sq.mul_(beta2).addcmul_(1 - beta2, grad, grad) bias_correction1 = 1 - beta1 ** state["step"] bias_correction2 = 1 - beta2 ** state["step"] step_size = group["lr"] * (bias_correction2**0.5) / bias_correction1 denom = exp_avg_sq.sqrt().add_(group["eps"]) p.data.addcdiv_(-step_size, exp_avg, denom) return loss ================================================ FILE: src/lmflow/optim/adamax.py ================================================ #!/usr/bin/env python import torch from torch.optim.optimizer import Optimizer class Adamax(Optimizer): def __init__(self, params, lr=2e-3, betas=(0.9, 0.999), eps=1e-8, weight_decay=0): if not 0.0 <= lr: raise ValueError("Invalid learning rate: {}".format(lr)) if not 0.0 <= eps: raise ValueError("Invalid epsilon value: {}".format(eps)) if not 0.0 <= betas[0] < 1.0: raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) if not 0.0 <= betas[1] < 1.0: raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) if not 0.0 <= weight_decay: raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) defaults = dict(lr=lr, betas=betas, eps=eps, weight_decay=weight_decay) super().__init__(params, defaults) def __setstate__(self, state): super().__setstate__(state) def step(self, closure=None): loss = None if closure is not None: loss = closure() for group in self.param_groups: for p in group["params"]: if p.grad is None: continue grad = p.grad.data if grad.is_sparse: raise RuntimeError("Adamax does not support sparse gradients") state = self.state[p] # State initialization if len(state) == 0: state["step"] = 0 state["exp_avg"] = torch.zeros_like(p.data) state["exp_inf"] = torch.zeros_like(p.data) exp_avg, exp_inf = state["exp_avg"], state["exp_inf"] beta1, beta2 = group["betas"] state["step"] += 1 if group["weight_decay"] != 0: grad = grad.add(group["weight_decay"], p.data) # Update biased first moment estimate exp_avg.mul_(beta1).add_(1 - beta1, grad) # Update the exponentially weighted infinity norm norm_buf = torch.cat([exp_inf.mul_(beta2).unsqueeze(0), grad.abs().unsqueeze_(0)], 0) torch.max(norm_buf, 0, keepdim=False, out=(exp_inf, exp_inf.new().long())) bias_correction = 1 - beta1 ** state["step"] clr = group["lr"] / bias_correction p.data.addcdiv_(-clr, exp_avg, exp_inf + group["eps"]) return loss ================================================ FILE: src/lmflow/optim/adamp.py ================================================ #!/usr/bin/env python import math import torch from torch.optim.optimizer import Optimizer class AdamP(Optimizer): r"""Implements AdamP algorithm. It has been proposed in `Slowing Down the Weight Norm Increase in Momentum-based Optimizers` https://arxiv.org/abs/2006.08217 Note: Reference code: https://github.com/clovaai/AdamP """ def __init__( self, params, lr: float = 1e-3, betas=(0.9, 0.999), eps: float = 1e-8, weight_decay: float = 0, delta: float = 0.1, wd_ratio: float = 0.1, nesterov: bool = False, ) -> None: if lr <= 0.0: raise ValueError("Invalid learning rate: {}".format(lr)) if eps < 0.0: raise ValueError("Invalid epsilon value: {}".format(eps)) if not 0.0 <= betas[0] < 1.0: raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) if not 0.0 <= betas[1] < 1.0: raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) if weight_decay < 0: raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) if delta < 0: raise ValueError("Invalid delta value: {}".format(delta)) if wd_ratio < 0: raise ValueError("Invalid wd_ratio value: {}".format(wd_ratio)) defaults = dict( lr=lr, betas=betas, eps=eps, weight_decay=weight_decay, delta=delta, wd_ratio=wd_ratio, nesterov=nesterov, ) super().__init__(params, defaults) @staticmethod def _channel_view(x): return x.view(x.size(0), -1) @staticmethod def _layer_view(x): return x.view(1, -1) @staticmethod def _cosine_similarity(x, y, eps, view_func): x = view_func(x) y = view_func(y) x_norm = x.norm(dim=1).add_(eps) y_norm = y.norm(dim=1).add_(eps) dot = (x * y).sum(dim=1) return dot.abs() / x_norm / y_norm def _projection(self, p, grad, perturb, delta, wd_ratio, eps): wd = 1 expand_size = [-1] + [1] * (len(p.shape) - 1) for view_func in [self._channel_view, self._layer_view]: cosine_sim = self._cosine_similarity(grad, p.data, eps, view_func) if cosine_sim.max() < delta / math.sqrt(view_func(p.data).size(1)): p_n = p.data / view_func(p.data).norm(dim=1).view(expand_size).add_(eps) perturb -= p_n * view_func(p_n * perturb).sum(dim=1).view(expand_size) wd = wd_ratio return perturb, wd return perturb, wd def step(self, closure=None): r"""Performs a single optimization step. Arguments: closure: A closure that reevaluates the model and returns the loss. """ loss = None if closure is not None: loss = closure() for group in self.param_groups: for p in group["params"]: if p.grad is None: continue grad = p.grad.data beta1, beta2 = group["betas"] nesterov = group["nesterov"] state = self.state[p] # State initialization if len(state) == 0: state["step"] = 0 state["exp_avg"] = torch.zeros_like(p.data, memory_format=torch.preserve_format) state["exp_avg_sq"] = torch.zeros_like(p.data, memory_format=torch.preserve_format) # Adam exp_avg, exp_avg_sq = state["exp_avg"], state["exp_avg_sq"] state["step"] += 1 bias_correction1 = 1 - beta1 ** state["step"] bias_correction2 = 1 - beta2 ** state["step"] exp_avg.mul_(beta1).add_(grad, alpha=1 - beta1) exp_avg_sq.mul_(beta2).addcmul_(grad, grad, value=1 - beta2) denom = (exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group["eps"]) step_size = group["lr"] / bias_correction1 if nesterov: perturb = (beta1 * exp_avg + (1 - beta1) * grad) / denom else: perturb = exp_avg / denom # Projection wd_ratio = 1 if len(p.shape) > 1: perturb, wd_ratio = self._projection( p, grad, perturb, group["delta"], group["wd_ratio"], group["eps"], ) # Weight decay if group["weight_decay"] > 0: p.data.mul_(1 - group["lr"] * group["weight_decay"] * wd_ratio) # Step p.data.add_(perturb, alpha=-step_size) return loss ================================================ FILE: src/lmflow/optim/adamw_schedule_free.py ================================================ # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. #!/usr/bin/env python # -*- coding: utf-8 -*- import math import torch import torch.optim class AdamWScheduleFree(torch.optim.Optimizer): r""" Schedule-Free AdamW As the name suggests, no scheduler is needed with this optimizer. To add warmup, rather than using a learning rate schedule you can just set the warmup_steps parameter. This optimizer requires that .train() and .eval() be called before the beginning of training and evaluation respectively. The optimizer should also be placed in eval mode when saving checkpoints. """ def __init__( self, params, lr=0.0025, betas=(0.9, 0.999), eps=1e-8, weight_decay=0, warmup_steps=0, r=0.0, weight_lr_power=2.0, foreach=None, ): if not foreach: foreach = hasattr(torch, "_foreach_mul_") defaults = dict( lr=lr, betas=betas, eps=eps, r=r, k=0, warmup_steps=warmup_steps, train_mode=True, weight_sum=0.0, lr_max=-1.0, weight_lr_power=weight_lr_power, weight_decay=weight_decay, foreach=foreach, ) super().__init__(params, defaults) def eval(self): for group in self.param_groups: train_mode = group["train_mode"] beta1, _ = group["betas"] if train_mode: for p in group["params"]: state = self.state[p] if "z" in state: # Set p.data to x p.data.lerp_(end=state["z"], weight=1 - 1 / beta1) group["train_mode"] = False def train(self): for group in self.param_groups: train_mode = group["train_mode"] beta1, _ = group["betas"] if not train_mode: for p in group["params"]: state = self.state[p] if "z" in state: # Set p.data to y p.data.lerp_(end=state["z"], weight=1 - beta1) group["train_mode"] = True def step(self, closure=None): """Performs a single optimization step. Arguments: closure (callable, optional): A closure that reevaluates the model and returns the loss. """ loss = None if closure is not None: loss = closure() for group in self.param_groups: eps = group["eps"] beta1, beta2 = group["betas"] decay = group["weight_decay"] k = group["k"] r = group["r"] warmup_steps = group["warmup_steps"] weight_lr_power = group["weight_lr_power"] if k < warmup_steps: sched = (k + 1) / warmup_steps else: sched = 1.0 bias_correction2 = 1 - beta2 ** (k + 1) lr = group["lr"] * sched * math.sqrt(bias_correction2) lr_max = group["lr_max"] = max(lr, group["lr_max"]) weight = ((k + 1) ** r) * (lr_max**weight_lr_power) weight_sum = group["weight_sum"] = group["weight_sum"] + weight try: ckp1 = weight / weight_sum except ZeroDivisionError: ckp1 = 0 if not group["train_mode"]: raise Exception("Not in train mode!") active_p = [p for p in group["params"] if p.grad is not None] for p in active_p: if "z" not in self.state[p]: self.state[p]["z"] = torch.clone(p.data) self.state[p]["exp_avg_sq"] = torch.zeros_like(p.data) if group["foreach"] and len(active_p) > 0: y, grad, exp_avg_sq, z = zip( *[(p.data, p.grad, self.state[p]["exp_avg_sq"], self.state[p]["z"]) for p in active_p] ) # Decay the first and second moment running average coefficient torch._foreach_mul_(exp_avg_sq, beta2) torch._foreach_addcmul_(exp_avg_sq, grad, grad, value=1 - beta2) denom = torch._foreach_sqrt(exp_avg_sq) torch._foreach_add_(denom, eps) # Normalize grad in-place for memory efficiency torch._foreach_div_(grad, denom) # Weight decay calculated at y if decay != 0: torch._foreach_add_(grad, y, alpha=decay) # These operations update y in-place, # without computing x explicitly. torch._foreach_lerp_(y, z, weight=ckp1) torch._foreach_add_(y, grad, alpha=lr * (beta1 * (1 - ckp1) - 1)) # z step torch._foreach_sub_(z, grad, alpha=lr) else: for p in active_p: y = p.data # Notation to match theory grad = p.grad.data state = self.state[p] z = state["z"] exp_avg_sq = state["exp_avg_sq"] exp_avg_sq.mul_(beta2).addcmul_(grad, grad, value=1 - beta2) denom = exp_avg_sq.sqrt().add_(eps) # Reuse grad buffer for memory efficiency grad_normalized = grad.div_(denom) # Weight decay calculated at y if decay != 0: grad_normalized.add_(y, alpha=decay) # These operations update y in-place, # without computing x explicitly. y.lerp_(end=z, weight=ckp1) y.add_(grad_normalized, alpha=lr * (beta1 * (1 - ckp1) - 1)) # z step z.sub_(grad_normalized, alpha=lr) group["k"] = k + 1 return loss ================================================ FILE: src/lmflow/optim/adan.py ================================================ #!/usr/bin/env python import math import torch from torch import Tensor from torch.optim.optimizer import Optimizer class Adan(Optimizer): """Implements a pytorch variant of Adan. Adan was proposed in Adan : Adaptive Nesterov Momentum Algorithm for Faster Optimizing Deep Models. https://arxiv.org/abs/2208.06677 """ def __init__( self, params, lr=1e-3, betas=(0.98, 0.92, 0.99), eps=1e-8, weight_decay=0.0, max_grad_norm=0.0, no_prox=False, foreach: bool = True, ): if not 0.0 <= max_grad_norm: raise ValueError("Invalid Max grad norm: {}".format(max_grad_norm)) if not 0.0 <= lr: raise ValueError("Invalid learning rate: {}".format(lr)) if not 0.0 <= eps: raise ValueError("Invalid epsilon value: {}".format(eps)) if not 0.0 <= betas[0] < 1.0: raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) if not 0.0 <= betas[1] < 1.0: raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) if not 0.0 <= betas[2] < 1.0: raise ValueError("Invalid beta parameter at index 2: {}".format(betas[2])) defaults = dict( lr=lr, betas=betas, eps=eps, weight_decay=weight_decay, max_grad_norm=max_grad_norm, no_prox=no_prox, foreach=foreach, ) super().__init__(params, defaults) def __setstate__(self, state): super().__setstate__(state) for group in self.param_groups: group.setdefault("no_prox", False) @torch.no_grad() def restart_opt(self): for group in self.param_groups: group["step"] = 0 for p in group["params"]: if p.requires_grad: state = self.state[p] # State initialization # Exponential moving average of gradient values state["exp_avg"] = torch.zeros_like(p) # Exponential moving average of squared gradient values state["exp_avg_sq"] = torch.zeros_like(p) # Exponential moving average of gradient difference state["exp_avg_diff"] = torch.zeros_like(p) @torch.no_grad() def step(self): """Performs a single optimization step.""" if self.defaults["max_grad_norm"] > 0: device = self.param_groups[0]["params"][0].device global_grad_norm = torch.zeros(1, device=device) max_grad_norm = torch.tensor(self.defaults["max_grad_norm"], device=device) for group in self.param_groups: for p in group["params"]: if p.grad is not None: grad = p.grad global_grad_norm.add_(grad.pow(2).sum()) global_grad_norm = torch.sqrt(global_grad_norm) + group["eps"] clip_global_grad_norm = torch.clamp(max_grad_norm / global_grad_norm, max=1.0) else: clip_global_grad_norm = 1.0 for group in self.param_groups: params_with_grad = [] grads = [] exp_avgs = [] exp_avg_sqs = [] exp_avg_diffs = [] pre_grads = [] beta1, beta2, beta3 = group["betas"] # assume same step across group now to simplify things # per parameter step can be easily support # by making it tensor, or pass list into kernel if "step" in group: group["step"] += 1 else: group["step"] = 1 bias_correction1 = 1.0 - beta1 ** group["step"] bias_correction2 = 1.0 - beta2 ** group["step"] bias_correction3 = 1.0 - beta3 ** group["step"] for p in group["params"]: if p.grad is None: continue params_with_grad.append(p) grads.append(p.grad) state = self.state[p] if len(state) == 0: state["exp_avg"] = torch.zeros_like(p) state["exp_avg_sq"] = torch.zeros_like(p) state["exp_avg_diff"] = torch.zeros_like(p) if "pre_grad" not in state or group["step"] == 1: # at first step grad wouldn't be clipped # by `clip_global_grad_norm` # this is only to simplify implementation state["pre_grad"] = p.grad exp_avgs.append(state["exp_avg"]) exp_avg_sqs.append(state["exp_avg_sq"]) exp_avg_diffs.append(state["exp_avg_diff"]) pre_grads.append(state["pre_grad"]) kwargs = dict( params=params_with_grad, grads=grads, exp_avgs=exp_avgs, exp_avg_sqs=exp_avg_sqs, exp_avg_diffs=exp_avg_diffs, pre_grads=pre_grads, beta1=beta1, beta2=beta2, beta3=beta3, bias_correction1=bias_correction1, bias_correction2=bias_correction2, bias_correction3_sqrt=math.sqrt(bias_correction3), lr=group["lr"], weight_decay=group["weight_decay"], eps=group["eps"], no_prox=group["no_prox"], clip_global_grad_norm=clip_global_grad_norm, ) if group["foreach"]: copy_grads = _multi_tensor_adan(**kwargs) else: copy_grads = _single_tensor_adan(**kwargs) for p, copy_grad in zip(params_with_grad, copy_grads): self.state[p]["pre_grad"] = copy_grad def _single_tensor_adan( params: list[Tensor], grads: list[Tensor], exp_avgs: list[Tensor], exp_avg_sqs: list[Tensor], exp_avg_diffs: list[Tensor], pre_grads: list[Tensor], *, beta1: float, beta2: float, beta3: float, bias_correction1: float, bias_correction2: float, bias_correction3_sqrt: float, lr: float, weight_decay: float, eps: float, no_prox: bool, clip_global_grad_norm: Tensor, ): copy_grads = [] for i, param in enumerate(params): grad = grads[i] exp_avg = exp_avgs[i] exp_avg_sq = exp_avg_sqs[i] exp_avg_diff = exp_avg_diffs[i] pre_grad = pre_grads[i] grad = grad.mul_(clip_global_grad_norm) copy_grads.append(grad.clone()) diff = grad - pre_grad update = grad + beta2 * diff exp_avg.mul_(beta1).add_(grad, alpha=1 - beta1) # m_t exp_avg_diff.mul_(beta2).add_(diff, alpha=1 - beta2) # diff_t exp_avg_sq.mul_(beta3).addcmul_(update, update, value=1 - beta3) # n_t denom = (exp_avg_sq.sqrt() / bias_correction3_sqrt).add_(eps) update = exp_avg / bias_correction1 update.add_(beta2 * exp_avg_diff / bias_correction2).div_(denom) if no_prox: param.mul_(1 - lr * weight_decay) param.add_(update, alpha=-lr) else: param.add_(update, alpha=-lr) param.div_(1 + lr * weight_decay) return copy_grads def _multi_tensor_adan( params: list[Tensor], grads: list[Tensor], exp_avgs: list[Tensor], exp_avg_sqs: list[Tensor], exp_avg_diffs: list[Tensor], pre_grads: list[Tensor], *, beta1: float, beta2: float, beta3: float, bias_correction1: float, bias_correction2: float, bias_correction3_sqrt: float, lr: float, weight_decay: float, eps: float, no_prox: bool, clip_global_grad_norm: Tensor, ): if clip_global_grad_norm < 1.0: torch._foreach_mul_(grads, clip_global_grad_norm.item()) copy_grads = [g.clone() for g in grads] diff = torch._foreach_sub(grads, pre_grads) # NOTE: line below while looking identical gives different result, # due to float precision errors. # using mul+add produces identical results to single-tensor, # using add+alpha doesn't # update = torch._foreach_add(grads, torch._foreach_mul(diff, beta2)) update = torch._foreach_add(grads, diff, alpha=beta2) torch._foreach_mul_(exp_avgs, beta1) torch._foreach_add_(exp_avgs, grads, alpha=1 - beta1) # m_t torch._foreach_mul_(exp_avg_diffs, beta2) torch._foreach_add_(exp_avg_diffs, diff, alpha=1 - beta2) # diff_t torch._foreach_mul_(exp_avg_sqs, beta3) torch._foreach_addcmul_(exp_avg_sqs, update, update, value=1 - beta3) # n_t denom = torch._foreach_sqrt(exp_avg_sqs) torch._foreach_div_(denom, bias_correction3_sqrt) torch._foreach_add_(denom, eps) update = torch._foreach_div(exp_avgs, bias_correction1) # NOTE: same issue as above. # beta2 * diff / bias_correction2 != diff * (beta2 / bias_correction2) # noqa # using faster version by default. uncomment for tests to pass # torch._foreach_add_(update, torch._foreach_div(torch._foreach_mul(exp_avg_diffs, beta2), bias_correction2)) # noqa torch._foreach_add_(update, torch._foreach_mul(exp_avg_diffs, beta2 / bias_correction2)) torch._foreach_div_(update, denom) if no_prox: torch._foreach_mul_(params, 1 - lr * weight_decay) else: torch._foreach_add_(params, update, alpha=-lr) torch._foreach_div_(params, 1 + lr * weight_decay) return copy_grads ================================================ FILE: src/lmflow/optim/dummy.py ================================================ #!/usr/bin/env python """Dummy Optimizer.""" from collections.abc import Iterable from typing import Callable import torch from torch import nn from torch.optim import Optimizer class Dummy(Optimizer): """ An dummy optimizer that does nothing. Parameters: params (:obj:`Iterable[nn.parameter.Parameter]`): Iterable of parameters to optimize or dictionaries defining parameter groups. lr (:obj:`float`, `optional`, defaults to 0): The learning rate to use. """ def __init__( self, params: Iterable[nn.parameter.Parameter], lr: float = 0.0, betas: tuple[float, float] = (0.9, 0.999), weight_decay: float = 0.0, ): if lr < 0.0: raise ValueError(f"Invalid learning rate: {lr} - should be >= 0.0") if not 0.0 <= betas[0] < 1.0: raise ValueError(f"Invalid beta parameter: {betas[0]} - should be in [0.0, 1.0)") if not 0.0 <= betas[1] < 1.0: raise ValueError(f"Invalid beta parameter: {betas[1]} - should be in [0.0, 1.0)") defaults = {"lr": lr, "betas": betas, "weight_decay": weight_decay} super().__init__(params, defaults) @torch.no_grad() def step(self, closure: Callable = None): """ Performs a single optimization step. Arguments: closure (:obj:`Callable`, `optional`): A closure that reevaluates the model and returns the loss. """ loss = None if closure is not None: loss = closure() for group in self.param_groups: for p in group["params"]: if p.grad is None: continue grad = p.grad if grad.is_sparse: raise RuntimeError("Dummy does not support sparse gradients yet") state = self.state[p] # State initialization if len(state) == 0: state["step"] = 0 state["exp_avg"] = torch.zeros_like(p) state["exp_avg2"] = torch.zeros_like(p) # v := exp_avg # m := double_exp_avg _, m = state["exp_avg"], state["exp_avg2"] # beta1, beta2 = group["betas"] # step_size = group["lr"] state["step"] += 1 p.add_(m, alpha=-0.0) if group["weight_decay"] > 0.0: p.add_(p, alpha=(-group["lr"] * group["weight_decay"])) return loss ================================================ FILE: src/lmflow/optim/lamb.py ================================================ #!/usr/bin/env python import math import torch from torch.optim.optimizer import Optimizer class Lamb(Optimizer): r"""Implements Lamb algorithm. It has been proposed in `Large Batch Optimization for Deep Learning: Training BERT in 76 minutes` https://arxiv.org/abs/1904.00962 Note: Reference code: https://github.com/cybertronai/pytorch-lamb """ def __init__( self, params, lr: float = 1e-3, betas=(0.9, 0.999), eps: float = 1e-6, weight_decay: float = 0, clamp_value: float = 10, adam: bool = False, debias: bool = False, ) -> None: if lr <= 0.0: raise ValueError("Invalid learning rate: {}".format(lr)) if eps < 0.0: raise ValueError("Invalid epsilon value: {}".format(eps)) if not 0.0 <= betas[0] < 1.0: raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) if not 0.0 <= betas[1] < 1.0: raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) if weight_decay < 0: raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) if clamp_value < 0.0: raise ValueError("Invalid clamp value: {}".format(clamp_value)) defaults = dict(lr=lr, betas=betas, eps=eps, weight_decay=weight_decay) self.clamp_value = clamp_value self.adam = adam self.debias = debias super().__init__(params, defaults) def step(self, closure=None): r"""Performs a single optimization step. Arguments: closure: A closure that reevaluates the model and returns the loss. """ loss = None if closure is not None: loss = closure() for group in self.param_groups: for p in group["params"]: if p.grad is None: continue grad = p.grad.data if grad.is_sparse: msg = "Lamb does not support sparse gradients, please consider SparseAdam instead" raise RuntimeError(msg) state = self.state[p] # State initialization if len(state) == 0: state["step"] = 0 # Exponential moving average of gradient values state["exp_avg"] = torch.zeros_like(p, memory_format=torch.preserve_format) # Exponential moving average of squared gradient values state["exp_avg_sq"] = torch.zeros_like(p, memory_format=torch.preserve_format) exp_avg, exp_avg_sq = state["exp_avg"], state["exp_avg_sq"] beta1, beta2 = group["betas"] state["step"] += 1 # Decay the first and second moment running average coefficient # m_t exp_avg.mul_(beta1).add_(grad, alpha=1 - beta1) # v_t exp_avg_sq.mul_(beta2).addcmul_(grad, grad, value=1 - beta2) # Paper v3 does not use debiasing. if self.debias: bias_correction = math.sqrt(1 - beta2 ** state["step"]) bias_correction /= 1 - beta1 ** state["step"] else: bias_correction = 1 # Apply bias to lr to avoid broadcast. step_size = group["lr"] * bias_correction weight_norm = torch.norm(p.data).clamp(0, self.clamp_value) adam_step = exp_avg / exp_avg_sq.sqrt().add(group["eps"]) if group["weight_decay"] != 0: adam_step.add_(p.data, alpha=group["weight_decay"]) adam_norm = torch.norm(adam_step) if weight_norm == 0 or adam_norm == 0: trust_ratio = 1 else: trust_ratio = weight_norm / adam_norm state["weight_norm"] = weight_norm state["adam_norm"] = adam_norm state["trust_ratio"] = trust_ratio if self.adam: trust_ratio = 1 p.data.add_(adam_step, alpha=-step_size * trust_ratio) return loss ================================================ FILE: src/lmflow/optim/lars.py ================================================ #!/usr/bin/env python import torch from torch.optim.optimizer import Optimizer class LARS(Optimizer): r"""Extends SGD in PyTorch with LARS scaling from the paper `Large batch training of Convolutional Networks`__. .. note:: The application of momentum in the SGD part is modified according to the PyTorch standards. LARS scaling fits into the equation in the following fashion. .. math:: \begin{aligned} g_{t+1} & = \text{lars_lr} * (\beta * p_{t} + g_{t+1}), \\ v_{t+1} & = \\mu * v_{t} + g_{t+1}, \\ p_{t+1} & = p_{t} - \text{lr} * v_{t+1}, \\end{aligned} where :math:`p`, :math:`g`, :math:`v`, :math:`\\mu` and :math:`\beta` denote the parameters, gradient, velocity, momentum, and weight decay respectively. The :math:`lars_lr` is defined by Eq. 6 in the paper. The Nesterov version is analogously modified. .. warning:: Parameters with weight decay set to 0 will automatically be excluded from layer-wise LR scaling. This is to ensure consistency with papers like SimCLR and BYOL. __ https://arxiv.org/pdf/1708.03888.pdf Note: Reference code: https://github.com/PyTorchLightning/lightning-bolts/ """ def __init__( self, params, lr: float = 1e-2, momentum: float = 0.0, dampening: float = 0.0, weight_decay: float = 0.0, nesterov: bool = False, trust_coefficient: float = 0.01, eps: float = 1e-8, ): if lr <= 0.0: raise ValueError("Invalid learning rate: {}".format(lr)) if eps < 0.0: raise ValueError("Invalid epsilon value: {}".format(eps)) if momentum < 0.0: raise ValueError("Invalid momentum value: {}".format(momentum)) if dampening < 0.0: raise ValueError("Invalid dampening value: {}".format(dampening)) if weight_decay < 0.0: raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) if trust_coefficient < 0.0: raise ValueError("Invalid trust_coefficient value: {}".format(trust_coefficient)) defaults = dict( lr=lr, momentum=momentum, dampening=dampening, weight_decay=weight_decay, nesterov=nesterov, trust_coefficient=trust_coefficient, eps=eps, ) if nesterov and (momentum <= 0 or dampening != 0): raise ValueError("Nesterov momentum requires a momentum and zero dampening") super().__init__(params, defaults) def __setstate__(self, state) -> None: super().__setstate__(state) for group in self.param_groups: group.setdefault("nesterov", False) @torch.no_grad() def step(self, closure=None): r"""Performs a single optimization step. Arguments: closure: A closure that reevaluates the model and returns the loss. """ loss = None if closure is not None: with torch.enable_grad(): loss = closure() # exclude scaling for params with 0 weight decay for group in self.param_groups: weight_decay = group["weight_decay"] momentum = group["momentum"] dampening = group["dampening"] nesterov = group["nesterov"] for p in group["params"]: if p.grad is None: continue d_p = p.grad p_norm = torch.norm(p.data) g_norm = torch.norm(p.grad.data) # lars scaling + weight decay part if weight_decay != 0: if p_norm != 0 and g_norm != 0: lars_lr = p_norm / (g_norm + p_norm * weight_decay + group["eps"]) lars_lr *= group["trust_coefficient"] d_p = d_p.add(p, alpha=weight_decay) d_p *= lars_lr if momentum != 0: param_state = self.state[p] if "momentum_buffer" not in param_state: buf = param_state["momentum_buffer"] = torch.clone(d_p).detach() else: buf = param_state["momentum_buffer"] buf.mul_(momentum).add_(d_p, alpha=1 - dampening) if nesterov: d_p = d_p.add(buf, alpha=momentum) else: d_p = buf p.add_(d_p, alpha=-group["lr"]) return loss ================================================ FILE: src/lmflow/optim/muon.py ================================================ #!/usr/bin/env python import math import torch from torch import Tensor def zeropower_via_newtonschulz5(G: Tensor, steps: int) -> Tensor: """ Newton-Schulz iteration to compute the zeroth power / orthogonalization of G. We opt to use a quintic iteration whose coefficients are selected to maximize the slope at zero. For the purpose of minimizing steps, it turns out to be empirically effective to keep increasing the slope at zero even beyond the point where the iteration no longer converges all the way to one everywhere on the interval. This iteration therefore does not produce UV^T but rather something like US'V^T where S' is diagonal with S_{ii}' ~ Uniform(0.5, 1.5), which turns out not to hurt model performance at all relative to UV^T, where USV^T = G is the SVD. """ assert ( G.ndim >= 2 ) # batched Muon implementation by @scottjmaddox, and put into practice in the record by @YouJiacheng a, b, c = (3.4445, -4.7750, 2.0315) X = G.bfloat16() if G.size(-2) > G.size(-1): X = X.mT # Ensure spectral norm is at most 1 X = X / (X.norm(dim=(-2, -1), keepdim=True) + 1e-7) # Perform the NS iterations for _ in range(steps): A = X @ X.mT B = ( b * A + c * A @ A ) # quintic computation strategy adapted from suggestion by @jxbz, @leloykun, and @YouJiacheng X = a * X + B @ X if G.size(-2) > G.size(-1): X = X.mT return X class Muon(torch.optim.Optimizer): """ Adam optimizer with orthogonalization step. """ def __init__(self, params, lr=0.001, betas=(0.9, 0.999), eps=1e-8, weight_decay=0, ns_steps=5): defaults = dict(lr=lr, betas=betas, eps=eps, weight_decay=weight_decay, ns_steps=ns_steps) super().__init__(params, defaults) @torch.no_grad() def step(self, closure=None): """ Performs a single optimization step. Args: closure (callable, optional): A closure that reevaluates the model and returns the loss. """ loss = None if closure is not None: loss = closure() for group in self.param_groups: for p in group["params"]: if p.grad is None: continue grad = p.grad state = self.state[p] # Initialize state if len(state) == 0: state["step"] = 0 state["exp_avg"] = torch.zeros_like(p) state["exp_avg_sq"] = torch.zeros_like(p) exp_avg, exp_avg_sq = state["exp_avg"], state["exp_avg_sq"] beta1, beta2 = group["betas"] state["step"] += 1 bias_correction1 = 1 - beta1 ** state["step"] bias_correction2 = 1 - beta2 ** state["step"] # Update momentum and squared gradient exp_avg.mul_(beta1).add_(grad, alpha=1 - beta1) exp_avg_sq.mul_(beta2).addcmul_(grad, grad, value=1 - beta2) # Compute the update denom = (exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group["eps"]) step_size = group["lr"] / bias_correction1 # Orthogonalize the update update = exp_avg / denom if update.ndim >= 2: update = zeropower_via_newtonschulz5(update, steps=group["ns_steps"]) # Apply the update p.add_(update, alpha=-step_size) # Apply weight decay if group["weight_decay"] != 0: p.add_(p, alpha=-group["lr"] * group["weight_decay"]) return loss ================================================ FILE: src/lmflow/optim/nadam.py ================================================ #!/usr/bin/env python import math import torch class NAdam(torch.optim.Optimizer): def __init__(self, params, lr=2e-3, betas=(0.9, 0.999), eps=1e-8, weight_decay=0, momentum_decay=4e-3): if not 0.0 <= lr: raise ValueError("Invalid learning rate: {}".format(lr)) if not 0.0 <= eps: raise ValueError("Invalid epsilon value: {}".format(eps)) if not 0.0 <= betas[0] < 1.0: raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) if not 0.0 <= betas[1] < 1.0: raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) if not 0.0 <= weight_decay: raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) if not 0.0 <= momentum_decay: raise ValueError("Invalid momentum_decay value: {}".format(momentum_decay)) defaults = dict(lr=lr, betas=betas, eps=eps, weight_decay=weight_decay, momentum_decay=momentum_decay) super().__init__(params, defaults) def __setstate__(self, state): super().__setstate__(state) def step(self, closure=None): loss = None if closure is not None: loss = closure() for group in self.param_groups: for p in group["params"]: if p.grad is None: continue grad = p.grad.data if grad.is_sparse: raise RuntimeError("NAdam does not support sparse gradients") state = self.state[p] # State initialization if len(state) == 0: state["step"] = 0 state["m_prev"] = torch.zeros_like(p.data) state["v"] = torch.zeros_like(p.data) m_prev, v = state["m_prev"], state["v"] beta1, beta2 = group["betas"] state["step"] += 1 bias_correction1 = 1 - beta1 ** state["step"] bias_correction2 = 1 - beta2 ** state["step"] if group["weight_decay"] != 0: grad = grad.add(group["weight_decay"], p.data) m = beta1 * m_prev + (1 - beta1) * grad v.mul_(beta2).addcmul_(1 - beta2, grad, grad) m_hat = m / bias_correction1 v_hat = v / bias_correction2 denom = v_hat.sqrt().add_(group["eps"]) momentum_decay = group["momentum_decay"] m_prev.mul_(beta1).add_(1 - beta1, grad) m_prev_hat = m_prev / bias_correction1 step_size = group["lr"] * math.sqrt(bias_correction2) / bias_correction1 p.data.addcdiv_(-step_size, m_hat + momentum_decay * m_prev_hat, denom) return loss ================================================ FILE: src/lmflow/optim/novograd.py ================================================ #!/usr/bin/env python import torch import torch.optim as optim class NovoGrad(optim.Optimizer): def __init__( self, params, lr=0.01, betas=(0.9, 0.999), eps=1e-8, weight_decay=0, grad_averaging=False, amsgrad=False ): if not 0.0 <= lr: raise ValueError("Invalid learning rate: {}".format(lr)) if not 0.0 <= eps: raise ValueError("Invalid epsilon value: {}".format(eps)) if not 0.0 <= betas[0] < 1.0: raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) if not 0.0 <= betas[1] < 1.0: raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) if not 0.0 <= weight_decay: raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) defaults = dict( lr=lr, betas=betas, eps=eps, weight_decay=weight_decay, grad_averaging=grad_averaging, amsgrad=amsgrad ) super().__init__(params, defaults) def __setstate__(self, state): super().__setstate__(state) for group in self.param_groups: group.setdefault("amsgrad", False) def step(self, closure=None): loss = None if closure is not None: loss = closure() for group in self.param_groups: for p in group["params"]: if p.grad is None: continue grad = p.grad.data if grad.is_sparse: raise RuntimeError("NovoGrad does not support sparse gradients") amsgrad = group["amsgrad"] state = self.state[p] # State initialization if len(state) == 0: state["step"] = 0 state["exp_avg"] = torch.zeros_like(p.data) state["exp_avg_sq"] = torch.zeros([]).to(state["exp_avg"].device) if amsgrad: state["max_exp_avg_sq"] = torch.zeros([]).to(state["exp_avg"].device) exp_avg, exp_avg_sq = state["exp_avg"], state["exp_avg_sq"] if amsgrad: max_exp_avg_sq = state["max_exp_avg_sq"] beta1, beta2 = group["betas"] state["step"] += 1 norm = torch.sum(torch.pow(grad, 2)) if exp_avg_sq == 0: exp_avg_sq.copy_(norm) else: exp_avg_sq.mul_(beta2).add_(1 - beta2, norm) if amsgrad: # Maintains the maximum of all 2nd moment running avg. till now torch.max(max_exp_avg_sq, exp_avg_sq, out=max_exp_avg_sq) # Use the max. for normalizing running avg. of gradient denom = max_exp_avg_sq.sqrt().add_(group["eps"]) else: denom = exp_avg_sq.sqrt().add_(group["eps"]) grad.div_(denom) if group["weight_decay"] != 0: grad.add_(group["weight_decay"], p.data) if group["grad_averaging"]: grad.mul_(1 - beta1) exp_avg.mul_(beta1).add_(grad) p.data.add_(-group["lr"], exp_avg) return loss ================================================ FILE: src/lmflow/optim/optimizers.py ================================================ #!/usr/bin/env python """All optimizers.""" ================================================ FILE: src/lmflow/optim/radam.py ================================================ #!/usr/bin/env python import math import warnings import torch from torch.optim.optimizer import Optimizer class RAdam(Optimizer): r"""Implements RAdam optimization algorithm. Note: Deprecated, please use version provided by PyTorch_. It has been proposed in `On the Variance of the Adaptive Learning Rate and Beyond`. https://arxiv.org/abs/1908.03265 Note: Reference code: https://github.com/LiyuanLucasLiu/RAdam """ def __init__( self, params, lr: float = 1e-3, betas=(0.9, 0.999), eps: float = 1e-8, weight_decay: float = 0, ) -> None: warnings.warn( "RAdam optimizer is deprecated, since it is included in pytorch natively.", DeprecationWarning, stacklevel=2, ) if lr <= 0.0: raise ValueError("Invalid learning rate: {}".format(lr)) if eps < 0.0: raise ValueError("Invalid epsilon value: {}".format(eps)) if not 0.0 <= betas[0] < 1.0: raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) if not 0.0 <= betas[1] < 1.0: raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) if weight_decay < 0: raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) if isinstance(params, (list, tuple)) and len(params) > 0 and isinstance(params[0], dict): for param in params: if "betas" in param and (param["betas"][0] != betas[0] or param["betas"][1] != betas[1]): param["buffer"] = [[None, None, None] for _ in range(10)] defaults = dict( lr=lr, betas=betas, eps=eps, weight_decay=weight_decay, buffer=[[None, None, None] for _ in range(10)], ) super().__init__(params, defaults) def __setstate__(self, state): super().__setstate__(state) def step(self, closure=None): r"""Performs a single optimization step. Arguments: closure: A closure that reevaluates the model and returns the loss. """ loss = None if closure is not None: loss = closure() for group in self.param_groups: lr = group["lr"] weight_decay = group["weight_decay"] beta1, beta2 = group["betas"] eps = group["eps"] for p in group["params"]: if p.grad is None: continue grad = p.grad.data.float() if grad.is_sparse: msg = "RAdam does not support sparse gradients, please consider SparseAdam instead" raise RuntimeError(msg) p_data_fp32 = p.data.float() state = self.state[p] if len(state) == 0: state["step"] = 0 state["exp_avg"] = torch.zeros_like(p_data_fp32, memory_format=torch.preserve_format) state["exp_avg_sq"] = torch.zeros_like(p_data_fp32, memory_format=torch.preserve_format) else: state["exp_avg"] = state["exp_avg"].type_as(p_data_fp32) state["exp_avg_sq"] = state["exp_avg_sq"].type_as(p_data_fp32) exp_avg, exp_avg_sq = state["exp_avg"], state["exp_avg_sq"] exp_avg_sq.mul_(beta2).addcmul_(grad, grad, value=1 - beta2) exp_avg.mul_(beta1).add_(grad, alpha=1 - beta1) state["step"] += 1 buffered = group["buffer"][int(state["step"] % 10)] if state["step"] == buffered[0]: N_sma, step_size = buffered[1], buffered[2] else: buffered[0] = state["step"] beta2_t = beta2 ** state["step"] N_sma_max = 2 / (1 - beta2) - 1 N_sma = N_sma_max - 2 * state["step"] * beta2_t / (1 - beta2_t) buffered[1] = N_sma # more conservative since it's an approximated value if N_sma >= 5: step_size = ( lr * math.sqrt( (1 - beta2_t) * (N_sma - 4) / (N_sma_max - 4) * (N_sma - 2) / N_sma * N_sma_max / (N_sma_max - 2) ) / (1 - beta1 ** state["step"]) ) else: step_size = lr / (1 - beta1 ** state["step"]) buffered[2] = step_size if weight_decay != 0: p_data_fp32.add_(p_data_fp32, alpha=-weight_decay * lr) # more conservative since it's an approximated value if N_sma >= 5: denom = exp_avg_sq.sqrt().add_(eps) p_data_fp32.addcdiv_(exp_avg, denom, value=-step_size) else: p_data_fp32.add_(exp_avg, alpha=-step_size) p.data.copy_(p_data_fp32) return loss ================================================ FILE: src/lmflow/optim/sgd_schedule_free.py ================================================ # Copyright (c) Meta Platforms, Inc. and affiliates. # All rights reserved. # # This source code is licensed under the license found in the # LICENSE file in the root directory of this source tree. #!/usr/bin/env python # -*- coding: utf-8 -*- import torch import torch.optim class SGDScheduleFree(torch.optim.Optimizer): r""" Schedule-Free SGD As the name suggests, no scheduler is needed with this optimizer. To add warmup, rather than using a learning rate schedule you can just set the warmup_steps parameter. This optimizer requires that .train() and .eval() be called before the beginning of training and evaluation respectively. The optimizer should also be placed in eval mode when saving checkpoints. """ def __init__( self, params, lr=1.0, momentum=0.9, weight_decay=0, warmup_steps=0, r=0.0, weight_lr_power=2, foreach=None, ): if not foreach: foreach = hasattr(torch, "_foreach_mul_") if lr < 0.0: raise ValueError("Invalid learning rate: {}".format(lr)) if weight_decay < 0.0: raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) if momentum <= 0 or momentum >= 1: raise ValueError("Momentum must be between 0 and 1 exclusive: {}".format(momentum)) defaults = dict( lr=lr, momentum=momentum, r=r, k=0, warmup_steps=warmup_steps, train_mode=True, weight_sum=0.0, lr_max=-1.0, weight_lr_power=weight_lr_power, weight_decay=weight_decay, foreach=foreach, ) super().__init__(params, defaults) def eval(self): for group in self.param_groups: train_mode = group["train_mode"] momentum = group["momentum"] if train_mode: for p in group["params"]: state = self.state[p] if "z" in state: # Set p.data to x p.data.lerp_(end=state["z"], weight=1 - 1 / momentum) group["train_mode"] = False def train(self): for group in self.param_groups: train_mode = group["train_mode"] momentum = group["momentum"] if not train_mode: for p in group["params"]: state = self.state[p] if "z" in state: # Set p.data to y p.data.lerp_(end=state["z"], weight=1 - momentum) group["train_mode"] = True def step(self, closure=None): """Performs a single optimization step. Arguments: closure (callable, optional): A closure that reevaluates the model and returns the loss. """ loss = None if closure is not None: loss = closure() for group in self.param_groups: momentum = group["momentum"] lr = group["lr"] weight_decay = group["weight_decay"] k = group["k"] warmup_steps = group["warmup_steps"] if k < warmup_steps: sched = (k + 1) / warmup_steps else: sched = 1.0 lr = group["lr"] * sched weight_lr_power = group["weight_lr_power"] r = group["r"] lr_max = group["lr_max"] = max(lr, group["lr_max"]) weight = ((k + 1) ** r) * (lr_max**weight_lr_power) weight_sum = group["weight_sum"] = group["weight_sum"] + weight try: ckp1 = weight / weight_sum except ZeroDivisionError: ckp1 = 0 if not group["train_mode"]: raise Exception("Not in train mode!") active_p = [p for p in group["params"] if p.grad is not None] for p in active_p: if "z" not in self.state[p]: self.state[p]["z"] = torch.clone(p.data) if group["foreach"] and len(active_p) > 0: y, grad, z = zip(*[(p.data, p.grad, self.state[p]["z"]) for p in active_p]) # Apply weight decay if weight_decay != 0: torch._foreach_add_(grad, y, alpha=weight_decay) # These operations update y in-place, # without computing x explicitly. torch._foreach_lerp_(y, z, weight=ckp1) torch._foreach_add_(y, grad, alpha=lr * (momentum * (1 - ckp1) - 1)) # SGD step torch._foreach_sub_(z, grad, alpha=lr) else: for p in active_p: y = p.data # Notation to match theory grad = p.grad.data z = self.state[p]["z"] # Apply weight decay if weight_decay != 0: grad.add_(y, alpha=weight_decay) # These operations update y in-place, # without computing x explicitly. y.lerp_(end=z, weight=ckp1) y.add_(grad, alpha=lr * (momentum * (1 - ckp1) - 1)) # SGD step z.sub_(grad, alpha=lr) group["k"] = k + 1 return loss ================================================ FILE: src/lmflow/optim/sgdp.py ================================================ #!/usr/bin/env python import math import torch from torch.optim.optimizer import Optimizer class SGDP(Optimizer): r"""Implements SGDP algorithm. It has been proposed in `Slowing Down the Weight Norm Increase in Momentum-based Optimizers`. https://arxiv.org/abs/2006.08217 Note: Reference code: https://github.com/clovaai/AdamP """ def __init__( self, params, lr: float = 1e-3, momentum: float = 0, dampening: float = 0, eps: float = 1e-8, weight_decay: float = 0, delta: float = 0.1, wd_ratio: float = 0.1, nesterov: bool = False, ) -> None: if lr <= 0.0: raise ValueError("Invalid learning rate: {}".format(lr)) if eps < 0.0: raise ValueError("Invalid epsilon value: {}".format(eps)) if momentum < 0.0: raise ValueError("Invalid momentum value: {}".format(momentum)) if dampening < 0.0: raise ValueError("Invalid dampening value: {}".format(dampening)) if weight_decay < 0: raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) if delta < 0: raise ValueError("Invalid delta value: {}".format(delta)) if wd_ratio < 0: raise ValueError("Invalid wd_ratio value: {}".format(wd_ratio)) defaults = dict( lr=lr, momentum=momentum, dampening=dampening, eps=eps, weight_decay=weight_decay, delta=delta, wd_ratio=wd_ratio, nesterov=nesterov, ) super().__init__(params, defaults) @staticmethod def _channel_view(x): return x.view(x.size(0), -1) @staticmethod def _layer_view(x): return x.view(1, -1) @staticmethod def _cosine_similarity(x, y, eps, view_func): x = view_func(x) y = view_func(y) x_norm = x.norm(dim=1).add_(eps) y_norm = y.norm(dim=1).add_(eps) dot = (x * y).sum(dim=1) return dot.abs() / x_norm / y_norm def _projection(self, p, grad, perturb, delta, wd_ratio, eps): wd = 1 expand_size = [-1] + [1] * (len(p.shape) - 1) for view_func in [self._channel_view, self._layer_view]: cosine_sim = self._cosine_similarity(grad, p.data, eps, view_func) if cosine_sim.max() < delta / math.sqrt(view_func(p.data).size(1)): p_n = p.data / view_func(p.data).norm(dim=1).view(expand_size).add_(eps) perturb -= p_n * view_func(p_n * perturb).sum(dim=1).view(expand_size) wd = wd_ratio return perturb, wd return perturb, wd def step(self, closure=None): r"""Performs a single optimization step. Arguments: closure: A closure that reevaluates the model and returns the loss. """ loss = None if closure is not None: loss = closure() for group in self.param_groups: weight_decay = group["weight_decay"] momentum = group["momentum"] dampening = group["dampening"] nesterov = group["nesterov"] for p in group["params"]: if p.grad is None: continue grad = p.grad.data state = self.state[p] # State initialization if len(state) == 0: state["momentum"] = torch.zeros_like(p.data, memory_format=torch.preserve_format) # SGD buf = state["momentum"] buf.mul_(momentum).add_(grad, alpha=1 - dampening) if nesterov: d_p = grad + momentum * buf else: d_p = buf # Projection wd_ratio = 1 if len(p.shape) > 1: d_p, wd_ratio = self._projection( p, grad, d_p, group["delta"], group["wd_ratio"], group["eps"], ) # Weight decay if weight_decay != 0: p.data.mul_(1 - group["lr"] * group["weight_decay"] * wd_ratio / (1 - momentum)) # Step p.data.add_(d_p, alpha=-group["lr"]) return loss ================================================ FILE: src/lmflow/optim/sophia.py ================================================ #!/usr/bin/env python import torch from torch.optim.optimizer import Optimizer class SophiaG(Optimizer): """ Sophia: A Scalable Stochastic Second-order Optimizer for Language Model Pre-training. Code from: https://github.com/Liuhong99/Sophia/ """ def __init__( self, params, lr=1e-4, betas=(0.965, 0.99), rho=0.04, weight_decay=1e-1, *, maximize: bool = False, capturable: bool = False, ): if not 0.0 <= lr: raise ValueError("Invalid learning rate: {}".format(lr)) if not 0.0 <= betas[0] < 1.0: raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) if not 0.0 <= betas[1] < 1.0: raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) if not 0.0 <= rho: raise ValueError("Invalid rho parameter at index 1: {}".format(rho)) if not 0.0 <= weight_decay: raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) defaults = dict( lr=lr, betas=betas, rho=rho, weight_decay=weight_decay, maximize=maximize, capturable=capturable ) super().__init__(params, defaults) def __setstate__(self, state): super().__setstate__(state) for group in self.param_groups: group.setdefault("maximize", False) group.setdefault("capturable", False) state_values = list(self.state.values()) step_is_tensor = (len(state_values) != 0) and torch.is_tensor(state_values[0]["step"]) if not step_is_tensor: for s in state_values: s["step"] = torch.tensor(float(s["step"])) @torch.no_grad() def update_hessian(self): for group in self.param_groups: beta1, beta2 = group["betas"] for p in group["params"]: if p.grad is None: continue state = self.state[p] if len(state) == 0: state["step"] = ( torch.zeros((1,), dtype=torch.float, device=p.device) if self.defaults["capturable"] else torch.tensor(0.0) ) state["exp_avg"] = torch.zeros_like(p, memory_format=torch.preserve_format) state["hessian"] = torch.zeros_like(p, memory_format=torch.preserve_format) if "hessian" not in state.keys(): state["hessian"] = torch.zeros_like(p, memory_format=torch.preserve_format) state["hessian"].mul_(beta2).addcmul_(p.grad, p.grad, value=1 - beta2) @torch.no_grad() def step(self, closure=None, bs=5120): loss = None if closure is not None: with torch.enable_grad(): loss = closure() for group in self.param_groups: params_with_grad = [] grads = [] exp_avgs = [] state_steps = [] hessian = [] beta1, beta2 = group["betas"] for p in group["params"]: if p.grad is None: continue params_with_grad.append(p) if p.grad.is_sparse: raise RuntimeError("SophiaG does not support sparse gradients") grads.append(p.grad) state = self.state[p] # State initialization if len(state) == 0: state["step"] = ( torch.zeros((1,), dtype=torch.float, device=p.device) if self.defaults["capturable"] else torch.tensor(0.0) ) state["exp_avg"] = torch.zeros_like(p, memory_format=torch.preserve_format) state["hessian"] = torch.zeros_like(p, memory_format=torch.preserve_format) if "hessian" not in state.keys(): state["hessian"] = torch.zeros_like(p, memory_format=torch.preserve_format) exp_avgs.append(state["exp_avg"]) state_steps.append(state["step"]) hessian.append(state["hessian"]) if self.defaults["capturable"]: bs = torch.ones((1,), dtype=torch.float, device=p.device) * bs # Perform the actual update step here instead of calling SophiaG again for p, grad, exp_avg, h, step in zip(params_with_grad, grads, exp_avgs, hessian, state_steps): if group["weight_decay"] != 0: grad = grad.add(p, alpha=group["weight_decay"]) # Decay the first and second moment running average coefficient exp_avg.mul_(beta1).add_(grad, alpha=1 - beta1) step.add_(1) # Compute the update using the hessian information update = exp_avg.div(1 - beta1 ** step.item()) h_sqrt = h.sqrt().add_(group["rho"]) p.addcdiv_(update, h_sqrt, value=-group["lr"]) return loss ================================================ FILE: src/lmflow/optim/utils.py ================================================ from typing import Any, Optional from transformers import PreTrainedModel from transformers.utils import is_sagemaker_mp_enabled import lmflow.optim.optimizers as optim from lmflow.args import OptimizerNames, TrainingArguments def create_customized_optimizer(base_trainer_class, model_args): class CustomizedOptimTrainer(base_trainer_class): @staticmethod def get_optimizer_cls_and_kwargs( args: TrainingArguments, model: Optional[PreTrainedModel] = None, ) -> tuple[Any, Any]: # parse args.optim_args optim_args = {} if args.customized_optim_args: for mapping in args.customized_optim_args.replace(" ", "").split(","): key, value = mapping.split("=") optim_args[key] = value optimizer_kwargs = {"lr": args.learning_rate} if args.customized_optim == OptimizerNames.DUMMY: optimizer_cls = optim.Dummy dummy_kwargs = { "betas": (args.optim_dummy_beta1, args.optim_dummy_beta2), } optimizer_kwargs.update(dummy_kwargs) elif args.customized_optim == OptimizerNames.ADABELIEF: optimizer_cls = optim.AdaBelief adabelief_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(adabelief_kwargs) elif args.customized_optim == OptimizerNames.ADABOUND: optimizer_cls = optim.AdaBound adabound_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(adabound_kwargs) elif args.customized_optim == OptimizerNames.LARS: optimizer_cls = optim.LARS lars_kwargs = { "momentum": (args.optim_momentum), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(lars_kwargs) elif args.customized_optim == OptimizerNames.LAMB: optimizer_cls = optim.Lamb lamb_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(lamb_kwargs) elif args.customized_optim == OptimizerNames.ADAMAX: optimizer_cls = optim.Adamax adamax_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(adamax_kwargs) elif args.customized_optim == OptimizerNames.NADAM: optimizer_cls = optim.NAdam nadam_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(nadam_kwargs) elif args.customized_optim == OptimizerNames.RADAM: optimizer_cls = optim.RAdam radam_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(radam_kwargs) elif args.customized_optim == OptimizerNames.ADAMP: optimizer_cls = optim.AdamP adamp_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(adamp_kwargs) elif args.customized_optim == OptimizerNames.SGDP: optimizer_cls = optim.SGDP sgdp_kwargs = { "momentum": (args.optim_momentum), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(sgdp_kwargs) elif args.customized_optim == OptimizerNames.YOGI: optimizer_cls = optim.Yogi yogi_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(yogi_kwargs) elif args.customized_optim == OptimizerNames.SOPHIA: optimizer_cls = optim.SophiaG sophia_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(sophia_kwargs) elif args.customized_optim == OptimizerNames.ADAM: optimizer_cls = optim.Adam adam_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), } optimizer_kwargs.update(adam_kwargs) elif args.customized_optim == OptimizerNames.NOVOGRAD: optimizer_cls = optim.NovoGrad novograd_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(novograd_kwargs) elif args.customized_optim == OptimizerNames.ADADELTA: optimizer_cls = optim.Adadelta adadelta_kwargs = {} optimizer_kwargs.update(adadelta_kwargs) elif args.customized_optim == OptimizerNames.ADAGRAD: optimizer_cls = optim.AdaGrad adagrad_kwargs = {} optimizer_kwargs.update(adagrad_kwargs) elif args.customized_optim == OptimizerNames.ADAMW_SCHEDULE_FREE: optimizer_cls = optim.AdamWScheduleFree adamw_schedule_free_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(adamw_schedule_free_kwargs) elif args.customized_optim == OptimizerNames.SGD_SCHEDULE_FREE: optimizer_cls = optim.SGDScheduleFree sgd_schedule_free_kwargs = { "momentum": (args.optim_momentum), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(sgd_schedule_free_kwargs) elif args.customized_optim == OptimizerNames.ADAN: optimizer_cls = optim.Adan adan_kwargs = { "betas": (args.optim_beta1, args.optim_beta2, args.optim_beta3), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(adan_kwargs) elif args.customized_optim == OptimizerNames.MUON: optimizer_cls = optim.Muon muon_kwargs = { "betas": (args.optim_beta1, args.optim_beta2), "weight_decay": (args.optim_weight_decay), } optimizer_kwargs.update(muon_kwargs) else: raise ValueError(f"Trainer cannot instantiate unsupported optimizer: {args.customized_optim}") return optimizer_cls, optimizer_kwargs def create_optimizer(self): opt_model = self.model_wrapped if is_sagemaker_mp_enabled() else self.model if self.optimizer is None: decay_parameters = self.get_decay_parameter_names(opt_model) optimizer_grouped_parameters = [ { "params": [ p for n, p in opt_model.named_parameters() if (n in decay_parameters and p.requires_grad) ], "weight_decay": self.args.weight_decay, }, { "params": [ p for n, p in opt_model.named_parameters() if (n not in decay_parameters and p.requires_grad) ], "weight_decay": 0.0, }, ] optimizer_cls, optimizer_kwargs = CustomizedOptimTrainer.get_optimizer_cls_and_kwargs( self.args, opt_model ) # Overwrite `params` in case it's created by # `get_optimizer_cls_and_kwargs` e.g. for GaLore optimizer. if "params" in optimizer_kwargs: optimizer_grouped_parameters = optimizer_kwargs.pop("params") # For layer-wise dummy optimizers we overwrite # optimizer_grouped_parameters with `optimizer_dict` to # avoid arguments conflicts. if "optimizer_dict" in optimizer_kwargs: optimizer_grouped_parameters = optimizer_kwargs.pop("optimizer_dict") self.optimizer = optimizer_cls(optimizer_grouped_parameters, **optimizer_kwargs) return CustomizedOptimTrainer ================================================ FILE: src/lmflow/optim/yogi.py ================================================ #!/usr/bin/env python import math import torch import torch.nn as nn from torch.optim.optimizer import Optimizer class Yogi(Optimizer): r"""Implements Yogi Optimizer Algorithm. It has been proposed in `Adaptive methods for Nonconvex Optimization`. https://papers.nips.cc/paper/8186-adaptive-methods-for-nonconvex-optimization # noqa Note: Reference code: https://github.com/4rtemi5/Yogi-Optimizer_Keras """ def __init__( self, params, lr: float = 1e-2, betas=(0.9, 0.999), eps: float = 1e-3, initial_accumulator: float = 1e-6, weight_decay: float = 0, ) -> None: if lr <= 0.0: raise ValueError("Invalid learning rate: {}".format(lr)) if eps < 0.0: raise ValueError("Invalid epsilon value: {}".format(eps)) if not 0.0 <= betas[0] < 1.0: raise ValueError("Invalid beta parameter at index 0: {}".format(betas[0])) if not 0.0 <= betas[1] < 1.0: raise ValueError("Invalid beta parameter at index 1: {}".format(betas[1])) if weight_decay < 0: raise ValueError("Invalid weight_decay value: {}".format(weight_decay)) defaults = dict( lr=lr, betas=betas, eps=eps, initial_accumulator=initial_accumulator, weight_decay=weight_decay, ) super().__init__(params, defaults) def step(self, closure=None): r"""Performs a single optimization step. Arguments: closure: A closure that reevaluates the model and returns the loss. """ loss = None if closure is not None: loss = closure() for group in self.param_groups: for p in group["params"]: if p.grad is None: continue grad = p.grad.data if grad.is_sparse: raise RuntimeError("Yogi does not support sparse gradients, please consider SparseAdam instead") state = self.state[p] # State initialization # Followed from official implementation in tensorflow addons: # https://github.com/tensorflow/addons/blob/master/tensorflow_addons/optimizers/yogi.py#L118 # noqa # For more details refer to the discussion: # https://github.com/jettify/pytorch-optimizer/issues/77 if len(state) == 0: state["step"] = 0 # Exponential moving average of gradient values state["exp_avg"] = nn.init.constant_( torch.empty_like(p.data, memory_format=torch.preserve_format), group["initial_accumulator"], ) # Exponential moving average of squared gradient values state["exp_avg_sq"] = nn.init.constant_( torch.empty_like(p.data, memory_format=torch.preserve_format), group["initial_accumulator"], ) exp_avg, exp_avg_sq = state["exp_avg"], state["exp_avg_sq"] beta1, beta2 = group["betas"] state["step"] += 1 bias_correction1 = 1 - beta1 ** state["step"] bias_correction2 = 1 - beta2 ** state["step"] if group["weight_decay"] != 0: grad = grad.add(p.data, alpha=group["weight_decay"]) # Decay the first and second moment running average coefficient exp_avg.mul_(beta1).add_(grad, alpha=1 - beta1) grad_squared = grad.mul(grad) exp_avg_sq.addcmul_( torch.sign(exp_avg_sq - grad_squared), grad_squared, value=-(1 - beta2), ) denom = (exp_avg_sq.sqrt() / math.sqrt(bias_correction2)).add_(group["eps"]) step_size = group["lr"] / bias_correction1 p.data.addcdiv_(exp_avg, denom, value=-step_size) return loss ================================================ FILE: src/lmflow/pipeline/__init__.py ================================================ ================================================ FILE: src/lmflow/pipeline/auto_pipeline.py ================================================ #!/usr/bin/env python """Return a pipeline automatically based on its name.""" from lmflow.pipeline.evaluator import Evaluator from lmflow.pipeline.finetuner import Finetuner from lmflow.pipeline.inferencer import Inferencer from lmflow.pipeline.rm_inferencer import RewardModelInferencer from lmflow.pipeline.rm_tuner import RewardModelTuner from lmflow.utils.versioning import is_package_version_at_least, is_ray_available, is_sglang_available, is_trl_available, is_vllm_available PIPELINE_MAPPING = { "evaluator": Evaluator, "finetuner": Finetuner, "inferencer": Inferencer, "rm_inferencer": RewardModelInferencer, "rm_tuner": RewardModelTuner, } PIPELINE_NEEDS_EXTRAS = [] if is_sglang_available(): from lmflow.pipeline.sglang_inferencer import SGLangInferencer PIPELINE_MAPPING["sglang_inferencer"] = SGLangInferencer else: PIPELINE_NEEDS_EXTRAS.append("sglang_inferencer") if not is_package_version_at_least("transformers", "4.35.0"): from lmflow.pipeline.raft_aligner import RaftAligner PIPELINE_MAPPING["raft_aligner"] = RaftAligner else: PIPELINE_NEEDS_EXTRAS.append("raft_aligner") if is_vllm_available(): from lmflow.pipeline.vllm_inferencer import VLLMInferencer PIPELINE_MAPPING["vllm_inferencer"] = VLLMInferencer else: PIPELINE_NEEDS_EXTRAS.append("vllm_inferencer") if is_trl_available(): from lmflow.pipeline.dpo_aligner import DPOAligner from lmflow.pipeline.dpov2_aligner import DPOv2Aligner PIPELINE_MAPPING["dpo_aligner"] = DPOAligner PIPELINE_MAPPING["dpov2_aligner"] = DPOv2Aligner else: PIPELINE_NEEDS_EXTRAS.extend(["dpo_aligner", "dpov2_aligner"]) if is_vllm_available() and is_trl_available() and is_ray_available(): from lmflow.pipeline.iterative_dpo_aligner import IterativeDPOAligner PIPELINE_MAPPING["iterative_dpo_aligner"] = IterativeDPOAligner else: PIPELINE_NEEDS_EXTRAS.append("iterative_dpo_aligner") class AutoPipeline: """ The class designed to return a pipeline automatically based on its name. """ @classmethod def get_pipeline(self, pipeline_name, model_args, data_args, pipeline_args, *args, **kwargs): if pipeline_name not in PIPELINE_MAPPING: if pipeline_name in PIPELINE_NEEDS_EXTRAS: raise NotImplementedError( f'Please install the necessary dependencies to use pipeline "{pipeline_name}"' ) raise NotImplementedError(f'Pipeline "{pipeline_name}" is not supported') pipeline = PIPELINE_MAPPING[pipeline_name](model_args, data_args, pipeline_args, *args, **kwargs) return pipeline ================================================ FILE: src/lmflow/pipeline/base_aligner.py ================================================ #!/usr/bin/env python """BaseTuner: a subclass of BasePipeline.""" from abc import abstractmethod from lmflow.pipeline.base_pipeline import BasePipeline class BaseAligner(BasePipeline): """A subclass of BasePipeline which is alignable.""" def __init__(self, *args, **kwargs): pass def _check_if_alignable(self, model, dataset, reward_model): # TODO: check if the model is alignable and dataset is compatible # TODO: add reward_model pass @abstractmethod def align(self, model, dataset, reward_model): raise NotImplementedError(".align is not implemented") ================================================ FILE: src/lmflow/pipeline/base_pipeline.py ================================================ #!/usr/bin/env python """BasePipeline.""" class BasePipeline: pass ================================================ FILE: src/lmflow/pipeline/base_tuner.py ================================================ #!/usr/bin/env python """BaseTuner: a subclass of BasePipeline.""" from abc import abstractmethod from lmflow.pipeline.base_pipeline import BasePipeline class BaseTuner(BasePipeline): """A subclass of BasePipeline which is tunable.""" def __init__(self, *args, **kwargs): pass def _check_if_tunable(self, model, dataset): # TODO: check if the model is tunable and dataset is compatible pass @abstractmethod def tune(self, model, dataset): raise NotImplementedError(".tune is not implemented") ================================================ FILE: src/lmflow/pipeline/dpo_aligner.py ================================================ #!/usr/bin/env python # @Time : 7/4/2024 21:12 # @Author : Yu Li # @Site : # @File : dpo_pipeline.py import os from pathlib import Path from typing import Optional from datasets import Dataset, load_dataset from peft import LoraConfig from transformers import TrainingArguments from lmflow.pipeline.base_aligner import BaseAligner from lmflow.utils.versioning import is_trl_available if is_trl_available(): from trl import DPOTrainer else: raise ImportError("Please install trl package to use dpo_aligner.py") def get_paired_dataset( data_root: str, data_dir: str, sanity_check: bool = False, cache_dir: Optional[str] = None, num_proc=24, ) -> Dataset: """Load dataset and convert it to the necessary format. The dataset is converted to a dictionary with the following structure: { 'prompt': list[str], 'chosen': list[str], 'rejected': list[str], } Prompts are structured as follows: "Question: " + + "\n\nAnswer: " """ data_path = Path(data_root) / data_dir data_files = [x.absolute().as_posix() for x in data_path.glob("*.json")] dataset = load_dataset( path=data_root, split="train", data_files=data_files, cache_dir=cache_dir, ) original_columns = dataset.column_names if sanity_check: dataset = dataset.select(range(min(len(dataset), 1000))) def return_prompt_and_responses(samples) -> dict[str, str]: return { "prompt": ["Question: " + question + "\n\nAnswer: " for question in samples["question"]], "chosen": samples["response_j"], "rejected": samples["response_k"], } return dataset.map( return_prompt_and_responses, batched=True, num_proc=num_proc, remove_columns=original_columns, ) class DPOAligner(BaseAligner): def __init__(self, model_args, data_args, aligner_args): self.model_args = model_args self.data_args = data_args self.aligner_args = aligner_args self.train_dataset = None self.eval_dataset = None def _initialize_trainer(self, model, tokenizer): peft_config = LoraConfig( r=self.model_args.lora_r, lora_alpha=self.model_args.lora_alpha, lora_dropout=self.model_args.lora_dropout, target_modules=[ "q_proj", "v_proj", "k_proj", "out_proj", "fc_in", "fc_out", "wte", ], bias="none", task_type="CAUSAL_LM", ) training_args = TrainingArguments( per_device_train_batch_size=self.aligner_args.per_device_train_batch_size, per_device_eval_batch_size=self.aligner_args.per_device_eval_batch_size, max_steps=self.aligner_args.max_steps, logging_steps=self.aligner_args.logging_steps, save_steps=self.aligner_args.save_steps, gradient_accumulation_steps=self.aligner_args.gradient_accumulation_steps, gradient_checkpointing=self.aligner_args.gradient_checkpointing, learning_rate=self.aligner_args.learning_rate, evaluation_strategy="steps", eval_steps=self.aligner_args.eval_steps, output_dir=self.aligner_args.output_dir, report_to=self.aligner_args.report_to, lr_scheduler_type=self.aligner_args.lr_scheduler_type, warmup_steps=self.aligner_args.warmup_steps, optim=self.aligner_args.optimizer_type, bf16=True, remove_unused_columns=False, run_name=self.aligner_args.run_name, ddp_find_unused_parameters=False, # gradient_checkpointing_kwargs=dict(use_reentrant=self.aligner_args.gradient_checkpointing_use_reentrant), seed=self.aligner_args.seed, ) dpo_trainer = DPOTrainer( model, ref_model=None, args=training_args, beta=self.aligner_args.beta, train_dataset=self.train_dataset, eval_dataset=self.eval_dataset if self.eval_dataset else None, tokenizer=tokenizer, peft_config=peft_config, max_prompt_length=self.aligner_args.beta, max_length=self.aligner_args.max_length, ) return dpo_trainer def _load_dataset(self): # load training set self.train_dataset = get_paired_dataset( data_root=self.data_args.dataset_path, data_dir="train", sanity_check=self.aligner_args.sanity_check ) self.train_dataset = self.train_dataset.filter( lambda x: len(x["prompt"]) + len(x["chosen"]) <= self.aligner_args.max_length and len(x["prompt"]) + len(x["rejected"]) <= self.aligner_args.max_length ) # load evaluation set if self.aligner_args.eval_dataset_path: self.eval_dataset = get_paired_dataset( data_root=self.aligner_args.eval_dataset_path, data_dir="test", sanity_check=True ) self.eval_dataset = self.eval_dataset.filter( lambda x: len(x["prompt"]) + len(x["chosen"]) <= self.aligner_args.max_length and len(x["prompt"]) + len(x["rejected"]) <= self.aligner_args.max_length ) def align(self, model, dataset, reward_model): tokenizer = model.get_tokenizer() tokenizer.pad_token = tokenizer.eos_token tokenizer.pad_token_id = tokenizer.eos_token_id self._load_dataset() model = model.get_backend_model() dpo_trainer = self._initialize_trainer(model, tokenizer) dpo_trainer.train() dpo_trainer.save_model(self.aligner_args.output_dir) # 7. save output_dir = os.path.join(self.aligner_args.output_dir, "final_checkpoint") dpo_trainer.model.save_pretrained(output_dir) ================================================ FILE: src/lmflow/pipeline/dpov2_aligner.py ================================================ import copy import importlib.resources as pkg_resources import logging import os import subprocess import sys from typing import Union import numpy as np import torch from tqdm import tqdm from transformers import TrainingArguments from lmflow.args import DatasetArguments, DPOv2AlignerArguments, ModelArguments from lmflow.datasets.dataset import KEY_INSTANCES, KEY_SCORE, KEY_TYPE, Dataset from lmflow.models.hf_decoder_model import HFDecoderModel from lmflow.pipeline.base_aligner import BaseAligner from lmflow.pipeline.utils.dpov2_trainer import DPOv2Trainer from lmflow.utils.common import add_dataclass_attr_prefix, create_copied_dataclass, make_shell_args_from_dataclass from lmflow.utils.constants import MEMORY_SAFE_DPOV2_ALIGN_ENV_VAR_TO_REMOVE logger = logging.getLogger(__name__) ReferenceModelArguments = create_copied_dataclass( original_dataclass=ModelArguments, field_prefix="reference_", class_prefix="Reference" ) class DPOv2Aligner(BaseAligner): def __init__( self, model_args: ModelArguments, data_args: DatasetArguments, aligner_args: DPOv2AlignerArguments, ref_model_args: ModelArguments, ): self.model_args = model_args self.ref_model_args = ref_model_args self.data_args = data_args self.aligner_args = aligner_args def align( self, model: HFDecoderModel, ref_model: HFDecoderModel, train_dataset: Dataset, eval_dataset: Dataset, transform_dataset_in_place: bool = True, ): if (train_dataset.get_type() not in ["text_to_scored_textlist", "paired_text_to_text"]) or ( eval_dataset.get_type() not in ["text_to_scored_textlist", "paired_text_to_text"] ): raise ValueError(f"Unsupported dataset type {train_dataset.get_type()} for DPOv2 aligner.") # step 0. setting up if self.aligner_args.gradient_checkpointing: logger.warning("Setting backend_model.config.use_cache to False since using gradient checkpointing") model.get_backend_model().config.use_cache = False ref_model.get_backend_model().config.use_cache = False # step 1. prepare datasets if train_dataset.get_type() == "text_to_scored_textlist": train_dataset = self.convert_to_paired_dataset( source_dataset=train_dataset, sampling_paired_method=self.aligner_args.sampling_paired_method, length_penalty=self.aligner_args.length_penalty, margin_scale=self.aligner_args.margin_scale, use_fast=False, ) if self.data_args.max_train_samples: train_dataset.backend_dataset = train_dataset.backend_dataset.select( range(self.data_args.max_train_samples) ) if eval_dataset.get_type() == "text_to_scored_textlist": eval_dataset = self.convert_to_paired_dataset( source_dataset=eval_dataset, sampling_paired_method=self.aligner_args.sampling_paired_method, margin_scale=self.aligner_args.margin_scale, use_fast=False, ) # step 2. prepare trainer dpo_trainer = DPOv2Trainer( model.get_backend_model(), ref_model.get_backend_model(), train_dataset=train_dataset.get_backend_dataset(), # tokenization is done in the trainer eval_dataset=eval_dataset.get_backend_dataset(), tokenizer=model.tokenizer, args=self.__prepare_training_args(self.aligner_args), beta=self.aligner_args.beta, loss_type=self.aligner_args.loss_type, max_prompt_length=self.aligner_args.max_prompt_length, max_length=self.aligner_args.max_length, mask_prompt=self.aligner_args.mask_prompt, len_penalty=self.aligner_args.length_penalty, ) # will trigger TypeError: cannot pickle 'torch._C._distributed_c10d.ProcessGroup' object # if we use preprocessing_num_workers # step 3. train dpo_trainer.train() dpo_trainer.save_model(self.aligner_args.output_dir) # step 4. save output_dir = os.path.join(self.aligner_args.output_dir, "final_checkpoint") dpo_trainer.model.save_pretrained(output_dir) # step 5. release resources with torch.no_grad(): torch.cuda.empty_cache() def __prepare_training_args( self, args: DPOv2AlignerArguments, ) -> TrainingArguments: training_args = TrainingArguments( per_device_train_batch_size=args.per_device_train_batch_size, per_device_eval_batch_size=args.per_device_eval_batch_size, num_train_epochs=args.num_train_epochs, save_strategy=args.save_strategy, logging_steps=args.logging_steps, save_steps=args.save_steps, gradient_accumulation_steps=args.gradient_accumulation_steps, gradient_checkpointing=args.gradient_checkpointing, learning_rate=args.learning_rate, evaluation_strategy=args.evaluation_strategy, eval_steps=args.eval_steps, output_dir=args.output_dir, lr_scheduler_type=args.lr_scheduler_type, warmup_steps=args.warmup_steps, optim=args.optim, bf16=args.bf16, report_to=args.report_to, run_name=args.run_name, remove_unused_columns=False, # DO NOT CHANGE THIS, may cause error https://discuss.huggingface.co/t/indexerror-invalid-key-16-is-out-of-bounds-for-size-0/14298/3 ) logger.debug(f"Actual training arguments for dpo trainer: {training_args}") return training_args def convert_to_paired_dataset( self, source_dataset: Dataset, sampling_paired_method: str = "random", length_penalty: float = 0.0, margin_scale: float = 1.0, use_fast: bool = False, ) -> Dataset: """Convert a scored one to multiple (text_to_scored_textlist) to a paired dataset by rejection sampling.""" output_dict = {KEY_INSTANCES: []} if source_dataset.get_type() in ["text_to_scored_textlist"]: output_dict[KEY_TYPE] = "paired_text_to_text" for sample in tqdm(source_dataset.get_backend_dataset(), desc="Converting to paired dataset"): sample_output_dict = {} lengths = self._calc_response_lengths(sample["output"], source_dataset.get_type()) penalized_rewards = self._calc_reward_with_length_penalty( rewards=[content[KEY_SCORE] for content in sample["output"]], lengths=lengths, length_penalty=length_penalty, ) chosen_idx, rejected_idx = self.sampling_paired_idx_from_rewards( rewards=penalized_rewards, sampling_paired_method=sampling_paired_method, use_fast=use_fast ) sample_output_dict["prompt"] = sample["input"] sample_output_dict["chosen"] = sample["output"][chosen_idx]["text"] sample_output_dict["rejected"] = sample["output"][rejected_idx]["text"] sample_output_dict["margin"] = ( sample["output"][chosen_idx][KEY_SCORE] - sample["output"][rejected_idx][KEY_SCORE] ) * margin_scale output_dict[KEY_INSTANCES].append(sample_output_dict) output_dataset_args = copy.deepcopy(source_dataset.data_args) output_dataset_args.dataset_path = None output_dataset_args.dataset_name = f"paired_{output_dataset_args.dataset_name}" output_dataset = Dataset(output_dataset_args) output_dataset = output_dataset.from_dict(output_dict) return output_dataset def _calc_response_lengths( self, outputs: list[Union[str, dict[str, str]]], dataset_type: str, ) -> list[int]: all_lengths = [] if dataset_type == "text_to_scored_textlist": all_lengths = [len(output["text"]) for output in outputs] else: raise NotImplementedError(f"Unknown dataset type {dataset_type} when calculating the response length.") return all_lengths def _calc_reward_with_length_penalty( self, rewards: list[float], lengths: list[int], length_penalty: float, ) -> list[float]: """When length_penalty > 0, penalize the longer sequence by subtracting length_penalty * length from the reward. Vice versa when length_penalty < 0. """ assert len(rewards) == len(lengths), "The number of rewards and lengths should be the same." return [reward - length_penalty * length for reward, length in zip(rewards, lengths)] def sampling_paired_idx_from_rewards( self, rewards: list[float], sampling_paired_method: str = "random", use_fast: bool = False, ) -> tuple[int, int]: """Prepare the dataset for DPO training by rejection sampling. We implement different strategies to select pairs, including random: randomly select two instances max_min: best v.s. worst max_max: best v.s. second best max_random: best v.s. random from the remaining """ if use_fast: return self._sampling_paired_idx_from_rewards_fast(rewards, sampling_paired_method) else: return self._sampling_paired_idx_from_rewards(rewards, sampling_paired_method) def _sampling_paired_idx_from_rewards( self, rewards: list[float], sampling_paired_method: str = "random" ) -> tuple[int, int]: idx_0, idx_1 = -1, -1 if sampling_paired_method == "random": idx_0, idx_1 = np.random.choice(len(rewards), size=2, replace=False) elif sampling_paired_method == "max_min": idx_0, idx_1 = np.argmax(rewards), np.argmin(rewards) elif sampling_paired_method == "max_max": sorted_indices = np.argsort(rewards) idx_0, idx_1 = sorted_indices[-1], sorted_indices[-2] elif sampling_paired_method == "max_random": idx_0 = np.argmax(rewards) idx_1 = np.random.choice([i for i in range(len(rewards)) if i != idx_0]) else: raise ValueError(f"Unknown sampling method: {sampling_paired_method}") chosen_idx, rejected_idx = (idx_0, idx_1) if rewards[idx_0] > rewards[idx_1] else (idx_1, idx_0) return chosen_idx, rejected_idx def _sampling_paired_idx_from_rewards_fast( self, rewards: list[float], sampling_paired_method: str = "random" ) -> tuple[int, int]: idx_0, idx_1 = -1, -1 if sampling_paired_method == "random": idx_0, idx_1 = 0, 1 elif sampling_paired_method == "max_min": idx_0, idx_1 = np.argmax(rewards), np.argmin(rewards) elif sampling_paired_method == "max_max": sorted_indices = np.argsort(rewards) idx_0, idx_1 = sorted_indices[-1], sorted_indices[-2] elif sampling_paired_method == "max_random": idx_0 = np.argmax(rewards) idx_1 = 0 if idx_0 != 0 else 1 else: raise ValueError(f"Unknown sampling method: {sampling_paired_method}") chosen_idx, rejected_idx = (idx_0, idx_1) if rewards[idx_0] > rewards[idx_1] else (idx_1, idx_0) return chosen_idx, rejected_idx class MemorySafeDPOv2Aligner: def __init__( self, model_args: ModelArguments, data_args: DatasetArguments, aligner_args: DPOv2AlignerArguments, ref_model_args: ModelArguments, ): self.model_args = model_args self.ref_model_args = ReferenceModelArguments(**add_dataclass_attr_prefix(ref_model_args, "reference_")) self.data_args = data_args self.aligner_args = aligner_args self.aligner_file_path = pkg_resources.files("lmflow.pipeline.utils") / "memory_safe_dpov2_align.py" def align(self): aligner_args = make_shell_args_from_dataclass( dataclass_objects=[self.model_args, self.data_args, self.aligner_args, self.ref_model_args], format="shell", ignored_args_list=["accelerator_config", "fsdp_config", "_n_gpu"], ) cmd = ( f"accelerate launch --config_file {self.aligner_args.accelerate_config_file}" + " " + str(self.aligner_file_path) + " " + aligner_args ) current_env = os.environ.copy() for var in MEMORY_SAFE_DPOV2_ALIGN_ENV_VAR_TO_REMOVE: current_env.pop(var, None) cli_res = subprocess.run( args=cmd, stdout=sys.stdout, stderr=sys.stdout, shell=True, preexec_fn=os.setsid, env=current_env, ) logger.info(f"MemorySafeDPOv2Aligner subprocess run finished, info at finish: {cli_res}") if cli_res.returncode != 0: print(cli_res.stderr) raise RuntimeError(f"Error during MemorySafeDPOv2Aligner: {cli_res}") ================================================ FILE: src/lmflow/pipeline/evaluator.py ================================================ """ The Evaluator class simplifies the process of running evaluation on a language model provided by a HFDecoderModel instance imported from the lmflow package. The class constructor takes three dictionaries as arguments: model_args containing arguments related to the language model, data_args containing arguments related to the data used for evaluation, and evaluator_args containing other arguments for the evaluation process. The class has two methods: create_dataloader() that loads the data from the test file, creates a data loader, and returns it with the size of the data, and evaluate(model) that generates output text given input text. It uses the create_dataloader() method to load the data, iterates over the data in mini-batches, and encodes the input text with the encode() method of the HFDecoderModel class. Then, it generates output text using the evaluate() method of the HFDecoderModel class, decodes the generated output text using the decode() method of the HFDecoderModel class, and writes the output to a file in the output directory. The method also logs some information to the console and Weights and Biases if the use_wandb argument is True. """ import datetime import json import os import numpy as np import torch import torch.distributed as dist import wandb # TODO: remove later from accelerate import Accelerator from transformers import AutoConfig from lmflow.args import DatasetArguments, EvaluatorArguments, ModelArguments from lmflow.datasets.dataset import Dataset from lmflow.pipeline.base_pipeline import BasePipeline from lmflow.utils.data_utils import answer_extraction, batchlize, set_random_seed from lmflow.utils.envs import is_accelerate_env from lmflow.utils.versioning import is_deepspeed_available os.environ["TOKENIZERS_PARALLELISM"] = "false" # To avoid warnings about parallelism in tokenizers class Evaluator(BasePipeline): """ Initializes the `Evaluator` class with given arguments. Parameters ------------ model_args : ModelArguments object. Contains the arguments required to load the model. data_args : DatasetArguments object. Contains the arguments required to load the dataset. evaluator_args : EvaluatorArguments object. Contains the arguments required to perform evaluation. """ def __init__( self, model_args: ModelArguments, data_args: DatasetArguments, evaluator_args: EvaluatorArguments, ): # our method self.data_args = data_args self.evaluator_args = evaluator_args self.model_args = model_args # logger if self.evaluator_args.use_wandb: wandb.init(project="lmflow_evaluation") # random seed set_random_seed(self.evaluator_args.random_seed) self.local_rank = int(os.getenv("LOCAL_RANK", "0")) self.world_size = int(os.getenv("WORLD_SIZE", "1")) torch.cuda.set_device(self.local_rank) # NOTE: cpu-only machine will have error if is_accelerate_env(): self.accelerator = Accelerator() self.accelerator.wait_for_everyone() else: if is_deepspeed_available(): import deepspeed else: raise ImportError('Deepspeed is not available, please install using `pip install -e ".[deepspeed]"`') deepspeed.init_distributed() self.config = AutoConfig.from_pretrained(model_args.model_name_or_path) try: self.model_hidden_size = self.config.hidden_size except Exception: print("Error in setting hidden size, use the default size 1024") self.model_hidden_size = 1024 # gpt2 seems do not have hidden_size in config print(f"model_hidden_size = {self.model_hidden_size}") # batch size has to be divisible by world_size, but can be bigger than world_size train_batch_size = self.evaluator_args.inference_batch_size_per_device * self.world_size self.evaluator_args.minibatch_size = train_batch_size self.block_size = evaluator_args.evaluate_block_size # dataloader, data_size = create_dataloader(args) # load dataset def create_dataloader(self, dataset: Dataset): data_dict = dataset.to_dict() inputs = [instance["input"] for instance in data_dict["instances"]] outputs = [instance["output"] for instance in data_dict["instances"]] dataset_size = len(outputs) dataset_buf = [] for idx in range(dataset_size): dataset_buf.append({"input": inputs[idx], "output": outputs[idx], "input_idx": idx}) dataloader = batchlize(dataset_buf, self.evaluator_args.minibatch_size, self.evaluator_args.random_shuffle) print( f"Successfully create dataloader with size {len(dataloader)}, " f"batch_size {self.evaluator_args.minibatch_size}." ) return dataloader, dataset_size # TODO: Split for better unittest def _match(self, predicted_answer, groundtruth, answer_type=None): case_insensitive_types = [ "strategyqa", "coin_flip", "pubmedqa", "binary_choice", "medmcqa", "usmle", ] if answer_type in case_insensitive_types: return predicted_answer.lower() == groundtruth.lower() else: return predicted_answer == groundtruth return False def evaluate( self, model, dataset: Dataset, metric="accuracy", verbose=True, ): """ Perform Evaluation for a model Parameters ------------ model : TunableModel object. TunableModel to perform inference dataset : Dataset object. """ if metric in ["acc", "accuracy"]: if is_accelerate_env(): acc = self._evaluate_acc_with_accelerate(model, dataset, verbose=verbose) else: acc = self._evaluate_acc_with_deepspeed(model, dataset, verbose=verbose) print(f"Evaluating final accuracy: {acc}") return acc elif metric in ["ppl", "perplexity"]: ppl = self._evaluate_ppl(model, dataset, verbose=verbose) print(f"Evaluating final perplexity: {ppl}") return ppl elif metric in ["nll", "neg_log_likelihood"]: nll = self._evaluate_nll(model, dataset, verbose=verbose) print(f"Evaluating final negative log likelihood: {nll}") return nll else: raise NotImplementedError(f"metric {metric} is not supported") def _evaluate_acc_with_accelerate(self, model, dataset, verbose=True): dataloader, data_size = self.create_dataloader(dataset) if self.accelerator.is_local_main_process: if not os.path.exists(self.evaluator_args.output_dir): os.makedirs(self.evaluator_args.output_dir) output_writer = open(f"{self.evaluator_args.output_dir}/evaluation.json", "w") correct_number_list = [] for batch_index, batch in enumerate(dataloader): if batch_index * self.world_size >= self.data_args.max_eval_samples: break if self.local_rank * self.evaluator_args.inference_batch_size_per_device >= len(batch): current_batch = batch[: self.evaluator_args.inference_batch_size_per_device] else: current_batch = batch[ self.local_rank * self.evaluator_args.inference_batch_size_per_device : (self.local_rank + 1) * self.evaluator_args.inference_batch_size_per_device ] prompt_structure = self.evaluator_args.prompt_structure input = [prompt_structure.format(input=i["input"]) for i in current_batch] output = [i["output"] for i in current_batch] batch_input = model.encode(input, return_tensors="pt", padding=True).to(self.accelerator.device) inputs = batch_input["input_ids"] mask = batch_input["attention_mask"] with self.accelerator.autocast(): outputs = model.inference( inputs, max_new_tokens=self.evaluator_args.max_new_tokens, attention_mask=mask, temperature=self.evaluator_args.temperature, repetition_penalty=self.evaluator_args.repetition_penalty, ) text_out = model.decode(outputs, skip_special_tokens=True) decoded_input = model.decode( inputs, skip_special_tokens=True, ) prompt_length = [len(i) for i in decoded_input] text_out = [text_out[i][prompt_length[i] :] for i in range(len(text_out))] answer_type = self.evaluator_args.answer_type pred_answer = [] for i in text_out: pred_answer.append( answer_extraction( i, answer_type=answer_type, ) ) if verbose: print( f"batch_index{batch_index} rank{self.local_rank}:\n question={input}\n prediction={text_out}\n" ) print(f"predicted answer: {pred_answer} \n") print(f"groundtruth answer: {output} \n") if self.local_rank * self.evaluator_args.inference_batch_size_per_device >= len(batch): correct_ = 0 else: correct_ = 0 for i in range(len(pred_answer)): if self._match(pred_answer[i], output[i], answer_type): correct_ += 1 # collect accuracy from all gpus all_process = torch.tensor([correct_], dtype=torch.float32, device=self.local_rank) all_process = self.accelerator.gather(all_process) correct_ = sum(all_process.tolist()) correct_number_list.append(correct_) # collect predictions from all gpus output_dict = {"question": input, "prediction": text_out, "pred_answer": pred_answer, "answer": output} if self.world_size > 1: all_process_list = [{}] * self.world_size dist.gather_object(output_dict, all_process_list if dist.get_rank() == 0 else None, dst=0) else: all_process_list = [output_dict] if self.accelerator.is_local_main_process: current_total = ( (batch_index + 1) * self.world_size * self.evaluator_args.inference_batch_size_per_device ) current_accuracy = ( np.sum(correct_number_list) / current_total if int(current_total) < data_size else np.sum(correct_number_list) / data_size ) print( datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), f"{int(current_total) if int(current_total) < data_size else data_size} / {data_size} finished, " f"# correct = {np.sum(correct_number_list)}, current accuracy = {current_accuracy}", ) if self.evaluator_args.use_wandb: wandb.log({"Accuracy": current_accuracy}) for index, output in enumerate(all_process_list): output_json = json.dumps(output) output_writer.write(output_json + "\n") if self.accelerator.is_local_main_process: current_accuracy = np.sum(correct_number_list) / data_size print( f"# Correct = {np.sum(correct_number_list)}, # Total = {data_size}, Final accuracy = ", current_accuracy ) output_writer.close() return np.sum(correct_number_list) / data_size def _evaluate_acc_with_deepspeed(self, model, dataset, verbose=True): dataloader, data_size = self.create_dataloader(dataset) if not dist.is_initialized() or dist.get_rank() == 0: if not os.path.exists(self.evaluator_args.output_dir): os.makedirs(self.evaluator_args.output_dir) output_writer = open(f"{self.evaluator_args.output_dir}/evaluation.json", "w") correct_number_list = [] for batch_index, batch in enumerate(dataloader): if batch_index * self.world_size >= self.data_args.max_eval_samples: break if self.local_rank * self.evaluator_args.inference_batch_size_per_device >= len(batch): current_batch = batch[: self.evaluator_args.inference_batch_size_per_device] else: current_batch = batch[ self.local_rank * self.evaluator_args.inference_batch_size_per_device : (self.local_rank + 1) * self.evaluator_args.inference_batch_size_per_device ] prompt_structure = self.evaluator_args.prompt_structure input = [prompt_structure.format(input=i["input"]) for i in current_batch] output = [i["output"] for i in current_batch] batch_input = model.encode(input, return_tensors="pt", padding=True).to(device=self.local_rank) inputs = batch_input["input_ids"] mask = batch_input["attention_mask"] outputs = model.inference( inputs, max_new_tokens=self.evaluator_args.max_new_tokens, attention_mask=mask, temperature=self.evaluator_args.temperature, repetition_penalty=self.evaluator_args.repetition_penalty, ) text_out = model.decode(outputs, skip_special_tokens=True) # # only return the generation, trucating the input decoded_input = model.decode( inputs, skip_special_tokens=True, ) prompt_length = [len(i) for i in decoded_input] text_out = [text_out[i][prompt_length[i] :] for i in range(len(text_out))] answer_type = self.evaluator_args.answer_type pred_answer = [] for i in text_out: pred_answer.append( answer_extraction( i, answer_type=answer_type, ) ) if verbose: print( f"batch_index{batch_index} rank{self.local_rank}:\n question={input}\n prediction={text_out}\n" ) print(f"predicted answer: {pred_answer} \n") print(f"groundtruth answer: {output} \n") if self.local_rank * self.evaluator_args.inference_batch_size_per_device >= len(batch): correct_ = 0 else: correct_ = 0 for i in range(len(pred_answer)): if self._match(pred_answer[i], output[i], answer_type): correct_ += 1 # collect accuracy from all gpus all_process = torch.tensor([correct_], dtype=torch.float32, device=self.local_rank) dist.all_reduce(all_process, dist.ReduceOp.SUM, async_op=False) correct_ = all_process.tolist() correct_number_list.append(correct_) # collect predictions from all gpus output_dict = {"question": input, "prediction": text_out, "pred_answer": pred_answer, "answer": output} all_process_list = [{}] * self.world_size dist.gather_object(output_dict, all_process_list if dist.get_rank() == 0 else None, dst=0) if not dist.is_initialized() or dist.get_rank() == 0: current_total = ( (batch_index + 1) * self.world_size * self.evaluator_args.inference_batch_size_per_device ) current_accuracy = ( np.sum(correct_number_list) / current_total if int(current_total) < data_size else np.sum(correct_number_list) / data_size ) print( datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), f"{int(current_total) if int(current_total) < data_size else data_size} / {data_size} finished, " f"# correct = {np.sum(correct_number_list)}, current accuracy = {current_accuracy}", ) if self.evaluator_args.use_wandb: wandb.log({"Accuracy": current_accuracy}) for index, output in enumerate(all_process_list): output_json = json.dumps(output) output_writer.write(output_json + "\n") if not dist.is_initialized() or dist.get_rank() == 0: current_accuracy = np.sum(correct_number_list) / data_size print( f"# Correct = {np.sum(correct_number_list)}, # Total = {data_size}, Final accuracy = ", current_accuracy ) output_writer.close() return np.sum(correct_number_list) / data_size def _evaluate_ppl(self, model, dataset: Dataset, verbose=True): data_dict = dataset.to_dict() if data_dict["type"] == "text2text": raise NotImplementedError( "ppl evaluation is currently not supported for text2text dataset, please use text_only dataset." ) texts = [instance["text"] for instance in data_dict["instances"]] encodings = model.get_tokenizer()("\n\n".join(texts), return_tensors="pt") # Define some constant if self.model_args.truncate_to_model_max_length: try: max_length = min(model.get_backend_model().config.n_positions, model.get_max_length()) except Exception: max_length = min(1024, model.get_max_length()) else: max_length = self.block_size if verbose: print(f"The maximum sequence length : {max_length}") seq_len = encodings.input_ids.size(1) nlls = [] prev_end_loc = 0 for begin_loc in range(0, seq_len, self.block_size): end_loc = min(begin_loc + max_length, seq_len) trg_len = end_loc - prev_end_loc # may be different from block_size on last loop input_ids = encodings.input_ids[:, begin_loc:end_loc].to(device=self.local_rank) target_ids = input_ids.clone() target_ids[:, :-trg_len] = -100 with torch.no_grad(): outputs = model.get_backend_model()(input_ids, labels=target_ids) # loss is calculated using CrossEntropyLoss which averages over valid labels # N.B. the model only calculates loss over trg_len - 1 labels, because it internally shifts the labels # to the left by 1. neg_log_likelihood = outputs.loss nlls.append(neg_log_likelihood) prev_end_loc = end_loc if verbose: print( f"Evaluating PPL: {int(begin_loc / self.block_size) + 1} / {int(seq_len / self.block_size)} " f"complete, current ppl : {torch.exp(torch.stack(nlls).mean())}" ) if end_loc == seq_len: break ppl = torch.exp(torch.stack(nlls).mean()) return ppl def _evaluate_nll( self, model, dataset: Dataset, verbose=True, ): """ Evaluates negative log likelihood of the model over a dataset. NLL = -1/N sum_{i=1}^N sum_{j=1}^|w_i| ln(p(w_{i,j}|context_window)), where N is the number of data samples, w_{i,j} is the j-th token in i-th sample. Here "context_window" = p(w_{i,start}, w_{i,start+1}, ..., p_{i,j-1} with start = max(0, j - window_length + 1). "window_length" is normally the maximum length accepted by the model. Returns: A float which represents the negative log likelihood. """ data_dict = dataset.to_dict() # Handles prompt structure if dataset.get_type() == "text2text": prompt = self.evaluator_args.prompt_structure data_dict["instances"] = [ {"input": prompt.format(input=instance["input"]), "output": instance["output"]} for instance in data_dict["instances"] ] dataset = dataset.from_dict(data_dict) tokenized_dataset = model.tokenize(dataset, add_special_tokens=False) tokenized_dataset = tokenized_dataset.get_backend_dataset() encoding_list = [ { "input_ids": torch.tensor([input_ids]), "labels": torch.tensor([labels]), } for input_ids, labels in zip(tokenized_dataset["input_ids"], tokenized_dataset["labels"]) ] # Gets context window length try: max_length = min(model.get_backend_model().config.n_positions, model.get_max_length()) except Exception: max_length = min(1024, model.get_max_length()) nlls = [] full_nlls = [] num_samples = len(encoding_list) for sample_idx, encodings in enumerate(encoding_list): seq_len = encodings["input_ids"].size(1) prev_end_loc = 0 for begin_loc in range(0, seq_len, self.block_size): end_loc = min(begin_loc + max_length, seq_len) # may be different from block_size on last loop trg_len = end_loc - prev_end_loc input_ids = encodings["input_ids"][:, begin_loc:end_loc] input_ids = input_ids.to(device=self.local_rank) labels = encodings["labels"][:, begin_loc:end_loc] target_ids = labels.clone() full_target_ids = input_ids.clone() def get_nll(label_ids, nll_list, input_ids, trg_len): label_ids[:, :-trg_len] = -100 label_ids = label_ids.to(device=self.local_rank) # Valid labels are from 0 to `vocab_size` num_valid_labels = torch.count_nonzero(label_ids >= 0) if label_ids[0, 0] != -100: num_valid_labels -= 1 if not torch.all(label_ids == -100): with torch.no_grad(): outputs = model.get_backend_model()(input_ids, labels=label_ids) # loss is calculated using CrossEntropyLoss which # sums over valid labels N.B. the model only # calculates loss over trg_len - 1 labels, because # it internally shifts the labels to the left by 1. neg_log_likelihood = outputs.loss * num_valid_labels else: neg_log_likelihood = torch.zeros([]).to(device=self.local_rank) nll_list.append(neg_log_likelihood) get_nll(target_ids, nlls, input_ids, trg_len) get_nll(full_target_ids, full_nlls, input_ids, trg_len) current_output_nll = torch.stack(nlls).sum() / (sample_idx + 1) current_full_nll = torch.stack(full_nlls).sum() / (sample_idx + 1) prev_end_loc = end_loc if verbose: if dataset.get_type() == "text_only": print( f"Evaluating negative log likelihood:" f" {sample_idx + 1} / {num_samples} Complete," f" current nll: {current_full_nll}" ) elif dataset.get_type() == "text2text": print( f"Evaluating negative log likelihood:" f" {sample_idx + 1} / {num_samples} Complete," f" current full nll / input nll / output nll:" f" {current_full_nll} /" f" {current_full_nll - current_output_nll} /" f" {current_output_nll}" ) else: raise NotImplementedError("f{dataset.get_type()} typed datasets are not supported") if end_loc == seq_len: break mean_nll = torch.stack(nlls).sum() / num_samples return mean_nll ================================================ FILE: src/lmflow/pipeline/finetuner.py ================================================ #!/usr/bin/env python import copy import logging import os import sys from copy import deepcopy from itertools import chain from typing import Union import datasets import evaluate import torch import transformers from transformers import ( Trainer, default_data_collator, set_seed, ) from transformers.trainer_utils import get_last_checkpoint try: from transformers.utils import send_example_telemetry except ImportError: send_example_telemetry = None from lmflow.args import DatasetArguments, FinetunerArguments, ModelArguments from lmflow.datasets.dataset import Dataset from lmflow.models.hf_decoder_model import HFDecoderModel # from lmflow.models.hf_encoder_decoder_model import HFEncoderDecoderModel from lmflow.models.hf_text_regression_model import HFTextRegressionModel from lmflow.optim import create_customized_optimizer from lmflow.pipeline.base_tuner import BaseTuner from lmflow.pipeline.utils.lisa_trainer import DynamicLayerActivationCallback from lmflow.utils.versioning import is_package_version_at_least logger = logging.getLogger(__name__) class Finetuner(BaseTuner): """ Initializes the `Finetuner` class with given arguments. Parameters ------------ model_args : ModelArguments object. Contains the arguments required to load the model. data_args : DatasetArguments object. Contains the arguments required to load the dataset. finetuner_args : FinetunerArguments object. Contains the arguments required to perform finetuning. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. """ def __init__( self, model_args: ModelArguments, data_args: DatasetArguments, finetuner_args: FinetunerArguments, *args, **kwargs, ): self.model_args = model_args self.data_args = data_args self.finetuner_args = finetuner_args # Sending telemetry. Tracking the example usage helps us better # allocate resources to maintain them. The information sent is the one # passed as arguments along with your Python/PyTorch versions. if send_example_telemetry is not None: send_example_telemetry("run_clm", model_args, data_args) # Setup logging logging.basicConfig( format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%m/%d/%Y %H:%M:%S", handlers=[logging.StreamHandler(sys.stdout)], ) log_level = finetuner_args.get_process_log_level() logger.setLevel(log_level) datasets.utils.logging.set_verbosity(log_level) transformers.utils.logging.set_verbosity(log_level) transformers.utils.logging.enable_default_handler() transformers.utils.logging.enable_explicit_format() # Log on each process the small summary: logger.warning( f"Process rank: {finetuner_args.local_rank}," f" device: {finetuner_args.device}," f" n_gpu: {finetuner_args.n_gpu}," f"distributed training: {bool(finetuner_args.local_rank != -1)}," f" 16-bits training: {finetuner_args.fp16}" ) logger.info(f"Training/evaluation parameters {finetuner_args}") # Detecting last checkpoint. last_checkpoint = None if ( os.path.isdir(finetuner_args.output_dir) and finetuner_args.do_train and not finetuner_args.overwrite_output_dir ): last_checkpoint = get_last_checkpoint(finetuner_args.output_dir) if last_checkpoint is None and len(os.listdir(finetuner_args.output_dir)) > 0: raise ValueError( f"Output directory ({finetuner_args.output_dir}) already" " exists and is not empty. " "Use --overwrite_output_dir to overcome." ) elif last_checkpoint is not None and finetuner_args.resume_from_checkpoint is None: logger.info( f"Checkpoint detected, resuming training at" f" {last_checkpoint}. To avoid this behavior, change" " the `--output_dir` or add `--overwrite_output_dir` to" " train from scratch." ) self.last_checkpoint = last_checkpoint # Set seed before initializing model. set_seed(finetuner_args.seed) def group_text(self, tokenized_datasets, model_max_length): """ Groups texts together to form blocks of maximum length `model_max_length` and returns the processed data as a dictionary. """ data_args = self.data_args finetuner_args = self.finetuner_args if data_args.block_size is None: block_size = model_max_length if block_size > 1024: logger.warning( "The chosen tokenizer supports a `model_max_length` that is" " longer than the default `block_size` value" " of 1024. If you would like to use a longer `block_size`" " up to `tokenizer.model_max_length` you can override this " " default with `--block_size xxx`." ) block_size = 1024 else: if data_args.block_size > model_max_length: if self.model_args.truncate_to_model_max_length: logger.warning( f"The block_size passed ({data_args.block_size}) is larger" f" than the maximum length for the model" f"({model_max_length})." f" Using block_size={model_max_length}." f"If you would like to use a longer 'block_size' that is" f" longer than the maximum length supported by the model," f" you can override this behavior with" f"default with `--truncate_to_model_max_length False`." ) block_size = model_max_length else: logger.warning( f"The block_size passed ({data_args.block_size}) is larger" f"than the maximum length for the model" f"({model_max_length})." f"Using block_size={data_args.block_size}." ) block_size = data_args.block_size else: block_size = data_args.block_size # Main data processing function that will concatenate all texts from # our dataset and generate chunks of block_size. def group_texts(examples): # Concatenate all texts. concatenated_examples = {k: list(chain(*examples[k])) for k in examples.keys()} total_length = len(concatenated_examples[list(examples.keys())[0]]) # We drop the small remainder, we could add padding if the model # supported it instead of this drop, you can customize this part to # your needs. total_length = (total_length // block_size) * block_size # Split by chunks of max_len. result = { k: [t[i : i + block_size] for i in range(0, total_length, block_size)] for k, t in concatenated_examples.items() } return result # Note that with `batched=True`, this map processes 1,000 texts # together, so group_texts throws away a remainder for each of those # groups of 1,000 texts. You can adjust that batch_size here but a # higher value might be slower to preprocess. # # To speed up this part, we use multiprocessing. See the documentation # of the map method for more information: # https://huggingface.co/docs/datasets/package_reference/main_classes.html#datasets.Dataset.map with finetuner_args.main_process_first(desc="grouping texts together"): group_batch_size = data_args.group_texts_batch_size if data_args.disable_group_texts: group_batch_size = 1 if not data_args.streaming: lm_datasets = tokenized_datasets.map( group_texts, batched=True, batch_size=group_batch_size, num_proc=data_args.preprocessing_num_workers, load_from_cache_file=not data_args.overwrite_cache, desc=f"Grouping texts in chunks of {block_size}", ) else: lm_datasets = tokenized_datasets.map( group_texts, batched=True, batch_size=group_batch_size, ) return lm_datasets def tune( self, model: Union[HFDecoderModel, HFTextRegressionModel], dataset: Dataset, transform_dataset_in_place=True, data_collator=None, ): """ Perform tuning for a model Parameters ------------ model : TunableModel object. TunableModel to perform tuning. dataset: dataset to train model. """ model_args = self.model_args data_args = self.data_args finetuner_args = self.finetuner_args if not transform_dataset_in_place: dataset = copy.deepcopy(dataset) # Tokenization and text grouping must be done in the main process if dataset.backend == "custom_multi_modal": dataset.backend_dataset.register_tokenizer(model.tokenizer, model.image_processor) lm_dataset = dataset else: with finetuner_args.main_process_first(desc="dataset map tokenization"): tokenized_dataset = model.tokenize(dataset) if data_args.disable_group_texts: lm_dataset = tokenized_dataset else: lm_dataset = self.group_text( tokenized_dataset, model_max_length=model.get_max_length(), ) train_dataset = lm_dataset.get_backend_dataset() if data_args.calculate_dataset_stats: total_tokens = 0 total_target_tokens = 0 pad_token_id = model.get_tokenizer().pad_token_id logger.warning("Calculating dataset stats...") import time start_time = time.time() for datapoint in train_dataset: total_tokens += len([label for label in datapoint["input_ids"] if label != pad_token_id]) total_target_tokens += len([label for label in datapoint["labels"] if label != -100]) logger.warning( "Dataset stats:\n\n" f"Total tokens: {total_tokens}\n" f"Total target tokens: {total_target_tokens}\n" f"Total samples: {len(train_dataset)}\n" f"Average tokens per sample: {total_tokens / len(train_dataset)}\n" f"Average target tokens per sample: {total_target_tokens / len(train_dataset)}\n" ) logger.warning("Calculating data stats took %s seconds", time.time() - start_time) else: logger.warning(f"Number of train samples: {len(train_dataset)}") if finetuner_args.do_eval: eval_dataset_args = deepcopy(data_args) eval_dataset_args.dataset_path = finetuner_args.eval_dataset_path eval_dataset = Dataset(eval_dataset_args) with finetuner_args.main_process_first(desc="dataset map tokenization"): tokenized_dataset = model.tokenize(eval_dataset) if data_args.disable_group_texts: lm_dataset = tokenized_dataset else: lm_dataset = self.group_text( tokenized_dataset, model_max_length=model.get_max_length(), ) eval_dataset = lm_dataset.get_backend_dataset() logger.info(f"Number of eval samples: {len(eval_dataset)}") def preprocess_logits_for_metrics(logits, labels): if isinstance(logits, tuple): # Depending on the model and config, logits may contain extra tensors, # like past_key_values, but logits always come first logits = logits[0] return logits.argmax(dim=-1) metric = evaluate.load("accuracy") def compute_metrics(eval_preds): preds, labels = eval_preds # preds have the same shape as the labels, after the argmax(-1) has been calculated # by preprocess_logits_for_metrics but we need to shift the labels labels = labels[:, 1:].reshape(-1) preds = preds[:, :-1].reshape(-1) return metric.compute(predictions=preds, references=labels) if finetuner_args.do_train: if data_args.max_train_samples is not None: max_train_samples = min(len(train_dataset), data_args.max_train_samples) train_dataset = train_dataset.select(range(max_train_samples)) # Initialize our Trainer training_args = finetuner_args FinetuningTrainer = Trainer trainer_callbacks = [] if data_collator is None: data_collator = default_data_collator if training_args.use_customized_optim: BaseTrainer = FinetuningTrainer FinetuningTrainer = create_customized_optimizer(BaseTrainer, model_args) if training_args.use_lisa: dynamic_layer_activation_callback = DynamicLayerActivationCallback( n_layers=training_args.lisa_activated_layers, # Number of layers to activate interval_steps=training_args.lisa_interval_steps, # Step interval to update active layers model=model.get_backend_model(), lisa_layers_attribute=training_args.lisa_layers_attribute, # Attribute to access layers of the model ) trainer_callbacks.append(dynamic_layer_activation_callback) trainer_kwargs = { "model": model.get_backend_model(), "args": training_args, "train_dataset": train_dataset if training_args.do_train else None, "eval_dataset": eval_dataset if training_args.do_eval else None, "data_collator": data_collator, "compute_metrics": compute_metrics if training_args.do_eval else None, "preprocess_logits_for_metrics": preprocess_logits_for_metrics if training_args.do_eval else None, "callbacks": trainer_callbacks, } if is_package_version_at_least("transformers", "4.46.0"): # https://github.com/huggingface/transformers/pull/32385 trainer_kwargs["processing_class"] = model.get_tokenizer() else: trainer_kwargs["tokenizer"] = model.get_tokenizer() trainer = FinetuningTrainer(**trainer_kwargs) # Training if training_args.do_train: checkpoint = None last_checkpoint = self.last_checkpoint if training_args.resume_from_checkpoint is not None: # load from lora checkpoint is also supported checkpoint = training_args.resume_from_checkpoint elif last_checkpoint is not None: checkpoint = last_checkpoint train_result = trainer.train(resume_from_checkpoint=checkpoint) if not model_args.use_lora: trainer.save_model() # Saves the tokenizer too for easy upload else: if model_args.save_aggregated_lora: model.merge_lora_weights() model.save(finetuner_args.output_dir, model_args.save_aggregated_lora) # save language_projection for multi-modal model; if self.finetuner_args.save_language_projection: language_projection_state = trainer.model.language_projection.state_dict() torch.save( os.path.join(self.finetuner_args.output_dir, "language_projection.pth"), language_projection_state ) metrics = train_result.metrics max_train_samples = ( data_args.max_train_samples if data_args.max_train_samples is not None else len(train_dataset) ) metrics["train_samples"] = min(max_train_samples, len(train_dataset)) trainer.log_metrics("train", metrics) trainer.save_metrics("train", metrics) trainer.save_state() kwargs = {"finetuned_from": model_args.model_name_or_path, "tasks": "text-generation"} if data_args.dataset_name is not None: kwargs["dataset_tags"] = data_args.dataset_name if data_args.dataset_config_name is not None: kwargs["dataset_args"] = data_args.dataset_config_name kwargs["dataset"] = f"{data_args.dataset_name} {data_args.dataset_config_name}" else: kwargs["dataset"] = data_args.dataset_name if training_args.push_to_hub: trainer.push_to_hub(**kwargs) else: trainer.create_model_card(**kwargs) return model ================================================ FILE: src/lmflow/pipeline/inferencer.py ================================================ #!/usr/bin/env python """The Inferencer class simplifies the process of model inferencing.""" import copy import logging import os import subprocess import numpy as np import torch import torch.distributed as dist import torch.nn.functional as F from accelerate import Accelerator from transformers import AutoConfig from lmflow.args import ( DatasetArguments, InferencerArguments, ModelArguments, ) from lmflow.datasets.dataset import Dataset from lmflow.models.hf_decoder_model import HFDecoderModel from lmflow.pipeline.base_pipeline import BasePipeline from lmflow.utils.constants import IMAGE_TOKEN_INDEX from lmflow.utils.data_utils import batchlize, set_random_seed from lmflow.utils.envs import is_accelerate_env from lmflow.utils.versioning import is_deepspeed_available os.environ["TOKENIZERS_PARALLELISM"] = "false" # To avoid warnings about parallelism in tokenizers def rstrip_partial_utf8(string): return string.replace("\ufffd", "") supported_dataset_type = [ "text_only", "image_text", ] logger = logging.getLogger(__name__) class Inferencer(BasePipeline): """ Initializes the `Inferencer` class with given arguments. Parameters ------------ model_args : ModelArguments object. Contains the arguments required to load the model. data_args : DatasetArguments object. Contains the arguments required to load the dataset. inferencer_args : InferencerArguments object. Contains the arguments required to perform inference. """ def __init__( self, model_args: ModelArguments, data_args: DatasetArguments, inferencer_args: InferencerArguments, ): self.data_args = data_args self.inferencer_args = inferencer_args self.model_args = model_args set_random_seed(self.inferencer_args.random_seed) self.local_rank = int(os.getenv("LOCAL_RANK", "0")) self.world_size = int(os.getenv("WORLD_SIZE", "1")) if inferencer_args.device == "gpu": # FIXME: a bit weird here torch.cuda.set_device(self.local_rank) # NOTE: cpu-only machine will have error if not is_accelerate_env() and is_deepspeed_available(): import deepspeed deepspeed.init_distributed() else: os.environ["MASTER_ADDR"] = "localhost" os.environ["MASTER_PORT"] = "15000" dist.init_process_group("gloo", rank=self.local_rank, world_size=self.world_size) self.config = AutoConfig.from_pretrained(model_args.model_name_or_path, trust_remote_code=True) try: self.model_hidden_size = self.config.hidden_size except Exception: print("Error in setting hidden size, use the default size 1024") self.model_hidden_size = 1024 # gpt2 seems do not have hidden_size in config if is_accelerate_env(): self.accelerator = Accelerator() self.accelerator.wait_for_everyone() def create_dataloader(self, dataset: Dataset): r"""Batchlize dataset and format it to dataloader. Args: dataset (Dataset): the dataset object Output: dataloader (batchlize): the dataloader object dataset_size (int): the length of the dataset """ if dataset.get_type() == "text_only": data_dict = dataset.to_dict() inputs = [instance["text"] for instance in data_dict["instances"]] elif dataset.get_type() == "image_text": inputs = dataset.to_list() dataset_size = len(inputs) dataset_buf = [] for idx in range(dataset_size): dataset_buf.append({"input": inputs[idx], "input_idx": idx}) dataloader = batchlize( dataset_buf, batch_size=1, random_shuffle=False, ) return dataloader, dataset_size def inference( self, model, dataset: Dataset, max_new_tokens: int = 100, temperature: float = 0.0, prompt_structure: str = "{input}", remove_image_flag: bool = False, chatbot_type: str = "mini_gpt", ): """ Perform inference for a model Parameters ------------ model : TunableModel object. TunableModel to perform inference dataset : Dataset object. Returns: output_dataset: Dataset object. """ if dataset.get_type() not in supported_dataset_type: raise NotImplementedError("input dataset should have type {}".format(supported_dataset_type)) dataloader, data_size = self.create_dataloader(dataset) # The output dataset output_dict = {"type": "text_only", "instances": []} for batch_index, batch in enumerate(dataloader): current_batch = batch[0] # batch size is 1 if isinstance(current_batch["input"], str): input = prompt_structure.format(input=current_batch["input"]) else: input = current_batch["input"] input["text"] = prompt_structure.format(input=input["text"]) if False and "images" in input and isinstance(input["images"], list): input["images"] = np.array(input["images"]) if remove_image_flag: # remove the image flag in tokenization; if chatbot_type == "mini_gpt": image_split_flag = "" elif chatbot_type: image_split_flag = "" else: raise NotImplementedError input["text"] = input["text"].split(image_split_flag) # TODO remove this code by update the tokenizer input_ids = [] attention_mask = [] image_token_indexes = [] temp_input = copy.deepcopy(input) for idx in range(len(input["text"])): temp_input["text"] = input["text"][idx] temp_inputs = model.encode(temp_input, return_tensors="pt", add_special_tokens=idx == 0).to( device=self.local_rank ) input_ids.append(temp_inputs["input_ids"]) attention_mask.append(temp_inputs["attention_mask"]) if chatbot_type == "llava": # add the flag for inserting the image. # TODO should merge the way of handling image flag in minigpt and llava. index_tensor = torch.tensor([IMAGE_TOKEN_INDEX]).to(device=self.local_rank) index_tensor = index_tensor.reshape(1, 1) input_ids.append(index_tensor) attention_mask.append(torch.ones(1, 1).to(device=self.local_rank)) image_token_indexes.append(temp_inputs["input_ids"].shape[1]) if len(image_token_indexes) > 1: image_token_indexes = image_token_indexes[:-1] if chatbot_type == "llava": input_ids = input_ids[:-1] attention_mask = attention_mask[:-1] inputs = temp_inputs inputs["input_ids"] = torch.cat(input_ids, dim=1) inputs["attention_mask"] = torch.cat(attention_mask, dim=1) else: if self.inferencer_args.device == "gpu": inputs = model.encode(input, return_tensors="pt").to(device=self.local_rank) elif self.inferencer_args.device == "cpu": inputs = model.encode(input, return_tensors="pt").to(device="cpu") else: raise NotImplementedError(f'device "{self.inferencer_args.device}" is not supported') if is_accelerate_env(): inputs = inputs.to(self.accelerator.device) if remove_image_flag: inputs["image_token_indexes"] = image_token_indexes inputs["one_sample_multiple_images"] = True if is_accelerate_env(): with self.accelerator.autocast(): outputs = model.inference( inputs, max_new_tokens=max_new_tokens, temperature=self.inferencer_args.temperature, repetition_penalty=self.inferencer_args.repetition_penalty, do_sample=self.inferencer_args.do_sample, ) else: outputs = model.inference( inputs, max_new_tokens=max_new_tokens, temperature=self.inferencer_args.temperature, repetition_penalty=self.inferencer_args.repetition_penalty, do_sample=self.inferencer_args.do_sample, ) # only return the generation, trucating the input if self.model_args.arch_type != "vision_encoder_decoder": text_out = model.decode(outputs[0], skip_special_tokens=True) prompt_length = len( model.decode( inputs[0], skip_special_tokens=True, ) ) text_out = text_out[prompt_length:] else: # to avoid redundant/missing leading space problem, we use a # part of the input text input_text = inputs["input_ids"][0][-1:] text_out = model.decode(torch.cat([input_text, outputs[0]]), skip_special_tokens=True) prompt_length = len( model.decode( input_text, skip_special_tokens=True, ) ) text_out = text_out[prompt_length:] output_dict["instances"].append({"text": text_out}) output_dataset = Dataset(DatasetArguments(dataset_path=None)) output_dataset = output_dataset.from_dict(output_dict) return output_dataset def stream_inference( self, context, model, max_new_tokens, token_per_step, temperature, end_string, input_dataset, remove_image_flag: bool = False, ): response = "" history = [] if "ChatGLMModel" in self.config.architectures: for response, _ in model.get_backend_model().stream_chat(model.get_tokenizer(), context, history=history): response = rstrip_partial_utf8(response) yield response, False else: for _ in range(0, self.inferencer_args.max_new_tokens // token_per_step): output_dataset = self.inference( model=model, dataset=input_dataset, max_new_tokens=token_per_step, temperature=self.inferencer_args.temperature, remove_image_flag=remove_image_flag, ) new_append_text = output_dataset.to_dict()["instances"][0]["text"] new_append_text = rstrip_partial_utf8(new_append_text) response += new_append_text input_dict = input_dataset.to_dict() input_dict["instances"][0]["text"] += new_append_text input_dataset = input_dataset.from_dict(input_dict) flag_break = False try: index = response.index(end_string) flag_break = True except ValueError: response += end_string index = response.index(end_string) response = response[:index] yield response, flag_break class SpeculativeInferencer(Inferencer): """ Ref: [arXiv:2211.17192v2](https://arxiv.org/abs/2211.17192) Parameters ------------ target_model_args : ModelArguments object. Contains the arguments required to load the target model. draft_model_args : ModelArguments object. Contains the arguments required to load the draft model. data_args : DatasetArguments object. Contains the arguments required to load the dataset. inferencer_args : InferencerArguments object. Contains the arguments required to perform inference. """ def __init__(self, model_args, draft_model_args, data_args, inferencer_args): super().__init__(model_args, data_args, inferencer_args) self.draft_model_args = draft_model_args self.draft_config = AutoConfig.from_pretrained(draft_model_args.model_name_or_path, trust_remote_code=True) try: self.draft_model_hidden_size = self.draft_config.hidden_size except Exception: print("Error in setting hidden size for draft model, use the default size 1024") self.draft_model_hidden_size = 768 @staticmethod def score_to_prob( scores: torch.Tensor, temperature: float = 0.0, top_p: float = 1.0, ) -> torch.Tensor: """ Convert scores (NOT softmaxed tensor) to probabilities with support for temperature, top-p sampling, and argmax. Parameters ---------- scores : torch.Tensor Input scores. temperature : float, optional Temperature parameter for controlling randomness. Higher values make the distribution more uniform, lower values make it peakier. When temperature <= 1e-6, argmax is used. by default 0.0 top_p : float, optional Top-p sampling parameter for controlling the cumulative probability threshold, by default 1.0 (no threshold) Returns ------- torch.Tensor Probability distribution after adjustments. """ assert temperature >= 0.0 assert 0.0 < top_p <= 1.0 if temperature <= 1e-6: final_prob = F.one_hot(scores.argmax(dim=1), num_classes=scores.size(1)).float() else: scores /= temperature if top_p < 1.0: sorted_scores, _ = torch.sort(scores, descending=True) probs = sorted_scores.softmax(dim=1) cumulative_probs = torch.cumsum(probs, dim=1) mask = cumulative_probs <= top_p if mask.any(): thresholded_probs = probs * mask thresholded_probs = thresholded_probs / thresholded_probs.sum(dim=1, keepdim=True) final_prob = torch.zeros_like(scores) final_prob.scatter_add_(1, sorted_scores.argsort(dim=1), thresholded_probs) else: final_prob = scores.softmax(dim=1) else: final_prob = scores.softmax(dim=1) return final_prob @staticmethod def sample(prob: torch.Tensor, num_samples: int = 1) -> dict: """Sample from a tensor of probabilities""" sampled_indices = torch.multinomial(prob, num_samples=num_samples, replacement=True) return { "sampled_token": sampled_indices, "sampled_prob": prob.gather(dim=1, index=sampled_indices), "all_prob": prob, } @staticmethod def predict_next_token(model: HFDecoderModel, input_ids: torch.Tensor, num_new_tokens: int = 1): """Predict the next token given the input_ids.""" output = model.inference( input_ids, max_new_tokens=num_new_tokens, return_dict_in_generate=True, output_scores=True, do_sample=True, num_beams=1, ) return output def autoregressive_sampling( self, input_ids: torch.Tensor, model: HFDecoderModel, temperature: float = 0.0, num_new_tokens: int = 5 ) -> dict: """Ref: [arXiv:2211.17192v2](https://arxiv.org/abs/2211.17192) Section 2.2""" sequence = input_ids new_tokens = [] for _ in range(num_new_tokens): pred = self.predict_next_token(model=model, input_ids=sequence, num_new_tokens=1) # predict next one token prob = self.score_to_prob(pred.scores[0], temperature=temperature) sampled = self.sample(prob=prob, num_samples=1) new_tokens.append(sampled) sequence = torch.cat([sequence, sampled["sampled_token"]], dim=1) return {"sequence": sequence, "new_tokens": new_tokens} def inference( self, model: HFDecoderModel, draft_model: HFDecoderModel, input: str, temperature: float = 0.0, gamma: int = 5, max_new_tokens: int = 100, ): """ Perform inference for a model Parameters ------------ model : HFDecoderModel object. TunableModel to verify tokens generated by the draft model. draft_model : HFDecoderModel object. TunableModel that provides approximations of the target model. input : str. The input text (i.e., the prompt) for the model. gamma : int. The number of tokens to be generated by the draft model within each iter. max_new_tokens : int. The maximum number of tokens to be generated by the target model. Returns ------- output: str. The output text generated by the model. """ assert gamma > 0 if self.inferencer_args.device == "gpu": inputs = model.encode(input, return_tensors="pt").to(device=self.local_rank) elif self.inferencer_args.device == "cpu": inputs = model.encode(input, return_tensors="pt").to(device="cpu") else: raise NotImplementedError(f'device "{self.inferencer_args.device}" is not supported') def speculative_sampling( input_ids: torch.Tensor, model: HFDecoderModel, draft_model: HFDecoderModel, temperature: float = 0.0 ) -> torch.Tensor: """Ref: [arXiv:2211.17192v2](https://arxiv.org/abs/2211.17192) Parameters ---------- input_ids : torch.Tensor draft_model : TunableModel object model_list : list[TunableModel object] Returns ------- torch.Tensor """ len_input_ids = input_ids.shape[1] logger.debug(f"len of input_ids: {len_input_ids}") # STEP 1: Sample γ guesses x1, ..., xγ from Mq (draft model) autoregressively output_draft = self.autoregressive_sampling(input_ids=input_ids, model=draft_model, num_new_tokens=gamma) logger.debug(f"draft result: {output_draft['sequence']}") logger.debug(f"draft result decoded: {draft_model.decode(output_draft['sequence'][0])}") # STEP 2: Run Mp (target model) in parallel # generate sequences [prefix, x1, x2, ..., xγ] output = model.get_backend_model()(input_ids=output_draft["sequence"], return_dict=True) logger.debug(f"shape of output: {output.logits.shape}") # STEP 3: Determine the number of accepted guesses n accepted = [False] * gamma for i in range(gamma): draft_sampled_token_id = output_draft["new_tokens"][i]["sampled_token"] draft_sampled_token_prob = output_draft["new_tokens"][i]["sampled_prob"] token_prob = self.score_to_prob(output.logits[:, len_input_ids + i - 1, :], temperature=temperature)[ 0, draft_sampled_token_id ] # reject the sample with probability 1 - p(x)/q(x) if torch.rand_like(token_prob) > token_prob / draft_sampled_token_prob: break else: accepted[i] = True logger.debug(f"Speculative Sampling: Accepted: {sum(accepted)}/{gamma}") # STEP 4: Adjust the distribution from Mp if needed if not all(accepted): all_prob = self.score_to_prob(output.logits[:, len_input_ids + i - 1, :], temperature=temperature) draft_all_prob = output_draft["new_tokens"][i]["all_prob"] adjusted_prob = torch.max(torch.zeros_like(all_prob), all_prob - draft_all_prob) prob = adjusted_prob / adjusted_prob.sum(dim=1, keepdim=True) else: prob = self.score_to_prob(output.logits[:, -1, :], temperature=temperature) # STEP 5: Return n tokens from Mq, and one token from Mp token_from_target_model = self.sample(prob)["sampled_token"] final_sequence = torch.concat( [output_draft["sequence"][:, : len_input_ids + sum(accepted)], token_from_target_model], dim=1 ) return final_sequence num_generated_new_tokens = 0 len_raw_input = len(inputs[0]) while num_generated_new_tokens < max_new_tokens: logger.debug("===== New iter =====") logger.debug(f"input_ids: {inputs}") sampling_result = speculative_sampling( input_ids=inputs, model=model, draft_model=draft_model, temperature=temperature ) logger.debug(f"sampling result: {sampling_result}") logger.debug(f"sampling result decoded: {model.decode(sampling_result[0])}") num_generated_new_tokens += len(sampling_result[0]) - len(inputs[0]) inputs = sampling_result # if, say, num_generated_new_tokens = 19, and the model accept 3 # tokens, the actual generated tokens would be 22. return model.decode(inputs[0, : len_raw_input + max_new_tokens]) def stream_inference(self): raise NotImplementedError("Streaming output for SpeculativeInferencer is not supported yet") class ToolInferencer(Inferencer): """ Initializes the `ToolInferencer` class with given arguments. Parameters ------------ model_args : ModelArguments object. Contains the arguments required to load the model. data_args : DatasetArguments object. Contains the arguments required to load the dataset. inferencer_args : InferencerArguments object. Contains the arguments required to perform inference. """ def __init__(self, model_args, data_args, inferencer_args): super().__init__(model_args, data_args, inferencer_args) self.model = HFDecoderModel(self.model_args) def inference( self, model: HFDecoderModel, input: str, max_new_tokens: int = 1024, ): """ Perform inference for a model Parameters ------------ model : HFDecoderModel object. TunableModel to perform inference input : str. The input text (i.e., the prompt) for the model. max_new_tokens : int. The maximum number of tokens to be generated by the model. Returns: output : str. The output text generated by the model. """ if self.inferencer_args.device == "gpu": input_id = model.encode(input, return_tensors="pt").to(device=self.local_rank) elif self.inferencer_args.device == "cpu": input_id = model.encode(input, return_tensors="pt").to(device="cpu") logger.debug(f"input_id: {input_id}") output_id = model.inference( input_id, max_new_tokens=max_new_tokens, # pad_token_id=model.tokenizer.eos_token_id, ) # logger.debug(f"output: {output_id}") output = model.decode(output_id[0]) output = output.replace(input, "") return output def code_exec(self, code): # Execute the code result = subprocess.run(["python", "-c", code], capture_output=True, text=True) # Print the result if result.returncode == 0: print("Successfully Executed, the result is:") print(result.stdout) return result.stdout else: print("Error:") print(result.stderr) return result ================================================ FILE: src/lmflow/pipeline/iterative_dpo_aligner.py ================================================ import copy import json import logging from dataclasses import fields from pathlib import Path from tqdm import tqdm from lmflow.args import ( DatasetArguments, DPOv2AlignerArguments, InferencerArguments, IterativeDPOAlignerArguments, ModelArguments, ) from lmflow.datasets.dataset import Dataset from lmflow.models.hf_decoder_model import HFDecoderModel from lmflow.models.hf_text_regression_model import HFTextRegressionModel from lmflow.pipeline.dpov2_aligner import MemorySafeDPOv2Aligner from lmflow.pipeline.rm_inferencer import RewardModelInferencer from lmflow.pipeline.vllm_inferencer import MemorySafeVLLMInferencer from lmflow.utils.common import print_banner logger = logging.getLogger(__name__) class IterativeDPOAligner: def __init__( self, model_args: ModelArguments, data_args: DatasetArguments, aligner_args: IterativeDPOAlignerArguments, ref_model_args: ModelArguments, reward_model_args: ModelArguments, **kwargs, ): self.model_args = model_args self.data_args = data_args self.aligner_args = aligner_args self.ref_model_args = ref_model_args self.reward_model_args = reward_model_args self.workspace_path = Path(self.aligner_args.output_dir) def align(self, dataset_list: list[Dataset]): num_iterations = len(dataset_list) for iter_idx in tqdm( range(self.aligner_args.initial_iter_idx, num_iterations), desc="Iterative DPO Align", unit="iteration" ): if iter_idx == 0: target_model_args = self.model_args else: target_model_args = copy.deepcopy(self.model_args) target_model_args.model_name_or_path = str(self.workspace_path / f"iteration_{iter_idx}" / "model") self._align_single_iteration( iteration_name=f"iteration_{iter_idx + 1}", target_model_args=target_model_args, reward_model_args=self.reward_model_args, ref_model_args=self.ref_model_args, dataset=dataset_list[iter_idx], ) def _align_single_iteration( self, iteration_name: str, target_model_args: ModelArguments, reward_model_args: ModelArguments, ref_model_args: ModelArguments, dataset: Dataset, ): if self.aligner_args.do_response_generation: # generate responses print_banner(f"Iterative DPO {iteration_name}: Generate responses") model = HFDecoderModel(model_args=target_model_args, do_train=False) self._do_target_model_inference( model=model, dataset=dataset, output_dir=str(self.workspace_path / iteration_name), ) del model if self.aligner_args.do_scoring: # reward model scoring print_banner(f"Iterative DPO {iteration_name}: Reward model scoring") reward_model = HFTextRegressionModel( model_args=reward_model_args, do_train=False, ) target_model_inference_result_data_args = copy.deepcopy(dataset.data_args) target_model_inference_result_data_args.dataset_path = str( self.workspace_path / iteration_name / "target_model_inference_result" ) target_model_inference_result_data_args.block_size = self.aligner_args.reward_model_inference_block_size target_model_inference_result_dataset = Dataset(target_model_inference_result_data_args) self._do_reward_model_inference( model=reward_model, dataset=target_model_inference_result_dataset, output_dir=str(self.workspace_path / iteration_name), ) del reward_model if self.aligner_args.do_dpo_align: # DPO training print_banner(f"Iterative DPO {iteration_name}: DPO training") dpo_train_data_args = copy.deepcopy(dataset.data_args) dpo_train_data_args.dataset_path = str( self.workspace_path / iteration_name / "reward_model_inference_result" ) self._do_single_dpo_align( model_args=target_model_args, ref_model_args=ref_model_args, data_args=dpo_train_data_args, output_dir=str(self.workspace_path / iteration_name / "model"), iteration_name=iteration_name, ) def _do_target_model_inference( self, model: HFDecoderModel, dataset: Dataset, output_dir: str, ): result_cache_path = str(Path(output_dir) / "cache" / "target_model_inference_result.json") inferencer = MemorySafeVLLMInferencer( model_args=model.model_args, data_args=dataset.data_args, inferencer_args=self._parse_target_model_inference_args( args=self.aligner_args, result_cache_path=result_cache_path, ), ) res = inferencer.inference() dataset_out = {"type": "text_to_textlist", "instances": res} target_model_inference_result_dir = Path(output_dir) / "target_model_inference_result" target_model_inference_result_dir.mkdir(parents=True, exist_ok=True) json.dump( dataset_out, open(str(target_model_inference_result_dir / "result.json"), "w", encoding="utf-8"), ensure_ascii=False, indent=4, ) def _do_reward_model_inference( self, model: HFTextRegressionModel, dataset: Dataset, output_dir: str, ): inferencer = RewardModelInferencer( model_args=model.model_args, data_args=dataset.data_args, inferencer_args=self._parse_reward_model_inference_args(self.aligner_args), ) res = inferencer.inference( model=model, dataset=dataset, transform_dataset_in_place=True, use_vllm=False, enable_distributed_inference=self.aligner_args.enable_distributed_inference, distributed_inference_num_instances=self.aligner_args.distributed_inference_num_instances, inference_batch_size=self.aligner_args.reward_model_inference_batch_size, ) reward_model_inference_result_dir = Path(output_dir) / "reward_model_inference_result" reward_model_inference_result_dir.mkdir(parents=True, exist_ok=True) res.save(str(reward_model_inference_result_dir / "result.json")) def _do_single_dpo_align( self, model_args: ModelArguments, ref_model_args: ModelArguments, data_args: DatasetArguments, output_dir: str, iteration_name: str, ): aligner = MemorySafeDPOv2Aligner( model_args=model_args, data_args=data_args, aligner_args=self._parse_dpo_aligner_args( args=self.aligner_args, output_dir=output_dir, iteration_name=iteration_name, ), ref_model_args=ref_model_args, ) aligner.align() def _parse_target_model_inference_args( self, args: IterativeDPOAlignerArguments, result_cache_path: str, ) -> InferencerArguments: inferencer_args = self.__filter_args( mixed_args=args, target_cls=InferencerArguments, ) inferencer_args.save_results = True inferencer_args.results_path = result_cache_path return inferencer_args def _parse_reward_model_inference_args( self, args: IterativeDPOAlignerArguments, ) -> InferencerArguments: inferencer_args = self.__filter_args( mixed_args=args, target_cls=InferencerArguments, ) return inferencer_args def _parse_dpo_aligner_args( self, args: IterativeDPOAlignerArguments, output_dir: str, iteration_name: str, ) -> DPOv2AlignerArguments: aligner_args = self.__filter_args( mixed_args=args, target_cls=DPOv2AlignerArguments, ) aligner_args.output_dir = output_dir aligner_args.run_name = f"{args.run_name}_{iteration_name}" return aligner_args def __filter_args( self, mixed_args, target_cls, ): target_cls_fields = {f.name for f in fields(target_cls) if f.init} common_fields = {f: getattr(mixed_args, f) for f in target_cls_fields if hasattr(mixed_args, f)} return target_cls(**common_fields) ================================================ FILE: src/lmflow/pipeline/raft_aligner.py ================================================ #!/usr/bin/env python """ The Aligner class simplifies the process of running alignment. """ import logging import os import sys import time from itertools import chain import numpy as np import torch import torch.distributed as dist import transformers from datasets import ( Dataset, DatasetDict, set_caching_enabled, ) from transformers import ( default_data_collator, set_seed, ) from transformers.testing_utils import CaptureLogger from lmflow.datasets.dataset import Dataset as LMFlowDataset from lmflow.pipeline.base_aligner import BaseAligner from lmflow.pipeline.utils.raft_trainer import RaftTrainer logger = logging.getLogger(__name__) class RaftAligner(BaseAligner): """ Initializes the `RaftAligner` class with given arguments. Parameters ------------ model_args : ModelArguments object. Contains the arguments required to load the model. data_args : DatasetArguments object. Contains the arguments required to load the dataset. raft_aligner_args : RaftAlignerArguments object. Contains the arguments required to perform alignment. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. """ def __init__(self, model_args, data_args, aligner_args, *args, **kwargs): self.model_args = model_args self.data_args = data_args self.aligner_args = aligner_args logging.basicConfig( format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", datefmt="%m/%d/%Y %H:%M:%S", handlers=[logging.StreamHandler(sys.stdout)], ) self.INF = 888888888 logger.setLevel(logging.INFO) output_reward_path = aligner_args.output_reward_path if output_reward_path is not None: os.makedirs(os.path.dirname(output_reward_path), exist_ok=True) # Deletes a maybe-exist file try: os.remove(output_reward_path) except OSError: pass def _initialize_trainer(self, model, tokenizer, training_args): """ This function takes the model and tokenizer as the input and initialize the trainer. """ trainer = RaftTrainer( model=model, args=training_args, train_dataset=Dataset.from_dict({"text": [" "]}), eval_dataset=Dataset.from_dict({}), tokenizer=tokenizer, data_collator=default_data_collator, compute_metrics=None, preprocess_logits_for_metrics=None, ) return trainer def _load_dataset( self, selected_dataset, model, tokenizer, model_args, data_args, training_args, ): """ This function prepares the dataset for every iteration. """ raw_datasets = selected_dataset if training_args.do_train: column_names = list(raw_datasets["train"].features) else: column_names = list(raw_datasets["validation"].features) text_column_name = "text" if "text" in column_names else column_names[0] # since this will be pickled to avoid _LazyModule error in Hasher force logger loading before tokenize_function tok_logger = transformers.utils.logging.get_logger("transformers.tokenization_utils_base") def tokenize_function(examples): with CaptureLogger(tok_logger) as cl: output = tokenizer(examples[text_column_name]) # clm input could be much much longer than block_size if "Token indices sequence length is longer than the" in cl.out: tok_logger.warning( "^^^^^^^^^^^^^^^^ Please ignore the warning above - this long input will be chunked into smaller bits" " before being passed to the model." ) return output with training_args.main_process_first(desc="dataset map tokenization"): if not data_args.streaming: tokenized_datasets = raw_datasets.map( tokenize_function, batched=True, num_proc=data_args.preprocessing_num_workers, remove_columns=column_names, load_from_cache_file=not data_args.overwrite_cache, desc="Running tokenizer on dataset", ) else: tokenized_datasets = raw_datasets.map( tokenize_function, batched=True, remove_columns=column_names, ) if data_args.block_size is None: block_size = tokenizer.model_max_length if block_size > 1024: logger.warning( "The chosen tokenizer supports a `model_max_length` that is longer than the default `block_size` value" " of 1024. If you would like to use a longer `block_size` up to `tokenizer.model_max_length` you can" " override this default with `--block_size xxx`." ) block_size = 512 else: if data_args.block_size > tokenizer.model_max_length: logger.warning( f"The block_size passed ({data_args.block_size}) is larger than the maximum length for the model" f"({tokenizer.model_max_length}). Using block_size={tokenizer.model_max_length}." ) block_size = min(data_args.block_size, tokenizer.model_max_length) # Main data processing function that will concatenate all texts from our dataset and generate chunks of block_size. def group_texts(examples): # Concatenate all texts. concatenated_examples = {k: list(chain(*examples[k])) for k in examples.keys()} total_length = len(concatenated_examples[list(examples.keys())[0]]) # We drop the small remainder, we could add padding if the model supported it instead of this drop, you can # customize this part to your needs. if total_length >= block_size: total_length = (total_length // block_size) * block_size # Split by chunks of max_len. result = { k: [t[i : i + block_size] for i in range(0, total_length, block_size)] for k, t in concatenated_examples.items() } result["labels"] = result["input_ids"].copy() return result # Note that with `batched=True`, this map processes 1,000 texts together, so group_texts throws away a remainder # for each of those groups of 1,000 texts. You can adjust that batch_size here but a higher value might be slower # to preprocess. # # To speed up this part, we use multiprocessing. See the documentation of the map method for more information: # https://huggingface.co/docs/datasets/package_reference/main_classes.html#datasets.Dataset.map with training_args.main_process_first(desc="grouping texts together"): group_batch_size = 1000 if data_args.disable_group_texts: group_batch_size = 1 if not data_args.streaming: lm_datasets = tokenized_datasets.map( group_texts, batched=True, batch_size=group_batch_size, num_proc=data_args.preprocessing_num_workers, load_from_cache_file=not data_args.overwrite_cache, desc=f"Grouping texts in chunks of {block_size}", ) else: lm_datasets = tokenized_datasets.map( group_texts, batched=True, batch_size=group_batch_size, ) if training_args.do_train: if "train" not in tokenized_datasets: raise ValueError("--do_train requires a train dataset") train_dataset = lm_datasets["train"] if data_args.max_train_samples is not None: max_train_samples = min(len(train_dataset), data_args.max_train_samples) train_dataset = train_dataset.select(range(max_train_samples)) return train_dataset def _load_input_dataset(self, dataset, tokenizer): """ Load input dataset (i.e. prompt/question dataset) for training. Args: dataset: A Dataset object. The dataset to be loaded. Returns: dataloader (`torch.utils.data.DataLoader`): The dataloader for the dataset. """ ds = dataset.get_backend_dataset() def tokenize(sample): sample["input_ids"] = tokenizer.encode(sample["text"]) sample["input"] = tokenizer.decode(sample["input_ids"]) return sample ds = ds.map(tokenize, batched=False) ds = ds.filter(lambda x: len(x["input_ids"]) <= 256) ds.set_format(type="torch") return ds def _clean_text(self, text): if len(text) == 0: return text stext = [x for x in text.split("###Human") if x] return stext[0].strip().strip("#") def _discard_sample(self, text): if "#" in text: return True elif len(text) < 2: # delete empty sample return True return False def _get_batch_dataset_top( self, model, batch_input, alpha=0.2, iter_id=0, local_rank=0, output_min_length=16, output_max_length=48, infer_batch_size=8, generation_kwargs={}, tokenizer=None, training_args=None, reward_model=None, output_reward_path=None, ): """ :param batch_input: input prompts """ # we will get the batch dataset via Dataset.from_dict start_time = time.time() query_tensors = batch_input["input_ids"] querys = batch_input["input"] data_size = len(querys) reward_eva = [] # record the reward of the samples input_texts = [] responses = [] for i, query_tensor in enumerate(query_tensors): query = querys[i] input_texts.append(query) if (i + 1) % infer_batch_size == 0 or (i + 1 == data_size): gen_len = np.random.randint(output_min_length, output_max_length) generation_kwargs["max_new_tokens"] = gen_len inputs = tokenizer(input_texts, return_tensors="pt", padding=True).to(training_args.device) with torch.no_grad(): outputs = model.generate(**inputs, **generation_kwargs) generated_texts = tokenizer.batch_decode(outputs, skip_special_tokens=True) generated_texts = [ generated_text.replace(input_texts[i], "") for i, generated_text in enumerate(generated_texts) ] texts_for_rewards = [q + r for q, r in zip(input_texts, generated_texts)] texts_for_reward_dataset = LMFlowDataset.create_from_dict( { "type": "text_only", "instances": [{"text": text} for text in texts_for_rewards], } ) reward_dataset = reward_model.inference(texts_for_reward_dataset) rewards = [sample["value"] for sample in reward_dataset.to_dict()["instances"]] reward_eva.extend(rewards) responses.extend(generated_texts) input_texts = [] data = [{"input": querys[j], "output": [responses[j]]} for j in range(len(reward_eva))] world_size = int(os.getenv("WORLD_SIZE", "1")) all_process_list = [{}] * world_size data_to_send = [[data[i], reward_eva[i]] for i in range(len(data))] dist.all_gather_object(all_process_list, data_to_send) gathered_data = [] gathered_reward = [] for i in range(world_size): tmp_data = [tmp[0] for tmp in all_process_list[i]] gathered_data.extend(tmp_data) tmp_reward = [tmp[1] for tmp in all_process_list[i]] gathered_reward.extend(tmp_reward) idx = np.argsort(gathered_reward)[::-1][: int(len(gathered_reward) * alpha)] gathered_data = [gathered_data[j] for j in idx] reward_train = [gathered_reward[j] for j in idx] self.reward_seq.append(np.mean(gathered_reward)) self.train_reawrd.append(np.mean(reward_train)) import matplotlib.pyplot as plt if training_args.local_rank == 0: plt.plot(self.reward_seq, marker="o") plt.plot(self.train_reawrd, marker="*") plt.legend(["Model reward", "Reward of SFT Set"]) plt.savefig(self.store_dir + "/training_reward.png") plt.close() logger.info(f"collected data of {len(gathered_data)}") logger.info([np.mean(gathered_reward), np.mean(reward_train)]) if training_args.local_rank == 0 and output_reward_path is not None: with open(output_reward_path, mode="a") as fout: fout.write( "mean reward: " + str(np.mean(gathered_reward)) + "mean reward in training set: " + str(np.mean(reward_train)) ) fout.write("\n") prompt_structure = "{definition}{input}{output}" tmp_output_dataset = { "text": [ prompt_structure.format(definition="", input=sample["input"], output=sample["output"][0]) for sample in gathered_data ] } # We store the training set for monitoring the RAFT training all_texts = tmp_output_dataset["text"] output_eval_dataset = {} output_eval_dataset["type"] = "text_only" output_eval_dataset["instances"] = [{"text": i_text} for i_text in all_texts] import json if local_rank == 0: with open(self.store_dir + "/train_set_" + str(iter_id) + ".json", "w", encoding="utf8") as f: json.dump(output_eval_dataset, f, ensure_ascii=False) # We need to make sure that the order of the samples are the same for each agent all_process_list = [{}] * world_size data_to_send = [tmp_output_dataset, local_rank] dist.all_gather_object(all_process_list, data_to_send) for i in range(world_size): if all_process_list[i][1] == 0: output_dataset = all_process_list[i][0] break return DatasetDict({"train": Dataset.from_dict(output_dataset)}) def _get_batch_dataset_local( self, model, batch_input, K=8, iter_id=0, local_rank=0, output_min_length=16, output_max_length=48, infer_batch_size=8, generation_kwargs={}, tokenizer=None, training_args=None, reward_model=None, output_reward_path=None, ): """ :param batch_input: input prompts """ # we will get the batch dataset via Dataset.from_dict start_time = time.time() querys = batch_input["input"] data_size = len(querys) reward_eva = [] reward_train = [] input_texts = [] responses = [] record_querys = [] all_outputs = [] for i, query in enumerate(querys): input_texts = [query for _ in range(K)] gen_len = np.random.randint(output_min_length, output_max_length) generation_kwargs["max_new_tokens"] = gen_len inputs = tokenizer(input_texts, return_tensors="pt", padding=True).to(training_args.device) with torch.no_grad(): outputs = model.generate(**inputs, **generation_kwargs) generated_texts = tokenizer.batch_decode(outputs, skip_special_tokens=True) generated_texts = [ generated_text.replace(input_texts[i], "") for i, generated_text in enumerate(generated_texts) ] generated_texts = [self._clean_text(generated_text) for generated_text in generated_texts] texts_for_rewards = [q + r for q, r in zip(input_texts, generated_texts)] texts_for_reward_dataset = LMFlowDataset.create_from_dict( { "type": "text_only", "instances": [{"text": texts_for_rewards[i]} for i in range(len(texts_for_rewards))], } ) reward_dataset = reward_model.inference(texts_for_reward_dataset) rewards = [sample["value"] for sample in reward_dataset.to_dict()["instances"]] reward_eva.append(rewards[0]) ################################ # we impose some post-detection and discard the samples with certain criteria. for kk in range(K): if self._discard_sample(generated_texts[kk]): rewards[kk] = -self.INF ################################ idx_to_record = np.argmax(rewards) all_outputs.append(generated_texts[0]) # if we discard all the samples, we do not record the sample if rewards[idx_to_record] != -self.INF: responses.append(generated_texts[idx_to_record]) reward_train.append(rewards[idx_to_record]) record_querys.append(query) input_texts = [] data = [] for j in range(len(reward_train)): sample = {} sample["input"] = record_querys[j] sample["output"] = [responses[j]] data.append(sample) world_size = int(os.getenv("WORLD_SIZE", "1")) all_process_data = [{}] * world_size dist.all_gather_object(all_process_data, data) all_process_eval_reward = [{}] * world_size dist.all_gather_object(all_process_eval_reward, reward_eva) all_process_train_set_reward = [{}] * world_size dist.all_gather_object(all_process_train_set_reward, reward_train) gathered_data = [] gathered_reward = [] gathered_train_reward = [] for i in range(world_size): gathered_data.extend(all_process_data[i]) gathered_reward.extend(all_process_eval_reward[i]) gathered_train_reward.extend(all_process_train_set_reward[i]) if training_args.local_rank == 0 and output_reward_path is not None: with open(output_reward_path, mode="a") as fout: fout.write( "mean reward: " + str(np.mean(gathered_reward)) + "mean reward in training set: " + str(np.mean(gathered_train_reward)) ) fout.write("\n") logger.info([np.mean(gathered_reward), np.mean(gathered_train_reward)]) self.reward_seq.append(np.mean(gathered_reward)) self.train_reawrd.append(np.mean(reward_train)) import matplotlib.pyplot as plt if training_args.local_rank == 0: plt.plot(self.reward_seq, marker="o") plt.plot(self.train_reawrd, marker="*") plt.legend(["Model reward", "Reward of SFT Set"]) plt.savefig(self.store_dir + "/training_reward.png") plt.close() prompt_structure = "{definition}{input}{output}" tmp_output_dataset = { "text": [ prompt_structure.format(definition="", input=sample["input"], output=sample["output"][0]) for sample in gathered_data ] } # We store the training set for monitoring the RAFT training all_texts = tmp_output_dataset["text"] output_eval_dataset = {} output_eval_dataset["type"] = "text_only" output_eval_dataset["instances"] = [{"text": i_text} for i_text in all_texts] import json if local_rank == 0: with open(self.store_dir + "/train_set_" + str(iter_id) + ".json", "w", encoding="utf8") as f: json.dump(output_eval_dataset, f, ensure_ascii=False) # We need to make sure that the order of the samples are the same for each agent all_process_list = [{}] * world_size data_to_send = [tmp_output_dataset, local_rank] dist.all_gather_object(all_process_list, data_to_send) for i in range(world_size): if all_process_list[i][1] == 0: output_dataset = all_process_list[i][0] break logger.info(f"collected data of {len(output_dataset['text'])}") return DatasetDict({"train": Dataset.from_dict(output_dataset)}) def align(self, model, dataset, reward_model): """ Perform alignment for a model Parameters ------------ model : BaseModel object. dataset: Dataset object. Input dataset for model to generate outputs. The input and output will then be feed into reward model to get the reward for alignment. reward_model: RegressionModel object. """ tokenizer = model.get_tokenizer() tokenizer.pad_token = tokenizer.eos_token tokenizer.pad_token_id = tokenizer.eos_token_id tokenizer.padding_side = "left" dataset = self._load_input_dataset(dataset, tokenizer) set_caching_enabled(False) wrapped_model = model model = model.get_backend_model() generation_kwargs = { "min_length": 1, "top_k": 0.0, "top_p": 1.0, "do_sample": True, "pad_token_id": tokenizer.eos_token_id, "temperature": 0.85, } aligner_args = self.aligner_args training_args = aligner_args model_args = self.model_args data_args = self.data_args world_size = int(os.getenv("WORLD_SIZE", "1")) set_seed(42 + training_args.local_rank) ITERATION = aligner_args.num_raft_iteration collection_strategy = aligner_args.collection_strategy sft_batch_size = aligner_args.raft_batch_size if collection_strategy == "top": alpha = aligner_args.top_reward_percentage M = int(sft_batch_size / world_size / alpha) elif collection_strategy == "local": K = int(1 / aligner_args.top_reward_percentage) M = int(sft_batch_size / world_size) else: raise NotImplementedError("We only support two data collection strategies") print(M, K) if training_args.local_rank == 0: print(aligner_args) self.store_dir = aligner_args.output_dir self.reward_seq = [] self.train_reawrd = [] data_size = len(dataset["input"]) lr = training_args.learning_rate random_idxs = np.arange(data_size) np.random.shuffle(random_idxs) raft_trainer = self._initialize_trainer(model, tokenizer, training_args) raft_trainer.train(resume_from_checkpoint=False, is_first_time=True) for iteration in range(ITERATION): set_seed(666 + training_args.local_rank + world_size * (iteration + 1)) end_idx = np.min([data_size, (iteration + 1) * M]) batch_input = dataset.select(random_idxs[iteration * M : end_idx]) model.gradient_checkpointing_disable() model.config.use_cache = True start_time = time.time() if collection_strategy == "top": selected_dataset = self._get_batch_dataset_top( raft_trainer.tmp_model, batch_input, alpha, iteration, training_args.local_rank, output_min_length=aligner_args.output_min_length, output_max_length=aligner_args.output_max_length, infer_batch_size=aligner_args.inference_batch_size_per_device, generation_kwargs=generation_kwargs, tokenizer=tokenizer, training_args=training_args, reward_model=reward_model, output_reward_path=aligner_args.output_reward_path, ) elif collection_strategy == "local": selected_dataset = self._get_batch_dataset_local( raft_trainer.tmp_model, batch_input, K, iteration, training_args.local_rank, output_min_length=aligner_args.output_min_length, output_max_length=aligner_args.output_max_length, infer_batch_size=K, generation_kwargs=generation_kwargs, tokenizer=tokenizer, training_args=training_args, reward_model=reward_model, output_reward_path=aligner_args.output_reward_path, ) end_time = time.time() logger.info("It takes %.2f s to inference one stage", end_time - start_time) raft_trainer.train_dataset = self._load_dataset( selected_dataset, raft_trainer.tmp_model, tokenizer, model_args, data_args, training_args, ) logger.info(f"iter {iteration}") start_time = time.time() model.gradient_checkpointing_enable() model.config.use_cache = False train_result = raft_trainer.train(resume_from_checkpoint=False) end_time = time.time() logger.info("It takes %.2f s to train one stage", end_time - start_time) if (iteration + 1) * M > data_size: logger.info("One epoch is completed.") break """ if training_args.local_rank == 0 and iteration % 2 == 0: wrapped_model.save(aligner_args.output_dir + "/" + "model" + str(iteration)) print(iteration, "I save a model with", self.reward_seq[-1]) """ if aligner_args.output_dir is not None: wrapped_model.save(aligner_args.output_dir) return wrapped_model ================================================ FILE: src/lmflow/pipeline/rm_inferencer.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import copy import logging import os from typing import Any, Union import numpy as np import torch import torch.distributed as dist from accelerate import Accelerator from tqdm import tqdm from transformers.modeling_outputs import SequenceClassifierOutputWithPast from lmflow.args import ( DatasetArguments, InferencerArguments, ModelArguments, ) from lmflow.datasets.dataset import Dataset from lmflow.models.hf_text_regression_model import HFTextRegressionModel from lmflow.pipeline.base_pipeline import BasePipeline from lmflow.utils.data_utils import ( RewardModelInferenceResultWithInput, batchlize, set_random_seed, ) from lmflow.utils.envs import is_accelerate_env from lmflow.utils.versioning import is_deepspeed_available, is_ray_available if is_ray_available(): import ray import ray.data from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy os.environ["TOKENIZERS_PARALLELISM"] = "false" # To avoid warnings about parallelism in tokenizers logger = logging.getLogger(__name__) class RewardModelInferencer(BasePipeline): """ Initializes the `Inferencer` class with given arguments. Parameters ------------ model_args : ModelArguments object. Contains the arguments required to load the model. data_args : DatasetArguments object. Contains the arguments required to load the dataset. inferencer_args : InferencerArguments object. Contains the arguments required to perform inference. """ def __init__( self, model_args: ModelArguments, data_args: DatasetArguments, inferencer_args: InferencerArguments, **kwargs, ): self.data_args = data_args self.inferencer_args = inferencer_args self.model_args = model_args set_random_seed(self.inferencer_args.random_seed) self.local_rank = int(os.getenv("LOCAL_RANK", "0")) self.world_size = int(os.getenv("WORLD_SIZE", "1")) if inferencer_args.device == "gpu": # FIXME: a bit weird here torch.cuda.set_device(self.local_rank) # NOTE: cpu-only machine will have error if not is_accelerate_env() and is_deepspeed_available(): import deepspeed deepspeed.init_distributed() else: dist.init_process_group("gloo", rank=self.local_rank, world_size=self.world_size) if is_accelerate_env(): self.accelerator: Accelerator = kwargs.get("accelerator", Accelerator()) def inference( self, model: HFTextRegressionModel, dataset: Dataset, transform_dataset_in_place: bool = True, use_vllm: bool = False, enable_distributed_inference: bool = False, **kwargs, ) -> Dataset: if use_vllm: logger.warning("VLLM doesn't support reward model inference, using normal inference instead.") use_vllm = False assert isinstance(model, HFTextRegressionModel), "model should be HFTextRegressionModel" if not transform_dataset_in_place: dataset = copy.deepcopy(dataset) model_input = model.prepare_inputs_for_inference( dataset=dataset, apply_chat_template=True, enable_distributed_inference=enable_distributed_inference, use_vllm=use_vllm, ) if use_vllm: inference_result = self.__vllm_inference( model=model, model_input=model_input, enable_distributed_inference=enable_distributed_inference, ) else: inference_result = self._inference( model=model, model_input=model_input, enable_distributed_inference=enable_distributed_inference, **kwargs, ) if enable_distributed_inference: output_dataset = model.postprocess_distributed_inference_outputs( dataset=dataset, inference_result=inference_result, ) else: output_dataset = model.postprocess_inference_outputs(dataset=dataset, scores=inference_result) return output_dataset def _inference( self, model: HFTextRegressionModel, model_input: Union[Dataset, "ray.data.Dataset"], enable_distributed_inference: bool = False, **kwargs, ): if enable_distributed_inference: if not is_ray_available(): raise ImportError('Ray is not installed. Please install via `pip install -e ".[ray]"`.') inference_res = self.__distributed_inference( model=model, model_input=model_input, num_instances=kwargs.get("distributed_inference_num_instances", 1), batch_size=kwargs.get("inference_batch_size", 1), ) else: inference_res = self.__inference( model=model, model_input=model_input, ) return inference_res def __inference( self, model: HFTextRegressionModel, model_input: Dataset, ) -> Union[list[float], list[list[float]]]: if model_input.get_type() in ["text_to_textlist"]: model_input_ids, num_outputs = self.flatten_list(model_input.get_backend_dataset()["input_ids"]) else: model_input_ids = model_input.get_backend_dataset()["input_ids"] dataloader = batchlize( examples=model_input_ids, batch_size=self.inferencer_args.inference_batch_size, random_shuffle=False, # DO NOT shuffle when inference ) num_batches = len(dataloader) final_output = [] for batch_index, batched_input_ids in tqdm( iterable=enumerate(dataloader), total=num_batches, desc="Inference", unit="batch" ): # len(batch) = batch_size, and batch element is dataset sample model_input_tensor = torch.LongTensor(batched_input_ids).to("cpu" if model.device == "cpu" else "cuda") if is_accelerate_env(): with self.accelerator.autocast(): batch_output = model.inference( inputs=model_input_tensor, use_vllm=False, ) else: batch_output = model.inference( inputs=model_input_tensor, use_vllm=False, ) batch_output = self.__post_process_model_output(batch_output) final_output.extend(batch_output) if model_input.get_type() in ["text_to_textlist"]: final_output = self.compress_list(final_output, num_outputs) return final_output def __distributed_inference( self, model: HFTextRegressionModel, model_input: "ray.data.Dataset", num_instances: int, batch_size: int, ) -> list[RewardModelInferenceResultWithInput]: def scheduling_strategy_fn(): # One bundle per tensor parallel worker pg = ray.util.placement_group( [{"GPU": 1, "CPU": 1}] * self.inferencer_args.tensor_parallel_size, strategy="STRICT_PACK", ) return dict( scheduling_strategy=PlacementGroupSchedulingStrategy(pg, placement_group_capture_child_tasks=True) ) resources_kwarg: dict[str, Any] = {} if self.inferencer_args.tensor_parallel_size == 1: # For tensor_parallel_size == 1, we simply set num_gpus=1. resources_kwarg["num_gpus"] = 1 else: # Otherwise, we have to set num_gpus=0 and provide # a function that will create a placement group for # each instance. resources_kwarg["num_gpus"] = 0 resources_kwarg["ray_remote_args_fn"] = scheduling_strategy_fn ## predictor class DistributedPredictor: def __init__( self, model_args: ModelArguments, ): self.model = HFTextRegressionModel( model_args=model_args, do_train=False, ) self.model.activate_model_for_inference(use_vllm=False) def __call__(self, batch: dict[str, np.ndarray]): """batch: dict[str, np.ndarray] Example (batch size=2): {'input': array(['...','...'], dtype=object), 'output': array([array(["...", "..."], dtype=object), array(["...", "..."], dtype=object),], dtype=object), 'input_ids': array([[[128000, 128006, 882, ..., 128256, 128256, 128256], [128000, 128006, 882, ..., 128256, 128256, 128256]], [[128000, 128006, 882, ..., 128256, 128256, 128256], [128000, 128006, 882, ..., 128256, 128256, 128256]]])} """ # The batch is managed by ray and the actual batch size may smaller than # inference_batch_size in config, since there may be some remainders. # For example, 10 examples with 2 inference instances and inference_batch_size=4, # there will be only 2 examples for instance 0 to run and then the # actual batch size changes. actual_batch_size = len(batch["input"]) input_tensor = ( torch.LongTensor( [[list(arr) for arr in batch["input_ids"][batch_idx]] for batch_idx in range(actual_batch_size)] ) .flatten(start_dim=0, end_dim=1) .to("cuda") ) batched_inference_res = self.model.inference(input_tensor).logits batched_inference_res = ( batched_inference_res.to("cpu").reshape(actual_batch_size, -1, 1).squeeze(dim=-1).tolist() ) # [bs, num_output_sequences] batched_final_res = { "input": batch["input"].tolist(), "output": [ [ {"score": batched_inference_res[j][i], "text": batch["output"][j][i]} for i in range(len(batch["output"][j])) ] for j in range(actual_batch_size) ], } # do this since we're writing to a pandas dataframe return batched_final_res # inference model_input_mapping = model_input.map_batches( DistributedPredictor, concurrency=num_instances, # Set the concurrency to the number of LLM instances. batch_size=batch_size, fn_constructor_kwargs={ "model_args": model.model_args, }, **resources_kwarg, ) df_model_output = model_input_mapping.to_pandas() # the actual forwards are executed here logger.info(f"Distributed reward model inference result preview:\n{df_model_output.head(10)}") model_output = [{"input": row["input"], "output": row["output"]} for _, row in df_model_output[:].iterrows()] return model_output def __vllm_inference( self, model: HFTextRegressionModel, model_input: list[str], enable_distributed_inference: bool = False, ) -> list[float]: raise NotImplementedError("VLLM inference for reward model is not implemented yet.") def __post_process_model_output( self, model_output: SequenceClassifierOutputWithPast, ) -> list[float]: final_output = model_output.logits.to("cpu").reshape(-1).tolist() return final_output def flatten_list(self, list_of_list: list[list]) -> tuple[list, list[int]]: sublist_lengths = [len(sublist) for sublist in list_of_list] flattened_list = [item for sublist in list_of_list for item in sublist] return flattened_list, sublist_lengths def compress_list(self, list_to_compress: list, sublist_lengths: list[int]) -> list[list]: assert sum(sublist_lengths) == len(list_to_compress), ( "Sum of sublist lengths should be equal to length of list to compress." ) compressed_list = [] start_index = 0 for length in sublist_lengths: sublist = list_to_compress[start_index : start_index + length] compressed_list.append(sublist) start_index += length return compressed_list ================================================ FILE: src/lmflow/pipeline/rm_tuner.py ================================================ import logging from copy import deepcopy import numpy as np from transformers.trainer_callback import TrainerCallback from lmflow.datasets import Dataset from lmflow.models.hf_text_regression_model import HFTextRegressionModel from lmflow.pipeline.finetuner import Finetuner from lmflow.pipeline.utils.rm_dataprocessor import RewardDataCollatorWithPadding from lmflow.pipeline.utils.rm_trainer import RewardTrainer, compute_metrics logger = logging.getLogger(__name__) class RewardModelTuner(Finetuner): """Initializes the `RewardModelTuner` class. Parameters ---------- model_args : ModelArguments object. Contains the arguments required to load the model. data_args : DatasetArguments object. Contains the arguments required to load the dataset. finetuner_args : RewardModelTunerArguments object. Contains the arguments required to perform finetuning. args : Optional. Positional arguments. kwargs : Optional. Keyword arguments. """ def __init__(self, model_args, data_args, finetuner_args, *args, **kwargs): super().__init__(model_args, data_args, finetuner_args, *args, **kwargs) def tune( self, model: HFTextRegressionModel, dataset, transform_dataset_in_place=True, data_collator=None, **kwargs ): # 0. basic init if not transform_dataset_in_place: dataset = deepcopy(dataset) # 1. prepare dataset with self.finetuner_args.main_process_first(desc="dataset map tokenization"): tokenized_dataset = model.tokenize(dataset) if self.data_args.disable_group_texts: lm_dataset = tokenized_dataset else: lm_dataset = self.group_text( tokenized_dataset, model_max_length=model.get_max_length(), ) train_dataset = lm_dataset.get_backend_dataset() logger.info(f"Number of train samples: {len(train_dataset)}") if self.finetuner_args.do_train and self.data_args.max_train_samples is not None: max_train_samples = min(len(train_dataset), self.data_args.max_train_samples) train_dataset = train_dataset.select(range(max_train_samples)) if self.finetuner_args.do_eval: eval_dataset_args = deepcopy(self.data_args) eval_dataset_args.dataset_path = self.finetuner_args.eval_dataset_path eval_dataset = Dataset(eval_dataset_args) with self.finetuner_args.main_process_first(desc="dataset map tokenization"): tokenized_dataset = model.tokenize(eval_dataset) if self.data_args.disable_group_texts: lm_dataset = tokenized_dataset else: lm_dataset = self.group_text( tokenized_dataset, model_max_length=model.get_max_length(), ) eval_dataset = lm_dataset.get_backend_dataset() logger.info(f"Number of eval samples: {len(eval_dataset)}") if data_collator is None: data_collator = RewardDataCollatorWithPadding( tokenizer=model.get_tokenizer(), max_length=self.model_args.model_max_length ) # 2. prepare trainer RewardModelingTrainer = RewardTrainer trainer_callbacks = [] if self.finetuner_args.use_lisa: class DynamicLayerActivationCallback(TrainerCallback): def __init__(self, n_layers, interval_steps, model, **kwargs): super().__init__() self.n_layers = n_layers self.interval_steps = interval_steps self.model = model # Determine the way to access layers based on the model type class_to_layers_map = { "LlamaForCausalLM": "model.model.layers", "Qwen2ForCausalLM": "model.model.layers", "MistralForCausalLM": "model.model.layers", "MixtralForCausalLM": "model.model.layers", "GemmaForCausalLM": "model.model.layers", "GPT2LMHeadModel": "model.transformer.h", } model_class_name = self.model.__class__.__name__ if model_class_name in class_to_layers_map: self.layers_attribute = class_to_layers_map[model_class_name] else: self.layers_attribute = kwargs.get("lisa_layers_attribute") self.total_layers = len( eval("self." + self.layers_attribute) ) # Dynamically execute to get the number of layers self.active_layers_indices = [] def freeze_all_layers(self): layers = eval("self." + self.layers_attribute) # Dynamically execute to get layers for layer in layers: for param in layer.parameters(): param.requires_grad = False def on_step_begin(self, args, state, control, **kwargs): # Check if it's time to switch active layers, including at step 0 if state.global_step % self.interval_steps == 0: self.switch_active_layers() def switch_active_layers(self): # First, disable gradients for all layers self.freeze_all_layers() # Randomly select n_layers to activate layers = eval("self." + self.layers_attribute) # Re-fetch layer references self.active_layers_indices = np.random.choice( range(self.total_layers), self.n_layers, replace=False ) print(f"Activating layers at indices: {self.active_layers_indices} for the next steps.", flush=True) # Enable gradients only for the selected layers for idx in self.active_layers_indices: for param in layers[idx].parameters(): param.requires_grad = True # Instantiate the callback dynamic_layer_activation_callback = DynamicLayerActivationCallback( n_layers=self.finetuner_args.lisa_activated_layers, # Number of layers to activate interval_steps=self.finetuner_args.lisa_interval_steps, # Step interval to update active layers model=model.get_backend_model(), lisa_layers_attribute=self.finetuner_args.lisa_layers_attribute, ) trainer_callbacks.append(dynamic_layer_activation_callback) trainer = RewardModelingTrainer( model=model.get_backend_model(), args=self.finetuner_args, train_dataset=train_dataset if self.finetuner_args.do_train else None, eval_dataset=eval_dataset if self.finetuner_args.do_eval else None, tokenizer=model.get_tokenizer(), data_collator=data_collator, compute_metrics=compute_metrics if self.finetuner_args.do_eval else None, callbacks=trainer_callbacks, ) # 3. training if self.finetuner_args.do_train: checkpoint = None last_checkpoint = self.last_checkpoint if self.finetuner_args.resume_from_checkpoint is not None: checkpoint = self.finetuner_args.resume_from_checkpoint elif last_checkpoint is not None: checkpoint = last_checkpoint if self.finetuner_args.gradient_checkpointing: if model.get_backend_model().config.use_cache: logger.warning( "Backend model config `use_cache=True` is incompatible with gradient checkpointing. " "Setting `use_cache=False`." ) model.get_backend_model().config.use_cache = False train_result = trainer.train(resume_from_checkpoint=checkpoint) trainer.save_model() # Saves the tokenizer too for easy upload metrics = train_result.metrics max_train_samples = ( self.data_args.max_train_samples if self.data_args.max_train_samples is not None else len(train_dataset) ) metrics["train_samples"] = min(max_train_samples, len(train_dataset)) trainer.log_metrics("train", metrics) trainer.save_metrics("train", metrics) trainer.save_state() kwargs = {"finetuned_from": self.model_args.model_name_or_path, "tasks": "reward-modeling"} if self.data_args.dataset_name is not None: kwargs["dataset_tags"] = self.data_args.dataset_name if self.data_args.dataset_config_name is not None: kwargs["dataset_args"] = self.data_args.dataset_config_name kwargs["dataset"] = f"{self.data_args.dataset_name} {self.data_args.dataset_config_name}" else: kwargs["dataset"] = self.data_args.dataset_name if self.finetuner_args.push_to_hub: trainer.push_to_hub(**kwargs) else: trainer.create_model_card(**kwargs) return model ================================================ FILE: src/lmflow/pipeline/sglang_inferencer.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import json import logging from typing import Optional, Union from transformers import AutoTokenizer from lmflow.args import ( DatasetArguments, InferencerArguments, ModelArguments, ) from lmflow.datasets import Dataset from lmflow.models.hf_decoder_model import HFDecoderModel from lmflow.pipeline.base_pipeline import BasePipeline from lmflow.utils.versioning import is_sglang_available from lmflow.utils.protocol import DataProto logger = logging.getLogger(__name__) if is_sglang_available(): pass else: raise ImportError("SGLang is not available, please install sglang using `pip install -e .[sglang]`.") class SGLangInferencer(BasePipeline): def __init__( self, model_args: ModelArguments, data_args: DatasetArguments, inferencer_args: InferencerArguments, ): assert inferencer_args.inference_engine == "sglang" self.model_args = model_args self.data_args = data_args self.inferencer_args = inferencer_args self.eos_token_id = AutoTokenizer.from_pretrained(model_args.model_name_or_path).eos_token_id self.sampling_params = self._parse_args_to_sampling_params(inferencer_args) def _parse_args_to_sampling_params( self, inference_args: InferencerArguments, ) -> dict: if inference_args.use_beam_search: logger.warning("`use_beam_search` is ignored, as SGLang does not support currently.") sampling_params = { "n": inference_args.num_output_sequences, "temperature": inference_args.temperature + 1e-6, "max_new_tokens": inference_args.max_new_tokens, "sampling_seed": inference_args.random_seed, "top_p": inference_args.top_p, "top_k": inference_args.top_k, "stop_token_ids": [self.eos_token_id] + inference_args.additional_stop_token_ids, } return sampling_params def inference( self, model: HFDecoderModel, dataset: Dataset, release_gpu: bool = False, inference_args: Optional[InferencerArguments] = None, ) -> DataProto: if inference_args: logger.warning("Overriding the default inference arguments with the provided arguments in .inference()") sampling_params = self._parse_args_to_sampling_params(inference_args) else: sampling_params = self.sampling_params # TODO: we need lmflow data sample protocol for better programming experience, data tracking, etc. model_input = model.prepare_inputs_for_inference( dataset=dataset, apply_chat_template=self.inferencer_args.apply_chat_template, inference_engine="sglang", sampling_params=sampling_params, ) outputs = model.inference( inputs=model_input, return_logprob=self.inferencer_args.return_logprob, release_gpu=release_gpu, inference_engine="sglang", gpu_memory_utilization=self.inferencer_args.inference_gpu_memory_utilization, tensor_parallel_size=self.inferencer_args.inference_tensor_parallel_size, enable_deterministic_inference=self.inferencer_args.enable_deterministic_inference, attention_backend=self.inferencer_args.attention_backend, ) if self.inferencer_args.save_inference_results: self.save_inference_results(outputs, self.inferencer_args.inference_results_path) return outputs def save_inference_results( self, outputs: DataProto, inference_results_path: str, ): if not inference_results_path.endswith(".pkl"): logger.warning(f"The inference results path must be a pickle file. Change the path to {inference_results_path}.pkl") inference_results_path = inference_results_path + ".pkl" outputs.save_to_disk(inference_results_path) logger.info(f"Inference results are saved to {inference_results_path}.") def load_inference_results( self, inference_results_path: str, ) -> DataProto: return DataProto.load_from_disk(inference_results_path) ================================================ FILE: src/lmflow/pipeline/utils/__init__.py ================================================ ================================================ FILE: src/lmflow/pipeline/utils/dpov2_dataprocessor.py ================================================ import logging from dataclasses import dataclass from typing import Any, Optional, Union import torch from torch.nn.utils.rnn import pad_sequence from transformers import ( PreTrainedModel, PreTrainedTokenizerBase, ) logger = logging.getLogger(__name__) @dataclass class PreferenceDataCollatorWithPadding: tokenizer: PreTrainedTokenizerBase model: Optional[PreTrainedModel] = None padding: Union[bool, str] = True max_length: Optional[int] = None max_prompt_length: Optional[int] = None label_pad_token_id: int = -100 padding_value: int = 0 truncation_mode: str = "keep_end" is_encoder_decoder: Optional[bool] = False max_target_length: Optional[int] = None mask_prompt: Optional[bool] = False def tokenize_batch_element( self, prompt: str, chosen: str, rejected: str, ) -> dict[str, Any]: """Tokenize a single batch element. At this stage, we don't convert to PyTorch tensors yet; we just handle the truncation in case the prompt + chosen or prompt + rejected responses is/are too long. First we truncate the prompt; if we're still too long, we truncate the chosen/rejected. We also create the labels for the chosen/rejected responses, which are of length equal to the sum of the length of the prompt and the chosen/rejected response, with label_pad_token_id for the prompt tokens. """ batch = {} if self.is_encoder_decoder: raise NotImplementedError chosen_tokens = self.tokenizer(chosen, add_special_tokens=False) rejected_tokens = self.tokenizer(rejected, add_special_tokens=False) prompt_tokens = self.tokenizer(prompt, add_special_tokens=False) eos_token_id = self.tokenizer.eos_token_id # Get indices in list prompt_tokens["input_ids"] that equals the EOS token (often 0) eos_indices_prompt = [i for i, x in enumerate(prompt_tokens["input_ids"]) if x == eos_token_id] # attention mask these indices to eos_token_id if self.mask_prompt: new_attention_mask = [0 for i, p in enumerate(prompt_tokens["attention_mask"])] else: new_attention_mask = [ 0 if i in eos_indices_prompt else p for i, p in enumerate(prompt_tokens["attention_mask"]) ] prompt_tokens["attention_mask"] = new_attention_mask # do the same for chosen and rejected eos_indices_chosen = [i for i, x in enumerate(chosen_tokens["input_ids"]) if x == eos_token_id] new_attention_mask_c = [ 0 if i in eos_indices_chosen else p for i, p in enumerate(chosen_tokens["attention_mask"]) ] chosen_tokens["attention_mask"] = new_attention_mask_c eos_indices_rejected = [i for i, x in enumerate(rejected_tokens["input_ids"]) if x == eos_token_id] new_attention_mask_r = [ 0 if i in eos_indices_rejected else p for i, p in enumerate(rejected_tokens["attention_mask"]) ] rejected_tokens["attention_mask"] = new_attention_mask_r # add EOS token to end of prompt chosen_tokens["input_ids"].append(self.tokenizer.eos_token_id) chosen_tokens["attention_mask"].append(1) rejected_tokens["input_ids"].append(self.tokenizer.eos_token_id) rejected_tokens["attention_mask"].append(1) longer_response_length = max(len(chosen_tokens["input_ids"]), len(rejected_tokens["input_ids"])) # if combined sequence is too long, truncate the prompt if len(prompt_tokens["input_ids"]) + longer_response_length > self.max_length: if self.truncation_mode == "keep_start": prompt_tokens = {k: v[: self.max_prompt_length] for k, v in prompt_tokens.items()} elif self.truncation_mode == "keep_end": prompt_tokens = {k: v[-self.max_prompt_length :] for k, v in prompt_tokens.items()} else: raise ValueError(f"Unknown truncation mode: {self.truncation_mode}") # if that's still too long, truncate the response if len(prompt_tokens["input_ids"]) + longer_response_length > self.max_length: chosen_tokens = {k: v[: self.max_length - self.max_prompt_length] for k, v in chosen_tokens.items()} rejected_tokens = {k: v[: self.max_length - self.max_prompt_length] for k, v in rejected_tokens.items()} # Create labels chosen_sequence_tokens = {k: prompt_tokens[k] + chosen_tokens[k] for k in chosen_tokens} rejected_sequence_tokens = {k: prompt_tokens[k] + rejected_tokens[k] for k in rejected_tokens} chosen_sequence_tokens["labels"] = chosen_sequence_tokens["input_ids"][:] chosen_sequence_tokens["labels"][: len(prompt_tokens["input_ids"])] = [self.label_pad_token_id] * len( prompt_tokens["input_ids"] ) rejected_sequence_tokens["labels"] = rejected_sequence_tokens["input_ids"][:] rejected_sequence_tokens["labels"][: len(prompt_tokens["input_ids"])] = [self.label_pad_token_id] * len( prompt_tokens["input_ids"] ) for k, toks in { "chosen": chosen_sequence_tokens, "rejected": rejected_sequence_tokens, "prompt": prompt_tokens, }.items(): for type_key, tokens in toks.items(): if type_key == "token_type_ids": continue batch[f"{k}_{type_key}"] = tokens batch["prompt"] = prompt batch["chosen"] = prompt + chosen batch["rejected"] = prompt + rejected batch["chosen_response_only"] = chosen batch["rejected_response_only"] = rejected return batch def collate(self, batch): # first, pad everything to the same length padded_batch = {} for k in batch[0].keys(): if k.endswith("_input_ids") or k.endswith("_attention_mask") or k.endswith("_labels"): if self.is_encoder_decoder: to_pad = [torch.LongTensor(ex[k]) for ex in batch] if (k.startswith("prompt")) and (k.endswith("input_ids")): padding_value = self.tokenizer.pad_token_id elif k.endswith("_attention_mask"): padding_value = 0 elif (k.startswith("chosen")) or (k.startswith("rejected")) or ("decoder" in k): padding_value = self.label_pad_token_id else: raise ValueError(f"Unexpected key in batch '{k}'") padded_batch[k] = pad_sequence(to_pad, batch_first=True, padding_value=padding_value) else: # adapted from https://stackoverflow.com/questions/73256206 if "prompt" in k: to_pad = [torch.LongTensor(ex[k][::-1]) for ex in batch] else: to_pad = [torch.LongTensor(ex[k]) for ex in batch] if k.endswith("_input_ids"): padding_value = self.tokenizer.pad_token_id elif k.endswith("_labels"): padding_value = self.label_pad_token_id elif k.endswith("_attention_mask"): padding_value = self.padding_value else: raise ValueError(f"Unexpected key in batch '{k}'") padded_batch[k] = pad_sequence(to_pad, batch_first=True, padding_value=padding_value) # for the prompt, flip back so padding is on left side if "prompt" in k: padded_batch[k] = padded_batch[k].flip(dims=[1]) else: padded_batch[k] = [ex[k] for ex in batch] return padded_batch def __call__(self, features: list[dict[str, Any]]) -> dict[str, Any]: tokenized_batch = [] for feature in features: prompt = feature["prompt"] chosen = feature["chosen"] rejected = feature["rejected"] batch_element = self.tokenize_batch_element(prompt, chosen, rejected) batch_element["margin"] = feature["margin"] tokenized_batch.append(batch_element) # return collated batch return self.collate(tokenized_batch) ================================================ FILE: src/lmflow/pipeline/utils/dpov2_trainer.py ================================================ import logging from typing import Callable, Literal, Optional, Union import torch import torch.nn as nn import torch.nn.functional as F from datasets import Dataset from transformers import ( DataCollator, PreTrainedModel, PreTrainedTokenizerBase, TrainingArguments, ) from transformers.trainer_callback import TrainerCallback from transformers.trainer_utils import EvalLoopOutput from lmflow.pipeline.utils.dpov2_dataprocessor import PreferenceDataCollatorWithPadding from lmflow.utils.versioning import is_trl_available if is_trl_available(): from trl import DPOTrainer else: raise ImportError("Please install trl package to use dpo_aligner.py") logger = logging.getLogger(__name__) class DPOv2Trainer(DPOTrainer): def __init__( self, model: Union[PreTrainedModel, nn.Module], ref_model: Optional[Union[PreTrainedModel, nn.Module]] = None, beta: float = 0.1, loss_type: Literal["sigmoid", "hinge", "cross_entropy", "kl", "rev_kl", "raft"] = "rev_kl", args: TrainingArguments = None, data_collator: Optional[DataCollator] = None, label_pad_token_id: int = -100, padding_value: int = 0, truncation_mode: str = "keep_end", train_dataset: Optional[Dataset] = None, eval_dataset: Optional[Union[Dataset, dict[str, Dataset]]] = None, tokenizer: Optional[PreTrainedTokenizerBase] = None, model_init: Optional[Callable[[], PreTrainedModel]] = None, callbacks: Optional[list[TrainerCallback]] = None, optimizers: tuple[Optional[torch.optim.Optimizer], Optional[torch.optim.lr_scheduler.LambdaLR]] = (None, None), preprocess_logits_for_metrics: Optional[Callable[[torch.Tensor, torch.Tensor], torch.Tensor]] = None, max_length: Optional[int] = None, max_prompt_length: Optional[int] = None, max_target_length: Optional[int] = None, peft_config: Optional[dict] = None, is_encoder_decoder: Optional[bool] = None, disable_dropout: bool = True, generate_during_eval: bool = False, compute_metrics: Optional[Callable[[EvalLoopOutput], dict]] = None, mask_prompt: Optional[bool] = False, len_penalty: float = 0, preprocessing_num_workers: int = 1, ): if data_collator is None: data_collator = PreferenceDataCollatorWithPadding( tokenizer, max_length=max_length, max_prompt_length=max_prompt_length, label_pad_token_id=label_pad_token_id, padding_value=padding_value, truncation_mode=truncation_mode, is_encoder_decoder=False, max_target_length=max_target_length, mask_prompt=mask_prompt, ) super().__init__( model=model, ref_model=ref_model, beta=beta, loss_type=loss_type, args=args, data_collator=data_collator, label_pad_token_id=label_pad_token_id, padding_value=padding_value, truncation_mode=truncation_mode, train_dataset=train_dataset, eval_dataset=eval_dataset, tokenizer=tokenizer, model_init=model_init, callbacks=callbacks, optimizers=optimizers, preprocess_logits_for_metrics=preprocess_logits_for_metrics, max_length=max_length, max_prompt_length=max_prompt_length, max_target_length=max_target_length, peft_config=peft_config, is_encoder_decoder=is_encoder_decoder, disable_dropout=disable_dropout, generate_during_eval=generate_during_eval, compute_metrics=compute_metrics, dataset_num_proc=preprocessing_num_workers, ) self.use_dpo_data_collator = True self.len_penalty = len_penalty def dpo_loss( self, policy_chosen_logps: torch.FloatTensor, policy_rejected_logps: torch.FloatTensor, reference_chosen_logps: torch.FloatTensor, reference_rejected_logps: torch.FloatTensor, reference_free: bool = False, margin: Optional[torch.FloatTensor] = None, len_penalty: float = 0, ) -> tuple[torch.FloatTensor, torch.FloatTensor, torch.FloatTensor]: """Compute the DPO loss for a batch of policy and reference model log probabilities. Args: policy_chosen_logps: Log probabilities of the policy model for the chosen responses. Shape: (batch_size,) policy_rejected_logps: Log probabilities of the policy model for the rejected responses. Shape: (batch_size,) reference_chosen_logps: Log probabilities of the reference model for the chosen responses. Shape: (batch_size,) reference_rejected_logps: Log probabilities of the reference model for the rejected responses. Shape: (batch_size,) beta: Temperature parameter for the DPO loss, typically something in the range of 0.1 to 0.5. We ignore the reference model as beta -> 0. reference_free: If True, we ignore the _provided_ reference model and implicitly use a reference model that assigns equal probability to all responses. Returns: A tuple of three tensors: (losses, chosen_rewards, rejected_rewards). The losses tensor contains the DPO loss for each example in the batch. The chosen_rewards and rejected_rewards tensors contain the rewards for the chosen and rejected responses, respectively. """ pi_logratios = policy_chosen_logps - policy_rejected_logps ref_logratios = reference_chosen_logps - reference_rejected_logps + len_penalty if reference_free: ref_logratios = 0 if self.loss_type == "sigmoid": logits = pi_logratios - ref_logratios losses = -F.logsigmoid(self.beta * logits) elif self.loss_type == "hinge": logits = pi_logratios - ref_logratios losses = torch.relu(1 - self.beta * logits) elif self.loss_type == "cross_entropy": logits = policy_chosen_logps - reference_chosen_logps losses = -F.logsigmoid(self.beta * logits) elif self.loss_type == "raft": losses = -policy_chosen_logps # F.logsigmoid(self.beta * logits) elif self.loss_type == "ipo": logits = pi_logratios - ref_logratios # eqn (17) of the paper where beta is the regularization parameter for the IPO loss, # denoted by tau in the paper. losses = (logits - 1 / (2 * self.beta)) ** 2 elif self.loss_type == "kl": logits = pi_logratios - ref_logratios p = F.sigmoid(self.beta * logits) p = torch.minimum(p, torch.ones_like(p) * 0.999) p_gt = torch.exp(margin) / (1 + torch.exp(margin) + 1e-3) losses = p * (torch.log(p) - torch.log(p_gt)) + (1 - p) * (torch.log(1 - p) - torch.log(1 - p_gt)) elif self.loss_type == "tv": logits = pi_logratios - ref_logratios p = F.sigmoid(self.beta * logits) p_gt = torch.exp(margin) / (1 + torch.exp(margin)) losses = torch.abs(p - p_gt) elif self.loss_type == "hellinger": logits = pi_logratios - ref_logratios p = F.sigmoid(self.beta * logits) p = torch.minimum(p, torch.ones_like(p) * 0.999) p_gt = torch.exp(margin) / (1 + torch.exp(margin)) losses = 0.5 * ((p**0.5 - p_gt**0.5) ** 2 + ((1 - p) ** 0.5 - (1 - p_gt) ** 0.5) ** 2) elif self.loss_type == "rev_kl": logits = pi_logratios - ref_logratios logp = F.logsigmoid(self.beta * logits) logp_neg = F.logsigmoid(-self.beta * logits) p_gt = F.sigmoid(margin) losses = -p_gt * (logp) - (1 - p_gt) * logp_neg else: raise ValueError(f"Unknown loss type: {self.loss_type}.") chosen_rewards = self.beta * (policy_chosen_logps - reference_chosen_logps).detach() rejected_rewards = self.beta * (policy_rejected_logps - reference_rejected_logps).detach() return losses, chosen_rewards, rejected_rewards def get_batch_loss_metrics( self, model, batch: dict[str, Union[list, torch.LongTensor]], train_eval: Literal["train", "eval"] = "train", ): return self.get_batch_metrics(model, batch, train_eval) def get_batch_metrics( self, model, batch: dict[str, Union[list, torch.LongTensor]], train_eval: Literal["train", "eval"] = "train", ): """Compute the DPO loss and other metrics for the given batch of inputs for train or test.""" metrics = {} ( policy_chosen_logps, policy_rejected_logps, policy_chosen_logits, policy_rejected_logits, ) = self.concatenated_forward(model, batch) with torch.no_grad(): if self.ref_model is None: with self.accelerator.unwrap_model(self.model).disable_adapter(): ( reference_chosen_logps, reference_rejected_logps, _, _, ) = self.concatenated_forward(self.model, batch) else: ( reference_chosen_logps, reference_rejected_logps, _, _, ) = self.concatenated_forward(self.ref_model, batch) if self.len_penalty > 0: chosen_len = batch["chosen_input_ids"].shape[1] * self.len_penalty rejected_len = batch["rejected_input_ids"].shape[1] * self.len_penalty len_penalty = chosen_len - rejected_len else: chosen_len = 1 rejected_len = 1 len_penalty = 0 margin = torch.tensor(batch["margin"], dtype=policy_chosen_logps.dtype).to(self.accelerator.device) losses, chosen_rewards, rejected_rewards = self.dpo_loss( policy_chosen_logps, policy_rejected_logps, reference_chosen_logps, reference_rejected_logps, margin=margin, len_penalty=len_penalty, ) reward_accuracies = (chosen_rewards > rejected_rewards).float() prefix = "eval_" if train_eval == "eval" else "" metrics[f"{prefix}rewards/chosen"] = chosen_rewards.cpu().mean() metrics[f"{prefix}rewards/rejected"] = rejected_rewards.cpu().mean() metrics[f"{prefix}rewards/accuracies"] = reward_accuracies.cpu().mean() metrics[f"{prefix}rewards/margins"] = (chosen_rewards - rejected_rewards).cpu().mean() metrics[f"{prefix}logps/rejected"] = policy_rejected_logps.detach().cpu().mean() metrics[f"{prefix}logps/chosen"] = policy_chosen_logps.detach().cpu().mean() metrics[f"{prefix}logits/rejected"] = policy_rejected_logits.detach().cpu().mean() metrics[f"{prefix}logits/chosen"] = policy_chosen_logits.detach().cpu().mean() return losses.mean(), metrics ================================================ FILE: src/lmflow/pipeline/utils/lisa_trainer.py ================================================ from typing import Optional import numpy as np from transformers import PreTrainedModel from transformers.trainer_callback import TrainerCallback class DynamicLayerActivationCallback(TrainerCallback): def __init__( self, n_layers: int, interval_steps: int, model: PreTrainedModel, lisa_layers_attribute: Optional[str] = None, ): super().__init__() self.n_layers = n_layers self.interval_steps = interval_steps self.model = model # Determine the way to access layers based on the model type class_to_layers_map = { "LlamaForCausalLM": "model.model.layers", "Qwen2ForCausalLM": "model.model.layers", "MistralForCausalLM": "model.model.layers", "MixtralForCausalLM": "model.model.layers", "GemmaForCausalLM": "model.model.layers", "GPT2LMHeadModel": "model.transformer.h", "HymbaForCausalLM": "model.model.layers", } model_class_name = self.model.__class__.__name__ if model_class_name in class_to_layers_map: self.layers_attribute = class_to_layers_map[model_class_name] else: assert lisa_layers_attribute is not None, "Please provide the attribute to access the layers of the model." self.layers_attribute = lisa_layers_attribute self.total_layers = len( eval("self." + self.layers_attribute) ) # Dynamically execute to get the number of layers self.active_layers_indices = [] def freeze_all_layers(self): layers = eval("self." + self.layers_attribute) # Dynamically execute to get layers for layer in layers: for param in layer.parameters(): param.requires_grad = False def on_step_begin(self, args, state, control, **kwargs): # Check if it's time to switch active layers, including at step 0 if state.global_step % self.interval_steps == 0: self.switch_active_layers() def switch_active_layers(self): # First, disable gradients for all layers self.freeze_all_layers() # Randomly select n_layers to activate layers = eval("self." + self.layers_attribute) # Re-fetch layer references self.active_layers_indices = np.random.choice(range(self.total_layers), self.n_layers, replace=False) print(f"Activating layers at indices: {self.active_layers_indices} for the next steps.", flush=True) # Enable gradients only for the selected layers for idx in self.active_layers_indices: for param in layers[idx].parameters(): param.requires_grad = True ================================================ FILE: src/lmflow/pipeline/utils/memory_safe_dpov2_align.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import copy import logging from transformers import HfArgumentParser from lmflow.args import ( DatasetArguments, DPOv2AlignerArguments, ModelArguments, ) from lmflow.datasets import Dataset from lmflow.models.hf_decoder_model import HFDecoderModel from lmflow.pipeline.dpov2_aligner import DPOv2Aligner from lmflow.utils.common import create_copied_dataclass, remove_dataclass_attr_prefix logger = logging.getLogger(__name__) ReferenceModelArguments: ModelArguments = create_copied_dataclass( original_dataclass=ModelArguments, field_prefix="reference_", class_prefix="Reference" ) def main(): # Parses arguments parser = HfArgumentParser( ( ModelArguments, ReferenceModelArguments, DatasetArguments, DPOv2AlignerArguments, ) ) target_model_args, ref_model_args, data_args, aligner_args = parser.parse_args_into_dataclasses() ref_model_args_dict = remove_dataclass_attr_prefix(ref_model_args, "reference_") ref_model_args = ModelArguments(**ref_model_args_dict) target_model = HFDecoderModel(target_model_args) ref_model = HFDecoderModel(ref_model_args) train_dataset = Dataset(data_args) eval_dataset = copy.deepcopy(train_dataset.sample(n=100, seed=aligner_args.random_seed)) aligner = DPOv2Aligner( model_args=target_model_args, data_args=train_dataset.data_args, aligner_args=aligner_args, ref_model_args=ref_model.model_args, ) aligner.align( model=target_model, ref_model=ref_model, train_dataset=train_dataset, eval_dataset=eval_dataset, ) if __name__ == "__main__": main() ================================================ FILE: src/lmflow/pipeline/utils/memory_safe_vllm_inference.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. # Note that this is only a workaround, since vllm # inference engine cannot release GPU memory properly by now. Please see this github # [issue](https://github.com/vllm-project/vllm/issues/1908). import logging import os import sys from transformers import HfArgumentParser from lmflow.args import ( AutoArguments, DatasetArguments, ModelArguments, ) from lmflow.datasets import Dataset from lmflow.models.auto_model import AutoModel from lmflow.pipeline.vllm_inferencer import VLLMInferencer from lmflow.utils.constants import MEMORY_SAFE_VLLM_INFERENCE_FINISH_FLAG logger = logging.getLogger(__name__) def main(): # Parses arguments pipeline_name = "vllm_inferencer" PipelineArguments = AutoArguments.get_pipeline_args_class(pipeline_name) parser = HfArgumentParser((ModelArguments, DatasetArguments, PipelineArguments)) if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): # If we pass only one argument to the script and it's the path to a json file, # let's parse it to get our arguments. model_args, data_args, pipeline_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) else: model_args, data_args, pipeline_args = parser.parse_args_into_dataclasses() dataset = Dataset(data_args) model = AutoModel.get_model(model_args, do_train=False) inferencer = VLLMInferencer(model_args, data_args, pipeline_args) res = inferencer.inference( model, dataset, release_gpu=False, enable_decode_inference_result=pipeline_args.enable_decode_inference_result, enable_distributed_inference=pipeline_args.enable_distributed_inference, distributed_inference_num_instances=pipeline_args.distributed_inference_num_instances, inference_batch_size=pipeline_args.vllm_inference_batch_size, ) print(len(res)) # use this as a flag, stdout will be captured by the pipeline print(MEMORY_SAFE_VLLM_INFERENCE_FINISH_FLAG) if __name__ == "__main__": main() ================================================ FILE: src/lmflow/pipeline/utils/raft_trainer.py ================================================ import contextlib import functools import glob import inspect import math import os import random import re import shutil import sys import time import warnings from collections.abc import Mapping from distutils.util import strtobool from pathlib import Path from typing import Any, Callable, Optional, Union # Integrations must be imported before ML frameworks: # isort: off ### Fix the import bug in the latest version try: from transformers.integrations import ( default_hp_search_backend, get_reporting_integration_callbacks, hp_params, is_fairscale_available, is_optuna_available, is_ray_tune_available, is_sigopt_available, is_wandb_available, run_hp_search_optuna, run_hp_search_ray, run_hp_search_sigopt, run_hp_search_wandb, ) except ImportError: from transformers.integrations import ( get_reporting_integration_callbacks, hp_params, is_fairscale_available, ) from transformers.hyperparameter_search import default_hp_search_backend, ALL_HYPERPARAMETER_SEARCH_BACKENDS # isort: on import numpy as np import torch import torch.distributed as dist from huggingface_hub import Repository, create_repo from packaging import version from torch import nn from torch.utils.data import DataLoader, Dataset, RandomSampler, SequentialSampler from torch.utils.data.distributed import DistributedSampler from transformers.configuration_utils import PretrainedConfig from transformers.data.data_collator import DataCollator, DataCollatorWithPadding, default_data_collator from transformers.debug_utils import DebugOption, DebugUnderflowOverflow from transformers.dependency_versions_check import dep_version_check from transformers.modelcard import TrainingSummary from transformers.modeling_utils import PreTrainedModel, load_sharded_checkpoint, unwrap_model from transformers.models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING_NAMES, MODEL_MAPPING_NAMES from transformers.optimization import Adafactor, get_scheduler from transformers.pytorch_utils import ALL_LAYERNORM_LAYERS is_torch_greater_or_equal_than_1_10 = version.parse(torch.__version__) >= version.parse("1.10") is_torch_less_than_1_11 = version.parse(torch.__version__) < version.parse("1.11") from transformers.tokenization_utils_base import PreTrainedTokenizerBase from transformers.trainer_callback import ( CallbackHandler, DefaultFlowCallback, PrinterCallback, ProgressCallback, TrainerCallback, TrainerControl, TrainerState, ) from transformers.trainer_pt_utils import ( DistributedLengthGroupedSampler, DistributedSamplerWithLoop, DistributedTensorGatherer, IterableDatasetShard, LabelSmoother, LengthGroupedSampler, SequentialDistributedSampler, ShardSampler, distributed_broadcast_scalars, distributed_concat, find_batch_size, get_module_class_from_name, get_parameter_names, nested_concat, nested_detach, nested_numpify, nested_truncate, nested_xla_mesh_reduce, reissue_pt_warnings, ) from transformers.trainer_utils import ( PREFIX_CHECKPOINT_DIR, BestRun, EvalLoopOutput, EvalPrediction, FSDPOption, HPSearchBackend, HubStrategy, IntervalStrategy, PredictionOutput, RemoveColumnsCollator, ShardedDDPOption, TrainerMemoryTracker, TrainOutput, default_compute_objective, denumpify_detensorize, enable_full_determinism, find_executable_batch_size, get_last_checkpoint, has_length, number_of_arguments, seed_worker, set_seed, speed_metrics, ) from transformers.training_args import OptimizerNames, ParallelMode, TrainingArguments from transformers.utils import ( CONFIG_NAME, WEIGHTS_INDEX_NAME, WEIGHTS_NAME, can_return_loss, find_labels, get_full_repo_name, is_apex_available, is_datasets_available, is_in_notebook, is_ipex_available, is_sagemaker_dp_enabled, is_sagemaker_mp_enabled, is_torch_compile_available, is_torch_neuroncore_available, is_torch_tpu_available, logging, ) from transformers.utils.generic import ContextManagers from lmflow.utils.versioning import is_package_version_at_least if is_package_version_at_least("transformers", "4.46.0"): from transformers.integrations.deepspeed import deepspeed_init, is_deepspeed_zero3_enabled else: from transformers.deepspeed import deepspeed_init, is_deepspeed_zero3_enabled _is_native_cpu_amp_available = is_torch_greater_or_equal_than_1_10 DEFAULT_CALLBACKS = [DefaultFlowCallback] DEFAULT_PROGRESS_CALLBACK = ProgressCallback if is_in_notebook(): from transformers.utils.notebook import NotebookProgressCallback DEFAULT_PROGRESS_CALLBACK = NotebookProgressCallback if is_apex_available(): from apex import amp if is_datasets_available(): import datasets if is_torch_tpu_available(check_device=False): import torch_xla.core.xla_model as xm import torch_xla.debug.metrics as met import torch_xla.distributed.parallel_loader as pl if is_fairscale_available(): dep_version_check("fairscale") import fairscale from fairscale.nn.data_parallel import FullyShardedDataParallel as FullyShardedDDP from fairscale.nn.data_parallel import ShardedDataParallel as ShardedDDP from fairscale.nn.wrap import auto_wrap from fairscale.optim import OSS from fairscale.optim.grad_scaler import ShardedGradScaler if is_sagemaker_mp_enabled(): import smdistributed.modelparallel.torch as smp from smdistributed.modelparallel import __version__ as SMP_VERSION IS_SAGEMAKER_MP_POST_1_10 = version.parse(SMP_VERSION) >= version.parse("1.10") from transformers.trainer_pt_utils import smp_forward_backward, smp_forward_only, smp_gather, smp_nested_concat else: IS_SAGEMAKER_MP_POST_1_10 = False skip_first_batches = None logger = logging.get_logger(__name__) # Name of the files used for checkpointing TRAINING_ARGS_NAME = "training_args.bin" TRAINER_STATE_NAME = "trainer_state.json" OPTIMIZER_NAME = "optimizer.pt" SCHEDULER_NAME = "scheduler.pt" SCALER_NAME = "scaler.pt" class RaftTrainer: """ Trainer is a simple but feature-complete training and eval loop for PyTorch, optimized for 🤗 Transformers. Args: model ([`PreTrainedModel`] or `torch.nn.Module`, *optional*): The model to train, evaluate or use for predictions. If not provided, a `model_init` must be passed. [`Trainer`] is optimized to work with the [`PreTrainedModel`] provided by the library. You can still use your own models defined as `torch.nn.Module` as long as they work the same way as the 🤗 Transformers models. args ([`TrainingArguments`], *optional*): The arguments to tweak for training. Will default to a basic instance of [`TrainingArguments`] with the `output_dir` set to a directory named *tmp_trainer* in the current directory if not provided. data_collator (`DataCollator`, *optional*): The function to use to form a batch from a list of elements of `train_dataset` or `eval_dataset`. Will default to [`default_data_collator`] if no `tokenizer` is provided, an instance of [`DataCollatorWithPadding`] otherwise. train_dataset (`torch.utils.data.Dataset` or `torch.utils.data.IterableDataset`, *optional*): The dataset to use for training. If it is a [`~datasets.Dataset`], columns not accepted by the `model.forward()` method are automatically removed. Note that if it's a `torch.utils.data.IterableDataset` with some randomization and you are training in a distributed fashion, your iterable dataset should either use a internal attribute `generator` that is a `torch.Generator` for the randomization that must be identical on all processes (and the Trainer will manually set the seed of this `generator` at each epoch) or have a `set_epoch()` method that internally sets the seed of the RNGs used. eval_dataset (Union[`torch.utils.data.Dataset`, dict[str, `torch.utils.data.Dataset`]), *optional*): The dataset to use for evaluation. If it is a [`~datasets.Dataset`], columns not accepted by the `model.forward()` method are automatically removed. If it is a dictionary, it will evaluate on each dataset prepending the dictionary key to the metric name. tokenizer ([`PreTrainedTokenizerBase`], *optional*): The tokenizer used to preprocess the data. If provided, will be used to automatically pad the inputs to the maximum length when batching inputs, and it will be saved along the model to make it easier to rerun an interrupted training or reuse the fine-tuned model. model_init (`Callable[[], PreTrainedModel]`, *optional*): A function that instantiates the model to be used. If provided, each call to [`~Trainer.train`] will start from a new instance of the model as given by this function. The function may have zero argument, or a single one containing the optuna/Ray Tune/SigOpt trial object, to be able to choose different architectures according to hyper parameters (such as layer count, sizes of inner layers, dropout probabilities etc). compute_metrics (`Callable[[EvalPrediction], dict]`, *optional*): The function that will be used to compute metrics at evaluation. Must take a [`EvalPrediction`] and return a dictionary string to metric values. callbacks (list of [`TrainerCallback`], *optional*): A list of callbacks to customize the training loop. Will add those to the list of default callbacks detailed in [here](callback). If you want to remove one of the default callbacks used, use the [`Trainer.remove_callback`] method. optimizers (`tuple[torch.optim.Optimizer, torch.optim.lr_scheduler.LambdaLR]`, *optional*): A tuple containing the optimizer and the scheduler to use. Will default to an instance of [`AdamW`] on your model and a scheduler given by [`get_linear_schedule_with_warmup`] controlled by `args`. preprocess_logits_for_metrics (`Callable[[torch.Tensor, torch.Tensor], torch.Tensor]`, *optional*): A function that preprocess the logits right before caching them at each evaluation step. Must take two tensors, the logits and the labels, and return the logits once processed as desired. The modifications made by this function will be reflected in the predictions received by `compute_metrics`. Note that the labels (second parameter) will be `None` if the dataset does not have them. Important attributes: - **model** -- Always points to the core model. If using a transformers model, it will be a [`PreTrainedModel`] subclass. - **model_wrapped** -- Always points to the most external model in case one or more other modules wrap the original model. This is the model that should be used for the forward pass. For example, under `DeepSpeed`, the inner model is wrapped in `DeepSpeed` and then again in `torch.nn.DistributedDataParallel`. If the inner model hasn't been wrapped, then `self.model_wrapped` is the same as `self.model`. - **is_model_parallel** -- Whether or not a model has been switched to a model parallel mode (different from data parallelism, this means some of the model layers are split on different GPUs). - **place_model_on_device** -- Whether or not to automatically place the model on the device - it will be set to `False` if model parallel or deepspeed is used, or if the default `TrainingArguments.place_model_on_device` is overridden to return `False` . - **is_in_train** -- Whether or not a model is currently running `train` (e.g. when `evaluate` is called while in `train`) """ from transformers.trainer_pt_utils import _get_learning_rate, log_metrics, metrics_format, save_metrics, save_state def __init__( self, model: Union[PreTrainedModel, nn.Module] = None, args: TrainingArguments = None, data_collator: Optional[DataCollator] = None, train_dataset: Optional[Dataset] = None, eval_dataset: Optional[Union[Dataset, dict[str, Dataset]]] = None, tokenizer: Optional[PreTrainedTokenizerBase] = None, model_init: Optional[Callable[[], PreTrainedModel]] = None, compute_metrics: Optional[Callable[[EvalPrediction], dict]] = None, callbacks: Optional[list[TrainerCallback]] = None, optimizers: tuple[Optional[torch.optim.Optimizer], Optional[torch.optim.lr_scheduler.LambdaLR]] = (None, None), preprocess_logits_for_metrics: Optional[Callable[[torch.Tensor, torch.Tensor], torch.Tensor]] = None, ): ############ self.save_counter = 0 ############## if args is None: output_dir = "tmp_trainer" logger.info(f"No `TrainingArguments` passed, using `output_dir={output_dir}`.") args = TrainingArguments(output_dir=output_dir) self.args = args # Seed must be set before instantiating the model when using model enable_full_determinism(self.args.seed) if self.args.full_determinism else set_seed(self.args.seed) self.hp_name = None self.deepspeed = None self.is_in_train = False # memory metrics - must set up as early as possible self._memory_tracker = TrainerMemoryTracker(self.args.skip_memory_metrics) self._memory_tracker.start() # set the correct log level depending on the node log_level = args.get_process_log_level() logging.set_verbosity(log_level) # force device and distributed setup init explicitly args._setup_devices if model is None: if model_init is not None: self.model_init = model_init model = self.call_model_init() else: raise RuntimeError("`Trainer` requires either a `model` or `model_init` argument") else: if model_init is not None: warnings.warn( "`Trainer` requires either a `model` or `model_init` argument, but not both. `model_init` will" " overwrite your model when calling the `train` method. This will become a fatal error in the next" " release.", FutureWarning, ) self.model_init = model_init if model.__class__.__name__ in MODEL_MAPPING_NAMES: raise ValueError( f"The model you have picked ({model.__class__.__name__}) cannot be used as is for training: it only " "computes hidden states and does not accept any labels. You should choose a model with a head " "suitable for your task like any of the `AutoModelForXxx` listed at " "https://huggingface.co/docs/transformers/model_doc/auto." ) if hasattr(model, "is_parallelizable") and model.is_parallelizable and model.model_parallel: self.is_model_parallel = True else: self.is_model_parallel = False # At this stage the model is already loaded if getattr(model, "is_loaded_in_8bit", False): if getattr(model, "_is_int8_training_enabled", False): logger.info( "The model is loaded in 8-bit precision. To train this model you need to add additional modules" " inside the model such as adapters using `peft` library and freeze the model weights. Please" " check " " the examples in https://github.com/huggingface/peft for more details." ) else: raise ValueError( "The model you want to train is loaded in 8-bit precision. if you want to fine-tune an 8-bit" " model, please make sure that you have installed `bitsandbytes>=0.37.0`. " ) # Setup Sharded DDP training self.sharded_ddp = None if len(args.sharded_ddp) > 0: if args.deepspeed: raise ValueError( "Using --sharded_ddp xxx together with --deepspeed is not possible, deactivate one of those flags." ) if len(args.fsdp) > 0: raise ValueError( "Using --sharded_ddp xxx together with --fsdp is not possible, deactivate one of those flags." ) if args.local_rank == -1: raise ValueError("Using sharded DDP only works in distributed training.") elif not is_fairscale_available(): raise ImportError("Sharded DDP training requires fairscale: `pip install fairscale`.") elif ShardedDDPOption.SIMPLE not in args.sharded_ddp and FullyShardedDDP is None: raise ImportError( "Sharded DDP in a mode other than simple training requires fairscale version >= 0.3, found " f"{fairscale.__version__}. Upgrade your fairscale library: `pip install --upgrade fairscale`." ) elif ShardedDDPOption.SIMPLE in args.sharded_ddp: self.sharded_ddp = ShardedDDPOption.SIMPLE elif ShardedDDPOption.ZERO_DP_2 in args.sharded_ddp: self.sharded_ddp = ShardedDDPOption.ZERO_DP_2 elif ShardedDDPOption.ZERO_DP_3 in args.sharded_ddp: self.sharded_ddp = ShardedDDPOption.ZERO_DP_3 self.fsdp = None if len(args.fsdp) > 0: if args.deepspeed: raise ValueError( "Using --fsdp xxx together with --deepspeed is not possible, deactivate one of those flags." ) if not args.fsdp_config["xla"] and args.local_rank == -1: raise ValueError("Using fsdp only works in distributed training.") # dep_version_check("torch>=1.12.0") # Would have to update setup.py with torch>=1.12.0 # which isn't ideally given that it will force people not using FSDP to also use torch>=1.12.0 # below is the current alternative. if version.parse(version.parse(torch.__version__).base_version) < version.parse("1.12.0"): raise ValueError("FSDP requires PyTorch >= 1.12.0") from torch.distributed.fsdp.fully_sharded_data_parallel import BackwardPrefetch, ShardingStrategy if FSDPOption.FULL_SHARD in args.fsdp: self.fsdp = ShardingStrategy.FULL_SHARD elif FSDPOption.SHARD_GRAD_OP in args.fsdp: self.fsdp = ShardingStrategy.SHARD_GRAD_OP elif FSDPOption.NO_SHARD in args.fsdp: self.fsdp = ShardingStrategy.NO_SHARD self.backward_prefetch = BackwardPrefetch.BACKWARD_PRE if "backward_prefetch" in self.args.fsdp_config and "backward_pos" not in self.backward_prefetch: self.backward_prefetch = BackwardPrefetch.BACKWARD_POST self.forword_prefetch = False if self.args.fsdp_config.get("forword_prefect", False): self.forword_prefetch = True self.limit_all_gathers = False if self.args.fsdp_config.get("limit_all_gathers", False): self.limit_all_gathers = True # one place to sort out whether to place the model on device or not # postpone switching model to cuda when: # 1. MP - since we are trying to fit a much bigger than 1 gpu model # 2. fp16-enabled DeepSpeed loads the model in half the size and it doesn't need .to() anyway, # and we only use deepspeed for training at the moment # 3. full bf16 or fp16 eval - since the model needs to be cast to the right dtype first # 4. Sharded DDP - same as MP # 5. FSDP - same as MP self.place_model_on_device = args.place_model_on_device if ( self.is_model_parallel or args.deepspeed or ((args.fp16_full_eval or args.bf16_full_eval) and not args.do_train) or (self.sharded_ddp in [ShardedDDPOption.ZERO_DP_2, ShardedDDPOption.ZERO_DP_3]) or (self.fsdp is not None) ): self.place_model_on_device = False default_collator = default_data_collator if tokenizer is None else DataCollatorWithPadding(tokenizer) self.data_collator = data_collator if data_collator is not None else default_collator self.train_dataset = train_dataset self.eval_dataset = eval_dataset self.tokenizer = tokenizer if self.place_model_on_device and not getattr(model, "is_loaded_in_8bit", False): self._move_model_to_device(model, args.device) # Force n_gpu to 1 to avoid DataParallel as MP will manage the GPUs if self.is_model_parallel: self.args._n_gpu = 1 # later use `self.model is self.model_wrapped` to check if it's wrapped or not self.model_wrapped = model self.model = model self.compute_metrics = compute_metrics self.preprocess_logits_for_metrics = preprocess_logits_for_metrics self.optimizer, self.lr_scheduler = optimizers if model_init is not None and (self.optimizer is not None or self.lr_scheduler is not None): raise RuntimeError( "Passing a `model_init` is incompatible with providing the `optimizers` argument. " "You should subclass `Trainer` and override the `create_optimizer_and_scheduler` method." ) if is_torch_tpu_available() and self.optimizer is not None: for param in self.model.parameters(): model_device = param.device break for param_group in self.optimizer.param_groups: if len(param_group["params"]) > 0: optimizer_device = param_group["params"][0].device break if model_device != optimizer_device: raise ValueError( "The model and the optimizer parameters are not on the same device, which probably means you" " created an optimizer around your model **before** putting on the device and passing it to the" " `Trainer`. Make sure the lines `import torch_xla.core.xla_model as xm` and" " `model.to(xm.xla_device())` is performed before the optimizer creation in your script." ) if ((self.sharded_ddp is not None) or args.deepspeed or (self.fsdp is not None)) and ( self.optimizer is not None or self.lr_scheduler is not None ): raise RuntimeError( "Passing `optimizers` is not allowed if Fairscale, Deepspeed or PyTorch FSDP is enabled." "You should subclass `Trainer` and override the `create_optimizer_and_scheduler` method." ) default_callbacks = DEFAULT_CALLBACKS + get_reporting_integration_callbacks(self.args.report_to) callbacks = default_callbacks if callbacks is None else default_callbacks + callbacks self.callback_handler = CallbackHandler( callbacks, self.model, self.tokenizer, self.optimizer, self.lr_scheduler ) self.add_callback(PrinterCallback if self.args.disable_tqdm else DEFAULT_PROGRESS_CALLBACK) # Will be set to True by `self._setup_loggers()` on first call to `self.log()`. self._loggers_initialized = False # Create clone of distant repo and output directory if needed if self.args.push_to_hub: self.init_git_repo(at_init=True) # In case of pull, we need to make sure every process has the latest. if is_torch_tpu_available(): xm.rendezvous("init git repo") elif args.local_rank != -1: dist.barrier() if self.args.should_save: os.makedirs(self.args.output_dir, exist_ok=True) if not callable(self.data_collator) and callable(getattr(self.data_collator, "collate_batch", None)): raise ValueError("The `data_collator` should be a simple callable (function, class with `__call__`).") if args.max_steps > 0: logger.info("max_steps is given, it will override any value given in num_train_epochs") if train_dataset is not None and not has_length(train_dataset) and args.max_steps <= 0: raise ValueError("train_dataset does not implement __len__, max_steps has to be specified") if ( train_dataset is not None and isinstance(train_dataset, torch.utils.data.IterableDataset) and args.group_by_length ): raise ValueError("the `--group_by_length` option is only available for `Dataset`, not `IterableDataset") self._signature_columns = None # Mixed precision setup self.use_apex = False self.use_cuda_amp = False self.use_cpu_amp = False # Mixed precision setup for SageMaker Model Parallel if is_sagemaker_mp_enabled(): # BF16 + model parallelism in SageMaker: currently not supported, raise an error if args.bf16: raise ValueError("SageMaker Model Parallelism does not support BF16 yet. Please use FP16 instead ") if IS_SAGEMAKER_MP_POST_1_10: # When there's mismatch between SMP config and trainer argument, use SMP config as truth if args.fp16 != smp.state.cfg.fp16: logger.warning( f"FP16 provided in SM_HP_MP_PARAMETERS is {smp.state.cfg.fp16}," f"but FP16 provided in trainer argument is {args.fp16}," f"setting to {smp.state.cfg.fp16}" ) args.fp16 = smp.state.cfg.fp16 else: # smp < 1.10 does not support fp16 in trainer. if hasattr(smp.state.cfg, "fp16"): logger.warning( f"FP16 provided in SM_HP_MP_PARAMETERS is {smp.state.cfg.fp16}, " "but SageMaker Model Parallelism < 1.10 does not support FP16 in trainer." ) if args.fp16 or args.bf16: if args.half_precision_backend == "auto": if args.device == torch.device("cpu"): if args.fp16: raise ValueError("Tried to use `fp16` but it is not supported on cpu") elif _is_native_cpu_amp_available: args.half_precision_backend = "cpu_amp" else: raise ValueError("Tried to use cpu amp but native cpu amp is not available") else: args.half_precision_backend = "cuda_amp" logger.info(f"Using {args.half_precision_backend} half precision backend") self.do_grad_scaling = False if (args.fp16 or args.bf16) and not (args.deepspeed or is_sagemaker_mp_enabled() or is_torch_tpu_available()): # deepspeed and SageMaker Model Parallel manage their own half precision if args.half_precision_backend == "cuda_amp": self.use_cuda_amp = True self.amp_dtype = torch.float16 if args.fp16 else torch.bfloat16 # bf16 does not need grad scaling self.do_grad_scaling = self.amp_dtype == torch.float16 if self.do_grad_scaling: if self.sharded_ddp is not None: self.scaler = ShardedGradScaler() elif self.fsdp is not None: from torch.distributed.fsdp.sharded_grad_scaler import ( ShardedGradScaler as FSDPShardedGradScaler, ) self.scaler = FSDPShardedGradScaler() elif is_torch_tpu_available(): from torch_xla.amp import GradScaler self.scaler = GradScaler() else: self.scaler = torch.cuda.amp.GradScaler() elif args.half_precision_backend == "cpu_amp": self.use_cpu_amp = True self.amp_dtype = torch.bfloat16 else: if not is_apex_available(): raise ImportError( "Using FP16 with APEX but APEX is not installed, please refer to" " https://www.github.com/nvidia/apex." ) self.use_apex = True # FP16 + model parallelism in SageMaker: gradient clipping does not work for now so we raise a helpful error. if ( is_sagemaker_mp_enabled() and self.use_cuda_amp and args.max_grad_norm is not None and args.max_grad_norm > 0 ): raise ValueError( "SageMaker Model Parallelism in mixed precision mode does not support gradient clipping yet. Pass " "along 'max_grad_norm': 0 in your hyperparameters." ) # Label smoothing if self.args.label_smoothing_factor != 0: self.label_smoother = LabelSmoother(epsilon=self.args.label_smoothing_factor) else: self.label_smoother = None self.state = TrainerState( is_local_process_zero=self.is_local_process_zero(), is_world_process_zero=self.is_world_process_zero(), ) self.control = TrainerControl() # Internal variable to count flos in each process, will be accumulated in `self.state.total_flos` then # returned to 0 every time flos need to be logged self.current_flos = 0 self.hp_search_backend = None self.use_tune_checkpoints = False default_label_names = find_labels(self.model.__class__) self.label_names = default_label_names if self.args.label_names is None else self.args.label_names self.can_return_loss = can_return_loss(self.model.__class__) self.control = self.callback_handler.on_init_end(self.args, self.state, self.control) # Internal variables to keep track of the original batch size self._train_batch_size = args.train_batch_size # very last self._memory_tracker.stop_and_update_metrics() # torch.compile if args.torch_compile and not is_torch_compile_available(): raise RuntimeError("Using torch.compile requires PyTorch 2.0 or higher.") def add_callback(self, callback): """ Add a callback to the current list of [`~transformer.TrainerCallback`]. Args: callback (`type` or [`~transformer.TrainerCallback`]): A [`~transformer.TrainerCallback`] class or an instance of a [`~transformer.TrainerCallback`]. In the first case, will instantiate a member of that class. """ self.callback_handler.add_callback(callback) def pop_callback(self, callback): """ Remove a callback from the current list of [`~transformer.TrainerCallback`] and returns it. If the callback is not found, returns `None` (and no error is raised). Args: callback (`type` or [`~transformer.TrainerCallback`]): A [`~transformer.TrainerCallback`] class or an instance of a [`~transformer.TrainerCallback`]. In the first case, will pop the first member of that class found in the list of callbacks. Returns: [`~transformer.TrainerCallback`]: The callback removed, if found. """ return self.callback_handler.pop_callback(callback) def remove_callback(self, callback): """ Remove a callback from the current list of [`~transformer.TrainerCallback`]. Args: callback (`type` or [`~transformer.TrainerCallback`]): A [`~transformer.TrainerCallback`] class or an instance of a [`~transformer.TrainerCallback`]. In the first case, will remove the first member of that class found in the list of callbacks. """ self.callback_handler.remove_callback(callback) def _move_model_to_device(self, model, device): model = model.to(device) # Moving a model to an XLA device disconnects the tied weights, so we have to retie them. if self.args.parallel_mode == ParallelMode.TPU and hasattr(model, "tie_weights"): model.tie_weights() def _set_signature_columns_if_needed(self): if self._signature_columns is None: # Inspect model forward signature to keep only the arguments it accepts. signature = inspect.signature(self.model.forward) self._signature_columns = list(signature.parameters.keys()) # Labels may be named label or label_ids, the default data collator handles that. self._signature_columns += list(set(["label", "label_ids"] + self.label_names)) def _remove_unused_columns(self, dataset: "datasets.Dataset", description: Optional[str] = None): if not self.args.remove_unused_columns: return dataset self._set_signature_columns_if_needed() signature_columns = self._signature_columns ignored_columns = list(set(dataset.column_names) - set(signature_columns)) if len(ignored_columns) > 0: dset_description = "" if description is None else f"in the {description} set" logger.info( f"The following columns {dset_description} don't have a corresponding argument in " f"`{self.model.__class__.__name__}.forward` and have been ignored: {', '.join(ignored_columns)}." f" If {', '.join(ignored_columns)} are not expected by `{self.model.__class__.__name__}.forward`, " " you can safely ignore this message." ) columns = [k for k in signature_columns if k in dataset.column_names] if version.parse(datasets.__version__) < version.parse("1.4.0"): dataset.set_format( type=dataset.format["type"], columns=columns, format_kwargs=dataset.format["format_kwargs"] ) return dataset else: return dataset.remove_columns(ignored_columns) def _get_collator_with_removed_columns( self, data_collator: Callable, description: Optional[str] = None ) -> Callable: """Wrap the data collator in a callable removing unused columns.""" if not self.args.remove_unused_columns: return data_collator self._set_signature_columns_if_needed() signature_columns = self._signature_columns remove_columns_collator = RemoveColumnsCollator( data_collator=data_collator, signature_columns=signature_columns, logger=logger, description=description, model_name=self.model.__class__.__name__, ) return remove_columns_collator def _get_train_sampler(self) -> Optional[torch.utils.data.Sampler]: if self.train_dataset is None or not has_length(self.train_dataset): return None generator = None if self.args.world_size <= 1: generator = torch.Generator() # for backwards compatibility, we generate a seed here (which is sampled from a generator seeded with # `args.seed`) if data_seed isn't provided. # Further on in this method, we default to `args.seed` instead. if self.args.data_seed is None: seed = int(torch.empty((), dtype=torch.int64).random_().item()) else: seed = self.args.data_seed generator.manual_seed(seed) seed = self.args.data_seed if self.args.data_seed is not None else self.args.seed # Build the sampler. if self.args.group_by_length: if is_datasets_available() and isinstance(self.train_dataset, datasets.Dataset): lengths = ( self.train_dataset[self.args.length_column_name] if self.args.length_column_name in self.train_dataset.column_names else None ) else: lengths = None model_input_name = self.tokenizer.model_input_names[0] if self.tokenizer is not None else None if self.args.world_size <= 1: return LengthGroupedSampler( self.args.train_batch_size * self.args.gradient_accumulation_steps, dataset=self.train_dataset, lengths=lengths, model_input_name=model_input_name, generator=generator, ) else: return DistributedLengthGroupedSampler( self.args.train_batch_size * self.args.gradient_accumulation_steps, dataset=self.train_dataset, num_replicas=self.args.world_size, rank=self.args.process_index, lengths=lengths, model_input_name=model_input_name, seed=seed, ) else: if self.args.world_size <= 1: return RandomSampler(self.train_dataset, generator=generator) elif ( self.args.parallel_mode in [ParallelMode.TPU, ParallelMode.SAGEMAKER_MODEL_PARALLEL] and not self.args.dataloader_drop_last ): # Use a loop for TPUs when drop_last is False to have all batches have the same size. return DistributedSamplerWithLoop( self.train_dataset, batch_size=self.args.per_device_train_batch_size, num_replicas=self.args.world_size, rank=self.args.process_index, seed=seed, ) else: return DistributedSampler( self.train_dataset, num_replicas=self.args.world_size, rank=self.args.process_index, seed=seed, ) def get_train_dataloader(self) -> DataLoader: """ Returns the training [`~torch.utils.data.DataLoader`]. Will use no sampler if `train_dataset` does not implement `__len__`, a random sampler (adapted to distributed training if necessary) otherwise. Subclass and override this method if you want to inject some custom behavior. """ if self.train_dataset is None: raise ValueError("Trainer: training requires a train_dataset.") train_dataset = self.train_dataset data_collator = self.data_collator if is_datasets_available() and isinstance(train_dataset, datasets.Dataset): train_dataset = self._remove_unused_columns(train_dataset, description="training") else: data_collator = self._get_collator_with_removed_columns(data_collator, description="training") if isinstance(train_dataset, torch.utils.data.IterableDataset): if self.args.world_size > 1: train_dataset = IterableDatasetShard( train_dataset, batch_size=self._train_batch_size, drop_last=self.args.dataloader_drop_last, num_processes=self.args.world_size, process_index=self.args.process_index, ) return DataLoader( train_dataset, batch_size=self._train_batch_size, collate_fn=data_collator, num_workers=self.args.dataloader_num_workers, pin_memory=self.args.dataloader_pin_memory, ) train_sampler = self._get_train_sampler() return DataLoader( train_dataset, batch_size=self._train_batch_size, sampler=train_sampler, collate_fn=data_collator, drop_last=self.args.dataloader_drop_last, num_workers=self.args.dataloader_num_workers, pin_memory=self.args.dataloader_pin_memory, worker_init_fn=seed_worker, ) def _get_eval_sampler(self, eval_dataset: Dataset) -> Optional[torch.utils.data.Sampler]: # Deprecated code if self.args.use_legacy_prediction_loop: if is_torch_tpu_available(): return SequentialDistributedSampler( eval_dataset, num_replicas=xm.xrt_world_size(), rank=xm.get_ordinal() ) elif is_sagemaker_mp_enabled(): return SequentialDistributedSampler( eval_dataset, num_replicas=smp.dp_size(), rank=smp.dp_rank(), batch_size=self.args.per_device_eval_batch_size, ) elif self.args.local_rank != -1: return SequentialDistributedSampler(eval_dataset) else: return SequentialSampler(eval_dataset) if self.args.world_size <= 1: return SequentialSampler(eval_dataset) else: return ShardSampler( eval_dataset, batch_size=self.args.per_device_eval_batch_size, num_processes=self.args.world_size, process_index=self.args.process_index, ) def get_eval_dataloader(self, eval_dataset: Optional[Dataset] = None) -> DataLoader: """ Returns the evaluation [`~torch.utils.data.DataLoader`]. Subclass and override this method if you want to inject some custom behavior. Args: eval_dataset (`torch.utils.data.Dataset`, *optional*): If provided, will override `self.eval_dataset`. If it is a [`~datasets.Dataset`], columns not accepted by the `model.forward()` method are automatically removed. It must implement `__len__`. """ if eval_dataset is None and self.eval_dataset is None: raise ValueError("Trainer: evaluation requires an eval_dataset.") eval_dataset = eval_dataset if eval_dataset is not None else self.eval_dataset data_collator = self.data_collator if is_datasets_available() and isinstance(eval_dataset, datasets.Dataset): eval_dataset = self._remove_unused_columns(eval_dataset, description="evaluation") else: data_collator = self._get_collator_with_removed_columns(data_collator, description="evaluation") if isinstance(eval_dataset, torch.utils.data.IterableDataset): if self.args.world_size > 1: eval_dataset = IterableDatasetShard( eval_dataset, batch_size=self.args.per_device_eval_batch_size, drop_last=self.args.dataloader_drop_last, num_processes=self.args.world_size, process_index=self.args.process_index, ) return DataLoader( eval_dataset, batch_size=self.args.eval_batch_size, collate_fn=data_collator, num_workers=self.args.dataloader_num_workers, pin_memory=self.args.dataloader_pin_memory, ) eval_sampler = self._get_eval_sampler(eval_dataset) return DataLoader( eval_dataset, sampler=eval_sampler, batch_size=self.args.eval_batch_size, collate_fn=data_collator, drop_last=self.args.dataloader_drop_last, num_workers=self.args.dataloader_num_workers, pin_memory=self.args.dataloader_pin_memory, ) def get_test_dataloader(self, test_dataset: Dataset) -> DataLoader: """ Returns the test [`~torch.utils.data.DataLoader`]. Subclass and override this method if you want to inject some custom behavior. Args: test_dataset (`torch.utils.data.Dataset`, *optional*): The test dataset to use. If it is a [`~datasets.Dataset`], columns not accepted by the `model.forward()` method are automatically removed. It must implement `__len__`. """ data_collator = self.data_collator if is_datasets_available() and isinstance(test_dataset, datasets.Dataset): test_dataset = self._remove_unused_columns(test_dataset, description="test") else: data_collator = self._get_collator_with_removed_columns(data_collator, description="test") if isinstance(test_dataset, torch.utils.data.IterableDataset): if self.args.world_size > 1: test_dataset = IterableDatasetShard( test_dataset, batch_size=self.args.eval_batch_size, drop_last=self.args.dataloader_drop_last, num_processes=self.args.world_size, process_index=self.args.process_index, ) return DataLoader( test_dataset, batch_size=self.args.eval_batch_size, collate_fn=data_collator, num_workers=self.args.dataloader_num_workers, pin_memory=self.args.dataloader_pin_memory, ) test_sampler = self._get_eval_sampler(test_dataset) # We use the same batch_size as for eval. return DataLoader( test_dataset, sampler=test_sampler, batch_size=self.args.eval_batch_size, collate_fn=data_collator, drop_last=self.args.dataloader_drop_last, num_workers=self.args.dataloader_num_workers, pin_memory=self.args.dataloader_pin_memory, ) def create_optimizer_and_scheduler(self, num_training_steps: int): """ Setup the optimizer and the learning rate scheduler. We provide a reasonable default that works well. If you want to use something else, you can pass a tuple in the Trainer's init through `optimizers`, or subclass and override this method (or `create_optimizer` and/or `create_scheduler`) in a subclass. """ self.create_optimizer() if IS_SAGEMAKER_MP_POST_1_10 and smp.state.cfg.fp16: # If smp >= 1.10 and fp16 is enabled, we unwrap the optimizer optimizer = self.optimizer.optimizer else: optimizer = self.optimizer self.create_scheduler(num_training_steps=num_training_steps, optimizer=optimizer) def create_optimizer(self): """ Setup the optimizer. We provide a reasonable default that works well. If you want to use something else, you can pass a tuple in the Trainer's init through `optimizers`, or subclass and override this method in a subclass. """ opt_model = self.model_wrapped if is_sagemaker_mp_enabled() else self.model if self.optimizer is None: decay_parameters = get_parameter_names(opt_model, ALL_LAYERNORM_LAYERS) decay_parameters = [name for name in decay_parameters if "bias" not in name] optimizer_grouped_parameters = [ { "params": [ p for n, p in opt_model.named_parameters() if (n in decay_parameters and p.requires_grad) ], "weight_decay": self.args.weight_decay, }, { "params": [ p for n, p in opt_model.named_parameters() if (n not in decay_parameters and p.requires_grad) ], "weight_decay": 0.0, }, ] optimizer_cls, optimizer_kwargs = Trainer.get_optimizer_cls_and_kwargs(self.args) if self.sharded_ddp == ShardedDDPOption.SIMPLE: self.optimizer = OSS( params=optimizer_grouped_parameters, optim=optimizer_cls, **optimizer_kwargs, ) else: self.optimizer = optimizer_cls(optimizer_grouped_parameters, **optimizer_kwargs) if optimizer_cls.__name__ == "Adam8bit": import bitsandbytes manager = bitsandbytes.optim.GlobalOptimManager.get_instance() skipped = 0 for module in opt_model.modules(): if isinstance(module, nn.Embedding): skipped += sum({p.data_ptr(): p.numel() for p in module.parameters()}.values()) print(f"skipped {module}: {skipped / 2**20}M params") manager.register_module_override(module, "weight", {"optim_bits": 32}) logger.debug(f"bitsandbytes: will optimize {module} in fp32") print(f"skipped: {skipped / 2**20}M params") if is_sagemaker_mp_enabled(): self.optimizer = smp.DistributedOptimizer(self.optimizer) return self.optimizer @staticmethod def get_optimizer_cls_and_kwargs(args: TrainingArguments) -> tuple[Any, Any]: """ Returns the optimizer class and optimizer parameters based on the training arguments. Args: args (`transformers.training_args.TrainingArguments`): The training arguments for the training session. """ # parse args.optim_args optim_args = {} if args.optim_args: for mapping in args.optim_args.replace(" ", "").split(","): key, value = mapping.split("=") optim_args[key] = value optimizer_kwargs = {"lr": args.learning_rate} adam_kwargs = { "betas": (args.adam_beta1, args.adam_beta2), "eps": args.adam_epsilon, } if args.optim == OptimizerNames.ADAFACTOR: optimizer_cls = Adafactor optimizer_kwargs.update({"scale_parameter": False, "relative_step": False}) elif args.optim == OptimizerNames.ADAMW_HF: from transformers.optimization import AdamW optimizer_cls = AdamW optimizer_kwargs.update(adam_kwargs) elif args.optim in [OptimizerNames.ADAMW_TORCH, OptimizerNames.ADAMW_TORCH_FUSED]: from torch.optim import AdamW optimizer_cls = AdamW optimizer_kwargs.update(adam_kwargs) if args.optim == OptimizerNames.ADAMW_TORCH_FUSED: optimizer_kwargs.update({"fused": True}) elif args.optim == OptimizerNames.ADAMW_TORCH_XLA: try: from torch_xla.amp.syncfree import AdamW optimizer_cls = AdamW optimizer_kwargs.update(adam_kwargs) except ImportError: raise ValueError("Trainer failed to import syncfree AdamW from torch_xla.") elif args.optim == OptimizerNames.ADAMW_APEX_FUSED: try: from apex.optimizers import FusedAdam optimizer_cls = FusedAdam optimizer_kwargs.update(adam_kwargs) except ImportError: raise ValueError("Trainer tried to instantiate apex FusedAdam but apex is not installed!") elif args.optim == OptimizerNames.ADAMW_BNB: try: from bitsandbytes.optim import Adam8bit optimizer_cls = Adam8bit optimizer_kwargs.update(adam_kwargs) except ImportError: raise ValueError("Trainer tried to instantiate bnb Adam8bit but bnb is not installed!") elif args.optim == OptimizerNames.ADAMW_ANYPRECISION: try: from torchdistx.optimizers import AnyPrecisionAdamW optimizer_cls = AnyPrecisionAdamW optimizer_kwargs.update(adam_kwargs) # TODO Change dtypes back to M=FP32, Var = BF16, Kahan = False once they can be cast together in torchdistx. optimizer_kwargs.update( { "use_kahan_summation": strtobool(optim_args.get("use_kahan_summation", "False")), "momentum_dtype": getattr(torch, optim_args.get("momentum_dtype", "float32")), "variance_dtype": getattr(torch, optim_args.get("variance_dtype", "float32")), "compensation_buffer_dtype": getattr( torch, optim_args.get("compensation_buffer_dtype", "bfloat16") ), } ) except ImportError: raise ValueError("Please install https://github.com/pytorch/torchdistx") elif args.optim == OptimizerNames.SGD: optimizer_cls = torch.optim.SGD elif args.optim == OptimizerNames.ADAGRAD: optimizer_cls = torch.optim.Adagrad else: raise ValueError(f"Trainer cannot instantiate unsupported optimizer: {args.optim}") return optimizer_cls, optimizer_kwargs def create_scheduler(self, num_training_steps: int, optimizer: torch.optim.Optimizer = None): """ Setup the scheduler. The optimizer of the trainer must have been set up either before this method is called or passed as an argument. Args: num_training_steps (int): The number of training steps to do. """ ############ num_training_steps *= 3 ############ if self.lr_scheduler is None: self.lr_scheduler = get_scheduler( self.args.lr_scheduler_type, optimizer=self.optimizer if optimizer is None else optimizer, num_warmup_steps=self.args.get_warmup_steps(num_training_steps), num_training_steps=num_training_steps, ) return self.lr_scheduler def num_examples(self, dataloader: DataLoader) -> int: """ Helper to get number of samples in a [`~torch.utils.data.DataLoader`] by accessing its dataset. When dataloader.dataset does not exist or has no length, estimates as best it can """ try: dataset = dataloader.dataset # Special case for IterableDatasetShard, we need to dig deeper if isinstance(dataset, IterableDatasetShard): return len(dataloader.dataset.dataset) return len(dataloader.dataset) except (NameError, AttributeError, TypeError): # no dataset or length, estimate by length of dataloader return len(dataloader) * self.args.per_device_train_batch_size def _hp_search_setup(self, trial: Union["optuna.Trial", dict[str, Any]]): """HP search setup code""" self._trial = trial if self.hp_search_backend is None or trial is None: return if self.hp_search_backend == HPSearchBackend.OPTUNA: params = self.hp_space(trial) elif self.hp_search_backend == HPSearchBackend.RAY: params = trial params.pop("wandb", None) elif self.hp_search_backend == HPSearchBackend.SIGOPT: params = {k: int(v) if isinstance(v, str) else v for k, v in trial.assignments.items()} elif self.hp_search_backend == HPSearchBackend.WANDB: params = trial for key, value in params.items(): if not hasattr(self.args, key): logger.warning( f"Trying to set {key} in the hyperparameter search but there is no corresponding field in" " `TrainingArguments`." ) continue old_attr = getattr(self.args, key, None) # Casting value to the proper type if old_attr is not None: value = type(old_attr)(value) setattr(self.args, key, value) if self.hp_search_backend == HPSearchBackend.OPTUNA: logger.info(f"Trial: {trial.params}") if self.hp_search_backend == HPSearchBackend.SIGOPT: logger.info(f"SigOpt Assignments: {trial.assignments}") if self.hp_search_backend == HPSearchBackend.WANDB: logger.info(f"W&B Sweep parameters: {trial}") if self.args.deepspeed: # Rebuild the deepspeed config to reflect the updated training parameters from transformers.deepspeed import HfTrainerDeepSpeedConfig self.args.hf_deepspeed_config = HfTrainerDeepSpeedConfig(self.args.deepspeed) self.args.hf_deepspeed_config.trainer_config_process(self.args) def _report_to_hp_search(self, trial: Union["optuna.Trial", dict[str, Any]], step: int, metrics: dict[str, float]): if self.hp_search_backend is None or trial is None: return self.objective = self.compute_objective(metrics.copy()) if self.hp_search_backend == HPSearchBackend.OPTUNA: import optuna trial.report(self.objective, step) if trial.should_prune(): self.callback_handler.on_train_end(self.args, self.state, self.control) raise optuna.TrialPruned() elif self.hp_search_backend == HPSearchBackend.RAY: from ray import tune if self.control.should_save: self._tune_save_checkpoint() tune.report(objective=self.objective, **metrics) def _tune_save_checkpoint(self): from ray import tune if not self.use_tune_checkpoints: return with tune.checkpoint_dir(step=self.state.global_step) as checkpoint_dir: output_dir = os.path.join(checkpoint_dir, f"{PREFIX_CHECKPOINT_DIR}-{self.state.global_step}") self.save_model(output_dir, _internal_call=True) if self.args.should_save: self.state.save_to_json(os.path.join(output_dir, TRAINER_STATE_NAME)) torch.save(self.optimizer.state_dict(), os.path.join(output_dir, OPTIMIZER_NAME)) torch.save(self.lr_scheduler.state_dict(), os.path.join(output_dir, SCHEDULER_NAME)) def call_model_init(self, trial=None): model_init_argcount = number_of_arguments(self.model_init) if model_init_argcount == 0: model = self.model_init() elif model_init_argcount == 1: model = self.model_init(trial) else: raise RuntimeError("model_init should have 0 or 1 argument.") if model is None: raise RuntimeError("model_init should not return None.") return model def torch_jit_model_eval(self, model, dataloader, training=False): if not training: if dataloader is None: logger.warning("failed to use PyTorch jit mode due to current dataloader is none.") return model example_batch = next(iter(dataloader)) example_batch = self._prepare_inputs(example_batch) try: jit_model = model.eval() with ContextManagers([self.autocast_smart_context_manager(cache_enabled=False), torch.no_grad()]): if version.parse(version.parse(torch.__version__).base_version) >= version.parse("1.14.0"): if isinstance(example_batch, dict): jit_model = torch.jit.trace(jit_model, example_kwarg_inputs=example_batch, strict=False) else: jit_model = torch.jit.trace( jit_model, example_kwarg_inputs={key: example_batch[key] for key in example_batch}, strict=False, ) else: jit_inputs = [] for key in example_batch: example_tensor = torch.ones_like(example_batch[key]) jit_inputs.append(example_tensor) jit_inputs = tuple(jit_inputs) jit_model = torch.jit.trace(jit_model, jit_inputs, strict=False) jit_model = torch.jit.freeze(jit_model) with torch.no_grad(): jit_model(**example_batch) jit_model(**example_batch) model = jit_model self.use_cpu_amp = False self.use_cuda_amp = False except (RuntimeError, TypeError, ValueError, NameError, IndexError) as e: logger.warning(f"failed to use PyTorch jit mode due to: {e}.") return model def ipex_optimize_model(self, model, training=False, dtype=torch.float32): if not is_ipex_available(): raise ImportError( "Using IPEX but IPEX is not installed or IPEX's version does not match current PyTorch, please refer" " to https://github.com/intel/intel-extension-for-pytorch." ) import intel_extension_for_pytorch as ipex if not training: model.eval() dtype = torch.bfloat16 if not self.is_in_train and self.args.bf16_full_eval else dtype # conv_bn_folding is disabled as it fails in symbolic tracing, resulting in ipex warnings model = ipex.optimize(model, dtype=dtype, level="O1", conv_bn_folding=False, inplace=not self.is_in_train) else: if not model.training: model.train() model, self.optimizer = ipex.optimize( model, dtype=dtype, optimizer=self.optimizer, inplace=True, level="O1" ) return model def _wrap_model(self, model, training=True, dataloader=None): if self.args.torch_compile: model = torch.compile(model, backend=self.args.torch_compile_backend, mode=self.args.torch_compile_mode) if self.args.use_ipex: dtype = torch.bfloat16 if self.use_cpu_amp else torch.float32 model = self.ipex_optimize_model(model, training, dtype=dtype) if is_sagemaker_mp_enabled(): # Wrapping the base model twice in a DistributedModel will raise an error. if isinstance(self.model_wrapped, smp.model.DistributedModel): return self.model_wrapped return smp.DistributedModel(model, backward_passes_per_step=self.args.gradient_accumulation_steps) # already initialized its own DDP and AMP if self.deepspeed: return self.deepspeed # train/eval could be run multiple-times - if already wrapped, don't re-wrap it again if unwrap_model(model) is not model: return model # Mixed precision training with apex (torch < 1.6) if self.use_apex and training: model, self.optimizer = amp.initialize(model, self.optimizer, opt_level=self.args.fp16_opt_level) # Multi-gpu training (should be after apex fp16 initialization) if self.args.n_gpu > 1: model = nn.DataParallel(model) if self.args.jit_mode_eval: start_time = time.time() model = self.torch_jit_model_eval(model, dataloader, training) self.jit_compilation_time = round(time.time() - start_time, 4) # Note: in torch.distributed mode, there's no point in wrapping the model # inside a DistributedDataParallel as we'll be under `no_grad` anyways. if not training: return model # Distributed training (should be after apex fp16 initialization) if self.sharded_ddp is not None: # Sharded DDP! if self.sharded_ddp == ShardedDDPOption.SIMPLE: model = ShardedDDP(model, self.optimizer) else: mixed_precision = self.args.fp16 or self.args.bf16 cpu_offload = ShardedDDPOption.OFFLOAD in self.args.sharded_ddp zero_3 = self.sharded_ddp == ShardedDDPOption.ZERO_DP_3 # XXX: Breaking the self.model convention but I see no way around it for now. if ShardedDDPOption.AUTO_WRAP in self.args.sharded_ddp: model = auto_wrap(model) self.model = model = FullyShardedDDP( model, mixed_precision=mixed_precision, reshard_after_forward=zero_3, cpu_offload=cpu_offload, ).to(self.args.device) # Distributed training using PyTorch FSDP elif self.fsdp is not None: if not self.args.fsdp_config["xla"]: # PyTorch FSDP! from torch.distributed.fsdp.fully_sharded_data_parallel import CPUOffload, MixedPrecision from torch.distributed.fsdp.fully_sharded_data_parallel import FullyShardedDataParallel as FSDP from torch.distributed.fsdp.wrap import size_based_auto_wrap_policy, transformer_auto_wrap_policy if FSDPOption.OFFLOAD in self.args.fsdp: cpu_offload = CPUOffload(offload_params=True) else: cpu_offload = CPUOffload(offload_params=False) auto_wrap_policy = None if FSDPOption.AUTO_WRAP in self.args.fsdp: if self.args.fsdp_config["fsdp_min_num_params"] > 0: auto_wrap_policy = functools.partial( size_based_auto_wrap_policy, min_num_params=self.args.fsdp_config["fsdp_min_num_params"] ) elif self.args.fsdp_config.get("fsdp_transformer_layer_cls_to_wrap", None) is not None: transformer_cls_to_wrap = set() for layer_class in self.args.fsdp_config["fsdp_transformer_layer_cls_to_wrap"]: transformer_cls = get_module_class_from_name(model, layer_class) if transformer_cls is None: raise Exception("Could not find the transformer layer class to wrap in the model.") else: transformer_cls_to_wrap.add(transformer_cls) auto_wrap_policy = functools.partial( transformer_auto_wrap_policy, # Transformer layer class to wrap transformer_layer_cls=transformer_cls_to_wrap, ) mixed_precision_policy = None dtype = None if self.args.fp16: dtype = torch.float16 elif self.args.bf16: dtype = torch.bfloat16 if dtype is not None: mixed_precision_policy = MixedPrecision(param_dtype=dtype, reduce_dtype=dtype, buffer_dtype=dtype) if type(model) != FSDP: # XXX: Breaking the self.model convention but I see no way around it for now. self.model = model = FSDP( model, sharding_strategy=self.fsdp, cpu_offload=cpu_offload, auto_wrap_policy=auto_wrap_policy, mixed_precision=mixed_precision_policy, device_id=self.args.device, backward_prefetch=self.backward_prefetch, forward_prefetch=self.forword_prefetch, limit_all_gathers=self.limit_all_gathers, ) else: try: from torch_xla.distributed.fsdp import XlaFullyShardedDataParallel as FSDP from torch_xla.distributed.fsdp import checkpoint_module from torch_xla.distributed.fsdp.wrap import ( size_based_auto_wrap_policy, transformer_auto_wrap_policy, ) except ImportError: raise ImportError("Missing XLA FSDP related module; please make sure to use torch-xla >= 2.0.") auto_wrap_policy = None auto_wrapper_callable = None if self.args.fsdp_config["fsdp_min_num_params"] > 0: auto_wrap_policy = functools.partial( size_based_auto_wrap_policy, min_num_params=self.args.fsdp_config["fsdp_min_num_params"] ) elif self.args.fsdp_config.get("fsdp_transformer_layer_cls_to_wrap", None) is not None: transformer_cls_to_wrap = set() for layer_class in self.args.fsdp_config["fsdp_transformer_layer_cls_to_wrap"]: transformer_cls = get_module_class_from_name(model, layer_class) if transformer_cls is None: raise Exception("Could not find the transformer layer class to wrap in the model.") else: transformer_cls_to_wrap.add(transformer_cls) auto_wrap_policy = functools.partial( transformer_auto_wrap_policy, # Transformer layer class to wrap transformer_layer_cls=transformer_cls_to_wrap, ) fsdp_kwargs = self.args.xla_fsdp_config if self.args.fsdp_config["xla_fsdp_grad_ckpt"]: # Apply gradient checkpointing to auto-wrapped sub-modules if specified def auto_wrapper_callable(m, *args, **kwargs): return FSDP(checkpoint_module(m), *args, **kwargs) # Wrap the base model with an outer FSDP wrapper self.model = model = FSDP( model, auto_wrap_policy=auto_wrap_policy, auto_wrapper_callable=auto_wrapper_callable, **fsdp_kwargs, ) # Patch `xm.optimizer_step` should not reduce gradients in this case, # as FSDP does not need gradient reduction over sharded parameters. def patched_optimizer_step(optimizer, barrier=False, optimizer_args={}): loss = optimizer.step(**optimizer_args) if barrier: xm.mark_step() return loss xm.optimizer_step = patched_optimizer_step elif is_sagemaker_dp_enabled(): model = nn.parallel.DistributedDataParallel(model, device_ids=[int(os.getenv("SMDATAPARALLEL_LOCAL_RANK"))]) elif self.args.local_rank != -1: kwargs = {} if self.args.ddp_find_unused_parameters is not None: kwargs["find_unused_parameters"] = self.args.ddp_find_unused_parameters elif isinstance(model, PreTrainedModel): # find_unused_parameters breaks checkpointing as per # https://github.com/huggingface/transformers/pull/4659#issuecomment-643356021 kwargs["find_unused_parameters"] = not model.is_gradient_checkpointing else: kwargs["find_unused_parameters"] = True if self.args.ddp_bucket_cap_mb is not None: kwargs["bucket_cap_mb"] = self.args.ddp_bucket_cap_mb if is_torch_neuroncore_available(): return model model = nn.parallel.DistributedDataParallel( model, device_ids=[self.args.local_rank] if self.args._n_gpu != 0 else None, output_device=self.args.local_rank if self.args._n_gpu != 0 else None, **kwargs, ) return model def train( self, resume_from_checkpoint: Optional[Union[str, bool]] = None, trial: Union["optuna.Trial", dict[str, Any]] = None, ignore_keys_for_eval: Optional[list[str]] = None, is_first_time=False, **kwargs, ): """ Main training entry point. Args: resume_from_checkpoint (`str` or `bool`, *optional*): If a `str`, local path to a saved checkpoint as saved by a previous instance of [`Trainer`]. If a `bool` and equals `True`, load the last checkpoint in *args.output_dir* as saved by a previous instance of [`Trainer`]. If present, training will resume from the model/optimizer/scheduler states loaded here. trial (`optuna.Trial` or `dict[str, Any]`, *optional*): The trial run or the hyperparameter dictionary for hyperparameter search. ignore_keys_for_eval (`list[str]`, *optional*) A list of keys in the output of your model (if it is a dictionary) that should be ignored when gathering predictions for evaluation during the training. kwargs: Additional keyword arguments used to hide deprecated arguments """ if resume_from_checkpoint is False: resume_from_checkpoint = None # memory metrics - must set up as early as possible self._memory_tracker.start() args = self.args # self.is_in_train = True # do_train is not a reliable argument, as it might not be set and .train() still called, so # the following is a workaround: if (args.fp16_full_eval or args.bf16_full_eval) and not args.do_train: self._move_model_to_device(self.model, args.device) if "model_path" in kwargs: resume_from_checkpoint = kwargs.pop("model_path") warnings.warn( "`model_path` is deprecated and will be removed in a future version. Use `resume_from_checkpoint` " "instead.", FutureWarning, ) if len(kwargs) > 0: raise TypeError(f"train() received got unexpected keyword arguments: {', '.join(list(kwargs.keys()))}.") # This might change the seed so needs to run first. self._hp_search_setup(trial) self._train_batch_size = self.args.train_batch_size # Model re-init model_reloaded = False if self.model_init is not None: # Seed must be set before instantiating the model when using model_init. enable_full_determinism(self.args.seed) if self.args.full_determinism else set_seed(self.args.seed) self.model = self.call_model_init(trial) model_reloaded = True # Reinitializes optimizer and scheduler self.optimizer, self.lr_scheduler = None, None # Load potential model checkpoint if isinstance(resume_from_checkpoint, bool) and resume_from_checkpoint: resume_from_checkpoint = get_last_checkpoint(args.output_dir) if resume_from_checkpoint is None: raise ValueError(f"No valid checkpoint found in output directory ({args.output_dir})") if resume_from_checkpoint is not None and not is_sagemaker_mp_enabled() and args.deepspeed is None: self._load_from_checkpoint(resume_from_checkpoint) # If model was re-initialized, put it on the right device and update self.model_wrapped if model_reloaded: if self.place_model_on_device: self._move_model_to_device(self.model, args.device) self.model_wrapped = self.model if is_first_time: inner_training_loop1 = find_executable_batch_size( self._inner_training_loop, self._train_batch_size, args.auto_find_batch_size ) return inner_training_loop1( args=args, resume_from_checkpoint=resume_from_checkpoint, trial=trial, ignore_keys_for_eval=ignore_keys_for_eval, ) else: inner_training_loop2 = find_executable_batch_size( self._one_train, self._train_batch_size, args.auto_find_batch_size ) return inner_training_loop2( args=args, resume_from_checkpoint=resume_from_checkpoint, trial=trial, ignore_keys_for_eval=ignore_keys_for_eval, ) def _one_train( self, batch_size=None, args=None, resume_from_checkpoint=None, trial=None, ignore_keys_for_eval=None ): # print(self.lr_scheduler) # print(dir(self.lr_scheduler)) self.state = TrainerState() self.state.is_hyper_param_search = trial is not None # Get dataloader self._train_batch_size = batch_size # Data loader and number of training steps train_dataloader = self.get_train_dataloader() # print("AAAAAAA", len(train_dataloader)) total_train_batch_size = args.train_batch_size * args.gradient_accumulation_steps * args.world_size len_dataloader = None if has_length(train_dataloader): len_dataloader = len(train_dataloader) num_update_steps_per_epoch = len_dataloader // args.gradient_accumulation_steps num_update_steps_per_epoch = max(num_update_steps_per_epoch, 1) num_examples = self.num_examples(train_dataloader) if args.max_steps > 0: max_steps = args.max_steps num_train_epochs = args.max_steps // num_update_steps_per_epoch + int( args.max_steps % num_update_steps_per_epoch > 0 ) # May be slightly incorrect if the last batch in the training dataloader has a smaller size but it's # the best we can do. num_train_samples = args.max_steps * total_train_batch_size else: max_steps = math.ceil(args.num_train_epochs * num_update_steps_per_epoch) num_train_epochs = math.ceil(args.num_train_epochs) num_train_samples = self.num_examples(train_dataloader) * args.num_train_epochs elif args.max_steps > 0: # Rely on max_steps when dataloader does not have a working size max_steps = args.max_steps # Setting a very large number of epochs so we go as many times as necessary over the iterator. num_train_epochs = sys.maxsize num_update_steps_per_epoch = max_steps num_examples = total_train_batch_size * args.max_steps num_train_samples = args.max_steps * total_train_batch_size else: raise ValueError( "args.max_steps must be set to a positive value if dataloader does not have a length, was" f" {args.max_steps}" ) ########### # num_train_epochs = 5 # Train! logger.info("***** Running training *****") logger.info(f" Num examples = {num_examples}") logger.info(f" Num Epochs = {num_train_epochs}") logger.info(f" Instantaneous batch size per device = {args.per_device_train_batch_size}") logger.info(f" Total train batch size (w. parallel, distributed & accumulation) = {total_train_batch_size}") logger.info(f" Gradient Accumulation steps = {args.gradient_accumulation_steps}") logger.info(f" Total optimization steps = {max_steps}") logger.info( f" Number of trainable parameters = {sum(p.numel() for p in self.tmp_model.parameters() if p.requires_grad)}" ) self.state.epoch = 0 start_time = time.time() epochs_trained = 0 steps_trained_in_current_epoch = 0 steps_trained_progress_bar = None # Update the references self.callback_handler.model = self.model self.callback_handler.optimizer = self.optimizer self.callback_handler.lr_scheduler = self.lr_scheduler self.callback_handler.train_dataloader = train_dataloader if self.hp_name is not None and self._trial is not None: # use self._trial because the SigOpt/Optuna hpo only call `_hp_search_setup(trial)` instead of passing trial # parameter to Train when using DDP. self.state.trial_name = self.hp_name(self._trial) if trial is not None: assignments = trial.assignments if self.hp_search_backend == HPSearchBackend.SIGOPT else trial self.state.trial_params = hp_params(assignments) else: self.state.trial_params = None # This should be the same if the state has been saved but in case the training arguments changed, it's safer # to set this after the load. self.state.max_steps = max_steps self.state.num_train_epochs = num_train_epochs self.state.is_local_process_zero = self.is_local_process_zero() self.state.is_world_process_zero = self.is_world_process_zero() # tr_loss is a tensor to avoid synchronization of TPUs through .item() tr_loss = torch.tensor(0.0).to(args.device) # _total_loss_scalar is updated everytime .item() has to be called on tr_loss and stores the sum of all losses self._total_loss_scalar = 0.0 self._globalstep_last_logged = self.state.global_step # model.zero_grad() self.tmp_model.zero_grad() self.control = self.callback_handler.on_train_begin(args, self.state, self.control) # Skip the first epochs_trained epochs to get the random state of the dataloader at the right point. if not args.ignore_data_skip: # print("I skip!") called for epoch in range(epochs_trained): is_random_sampler = hasattr(train_dataloader, "sampler") and isinstance( train_dataloader.sampler, RandomSampler ) if is_torch_less_than_1_11 or not is_random_sampler: # We just need to begin an iteration to create the randomization of the sampler. # That was before PyTorch 1.11 however... for _ in train_dataloader: break else: # Otherwise we need to call the whooooole sampler cause there is some random operation added # AT THE VERY END! _ = list(train_dataloader.sampler) ############### # num_train_epochs = 10 self.is_in_train = True # print("The number of epoches: ", num_train_epochs) ############# total_batched_samples = 0 for epoch in range(epochs_trained, num_train_epochs): if isinstance(train_dataloader, DataLoader) and isinstance(train_dataloader.sampler, DistributedSampler): train_dataloader.sampler.set_epoch(epoch) elif hasattr(train_dataloader, "dataset") and isinstance(train_dataloader.dataset, IterableDatasetShard): train_dataloader.dataset.set_epoch(epoch) if is_torch_tpu_available(): parallel_loader = pl.ParallelLoader(train_dataloader, [args.device]).per_device_loader(args.device) epoch_iterator = parallel_loader else: epoch_iterator = train_dataloader # Reset the past mems state at the beginning of each epoch if necessary. if args.past_index >= 0: self._past = None steps_in_epoch = ( len(epoch_iterator) if len_dataloader is not None else args.max_steps * args.gradient_accumulation_steps ) self.control = self.callback_handler.on_epoch_begin(args, self.state, self.control) if epoch == epochs_trained and resume_from_checkpoint is not None and steps_trained_in_current_epoch == 0: self._load_rng_state(resume_from_checkpoint) rng_to_sync = False steps_skipped = 0 if skip_first_batches is not None and steps_trained_in_current_epoch > 0: epoch_iterator = skip_first_batches(epoch_iterator, steps_trained_in_current_epoch) steps_skipped = steps_trained_in_current_epoch steps_trained_in_current_epoch = 0 rng_to_sync = True # print("The number of one epoch: ", len(epoch_iterator)) step = -1 for step, inputs in enumerate(epoch_iterator): total_batched_samples += 1 if rng_to_sync: self._load_rng_state(resume_from_checkpoint) rng_to_sync = False # Skip past any already trained steps if resuming training if steps_trained_in_current_epoch > 0: steps_trained_in_current_epoch -= 1 if steps_trained_progress_bar is not None: steps_trained_progress_bar.update(1) if steps_trained_in_current_epoch == 0: self._load_rng_state(resume_from_checkpoint) continue elif steps_trained_progress_bar is not None: steps_trained_progress_bar.close() steps_trained_progress_bar = None if step % args.gradient_accumulation_steps == 0: self.control = self.callback_handler.on_step_begin(args, self.state, self.control) if ( (total_batched_samples % args.gradient_accumulation_steps != 0) and args.local_rank != -1 and args._no_sync_in_gradient_accumulation ): # Avoid unnecessary DDP synchronization since there will be no backward pass on this example. with self.tmp_model.no_sync(): tr_loss_step = self.training_step(self.tmp_model, inputs) # with model.no_sync(): # tr_loss_step = self.training_step(model, inputs) else: tr_loss_step = self.training_step(self.tmp_model, inputs) if ( args.logging_nan_inf_filter and not is_torch_tpu_available() and (torch.isnan(tr_loss_step) or torch.isinf(tr_loss_step)) ): # if loss is nan or inf simply add the average of previous logged losses tr_loss += tr_loss / (1 + self.state.global_step - self._globalstep_last_logged) else: tr_loss += tr_loss_step self.current_flos += float(self.floating_point_ops(inputs)) # Optimizer step for deepspeed must be called on every step regardless of the value of gradient_accumulation_steps if self.deepspeed: self.deepspeed.step() if total_batched_samples % args.gradient_accumulation_steps == 0 or ( # last step in epoch but step is always smaller than gradient_accumulation_steps steps_in_epoch <= args.gradient_accumulation_steps and (step + 1) == steps_in_epoch ): # Gradient clipping if args.max_grad_norm is not None and args.max_grad_norm > 0 and not self.deepspeed: # deepspeed does its own clipping if self.do_grad_scaling: # Reduce gradients first for XLA if is_torch_tpu_available(): gradients = xm._fetch_gradients(self.optimizer) xm.all_reduce("sum", gradients, scale=1.0 / xm.xrt_world_size()) # AMP: gradients need unscaling self.scaler.unscale_(self.optimizer) if is_sagemaker_mp_enabled() and args.fp16: self.optimizer.clip_master_grads(args.max_grad_norm) elif hasattr(self.optimizer, "clip_grad_norm"): # Some optimizers (like the sharded optimizer) have a specific way to do gradient clipping self.optimizer.clip_grad_norm(args.max_grad_norm) elif hasattr(model, "clip_grad_norm_"): # Some models (like FullyShardedDDP) have a specific way to do gradient clipping model.clip_grad_norm_(args.max_grad_norm) else: # Revert to normal clipping otherwise, handling Apex or full precision nn.utils.clip_grad_norm_( amp.master_params(self.optimizer) if self.use_apex else model.parameters(), args.max_grad_norm, ) # Optimizer step optimizer_was_run = True if self.deepspeed: pass # called outside the loop elif is_torch_tpu_available(): if self.do_grad_scaling: self.scaler.step(self.optimizer) self.scaler.update() else: xm.optimizer_step(self.optimizer) elif self.do_grad_scaling: scale_before = self.scaler.get_scale() self.scaler.step(self.optimizer) self.scaler.update() scale_after = self.scaler.get_scale() optimizer_was_run = scale_before <= scale_after else: self.optimizer.step() if optimizer_was_run and not self.deepspeed: self.lr_scheduler.step() self.tmp_model.zero_grad() self.state.global_step += 1 self.state.epoch = epoch + (step + 1 + steps_skipped) / steps_in_epoch self.control = self.callback_handler.on_step_end(args, self.state, self.control) self._maybe_log_save_evaluate(tr_loss, self.tmp_model, trial, epoch, ignore_keys_for_eval) else: self.control = self.callback_handler.on_substep_end(args, self.state, self.control) if self.control.should_epoch_stop or self.control.should_training_stop: break if step < 0: logger.warning( "There seems to be not a single sample in your epoch_iterator, stopping training at step" f" {self.state.global_step}! This is expected if you're using an IterableDataset and set" f" num_steps ({max_steps}) higher than the number of available samples." ) self.control.should_training_stop = True self.control = self.callback_handler.on_epoch_end(args, self.state, self.control) self._maybe_log_save_evaluate(tr_loss, self.tmp_model, trial, epoch, ignore_keys_for_eval) if DebugOption.TPU_METRICS_DEBUG in self.args.debug: if is_torch_tpu_available(): # tpu-comment: Logging debug metrics for PyTorch/XLA (compile, execute times, ops, etc.) xm.master_print(met.metrics_report()) else: logger.warning( "You enabled PyTorch/XLA debug metrics but you don't have a TPU " "configured. Check your training configuration if this is unexpected." ) if self.control.should_training_stop: break if args.past_index and hasattr(self, "_past"): # Clean the state at the end of training delattr(self, "_past") logger.info("\n\nTraining completed. Do not forget to share your model on huggingface.co/models =)\n\n") if args.load_best_model_at_end and self.state.best_model_checkpoint is not None: # Wait for everyone to get here so we are sur the model has been saved by process 0. if is_torch_tpu_available(): xm.rendezvous("load_best_model_at_end") elif args.local_rank != -1: dist.barrier() elif is_sagemaker_mp_enabled(): smp.barrier() self._load_best_model() # add remaining tr_loss self._total_loss_scalar += tr_loss.item() train_loss = self._total_loss_scalar / self.state.global_step metrics = speed_metrics("train", start_time, num_samples=num_train_samples, num_steps=self.state.max_steps) self.store_flos() metrics["total_flos"] = self.state.total_flos metrics["train_loss"] = train_loss self.is_in_train = False self._memory_tracker.stop_and_update_metrics(metrics) self.log(metrics) run_dir = self._get_output_dir(trial) checkpoints_sorted = self._sorted_checkpoints(use_mtime=False, output_dir=run_dir) # Delete the last checkpoint when save_total_limit=1 if it's different from the best checkpoint and process allowed to save. if self.args.should_save and self.state.best_model_checkpoint is not None and self.args.save_total_limit == 1: for checkpoint in checkpoints_sorted: if checkpoint != self.state.best_model_checkpoint: logger.info(f"Deleting older checkpoint [{checkpoint}] due to args.save_total_limit") shutil.rmtree(checkpoint) self.control = self.callback_handler.on_train_end(args, self.state, self.control) return TrainOutput(self.state.global_step, train_loss, metrics) def _inner_training_loop( self, batch_size=None, args=None, resume_from_checkpoint=None, trial=None, ignore_keys_for_eval=None ): """ 0 This function serves to train one time 1 Update the self.train_dataset before calling this function """ # 1 Get dataloader self._train_batch_size = batch_size # Data loader and number of training steps train_dataloader = self.get_train_dataloader() total_train_batch_size = args.train_batch_size * args.gradient_accumulation_steps * args.world_size len_dataloader = None if has_length(train_dataloader): len_dataloader = len(train_dataloader) num_update_steps_per_epoch = len_dataloader // args.gradient_accumulation_steps num_update_steps_per_epoch = max(num_update_steps_per_epoch, 1) num_examples = self.num_examples(train_dataloader) if args.max_steps > 0: max_steps = args.max_steps num_train_epochs = args.max_steps // num_update_steps_per_epoch + int( args.max_steps % num_update_steps_per_epoch > 0 ) # May be slightly incorrect if the last batch in the training dataloader has a smaller size but it's # the best we can do. num_train_samples = args.max_steps * total_train_batch_size else: max_steps = math.ceil(args.num_train_epochs * num_update_steps_per_epoch) num_train_epochs = math.ceil(args.num_train_epochs) num_train_samples = self.num_examples(train_dataloader) * args.num_train_epochs elif args.max_steps > 0: # Rely on max_steps when dataloader does not have a working size max_steps = args.max_steps # Setting a very large number of epochs so we go as many times as necessary over the iterator. num_train_epochs = sys.maxsize num_update_steps_per_epoch = max_steps num_examples = total_train_batch_size * args.max_steps num_train_samples = args.max_steps * total_train_batch_size else: raise ValueError( "args.max_steps must be set to a positive value if dataloader does not have a length, was" f" {args.max_steps}" ) if DebugOption.UNDERFLOW_OVERFLOW in self.args.debug: if self.args.n_gpu > 1: # nn.DataParallel(model) replicates the model, creating new variables and module # references registered here no longer work on other gpus, breaking the module raise ValueError( "Currently --debug underflow_overflow is not supported under DP. Please use DDP" " (torch.distributed.launch)." ) else: debug_overflow = DebugUnderflowOverflow(self.model) # noqa delay_optimizer_creation = ( self.sharded_ddp is not None and self.sharded_ddp != ShardedDDPOption.SIMPLE or is_sagemaker_mp_enabled() or self.fsdp is not None ) if args.deepspeed: deepspeed_engine, optimizer, lr_scheduler = deepspeed_init( self, num_training_steps=max_steps, resume_from_checkpoint=resume_from_checkpoint ) self.model = deepspeed_engine.module self.model_wrapped = deepspeed_engine self.deepspeed = deepspeed_engine self.optimizer = optimizer self.lr_scheduler = lr_scheduler # print("I just create a optimizer here!") # called elif not delay_optimizer_creation: self.create_optimizer_and_scheduler(num_training_steps=max_steps) self.state = TrainerState() self.state.is_hyper_param_search = trial is not None # Activate gradient checkpointing if needed if args.gradient_checkpointing: self.model.gradient_checkpointing_enable() # model = self._wrap_model(self.model_wrapped) self.tmp_model = self._wrap_model(self.model_wrapped) # if is_sagemaker_mp_enabled() and resume_from_checkpoint is not None: # self._load_from_checkpoint(resume_from_checkpoint, model) # for the rest of this function `model` is the outside model, whether it was wrapped or not if self.tmp_model is not self.model: self.model_wrapped = self.tmp_model if delay_optimizer_creation: print("I create here!") # not called self.create_optimizer_and_scheduler(num_training_steps=max_steps) return True # Check if saved optimizer or scheduler states exist # self._load_optimizer_and_scheduler(resume_from_checkpoint) # important: at this point: # self.model is the Transformers Model # self.model_wrapped is DDP(Transformers Model), Deepspeed(Transformers Model), etc. def _get_output_dir(self, trial): if self.hp_search_backend is not None and trial is not None: if self.hp_search_backend == HPSearchBackend.OPTUNA: run_id = trial.number elif self.hp_search_backend == HPSearchBackend.RAY: from ray import tune run_id = tune.get_trial_id() elif self.hp_search_backend == HPSearchBackend.SIGOPT: run_id = trial.id elif self.hp_search_backend == HPSearchBackend.WANDB: import wandb run_id = wandb.run.id run_name = self.hp_name(trial) if self.hp_name is not None else f"run-{run_id}" run_dir = os.path.join(self.args.output_dir, run_name) else: run_dir = self.args.output_dir return run_dir def _load_from_checkpoint(self, resume_from_checkpoint, model=None): if model is None: model = self.model if not os.path.isfile(os.path.join(resume_from_checkpoint, WEIGHTS_NAME)) and not os.path.isfile( os.path.join(resume_from_checkpoint, WEIGHTS_INDEX_NAME) ): raise ValueError(f"Can't find a valid checkpoint at {resume_from_checkpoint}") logger.info(f"Loading model from {resume_from_checkpoint}.") if os.path.isfile(os.path.join(resume_from_checkpoint, CONFIG_NAME)): config = PretrainedConfig.from_json_file(os.path.join(resume_from_checkpoint, CONFIG_NAME)) checkpoint_version = config.transformers_version if checkpoint_version is not None and checkpoint_version != __version__: logger.warning( f"You are resuming training from a checkpoint trained with {checkpoint_version} of " f"Transformers but your current version is {__version__}. This is not recommended and could " "yield to errors or unwanted behaviors." ) if os.path.isfile(os.path.join(resume_from_checkpoint, WEIGHTS_NAME)): # If the model is on the GPU, it still works! if is_sagemaker_mp_enabled(): if os.path.isfile(os.path.join(resume_from_checkpoint, "user_content.pt")): # If the 'user_content.pt' file exists, load with the new smp api. # Checkpoint must have been saved with the new smp api. smp.resume_from_checkpoint( path=resume_from_checkpoint, tag=WEIGHTS_NAME, partial=False, load_optimizer=False ) else: # If the 'user_content.pt' file does NOT exist, load with the old smp api. # Checkpoint must have been saved with the old smp api. if hasattr(self.args, "fp16") and self.args.fp16 is True: logger.warning( "Enabling FP16 and loading from smp < 1.10 checkpoint together is not suppported." ) state_dict = torch.load(os.path.join(resume_from_checkpoint, WEIGHTS_NAME), map_location="cpu") # Required for smp to not auto-translate state_dict from hf to smp (is already smp). state_dict["_smp_is_partial"] = False load_result = model.load_state_dict(state_dict, strict=True) # release memory del state_dict else: # We load the model state dict on the CPU to avoid an OOM error. state_dict = torch.load(os.path.join(resume_from_checkpoint, WEIGHTS_NAME), map_location="cpu") # workaround for FSDP bug https://github.com/pytorch/pytorch/issues/82963 # which takes *args instead of **kwargs load_result = model.load_state_dict(state_dict, False) # release memory del state_dict self._issue_warnings_after_load(load_result) else: # We load the sharded checkpoint load_result = load_sharded_checkpoint(model, resume_from_checkpoint, strict=is_sagemaker_mp_enabled()) if not is_sagemaker_mp_enabled(): self._issue_warnings_after_load(load_result) def _load_best_model(self): logger.info(f"Loading best model from {self.state.best_model_checkpoint} (score: {self.state.best_metric}).") best_model_path = os.path.join(self.state.best_model_checkpoint, WEIGHTS_NAME) model = self.model_wrapped if is_sagemaker_mp_enabled() else self.model if os.path.exists(best_model_path): if self.deepspeed: if self.model_wrapped is not None: # this removes the pre-hooks from the previous engine self.model_wrapped.destroy() self.model_wrapped = None # temp hack until Deepspeed fixes the problem with resume from an existing engine that did some stepping deepspeed_engine, optimizer, lr_scheduler = deepspeed_init( self, num_training_steps=self.args.max_steps, resume_from_checkpoint=self.state.best_model_checkpoint, ) self.model = deepspeed_engine.module self.model_wrapped = deepspeed_engine self.deepspeed = deepspeed_engine self.optimizer = optimizer self.lr_scheduler = lr_scheduler else: if is_sagemaker_mp_enabled(): if os.path.isfile(os.path.join(self.state.best_model_checkpoint, "user_content.pt")): # If the 'user_content.pt' file exists, load with the new smp api. # Checkpoint must have been saved with the new smp api. smp.resume_from_checkpoint( path=self.state.best_model_checkpoint, tag=WEIGHTS_NAME, partial=False, load_optimizer=False, ) else: # If the 'user_content.pt' file does NOT exist, load with the old smp api. # Checkpoint must have been saved with the old smp api. state_dict = torch.load(best_model_path, map_location="cpu") state_dict["_smp_is_partial"] = False load_result = model.load_state_dict(state_dict, strict=True) else: # We load the model state dict on the CPU to avoid an OOM error. state_dict = torch.load(best_model_path, map_location="cpu") # If the model is on the GPU, it still works! # workaround for FSDP bug https://github.com/pytorch/pytorch/issues/82963 # which takes *args instead of **kwargs load_result = model.load_state_dict(state_dict, False) if not is_sagemaker_mp_enabled(): self._issue_warnings_after_load(load_result) elif os.path.exists(os.path.join(self.state.best_model_checkpoint, WEIGHTS_INDEX_NAME)): load_result = load_sharded_checkpoint( model, self.state.best_model_checkpoint, strict=is_sagemaker_mp_enabled() ) if not is_sagemaker_mp_enabled(): self._issue_warnings_after_load(load_result) else: logger.warning( f"Could not locate the best model at {best_model_path}, if you are running a distributed training " "on multiple nodes, you should activate `--save_on_each_node`." ) def _issue_warnings_after_load(self, load_result): if len(load_result.missing_keys) != 0: if self.model._keys_to_ignore_on_save is not None and set(load_result.missing_keys) == set( self.model._keys_to_ignore_on_save ): self.model.tie_weights() else: logger.warning(f"There were missing keys in the checkpoint model loaded: {load_result.missing_keys}.") if len(load_result.unexpected_keys) != 0: logger.warning(f"There were unexpected keys in the checkpoint model loaded: {load_result.unexpected_keys}.") def _maybe_log_save_evaluate(self, tr_loss, model, trial, epoch, ignore_keys_for_eval): if self.control.should_log: if is_torch_tpu_available(): xm.mark_step() logs: dict[str, float] = {} # all_gather + mean() to get average loss over all processes tr_loss_scalar = self._nested_gather(tr_loss).mean().item() # reset tr_loss to zero tr_loss -= tr_loss logs["loss"] = round(tr_loss_scalar / (self.state.global_step - self._globalstep_last_logged), 4) logs["learning_rate"] = self._get_learning_rate() self._total_loss_scalar += tr_loss_scalar self._globalstep_last_logged = self.state.global_step self.store_flos() self.log(logs) metrics = None if self.control.should_evaluate: if isinstance(self.eval_dataset, dict): for eval_dataset_name, eval_dataset in self.eval_dataset.items(): metrics = self.evaluate( eval_dataset=eval_dataset, ignore_keys=ignore_keys_for_eval, metric_key_prefix=f"eval_{eval_dataset_name}", ) else: metrics = self.evaluate(ignore_keys=ignore_keys_for_eval) self._report_to_hp_search(trial, self.state.global_step, metrics) if self.control.should_save: self._save_checkpoint(model, trial, metrics=metrics) self.control = self.callback_handler.on_save(self.args, self.state, self.control) def _load_rng_state(self, checkpoint): # Load RNG states from `checkpoint` if checkpoint is None: return if self.args.world_size > 1: process_index = self.args.process_index rng_file = os.path.join(checkpoint, f"rng_state_{process_index}.pth") if not os.path.isfile(rng_file): logger.info( f"Didn't find an RNG file for process {process_index}, if you are resuming a training that " "wasn't launched in a distributed fashion, reproducibility is not guaranteed." ) return else: rng_file = os.path.join(checkpoint, "rng_state.pth") if not os.path.isfile(rng_file): logger.info( "Didn't find an RNG file, if you are resuming a training that was launched in a distributed " "fashion, reproducibility is not guaranteed." ) return checkpoint_rng_state = torch.load(rng_file) random.setstate(checkpoint_rng_state["python"]) np.random.set_state(checkpoint_rng_state["numpy"]) torch.random.set_rng_state(checkpoint_rng_state["cpu"]) if torch.cuda.is_available(): if self.args.local_rank != -1: torch.cuda.random.set_rng_state(checkpoint_rng_state["cuda"]) else: try: torch.cuda.random.set_rng_state_all(checkpoint_rng_state["cuda"]) except Exception as e: logger.info( f"Didn't manage to set back the RNG states of the GPU because of the following error:\n {e}" "\nThis won't yield the same results as if the training had not been interrupted." ) if is_torch_tpu_available(): xm.set_rng_state(checkpoint_rng_state["xla"]) def _save_checkpoint(self, model, trial, metrics=None): # In all cases, including ddp/dp/deepspeed, self.model is always a reference to the model we # want to save except FullyShardedDDP. # assert unwrap_model(model) is self.model, "internal model should be a reference to self.model" # Save model checkpoint # checkpoint_folder = f"{PREFIX_CHECKPOINT_DIR}-{self.state.global_step}" checkpoint_folder = f"{PREFIX_CHECKPOINT_DIR}-{self.save_counter}" ########## self.save_counter += 1 ########## if self.hp_search_backend is None and trial is None: self.store_flos() run_dir = self._get_output_dir(trial=trial) output_dir = os.path.join(run_dir, checkpoint_folder) self.save_model(output_dir, _internal_call=True) if self.deepspeed: # under zero3 model file itself doesn't get saved since it's bogus! Unless deepspeed # config `stage3_gather_16bit_weights_on_model_save` is True self.deepspeed.save_checkpoint(output_dir) # Save optimizer and scheduler if self.sharded_ddp == ShardedDDPOption.SIMPLE: self.optimizer.consolidate_state_dict() if is_torch_tpu_available(): xm.rendezvous("saving_optimizer_states") xm.save(self.optimizer.state_dict(), os.path.join(output_dir, OPTIMIZER_NAME)) with warnings.catch_warnings(record=True) as caught_warnings: xm.save(self.lr_scheduler.state_dict(), os.path.join(output_dir, SCHEDULER_NAME)) reissue_pt_warnings(caught_warnings) elif is_sagemaker_mp_enabled(): opt_state_dict = self.optimizer.local_state_dict(gather_if_shard=False) smp.barrier() if smp.rdp_rank() == 0 or smp.state.cfg.shard_optimizer_state: smp.save( opt_state_dict, os.path.join(output_dir, OPTIMIZER_NAME), partial=True, v3=smp.state.cfg.shard_optimizer_state, ) if self.args.should_save: with warnings.catch_warnings(record=True) as caught_warnings: torch.save(self.lr_scheduler.state_dict(), os.path.join(output_dir, SCHEDULER_NAME)) reissue_pt_warnings(caught_warnings) if self.do_grad_scaling: torch.save(self.scaler.state_dict(), os.path.join(output_dir, SCALER_NAME)) elif self.args.should_save and not self.deepspeed: # deepspeed.save_checkpoint above saves model/optim/sched torch.save(self.optimizer.state_dict(), os.path.join(output_dir, OPTIMIZER_NAME)) with warnings.catch_warnings(record=True) as caught_warnings: torch.save(self.lr_scheduler.state_dict(), os.path.join(output_dir, SCHEDULER_NAME)) reissue_pt_warnings(caught_warnings) if self.do_grad_scaling: torch.save(self.scaler.state_dict(), os.path.join(output_dir, SCALER_NAME)) # Determine the new best metric / best model checkpoint if metrics is not None and self.args.metric_for_best_model is not None: metric_to_check = self.args.metric_for_best_model if not metric_to_check.startswith("eval_"): metric_to_check = f"eval_{metric_to_check}" metric_value = metrics[metric_to_check] operator = np.greater if self.args.greater_is_better else np.less if ( self.state.best_metric is None or self.state.best_model_checkpoint is None or operator(metric_value, self.state.best_metric) ): self.state.best_metric = metric_value self.state.best_model_checkpoint = output_dir # Save the Trainer state if self.args.should_save: self.state.save_to_json(os.path.join(output_dir, TRAINER_STATE_NAME)) # Save RNG state in non-distributed training rng_states = { "python": random.getstate(), "numpy": np.random.get_state(), "cpu": torch.random.get_rng_state(), } if torch.cuda.is_available(): if self.args.local_rank == -1: # In non distributed, we save the global CUDA RNG state (will take care of DataParallel) rng_states["cuda"] = torch.cuda.random.get_rng_state_all() else: rng_states["cuda"] = torch.cuda.random.get_rng_state() if is_torch_tpu_available(): rng_states["xla"] = xm.get_rng_state() # A process can arrive here before the process 0 has a chance to save the model, in which case output_dir may # not yet exist. os.makedirs(output_dir, exist_ok=True) if self.args.world_size <= 1: torch.save(rng_states, os.path.join(output_dir, "rng_state.pth")) else: torch.save(rng_states, os.path.join(output_dir, f"rng_state_{self.args.process_index}.pth")) if self.args.push_to_hub: self._push_from_checkpoint(output_dir) # Maybe delete some older checkpoints. if self.args.should_save: self._rotate_checkpoints(use_mtime=True, output_dir=run_dir) def _load_optimizer_and_scheduler(self, checkpoint): """If optimizer and scheduler states exist, load them.""" if checkpoint is None: return if self.deepspeed: # deepspeed loads optimizer/lr_scheduler together with the model in deepspeed_init return checkpoint_file_exists = ( glob.glob(os.path.join(checkpoint, OPTIMIZER_NAME) + "_*") if is_sagemaker_mp_enabled() else os.path.isfile(os.path.join(checkpoint, OPTIMIZER_NAME)) ) if checkpoint_file_exists and os.path.isfile(os.path.join(checkpoint, SCHEDULER_NAME)): # Load in optimizer and scheduler states if is_torch_tpu_available(): # On TPU we have to take some extra precautions to properly load the states on the right device. optimizer_state = torch.load(os.path.join(checkpoint, OPTIMIZER_NAME), map_location="cpu") with warnings.catch_warnings(record=True) as caught_warnings: lr_scheduler_state = torch.load(os.path.join(checkpoint, SCHEDULER_NAME), map_location="cpu") reissue_pt_warnings(caught_warnings) xm.send_cpu_data_to_device(optimizer_state, self.args.device) xm.send_cpu_data_to_device(lr_scheduler_state, self.args.device) self.optimizer.load_state_dict(optimizer_state) self.lr_scheduler.load_state_dict(lr_scheduler_state) else: map_location = "cpu" if is_sagemaker_mp_enabled() else self.args.device if is_sagemaker_mp_enabled(): if os.path.isfile(os.path.join(checkpoint, "user_content.pt")): # Optimizer checkpoint was saved with smp >= 1.10 def opt_load_hook(mod, opt): opt.load_state_dict(smp.load(os.path.join(checkpoint, OPTIMIZER_NAME), partial=True)) else: # Optimizer checkpoint was saved with smp < 1.10 def opt_load_hook(mod, opt): if IS_SAGEMAKER_MP_POST_1_10: opt.load_state_dict( smp.load(os.path.join(checkpoint, OPTIMIZER_NAME), partial=True, back_compat=True) ) else: opt.load_state_dict(smp.load(os.path.join(checkpoint, OPTIMIZER_NAME), partial=True)) self.model_wrapped.register_post_step_hook(opt_load_hook) else: self.optimizer.load_state_dict( torch.load(os.path.join(checkpoint, OPTIMIZER_NAME), map_location=map_location) ) with warnings.catch_warnings(record=True) as caught_warnings: self.lr_scheduler.load_state_dict(torch.load(os.path.join(checkpoint, SCHEDULER_NAME))) reissue_pt_warnings(caught_warnings) if self.do_grad_scaling and os.path.isfile(os.path.join(checkpoint, SCALER_NAME)): self.scaler.load_state_dict(torch.load(os.path.join(checkpoint, SCALER_NAME))) def hyperparameter_search( self, hp_space: Optional[Callable[["optuna.Trial"], dict[str, float]]] = None, compute_objective: Optional[Callable[[dict[str, float]], float]] = None, n_trials: int = 20, direction: str = "minimize", backend: Optional[Union["str", HPSearchBackend]] = None, hp_name: Optional[Callable[["optuna.Trial"], str]] = None, **kwargs, ) -> BestRun: """ Launch an hyperparameter search using `optuna` or `Ray Tune` or `SigOpt`. The optimized quantity is determined by `compute_objective`, which defaults to a function returning the evaluation loss when no metric is provided, the sum of all metrics otherwise. To use this method, you need to have provided a `model_init` when initializing your [`Trainer`]: we need to reinitialize the model at each new run. This is incompatible with the `optimizers` argument, so you need to subclass [`Trainer`] and override the method [`~Trainer.create_optimizer_and_scheduler`] for custom optimizer/scheduler. Args: hp_space (`Callable[["optuna.Trial"], dict[str, float]]`, *optional*): A function that defines the hyperparameter search space. Will default to [`~trainer_utils.default_hp_space_optuna`] or [`~trainer_utils.default_hp_space_ray`] or [`~trainer_utils.default_hp_space_sigopt`] depending on your backend. compute_objective (`Callable[[dict[str, float]], float]`, *optional*): A function computing the objective to minimize or maximize from the metrics returned by the `evaluate` method. Will default to [`~trainer_utils.default_compute_objective`]. n_trials (`int`, *optional*, defaults to 100): The number of trial runs to test. direction (`str`, *optional*, defaults to `"minimize"`): Whether to optimize greater or lower objects. Can be `"minimize"` or `"maximize"`, you should pick `"minimize"` when optimizing the validation loss, `"maximize"` when optimizing one or several metrics. backend (`str` or [`~training_utils.HPSearchBackend`], *optional*): The backend to use for hyperparameter search. Will default to optuna or Ray Tune or SigOpt, depending on which one is installed. If all are installed, will default to optuna. hp_name (`Callable[["optuna.Trial"], str]]`, *optional*): A function that defines the trial/run name. Will default to None. kwargs (`dict[str, Any]`, *optional*): Additional keyword arguments passed along to `optuna.create_study` or `ray.tune.run`. For more information see: - the documentation of [optuna.create_study](https://optuna.readthedocs.io/en/stable/reference/generated/optuna.study.create_study.html) - the documentation of [tune.run](https://docs.ray.io/en/latest/tune/api_docs/execution.html#tune-run) - the documentation of [sigopt](https://app.sigopt.com/docs/endpoints/experiments/create) Returns: [`trainer_utils.BestRun`]: All the information about the best run. Experiment summary can be found in `run_summary` attribute for Ray backend. """ if backend is None: backend = default_hp_search_backend() if backend is None: raise RuntimeError( "At least one of optuna or ray should be installed. " "To install optuna run `pip install optuna`. " "To install ray run `pip install ray[tune]`. " "To install sigopt run `pip install sigopt`." ) backend = HPSearchBackend(backend) if backend == HPSearchBackend.OPTUNA: raise RuntimeError("You picked the optuna backend, but it is not installed. Use `pip install optuna`.") if backend == HPSearchBackend.RAY: raise RuntimeError( "You picked the Ray Tune backend, but it is not installed. Use `pip install 'ray[tune]'`." ) if backend == HPSearchBackend.SIGOPT: raise RuntimeError("You picked the sigopt backend, but it is not installed. Use `pip install sigopt`.") if backend == HPSearchBackend.WANDB: raise RuntimeError("You picked the wandb backend, but it is not installed. Use `pip install wandb`.") self.hp_search_backend = backend if self.model_init is None: raise RuntimeError( "To use hyperparameter search, you need to pass your model through a model_init function." ) try: backend_dict = { HPSearchBackend.OPTUNA: run_hp_search_optuna, HPSearchBackend.RAY: run_hp_search_ray, HPSearchBackend.SIGOPT: run_hp_search_sigopt, HPSearchBackend.WANDB: run_hp_search_wandb, } backend_run = backend_dict[backend] except NameError: backend_obj = ALL_HYPERPARAMETER_SEARCH_BACKENDS[backend]() backend_run = backend_obj.run try: from transformers.trainer_utils import default_hp_space except ImportError: default_hp_space = backend_obj.default_hp_space self.hp_space = default_hp_space[backend] if hp_space is None else hp_space self.hp_name = hp_name self.compute_objective = default_compute_objective if compute_objective is None else compute_objective best_run = backend_run(self, n_trials, direction, **kwargs) self.hp_search_backend = None return best_run def log(self, logs: dict[str, float]) -> None: """ Log `logs` on the various objects watching training. Subclass and override this method to inject custom behavior. Args: logs (`dict[str, float]`): The values to log. """ if self.state.epoch is not None: logs["epoch"] = round(self.state.epoch, 2) output = {**logs, **{"step": self.state.global_step}} self.state.log_history.append(output) self.control = self.callback_handler.on_log(self.args, self.state, self.control, logs) def _prepare_input(self, data: Union[torch.Tensor, Any]) -> Union[torch.Tensor, Any]: """ Prepares one `data` before feeding it to the model, be it a tensor or a nested list/dictionary of tensors. """ if isinstance(data, Mapping): return type(data)({k: self._prepare_input(v) for k, v in data.items()}) elif isinstance(data, (tuple, list)): return type(data)(self._prepare_input(v) for v in data) elif isinstance(data, torch.Tensor): kwargs = {"device": self.args.device} if self.deepspeed and (torch.is_floating_point(data) or torch.is_complex(data)): # NLP models inputs are int/uint and those get adjusted to the right dtype of the # embedding. Other models such as wav2vec2's inputs are already float and thus # may need special handling to match the dtypes of the model kwargs.update({"dtype": self.args.hf_deepspeed_config.dtype()}) return data.to(**kwargs) return data def _prepare_inputs(self, inputs: dict[str, Union[torch.Tensor, Any]]) -> dict[str, Union[torch.Tensor, Any]]: """ Prepare `inputs` before feeding them to the model, converting them to tensors if they are not already and handling potential state. """ inputs = self._prepare_input(inputs) if len(inputs) == 0: raise ValueError( "The batch received was empty, your model won't be able to train on it. Double-check that your " f"training dataset contains keys expected by the model: {','.join(self._signature_columns)}." ) if self.args.past_index >= 0 and self._past is not None: inputs["mems"] = self._past return inputs def compute_loss_context_manager(self): """ A helper wrapper to group together context managers. """ return self.autocast_smart_context_manager() def autocast_smart_context_manager(self, cache_enabled: Optional[bool] = True): """ A helper wrapper that creates an appropriate context manager for `autocast` while feeding it the desired arguments, depending on the situation. """ if self.use_cuda_amp or self.use_cpu_amp: if is_torch_greater_or_equal_than_1_10: ctx_manager = ( torch.cpu.amp.autocast(cache_enabled=cache_enabled, dtype=self.amp_dtype) if self.use_cpu_amp else torch.cuda.amp.autocast(cache_enabled=cache_enabled, dtype=self.amp_dtype) ) else: ctx_manager = torch.cuda.amp.autocast() else: ctx_manager = contextlib.nullcontext() if sys.version_info >= (3, 7) else contextlib.suppress() return ctx_manager def training_step(self, model: nn.Module, inputs: dict[str, Union[torch.Tensor, Any]]) -> torch.Tensor: """ Perform a training step on a batch of inputs. Subclass and override to inject custom behavior. Args: model (`nn.Module`): The model to train. inputs (`dict[str, Union[torch.Tensor, Any]]`): The inputs and targets of the model. The dictionary will be unpacked before being fed to the model. Most models expect the targets under the argument `labels`. Check your model's documentation for all accepted arguments. Return: `torch.Tensor`: The tensor with training loss on this batch. """ model.train() inputs = self._prepare_inputs(inputs) if is_sagemaker_mp_enabled(): loss_mb = smp_forward_backward(model, inputs, self.args.gradient_accumulation_steps) return loss_mb.reduce_mean().detach().to(self.args.device) with self.compute_loss_context_manager(): loss = self.compute_loss(model, inputs) if self.args.n_gpu > 1: loss = loss.mean() # mean() to average on multi-gpu parallel training if self.args.gradient_accumulation_steps > 1 and not self.deepspeed: # deepspeed handles loss scaling by gradient_accumulation_steps in its `backward` loss = loss / self.args.gradient_accumulation_steps if self.do_grad_scaling: self.scaler.scale(loss).backward() elif self.use_apex: with amp.scale_loss(loss, self.optimizer) as scaled_loss: scaled_loss.backward() elif self.deepspeed: # loss gets scaled under gradient_accumulation_steps in deepspeed loss = self.deepspeed.backward(loss) else: loss.backward() return loss.detach() def compute_loss(self, model, inputs, return_outputs=False): """ How the loss is computed by Trainer. By default, all models return the loss in the first element. Subclass and override for custom behavior. """ if self.label_smoother is not None and "labels" in inputs: labels = inputs.pop("labels") else: labels = None outputs = model(**inputs) # Save past state if it exists # TODO: this needs to be fixed and made cleaner later. if self.args.past_index >= 0: self._past = outputs[self.args.past_index] if labels is not None: if unwrap_model(model)._get_name() in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES.values(): loss = self.label_smoother(outputs, labels, shift_labels=True) else: loss = self.label_smoother(outputs, labels) else: if isinstance(outputs, dict) and "loss" not in outputs: raise ValueError( "The model did not return a loss from the inputs, only the following keys: " f"{','.join(outputs.keys())}. For reference, the inputs it received are {','.join(inputs.keys())}." ) # We don't use .loss here since the model may return tuples instead of ModelOutput. loss = outputs["loss"] if isinstance(outputs, dict) else outputs[0] return (loss, outputs) if return_outputs else loss def is_local_process_zero(self) -> bool: """ Whether or not this process is the local (e.g., on one machine if training in a distributed fashion on several machines) main process. """ return self.args.local_process_index == 0 def is_world_process_zero(self) -> bool: """ Whether or not this process is the global main process (when training in a distributed fashion on several machines, this is only going to be `True` for one process). """ # Special case for SageMaker ModelParallel since there process_index is dp_process_index, not the global # process index. if is_sagemaker_mp_enabled(): return smp.rank() == 0 else: return self.args.process_index == 0 def save_model(self, output_dir: Optional[str] = None, _internal_call: bool = False): """ Will save the model, so you can reload it using `from_pretrained()`. Will only save from the main process. """ if output_dir is None: output_dir = self.args.output_dir if is_torch_tpu_available(): self._save_tpu(output_dir) elif is_sagemaker_mp_enabled(): # Calling the state_dict needs to be done on the wrapped model and on all processes. os.makedirs(output_dir, exist_ok=True) state_dict = self.model_wrapped.state_dict() if self.args.should_save: self._save(output_dir, state_dict=state_dict) if IS_SAGEMAKER_MP_POST_1_10: # 'user_content.pt' indicates model state_dict saved with smp >= 1.10 Path(os.path.join(output_dir, "user_content.pt")).touch() elif ( ShardedDDPOption.ZERO_DP_2 in self.args.sharded_ddp or ShardedDDPOption.ZERO_DP_3 in self.args.sharded_ddp or self.fsdp is not None ): state_dict = self.model.state_dict() if self.args.should_save: self._save(output_dir, state_dict=state_dict) elif self.deepspeed: # this takes care of everything as long as we aren't under zero3 if self.args.should_save: self._save(output_dir) if is_deepspeed_zero3_enabled(): # It's too complicated to try to override different places where the weights dump gets # saved, so since under zero3 the file is bogus, simply delete it. The user should # either user deepspeed checkpoint to resume or to recover full weights use # zero_to_fp32.py stored in the checkpoint. if self.args.should_save: file = os.path.join(output_dir, WEIGHTS_NAME) if os.path.isfile(file): # logger.info(f"deepspeed zero3: removing {file}, see zero_to_fp32.py to recover weights") os.remove(file) # now save the real model if stage3_gather_16bit_weights_on_model_save=True # if false it will not be saved. # This must be called on all ranks if not self.deepspeed.save_16bit_model(output_dir, WEIGHTS_NAME): logger.warning( "deepspeed.save_16bit_model didn't save the model, since" " stage3_gather_16bit_weights_on_model_save=false. Saving the full checkpoint instead, use" " zero_to_fp32.py to recover weights" ) self.deepspeed.save_checkpoint(output_dir) elif self.args.should_save: self._save(output_dir) # Push to the Hub when `save_model` is called by the user. if self.args.push_to_hub and not _internal_call: self.push_to_hub(commit_message="Model save") def _save_tpu(self, output_dir: Optional[str] = None): output_dir = output_dir if output_dir is not None else self.args.output_dir logger.info(f"Saving model checkpoint to {output_dir}") if xm.is_master_ordinal(): os.makedirs(output_dir, exist_ok=True) torch.save(self.args, os.path.join(output_dir, TRAINING_ARGS_NAME)) # Save a trained model and configuration using `save_pretrained()`. # They can then be reloaded using `from_pretrained()` xm.rendezvous("saving_checkpoint") if not isinstance(self.model, PreTrainedModel): if isinstance(unwrap_model(self.model), PreTrainedModel): unwrap_model(self.model).save_pretrained( output_dir, is_main_process=self.args.should_save, state_dict=self.model.state_dict(), save_function=xm.save, ) else: logger.info("Trainer.model is not a `PreTrainedModel`, only saving its state dict.") state_dict = self.model.state_dict() xm.save(state_dict, os.path.join(output_dir, WEIGHTS_NAME)) else: self.model.save_pretrained(output_dir, is_main_process=self.args.should_save, save_function=xm.save) if self.tokenizer is not None and self.args.should_save: self.tokenizer.save_pretrained(output_dir) def _save(self, output_dir: Optional[str] = None, state_dict=None): # If we are executing this function, we are the process zero, so we don't check for that. output_dir = output_dir if output_dir is not None else self.args.output_dir os.makedirs(output_dir, exist_ok=True) logger.info(f"Saving model checkpoint to {output_dir}") # Save a trained model and configuration using `save_pretrained()`. # They can then be reloaded using `from_pretrained()` if not isinstance(self.model, PreTrainedModel): if isinstance(unwrap_model(self.model), PreTrainedModel): if state_dict is None: state_dict = self.model.state_dict() unwrap_model(self.model).save_pretrained(output_dir, state_dict=state_dict) else: logger.info("Trainer.model is not a `PreTrainedModel`, only saving its state dict.") if state_dict is None: state_dict = self.model.state_dict() torch.save(state_dict, os.path.join(output_dir, WEIGHTS_NAME)) else: self.model.save_pretrained(output_dir, state_dict=state_dict) if self.tokenizer is not None: self.tokenizer.save_pretrained(output_dir) # Good practice: save your training arguments together with the trained model torch.save(self.args, os.path.join(output_dir, TRAINING_ARGS_NAME)) def store_flos(self): # Storing the number of floating-point operations that went into the model if self.args.local_rank != -1: self.state.total_flos += ( distributed_broadcast_scalars([self.current_flos], device=self.args.device).sum().item() ) self.current_flos = 0 else: self.state.total_flos += self.current_flos self.current_flos = 0 def _sorted_checkpoints( self, output_dir=None, checkpoint_prefix=PREFIX_CHECKPOINT_DIR, use_mtime=False ) -> list[str]: ordering_and_checkpoint_path = [] glob_checkpoints = [str(x) for x in Path(output_dir).glob(f"{checkpoint_prefix}-*") if os.path.isdir(x)] for path in glob_checkpoints: if use_mtime: ordering_and_checkpoint_path.append((os.path.getmtime(path), path)) else: regex_match = re.match(f".*{checkpoint_prefix}-([0-9]+)", path) if regex_match is not None and regex_match.groups() is not None: ordering_and_checkpoint_path.append((int(regex_match.groups()[0]), path)) checkpoints_sorted = sorted(ordering_and_checkpoint_path) checkpoints_sorted = [checkpoint[1] for checkpoint in checkpoints_sorted] # Make sure we don't delete the best model. if self.state.best_model_checkpoint is not None: best_model_index = checkpoints_sorted.index(str(Path(self.state.best_model_checkpoint))) for i in range(best_model_index, len(checkpoints_sorted) - 2): checkpoints_sorted[i], checkpoints_sorted[i + 1] = checkpoints_sorted[i + 1], checkpoints_sorted[i] return checkpoints_sorted def _rotate_checkpoints(self, use_mtime=False, output_dir=None) -> None: if self.args.save_total_limit is None or self.args.save_total_limit <= 0: return # Check if we should delete older checkpoint(s) checkpoints_sorted = self._sorted_checkpoints(use_mtime=use_mtime, output_dir=output_dir) if len(checkpoints_sorted) <= self.args.save_total_limit: return # If save_total_limit=1 with load_best_model_at_end=True, we could end up deleting the last checkpoint, which # we don't do to allow resuming. save_total_limit = self.args.save_total_limit if ( self.state.best_model_checkpoint is not None and self.args.save_total_limit == 1 and checkpoints_sorted[-1] != self.state.best_model_checkpoint ): save_total_limit = 2 number_of_checkpoints_to_delete = max(0, len(checkpoints_sorted) - save_total_limit) checkpoints_to_be_deleted = checkpoints_sorted[:number_of_checkpoints_to_delete] for checkpoint in checkpoints_to_be_deleted: logger.info(f"Deleting older checkpoint [{checkpoint}] due to args.save_total_limit") shutil.rmtree(checkpoint, ignore_errors=True) def evaluate( self, eval_dataset: Optional[Dataset] = None, ignore_keys: Optional[list[str]] = None, metric_key_prefix: str = "eval", ) -> dict[str, float]: """ Run evaluation and returns metrics. The calling script will be responsible for providing a method to compute metrics, as they are task-dependent (pass it to the init `compute_metrics` argument). You can also subclass and override this method to inject custom behavior. Args: eval_dataset (`Dataset`, *optional*): Pass a dataset if you wish to override `self.eval_dataset`. If it is a [`~datasets.Dataset`], columns not accepted by the `model.forward()` method are automatically removed. It must implement the `__len__` method. ignore_keys (`Lst[str]`, *optional*): A list of keys in the output of your model (if it is a dictionary) that should be ignored when gathering predictions. metric_key_prefix (`str`, *optional*, defaults to `"eval"`): An optional prefix to be used as the metrics key prefix. For example the metrics "bleu" will be named "eval_bleu" if the prefix is "eval" (default) Returns: A dictionary containing the evaluation loss and the potential metrics computed from the predictions. The dictionary also contains the epoch number which comes from the training state. """ # memory metrics - must set up as early as possible self._memory_tracker.start() eval_dataloader = self.get_eval_dataloader(eval_dataset) start_time = time.time() eval_loop = self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop output = eval_loop( eval_dataloader, description="Evaluation", # No point gathering the predictions if there are no metrics, otherwise we defer to # self.args.prediction_loss_only prediction_loss_only=True if self.compute_metrics is None else None, ignore_keys=ignore_keys, metric_key_prefix=metric_key_prefix, ) total_batch_size = self.args.eval_batch_size * self.args.world_size if f"{metric_key_prefix}_jit_compilation_time" in output.metrics: start_time += output.metrics[f"{metric_key_prefix}_jit_compilation_time"] output.metrics.update( speed_metrics( metric_key_prefix, start_time, num_samples=output.num_samples, num_steps=math.ceil(output.num_samples / total_batch_size), ) ) self.log(output.metrics) if DebugOption.TPU_METRICS_DEBUG in self.args.debug: # tpu-comment: Logging debug metrics for PyTorch/XLA (compile, execute times, ops, etc.) xm.master_print(met.metrics_report()) self.control = self.callback_handler.on_evaluate(self.args, self.state, self.control, output.metrics) self._memory_tracker.stop_and_update_metrics(output.metrics) return output.metrics def predict( self, test_dataset: Dataset, ignore_keys: Optional[list[str]] = None, metric_key_prefix: str = "test" ) -> PredictionOutput: """ Run prediction and returns predictions and potential metrics. Depending on the dataset and your use case, your test dataset may contain labels. In that case, this method will also return metrics, like in `evaluate()`. Args: test_dataset (`Dataset`): Dataset to run the predictions on. If it is an `datasets.Dataset`, columns not accepted by the `model.forward()` method are automatically removed. Has to implement the method `__len__` ignore_keys (`Lst[str]`, *optional*): A list of keys in the output of your model (if it is a dictionary) that should be ignored when gathering predictions. metric_key_prefix (`str`, *optional*, defaults to `"test"`): An optional prefix to be used as the metrics key prefix. For example the metrics "bleu" will be named "test_bleu" if the prefix is "test" (default) If your predictions or labels have different sequence length (for instance because you're doing dynamic padding in a token classification task) the predictions will be padded (on the right) to allow for concatenation into one array. The padding index is -100. Returns: *Namedtuple* A namedtuple with the following keys: - predictions (`np.ndarray`): The predictions on `test_dataset`. - label_ids (`np.ndarray`, *optional*): The labels (if the dataset contained some). - metrics (`dict[str, float]`, *optional*): The potential dictionary of metrics (if the dataset contained labels). """ # memory metrics - must set up as early as possible self._memory_tracker.start() test_dataloader = self.get_test_dataloader(test_dataset) start_time = time.time() eval_loop = self.prediction_loop if self.args.use_legacy_prediction_loop else self.evaluation_loop output = eval_loop( test_dataloader, description="Prediction", ignore_keys=ignore_keys, metric_key_prefix=metric_key_prefix ) total_batch_size = self.args.eval_batch_size * self.args.world_size if f"{metric_key_prefix}_jit_compilation_time" in output.metrics: start_time += output.metrics[f"{metric_key_prefix}_jit_compilation_time"] output.metrics.update( speed_metrics( metric_key_prefix, start_time, num_samples=output.num_samples, num_steps=math.ceil(output.num_samples / total_batch_size), ) ) self.control = self.callback_handler.on_predict(self.args, self.state, self.control, output.metrics) self._memory_tracker.stop_and_update_metrics(output.metrics) return PredictionOutput(predictions=output.predictions, label_ids=output.label_ids, metrics=output.metrics) def evaluation_loop( self, dataloader: DataLoader, description: str, prediction_loss_only: Optional[bool] = None, ignore_keys: Optional[list[str]] = None, metric_key_prefix: str = "eval", ) -> EvalLoopOutput: """ Prediction/evaluation loop, shared by `Trainer.evaluate()` and `Trainer.predict()`. Works both with or without labels. """ args = self.args prediction_loss_only = prediction_loss_only if prediction_loss_only is not None else args.prediction_loss_only # if eval is called w/o train init deepspeed here if args.deepspeed and not self.deepspeed: # XXX: eval doesn't have `resume_from_checkpoint` arg but we should be able to do eval # from the checkpoint eventually deepspeed_engine, _, _ = deepspeed_init( self, num_training_steps=0, resume_from_checkpoint=None, inference=True ) self.model = deepspeed_engine.module self.model_wrapped = deepspeed_engine self.deepspeed = deepspeed_engine model = self._wrap_model(self.model, training=False, dataloader=dataloader) # if full fp16 or bf16 eval is wanted and this ``evaluation`` or ``predict`` isn't called # while ``train`` is running, cast it to the right dtype first and then put on device if not self.is_in_train: if args.fp16_full_eval: model = model.to(dtype=torch.float16, device=args.device) elif args.bf16_full_eval: model = model.to(dtype=torch.bfloat16, device=args.device) batch_size = self.args.eval_batch_size logger.info(f"***** Running {description} *****") if has_length(dataloader): logger.info(f" Num examples = {self.num_examples(dataloader)}") else: logger.info(" Num examples: Unknown") logger.info(f" Batch size = {batch_size}") model.eval() self.callback_handler.eval_dataloader = dataloader # Do this before wrapping. eval_dataset = getattr(dataloader, "dataset", None) if is_torch_tpu_available(): dataloader = pl.ParallelLoader(dataloader, [args.device]).per_device_loader(args.device) if args.past_index >= 0: self._past = None # Initialize containers # losses/preds/labels on GPU/TPU (accumulated for eval_accumulation_steps) losses_host = None preds_host = None labels_host = None inputs_host = None # losses/preds/labels on CPU (final containers) all_losses = None all_preds = None all_labels = None all_inputs = None # Will be useful when we have an iterable dataset so don't know its length. observed_num_examples = 0 # Main evaluation loop for step, inputs in enumerate(dataloader): # Update the observed num examples observed_batch_size = find_batch_size(inputs) if observed_batch_size is not None: observed_num_examples += observed_batch_size # For batch samplers, batch_size is not known by the dataloader in advance. if batch_size is None: batch_size = observed_batch_size # Prediction step loss, logits, labels = self.prediction_step(model, inputs, prediction_loss_only, ignore_keys=ignore_keys) inputs_decode = self._prepare_input(inputs["input_ids"]) if args.include_inputs_for_metrics else None if is_torch_tpu_available(): xm.mark_step() # Update containers on host if loss is not None: losses = self._nested_gather(loss.repeat(batch_size)) losses_host = losses if losses_host is None else torch.cat((losses_host, losses), dim=0) if labels is not None: labels = self._pad_across_processes(labels) labels = self._nested_gather(labels) labels_host = labels if labels_host is None else nested_concat(labels_host, labels, padding_index=-100) if inputs_decode is not None: inputs_decode = self._pad_across_processes(inputs_decode) inputs_decode = self._nested_gather(inputs_decode) inputs_host = ( inputs_decode if inputs_host is None else nested_concat(inputs_host, inputs_decode, padding_index=-100) ) if logits is not None: logits = self._pad_across_processes(logits) logits = self._nested_gather(logits) if self.preprocess_logits_for_metrics is not None: logits = self.preprocess_logits_for_metrics(logits, labels) preds_host = logits if preds_host is None else nested_concat(preds_host, logits, padding_index=-100) self.control = self.callback_handler.on_prediction_step(args, self.state, self.control) # Gather all tensors and put them back on the CPU if we have done enough accumulation steps. if args.eval_accumulation_steps is not None and (step + 1) % args.eval_accumulation_steps == 0: if losses_host is not None: losses = nested_numpify(losses_host) all_losses = losses if all_losses is None else np.concatenate((all_losses, losses), axis=0) if preds_host is not None: logits = nested_numpify(preds_host) all_preds = logits if all_preds is None else nested_concat(all_preds, logits, padding_index=-100) if inputs_host is not None: inputs_decode = nested_numpify(inputs_host) all_inputs = ( inputs_decode if all_inputs is None else nested_concat(all_inputs, inputs_decode, padding_index=-100) ) if labels_host is not None: labels = nested_numpify(labels_host) all_labels = labels if all_labels is None else nested_concat(all_labels, labels, padding_index=-100) # Set back to None to begin a new accumulation losses_host, preds_host, inputs_host, labels_host = None, None, None, None if args.past_index and hasattr(self, "_past"): # Clean the state at the end of the evaluation loop delattr(self, "_past") # Gather all remaining tensors and put them back on the CPU if losses_host is not None: losses = nested_numpify(losses_host) all_losses = losses if all_losses is None else np.concatenate((all_losses, losses), axis=0) if preds_host is not None: logits = nested_numpify(preds_host) all_preds = logits if all_preds is None else nested_concat(all_preds, logits, padding_index=-100) if inputs_host is not None: inputs_decode = nested_numpify(inputs_host) all_inputs = ( inputs_decode if all_inputs is None else nested_concat(all_inputs, inputs_decode, padding_index=-100) ) if labels_host is not None: labels = nested_numpify(labels_host) all_labels = labels if all_labels is None else nested_concat(all_labels, labels, padding_index=-100) # Number of samples if has_length(eval_dataset): num_samples = len(eval_dataset) # The instance check is weird and does not actually check for the type, but whether the dataset has the right # methods. Therefore we need to make sure it also has the attribute. elif isinstance(eval_dataset, IterableDatasetShard) and getattr(eval_dataset, "num_examples", 0) > 0: num_samples = eval_dataset.num_examples else: if has_length(dataloader): num_samples = self.num_examples(dataloader) else: # both len(dataloader.dataset) and len(dataloader) fail num_samples = observed_num_examples if num_samples == 0 and observed_num_examples > 0: num_samples = observed_num_examples # Number of losses has been rounded to a multiple of batch_size and in a distributed training, the number of # samplers has been rounded to a multiple of batch_size, so we truncate. if all_losses is not None: all_losses = all_losses[:num_samples] if all_preds is not None: all_preds = nested_truncate(all_preds, num_samples) if all_labels is not None: all_labels = nested_truncate(all_labels, num_samples) if all_inputs is not None: all_inputs = nested_truncate(all_inputs, num_samples) # Metrics! if self.compute_metrics is not None and all_preds is not None and all_labels is not None: if args.include_inputs_for_metrics: metrics = self.compute_metrics( EvalPrediction(predictions=all_preds, label_ids=all_labels, inputs=all_inputs) ) else: metrics = self.compute_metrics(EvalPrediction(predictions=all_preds, label_ids=all_labels)) else: metrics = {} # To be JSON-serializable, we need to remove numpy types or zero-d tensors metrics = denumpify_detensorize(metrics) if all_losses is not None: metrics[f"{metric_key_prefix}_loss"] = all_losses.mean().item() if hasattr(self, "jit_compilation_time"): metrics[f"{metric_key_prefix}_jit_compilation_time"] = self.jit_compilation_time # Prefix all keys with metric_key_prefix + '_' for key in list(metrics.keys()): if not key.startswith(f"{metric_key_prefix}_"): metrics[f"{metric_key_prefix}_{key}"] = metrics.pop(key) return EvalLoopOutput(predictions=all_preds, label_ids=all_labels, metrics=metrics, num_samples=num_samples) def _nested_gather(self, tensors, name=None): """ Gather value of `tensors` (tensor or list/tuple of nested tensors) and convert them to numpy before concatenating them to `gathered` """ if tensors is None: return if is_torch_tpu_available(): if name is None: name = "nested_gather" tensors = nested_xla_mesh_reduce(tensors, name) elif is_sagemaker_mp_enabled(): tensors = smp_gather(tensors) elif self.args.local_rank != -1: tensors = distributed_concat(tensors) return tensors # Copied from Accelerate. def _pad_across_processes(self, tensor, pad_index=-100): """ Recursively pad the tensors in a nested list/tuple/dictionary of tensors from all devices to the same size so they can safely be gathered. """ if isinstance(tensor, (list, tuple)): return type(tensor)(self._pad_across_processes(t, pad_index=pad_index) for t in tensor) elif isinstance(tensor, dict): return type(tensor)({k: self._pad_across_processes(v, pad_index=pad_index) for k, v in tensor.items()}) elif not isinstance(tensor, torch.Tensor): raise TypeError(f"Can't pad the values of type {type(tensor)}, only of nested list/tuple/dicts of tensors.") if len(tensor.shape) < 2: return tensor # Gather all sizes size = torch.tensor(tensor.shape, device=tensor.device)[None] sizes = self._nested_gather(size).cpu() max_size = max(s[1] for s in sizes) # When extracting XLA graphs for compilation, max_size is 0, # so use inequality to avoid errors. if tensor.shape[1] >= max_size: return tensor # Then pad to the maximum size old_size = tensor.shape new_size = list(old_size) new_size[1] = max_size new_tensor = tensor.new_zeros(tuple(new_size)) + pad_index new_tensor[:, : old_size[1]] = tensor return new_tensor def prediction_step( self, model: nn.Module, inputs: dict[str, Union[torch.Tensor, Any]], prediction_loss_only: bool, ignore_keys: Optional[list[str]] = None, ) -> tuple[Optional[torch.Tensor], Optional[torch.Tensor], Optional[torch.Tensor]]: """ Perform an evaluation step on `model` using `inputs`. Subclass and override to inject custom behavior. Args: model (`nn.Module`): The model to evaluate. inputs (`dict[str, Union[torch.Tensor, Any]]`): The inputs and targets of the model. The dictionary will be unpacked before being fed to the model. Most models expect the targets under the argument `labels`. Check your model's documentation for all accepted arguments. prediction_loss_only (`bool`): Whether or not to return the loss only. ignore_keys (`Lst[str]`, *optional*): A list of keys in the output of your model (if it is a dictionary) that should be ignored when gathering predictions. Return: tuple[Optional[torch.Tensor], Optional[torch.Tensor], Optional[torch.Tensor]]: A tuple with the loss, logits and labels (each being optional). """ has_labels = False if len(self.label_names) == 0 else all(inputs.get(k) is not None for k in self.label_names) # For CLIP-like models capable of returning loss values. # If `return_loss` is not specified or being `None` in `inputs`, we check if the default value of `return_loss` # is `True` in `model.forward`. return_loss = inputs.get("return_loss", None) if return_loss is None: return_loss = self.can_return_loss loss_without_labels = True if len(self.label_names) == 0 and return_loss else False inputs = self._prepare_inputs(inputs) if ignore_keys is None: if hasattr(self.model, "config"): ignore_keys = getattr(self.model.config, "keys_to_ignore_at_inference", []) else: ignore_keys = [] # labels may be popped when computing the loss (label smoothing for instance) so we grab them first. if has_labels or loss_without_labels: labels = nested_detach(tuple(inputs.get(name) for name in self.label_names)) if len(labels) == 1: labels = labels[0] else: labels = None with torch.no_grad(): if is_sagemaker_mp_enabled(): raw_outputs = smp_forward_only(model, inputs) if has_labels or loss_without_labels: if isinstance(raw_outputs, dict): loss_mb = raw_outputs["loss"] logits_mb = tuple(v for k, v in raw_outputs.items() if k not in ignore_keys + ["loss"]) else: loss_mb = raw_outputs[0] logits_mb = raw_outputs[1:] loss = loss_mb.reduce_mean().detach().cpu() logits = smp_nested_concat(logits_mb) else: loss = None if isinstance(raw_outputs, dict): logits_mb = tuple(v for k, v in raw_outputs.items() if k not in ignore_keys) else: logits_mb = raw_outputs logits = smp_nested_concat(logits_mb) else: if has_labels or loss_without_labels: with self.compute_loss_context_manager(): loss, outputs = self.compute_loss(model, inputs, return_outputs=True) loss = loss.mean().detach() if isinstance(outputs, dict): logits = tuple(v for k, v in outputs.items() if k not in ignore_keys + ["loss"]) else: logits = outputs[1:] else: loss = None with self.compute_loss_context_manager(): outputs = model(**inputs) if isinstance(outputs, dict): logits = tuple(v for k, v in outputs.items() if k not in ignore_keys) else: logits = outputs # TODO: this needs to be fixed and made cleaner later. if self.args.past_index >= 0: self._past = outputs[self.args.past_index - 1] if prediction_loss_only: return (loss, None, None) logits = nested_detach(logits) if len(logits) == 1: logits = logits[0] return (loss, logits, labels) def floating_point_ops(self, inputs: dict[str, Union[torch.Tensor, Any]]): """ For models that inherit from [`PreTrainedModel`], uses that method to compute the number of floating point operations for every backward + forward pass. If using another model, either implement such a method in the model or subclass and override this method. Args: inputs (`dict[str, Union[torch.Tensor, Any]]`): The inputs and targets of the model. Returns: `int`: The number of floating-point operations. """ if hasattr(self.model, "floating_point_ops"): return self.model.floating_point_ops(inputs) else: return 0 def init_git_repo(self, at_init: bool = False): """ Initializes a git repo in `self.args.hub_model_id`. Args: at_init (`bool`, *optional*, defaults to `False`): Whether this function is called before any training or not. If `self.args.overwrite_output_dir` is `True` and `at_init` is `True`, the path to the repo (which is `self.args.output_dir`) might be wiped out. """ if not self.is_world_process_zero(): return if self.args.hub_model_id is None: repo_name = Path(self.args.output_dir).absolute().name else: repo_name = self.args.hub_model_id if "/" not in repo_name: repo_name = get_full_repo_name(repo_name, token=self.args.hub_token) # Make sure the repo exists. create_repo(repo_name, token=self.args.hub_token, private=self.args.hub_private_repo, exist_ok=True) try: self.repo = Repository(self.args.output_dir, clone_from=repo_name, token=self.args.hub_token) except OSError: if self.args.overwrite_output_dir and at_init: # Try again after wiping output_dir shutil.rmtree(self.args.output_dir) self.repo = Repository(self.args.output_dir, clone_from=repo_name, token=self.args.hub_token) else: raise self.repo.git_pull() # By default, ignore the checkpoint folders if ( not os.path.exists(os.path.join(self.args.output_dir, ".gitignore")) and self.args.hub_strategy != HubStrategy.ALL_CHECKPOINTS ): with open(os.path.join(self.args.output_dir, ".gitignore"), "w", encoding="utf-8") as writer: writer.writelines(["checkpoint-*/"]) # Add "*.sagemaker" to .gitignore if using SageMaker if os.environ.get("SM_TRAINING_ENV"): self._add_sm_patterns_to_gitignore() self.push_in_progress = None def create_model_card( self, language: Optional[str] = None, license: Optional[str] = None, tags: Union[str, list[str], None] = None, model_name: Optional[str] = None, finetuned_from: Optional[str] = None, tasks: Union[str, list[str], None] = None, dataset_tags: Union[str, list[str], None] = None, dataset: Union[str, list[str], None] = None, dataset_args: Union[str, list[str], None] = None, ): """ Creates a draft of a model card using the information available to the `Trainer`. Args: language (`str`, *optional*): The language of the model (if applicable) license (`str`, *optional*): The license of the model. Will default to the license of the pretrained model used, if the original model given to the `Trainer` comes from a repo on the Hub. tags (`str` or `list[str]`, *optional*): Some tags to be included in the metadata of the model card. model_name (`str`, *optional*): The name of the model. finetuned_from (`str`, *optional*): The name of the model used to fine-tune this one (if applicable). Will default to the name of the repo of the original model given to the `Trainer` (if it comes from the Hub). tasks (`str` or `list[str]`, *optional*): One or several task identifiers, to be included in the metadata of the model card. dataset_tags (`str` or `list[str]`, *optional*): One or several dataset tags, to be included in the metadata of the model card. dataset (`str` or `list[str]`, *optional*): One or several dataset identifiers, to be included in the metadata of the model card. dataset_args (`str` or `list[str]`, *optional*): One or several dataset arguments, to be included in the metadata of the model card. """ if not self.is_world_process_zero(): return training_summary = TrainingSummary.from_trainer( self, language=language, license=license, tags=tags, model_name=model_name, finetuned_from=finetuned_from, tasks=tasks, dataset_tags=dataset_tags, dataset=dataset, dataset_args=dataset_args, ) model_card = training_summary.to_model_card() with open(os.path.join(self.args.output_dir, "README.md"), "w") as f: f.write(model_card) def _push_from_checkpoint(self, checkpoint_folder): # Only push from one node. if not self.is_world_process_zero() or self.args.hub_strategy == HubStrategy.END: return # If we haven't finished the last push, we don't do this one. if self.push_in_progress is not None and not self.push_in_progress.is_done: return output_dir = self.args.output_dir # To avoid a new synchronization of all model weights, we just copy the file from the checkpoint folder modeling_files = [CONFIG_NAME, WEIGHTS_NAME] for modeling_file in modeling_files: if os.path.isfile(os.path.join(checkpoint_folder, modeling_file)): shutil.copy(os.path.join(checkpoint_folder, modeling_file), os.path.join(output_dir, modeling_file)) # Saving the tokenizer is fast and we don't know how many files it may have spawned, so we resave it to be sure. if self.tokenizer is not None: self.tokenizer.save_pretrained(output_dir) # Same for the training arguments torch.save(self.args, os.path.join(output_dir, TRAINING_ARGS_NAME)) try: if self.args.hub_strategy == HubStrategy.CHECKPOINT: # Temporarily move the checkpoint just saved for the push tmp_checkpoint = os.path.join(output_dir, "last-checkpoint") # We have to remove the "last-checkpoint" dir if it exists, otherwise the checkpoint is moved as a # subfolder. if os.path.isdir(tmp_checkpoint): shutil.rmtree(tmp_checkpoint) shutil.move(checkpoint_folder, tmp_checkpoint) if self.args.save_strategy == IntervalStrategy.STEPS: commit_message = f"Training in progress, step {self.state.global_step}" else: commit_message = f"Training in progress, epoch {int(self.state.epoch)}" _, self.push_in_progress = self.repo.push_to_hub( commit_message=commit_message, blocking=False, auto_lfs_prune=True ) finally: if self.args.hub_strategy == HubStrategy.CHECKPOINT: # Move back the checkpoint to its place shutil.move(tmp_checkpoint, checkpoint_folder) def push_to_hub(self, commit_message: Optional[str] = "End of training", blocking: bool = True, **kwargs) -> str: """ Upload *self.model* and *self.tokenizer* to the 🤗 model hub on the repo *self.args.hub_model_id*. Parameters: commit_message (`str`, *optional*, defaults to `"End of training"`): Message to commit while pushing. blocking (`bool`, *optional*, defaults to `True`): Whether the function should return only when the `git push` has finished. kwargs: Additional keyword arguments passed along to [`~Trainer.create_model_card`]. Returns: The url of the commit of your model in the given repository if `blocking=False`, a tuple with the url of the commit and an object to track the progress of the commit if `blocking=True` """ # If a user calls manually `push_to_hub` with `self.args.push_to_hub = False`, we try to create the repo but # it might fail. if not hasattr(self, "repo"): self.init_git_repo() model_name = kwargs.pop("model_name", None) if model_name is None and self.args.should_save: if self.args.hub_model_id is None: model_name = Path(self.args.output_dir).name else: model_name = self.args.hub_model_id.split("/")[-1] # Needs to be executed on all processes for TPU training, but will only save on the processed determined by # self.args.should_save. self.save_model(_internal_call=True) # Only push from one node. if not self.is_world_process_zero(): return # Cancel any async push in progress if blocking=True. The commits will all be pushed together. if blocking and self.push_in_progress is not None and not self.push_in_progress.is_done: self.push_in_progress._process.kill() self.push_in_progress = None git_head_commit_url = self.repo.push_to_hub( commit_message=commit_message, blocking=blocking, auto_lfs_prune=True ) # push separately the model card to be independant from the rest of the model if self.args.should_save: self.create_model_card(model_name=model_name, **kwargs) try: self.repo.push_to_hub( commit_message="update model card README.md", blocking=blocking, auto_lfs_prune=True ) except OSError as exc: logger.error(f"Error pushing update to the model card. Please read logs and retry.\n${exc}") return git_head_commit_url # # Deprecated code # def prediction_loop( self, dataloader: DataLoader, description: str, prediction_loss_only: Optional[bool] = None, ignore_keys: Optional[list[str]] = None, metric_key_prefix: str = "eval", ) -> EvalLoopOutput: """ Prediction/evaluation loop, shared by `Trainer.evaluate()` and `Trainer.predict()`. Works both with or without labels. """ args = self.args if not has_length(dataloader): raise ValueError("dataloader must implement a working __len__") prediction_loss_only = prediction_loss_only if prediction_loss_only is not None else args.prediction_loss_only # if eval is called w/o train init deepspeed here if args.deepspeed and not self.deepspeed: # XXX: eval doesn't have `resume_from_checkpoint` arg but we should be able to do eval # from the checkpoint eventually deepspeed_engine, _, _ = deepspeed_init(self, num_training_steps=0, resume_from_checkpoint=None) self.model = deepspeed_engine.module self.model_wrapped = deepspeed_engine self.deepspeed = deepspeed_engine # XXX: we don't need optim/sched for inference, but this needs to be sorted out, since # for example the Z3-optimizer is a must for zero3 to work even for inference - what we # don't need is the deepspeed basic optimizer which is self.optimizer.optimizer deepspeed_engine.optimizer.optimizer = None deepspeed_engine.lr_scheduler = None model = self._wrap_model(self.model, training=False, dataloader=dataloader) # if full fp16 or bf16 eval is wanted and this ``evaluation`` or ``predict`` isn't called # while ``train`` is running, cast it to the right dtype first and then put on device if not self.is_in_train: if args.fp16_full_eval: model = model.to(dtype=torch.float16, device=args.device) elif args.bf16_full_eval: model = model.to(dtype=torch.bfloat16, device=args.device) batch_size = dataloader.batch_size num_examples = self.num_examples(dataloader) logger.info(f"***** Running {description} *****") logger.info(f" Num examples = {num_examples}") logger.info(f" Batch size = {batch_size}") losses_host: torch.Tensor = None preds_host: Union[torch.Tensor, list[torch.Tensor]] = None labels_host: Union[torch.Tensor, list[torch.Tensor]] = None inputs_host: Union[torch.Tensor, list[torch.Tensor]] = None world_size = max(1, args.world_size) eval_losses_gatherer = DistributedTensorGatherer(world_size, num_examples, make_multiple_of=batch_size) if not prediction_loss_only: # The actual number of eval_sample can be greater than num_examples in distributed settings (when we pass # a batch size to the sampler) make_multiple_of = None if hasattr(dataloader, "sampler") and isinstance(dataloader.sampler, SequentialDistributedSampler): make_multiple_of = dataloader.sampler.batch_size preds_gatherer = DistributedTensorGatherer(world_size, num_examples, make_multiple_of=make_multiple_of) labels_gatherer = DistributedTensorGatherer(world_size, num_examples, make_multiple_of=make_multiple_of) inputs_gatherer = DistributedTensorGatherer(world_size, num_examples, make_multiple_of=make_multiple_of) model.eval() if is_torch_tpu_available(): dataloader = pl.ParallelLoader(dataloader, [args.device]).per_device_loader(args.device) if args.past_index >= 0: self._past = None self.callback_handler.eval_dataloader = dataloader for step, inputs in enumerate(dataloader): loss, logits, labels = self.prediction_step(model, inputs, prediction_loss_only, ignore_keys=ignore_keys) inputs_decode = self._prepare_input(inputs["input_ids"]) if args.include_inputs_for_metrics else None if loss is not None: losses = loss.repeat(batch_size) losses_host = losses if losses_host is None else torch.cat((losses_host, losses), dim=0) if logits is not None: preds_host = logits if preds_host is None else nested_concat(preds_host, logits, padding_index=-100) if labels is not None: labels_host = labels if labels_host is None else nested_concat(labels_host, labels, padding_index=-100) if inputs_decode is not None: inputs_host = ( inputs_decode if inputs_host is None else nested_concat(inputs_host, inputs_decode, padding_index=-100) ) self.control = self.callback_handler.on_prediction_step(args, self.state, self.control) # Gather all tensors and put them back on the CPU if we have done enough accumulation steps. if args.eval_accumulation_steps is not None and (step + 1) % args.eval_accumulation_steps == 0: eval_losses_gatherer.add_arrays(self._gather_and_numpify(losses_host, "eval_losses")) if not prediction_loss_only: preds_gatherer.add_arrays(self._gather_and_numpify(preds_host, "eval_preds")) labels_gatherer.add_arrays(self._gather_and_numpify(labels_host, "eval_label_ids")) inputs_gatherer.add_arrays(self._gather_and_numpify(inputs_host, "eval_inputs_ids")) # Set back to None to begin a new accumulation losses_host, preds_host, labels_host, inputs_host = None, None, None, None if args.past_index and hasattr(self, "_past"): # Clean the state at the end of the evaluation loop delattr(self, "_past") # Gather all remaining tensors and put them back on the CPU eval_losses_gatherer.add_arrays(self._gather_and_numpify(losses_host, "eval_losses")) if not prediction_loss_only: preds_gatherer.add_arrays(self._gather_and_numpify(preds_host, "eval_preds")) labels_gatherer.add_arrays(self._gather_and_numpify(labels_host, "eval_label_ids")) inputs_gatherer.add_arrays(self._gather_and_numpify(inputs_host, "eval_inputs_ids")) eval_loss = eval_losses_gatherer.finalize() preds = preds_gatherer.finalize() if not prediction_loss_only else None label_ids = labels_gatherer.finalize() if not prediction_loss_only else None inputs_ids = inputs_gatherer.finalize() if not prediction_loss_only else None if self.compute_metrics is not None and preds is not None and label_ids is not None: if args.include_inputs_for_metrics: metrics = self.compute_metrics( EvalPrediction(predictions=preds, label_ids=label_ids, inputs=inputs_ids) ) else: metrics = self.compute_metrics(EvalPrediction(predictions=preds, label_ids=label_ids)) else: metrics = {} # To be JSON-serializable, we need to remove numpy types or zero-d tensors metrics = denumpify_detensorize(metrics) if eval_loss is not None: metrics[f"{metric_key_prefix}_loss"] = eval_loss.mean().item() # Prefix all keys with metric_key_prefix + '_' for key in list(metrics.keys()): if not key.startswith(f"{metric_key_prefix}_"): metrics[f"{metric_key_prefix}_{key}"] = metrics.pop(key) return EvalLoopOutput(predictions=preds, label_ids=label_ids, metrics=metrics, num_samples=num_examples) def _gather_and_numpify(self, tensors, name): """ Gather value of `tensors` (tensor or list/tuple of nested tensors) and convert them to numpy before concatenating them to `gathered` """ if tensors is None: return if is_torch_tpu_available(): tensors = nested_xla_mesh_reduce(tensors, name) elif is_sagemaker_mp_enabled(): tensors = smp_gather(tensors) elif self.args.local_rank != -1: tensors = distributed_concat(tensors) return nested_numpify(tensors) def _add_sm_patterns_to_gitignore(self) -> None: """Add SageMaker Checkpointing patterns to .gitignore file.""" # Make sure we only do this on the main process if not self.is_world_process_zero(): return patterns = ["*.sagemaker-uploading", "*.sagemaker-uploaded"] # Get current .gitignore content if os.path.exists(os.path.join(self.repo.local_dir, ".gitignore")): with open(os.path.join(self.repo.local_dir, ".gitignore")) as f: current_content = f.read() else: current_content = "" # Add the patterns to .gitignore content = current_content for pattern in patterns: if pattern not in content: if content.endswith("\n"): content += pattern else: content += f"\n{pattern}" # Write the .gitignore file if it has changed if content != current_content: with open(os.path.join(self.repo.local_dir, ".gitignore"), "w") as f: logger.debug(f"Writing .gitignore file. Content: {content}") f.write(content) self.repo.git_add(".gitignore") # avoid race condition with git status time.sleep(0.5) if not self.repo.is_repo_clean(): self.repo.git_commit("Add *.sagemaker patterns to .gitignore.") self.repo.git_push() ================================================ FILE: src/lmflow/pipeline/utils/rm_dataprocessor.py ================================================ import logging from dataclasses import dataclass from typing import Any, Optional, Union from transformers import AutoTokenizer from transformers.utils import PaddingStrategy logger = logging.getLogger(__name__) @dataclass class RewardDataCollatorWithPadding: tokenizer: AutoTokenizer padding: Union[bool, str, PaddingStrategy] = True max_length: Optional[int] = None pad_to_multiple_of: Optional[int] = None return_tensors: str = "pt" def __call__(self, features: list[dict[str, Any]]) -> dict[str, Any]: merged_features = [] for feature in features: merged_features.append( { "input_ids": feature["input_ids_chosen"], "attention_mask": feature["attention_mask_chosen"], } ) merged_features.append( { "input_ids": feature["input_ids_rejected"], "attention_mask": feature["attention_mask_rejected"], } ) logger.debug(f"Chosen: {self.tokenizer.decode(feature['input_ids_chosen'])}") logger.debug(f"Rejected: {self.tokenizer.decode(feature['input_ids_rejected'])}") batch = self.tokenizer.pad( merged_features, padding=self.padding, max_length=self.max_length, pad_to_multiple_of=self.pad_to_multiple_of, return_tensors=self.return_tensors, ) batch = { "input_ids": batch["input_ids"], "attention_mask": batch["attention_mask"], "return_loss": True, } return batch ================================================ FILE: src/lmflow/pipeline/utils/rm_trainer.py ================================================ import numpy as np import torch import torch.nn as nn from transformers import Trainer def compute_metrics(eval_pred): result = {} pos_predictions_scores = eval_pred.predictions[0] neg_predictions_scores = eval_pred.predictions[1] # We assume that the first sample is preferred by default in groundtruth result["accuracy"] = np.sum(pos_predictions_scores > neg_predictions_scores) / len(pos_predictions_scores) return result def rm_loss(model, inputs, return_outputs=False): rewards = model(input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"])[0] bsz = rewards.size(0) jidx = torch.arange(0, bsz, 2) kidx = jidx + 1 rewards_j = rewards[jidx] rewards_k = rewards[kidx] loss = -nn.functional.logsigmoid(rewards_j - rewards_k).mean() if return_outputs: return loss, {"rewards_j": rewards_j, "rewards_k": rewards_k} return loss class RewardTrainer(Trainer): def compute_loss(self, model, inputs, return_outputs=False): return rm_loss(model, inputs, return_outputs) ================================================ FILE: src/lmflow/pipeline/vllm_inferencer.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import copy import importlib.resources as pkg_resources import json import logging import os os.environ["VLLM_WORKER_MULTIPROC_METHOD"] = "spawn" import subprocess import sys from typing import Any, Optional, Union import numpy as np from transformers import AutoTokenizer from lmflow.args import ( DatasetArguments, InferencerArguments, ModelArguments, ) from lmflow.datasets import Dataset from lmflow.models.hf_decoder_model import HFDecoderModel from lmflow.pipeline.base_pipeline import BasePipeline from lmflow.utils.common import make_shell_args_from_dataclass from lmflow.utils.constants import MEMORY_SAFE_VLLM_INFERENCE_ENV_VAR_TO_REMOVE, RETURN_CODE_ERROR_BUFFER from lmflow.utils.data_utils import VLLMInferenceResultWithInput from lmflow.utils.versioning import is_ray_available, is_vllm_available logger = logging.getLogger(__name__) if is_vllm_available(): from vllm import SamplingParams else: raise ImportError("VLLM is not available, please install vllm.") if is_ray_available(): import ray import ray.data from ray.util.scheduling_strategies import PlacementGroupSchedulingStrategy else: logger.warning("Ray is not available, distributed vllm inference will not be supported.") class InferencerWithOffloading(BasePipeline): def __init__( self, model_args: ModelArguments, data_args: DatasetArguments, inferencer_args: InferencerArguments, ): self.model_args = model_args self.data_args = data_args self.inferencer_args = inferencer_args self.eos_token_id = AutoTokenizer.from_pretrained(model_args.model_name_or_path).eos_token_id def inference(self): raise NotImplementedError(".inference is not implemented") def save_inference_results(self): raise NotImplementedError(".save_inference_results is not implemented") def load_inference_results(self): raise NotImplementedError(".load_inference_results is not implemented") class VLLMInferencer(InferencerWithOffloading): def __init__( self, model_args: ModelArguments, data_args: DatasetArguments, inferencer_args: InferencerArguments, ): assert inferencer_args.use_vllm, "The inferencer_args.use_vllm must be True." super().__init__(model_args, data_args, inferencer_args) self.sampling_params = self.parse_to_sampling_params(inferencer_args) def parse_to_sampling_params( self, inference_args: InferencerArguments, ) -> SamplingParams: return SamplingParams( use_beam_search=inference_args.use_beam_search, n=inference_args.num_output_sequences, temperature=inference_args.temperature + 1e-6, max_tokens=inference_args.max_new_tokens, seed=inference_args.random_seed, top_p=inference_args.top_p, top_k=inference_args.top_k, stop_token_ids=[self.eos_token_id] + inference_args.additional_stop_token_ids, ) def inference( self, model: HFDecoderModel, dataset: Dataset, enable_decode_inference_result: bool = True, release_gpu: bool = False, inference_args: Optional[InferencerArguments] = None, enable_distributed_inference: bool = False, **kwargs, ) -> list[VLLMInferenceResultWithInput]: """Perform inference using the provided model and dataset. Will save inference results if `save_results` is set to True in `inferencer_args`. Parameters ---------- model : HFDecoderModel LMFlow HFDecoderModel object dataset : Dataset LMFlow Dataset object apply_chat_template : bool, optional Whether to apply chat template to the input, by default True. enable_decode_inference_result : bool, optional Whether to decode after generation, by default False. release_gpu : bool, optional Whether to release gpu resources, by default False. inference_args : InferencerArguments, optional by default None Returns ------- list[VLLMInferenceResultWithInput] Return a list of VLLMInferenceResultWithInput, where each element contains the input prompt and the corresponding output. When `enable_decode_inference_result = True`, the output would be a list of strings, contains sampling_params.n samples for the corresponding prompt. When `enable_decode_inference_result = False`, return a list of list of ints (token ids, no decoding after generation). """ if inference_args: logger.warning("Overriding the default inference arguments with the provided arguments in .inference()") sampling_params = self.parse_to_sampling_params(inference_args) else: sampling_params = self.sampling_params sampling_params.detokenize = enable_decode_inference_result model_input = model.prepare_inputs_for_inference( dataset=dataset, apply_chat_template=self.inferencer_args.apply_chat_template, use_vllm=self.inferencer_args.use_vllm, enable_distributed_inference=enable_distributed_inference, ) if enable_distributed_inference: outputs = self._distributed_inference( model=model, model_input=model_input, sampling_params=sampling_params, num_instances=kwargs.get("distributed_inference_num_instances"), batch_size=kwargs.get("inference_batch_size", 4), release_gpu=release_gpu, ) else: outputs = self._inference( model=model, model_input=model_input, sampling_params=sampling_params, release_gpu=release_gpu, ) if self.inferencer_args.save_results: self.save_inference_results(outputs, self.inferencer_args.results_path) return outputs def _inference( self, model: HFDecoderModel, model_input: list[str], sampling_params: SamplingParams, release_gpu: bool = False, ) -> list[VLLMInferenceResultWithInput]: outputs = model.inference( inputs=model_input, sampling_params=sampling_params, release_gpu=release_gpu, use_vllm=True, gpu_memory_utilization=self.inferencer_args.inference_gpu_memory_utilization, tensor_parallel_size=self.inferencer_args.inference_tensor_parallel_size, ) return outputs def _distributed_inference( self, model: HFDecoderModel, model_input: ray.data.Dataset, sampling_params: SamplingParams, num_instances: int, batch_size: int = 4, release_gpu: bool = False, ) -> list[VLLMInferenceResultWithInput]: # prepare distributed inference resources # from https://github.com/vllm-project/vllm/blob/main/examples/offline_inference_distributed.py ## strategy def scheduling_strategy_fn(): # One bundle per tensor parallel worker pg = ray.util.placement_group( [{"GPU": 1, "CPU": 1}] * self.inferencer_args.inference_tensor_parallel_size, strategy="STRICT_PACK", ) return dict( scheduling_strategy=PlacementGroupSchedulingStrategy(pg, placement_group_capture_child_tasks=True) ) resources_kwarg: dict[str, Any] = {} if self.inferencer_args.inference_tensor_parallel_size == 1: # For tensor_parallel_size == 1, we simply set num_gpus=1. resources_kwarg["num_gpus"] = 1 else: # Otherwise, we have to set num_gpus=0 and provide # a function that will create a placement group for # each instance. resources_kwarg["num_gpus"] = 0 resources_kwarg["ray_remote_args_fn"] = scheduling_strategy_fn ## predictor class DistributedPredictor: def __init__( self, model: HFDecoderModel, sampling_params: SamplingParams, gpu_memory_utilization: float, tensor_parallel_size: int, release_gpu: bool = False, ): self.model = copy.deepcopy(model) self.model.activate_model_for_inference( use_vllm=True, gpu_memory_utilization=gpu_memory_utilization, tensor_parallel_size=tensor_parallel_size, ) self.sampling_params = sampling_params self.release_gpu = release_gpu def __call__(self, batch: dict[str, np.ndarray]): """batch: dict[str, np.ndarray], {"item": array(['...', '...', '...', ...])}""" batched_inference_res = self.model.inference( inputs=batch["item"], sampling_params=self.sampling_params, release_gpu=self.release_gpu, use_vllm=True, ) # this is the postprocessed output, see model.__vllm_inference batched_final_res = { "input": [sample["input"] for sample in batched_inference_res], "output": [sample["output"] for sample in batched_inference_res], } # do this since we're writing to a pandas dataframe return batched_final_res # inference model_input_mapping = model_input.map_batches( DistributedPredictor, concurrency=num_instances, # Set the concurrency to the number of LLM instances. batch_size=batch_size, fn_constructor_kwargs={ "model": model, "sampling_params": sampling_params, "gpu_memory_utilization": self.inferencer_args.inference_gpu_memory_utilization, "tensor_parallel_size": self.inferencer_args.inference_tensor_parallel_size, "release_gpu": release_gpu, }, **resources_kwarg, ) df_model_output = model_input_mapping.to_pandas() # the actual forwards are executed here logger.info(f"Distributed vllm inference result preview:\n{df_model_output.head(10)}") model_output = [{"input": row["input"], "output": row["output"]} for _, row in df_model_output[:].iterrows()] return model_output def save_inference_results( self, outputs: Union[list[list[str]], list[list[list[int]]]], save_file_path: str, ): with open(save_file_path, "w", encoding="utf-8") as f: json.dump(outputs, f, ensure_ascii=False, indent=4) logger.info(f"Inference results are saved to {save_file_path}.") def load_inference_results( self, results_path: str, ) -> Union[list[list[str]], list[list[list[int]]]]: with open(results_path) as f: results = json.load(f) return results class MemorySafeVLLMInferencer(VLLMInferencer): def __init__( self, model_args: ModelArguments, data_args: DatasetArguments, inferencer_args: InferencerArguments, ): assert inferencer_args.save_results, "For MemorySafeVLLMInferencer, `save_results` must be True." super().__init__(model_args, data_args, inferencer_args) self.inferencer_file_path = pkg_resources.files("lmflow.pipeline.utils") / "memory_safe_vllm_inference.py" def inference(self) -> list[VLLMInferenceResultWithInput]: inferencer_args = make_shell_args_from_dataclass( dataclass_objects=[ self.model_args, self.data_args, self.inferencer_args, ], format="shell", ) cmd = "python " + str(self.inferencer_file_path) + " " + inferencer_args current_env = os.environ.copy() for var in MEMORY_SAFE_VLLM_INFERENCE_ENV_VAR_TO_REMOVE: current_env.pop(var, None) cli_res = subprocess.run( args=cmd, stdout=sys.stdout, stderr=sys.stdout, shell=True, preexec_fn=os.setsid, env=current_env, ) logger.info(f"MemorySafeVLLMInference subprocess run finished, info at finish: {cli_res}") if cli_res.returncode in RETURN_CODE_ERROR_BUFFER: # > Fatal Python error: _enter_buffered_busy: could not acquire lock for # > <_io.BufferedWriter name=''> at interpreter shutdown, possibly # > due to daemon threads logger.warning( "^^^^^^^^^^ Please ignore the above error, as it comes from the subprocess. " "This may due to a kill signal with unfinished stdout/stderr writing in the subprocess. " ) else: if cli_res.returncode != 0: raise RuntimeError(f"Error during MemorySafeVLLMInference: {cli_res}") outputs = self.load_inference_results(self.inferencer_args.results_path) logger.info("MemorySafeVLLMInference result captured.") return outputs ================================================ FILE: src/lmflow/tokenization/__init__.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. ================================================ FILE: src/lmflow/tokenization/hf_decoder_model.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import logging from typing import Union import transformers from transformers import PreTrainedTokenizer, PreTrainedTokenizerFast from transformers.testing_utils import CaptureLogger from lmflow.args import DatasetArguments from lmflow.utils.constants import CONVERSATION_ROLE_NAMES from lmflow.utils.conversation_template import ConversationTemplate logger = logging.getLogger(__name__) tok_logger = transformers.utils.logging.get_logger("transformers.tokenization_utils_base") def blocking( token_dict: dict, block_size: int, model_max_length: int, pad_token_id: int, padding_side: str, truncation_side: str = "right", ) -> dict: num_example = len(token_dict[list(token_dict.keys())[0]]) for i in range(num_example): max_length = min(block_size, model_max_length) pad_length = max_length - len(token_dict["input_ids"][i]) if pad_length < 0: # Truncates too long samples for key in ["input_ids", "attention_mask", "labels"]: if truncation_side == "right": token_dict[key][i] = token_dict[key][i][:max_length] elif truncation_side == "left": token_dict[key][i] = token_dict[key][i][-max_length:] else: raise ValueError(f"truncation_side should be either 'right' or 'left', got {truncation_side}") else: if padding_side == "right": # Pads too short samples token_dict["input_ids"][i].extend([pad_token_id for _ in range(pad_length)]) token_dict["attention_mask"][i].extend([0 for _ in range(pad_length)]) token_dict["labels"][i].extend([-100 for _ in range(pad_length)]) elif padding_side == "left": # Pads too short samples token_dict["input_ids"][i] = [pad_token_id for _ in range(pad_length)] + token_dict["input_ids"][i] token_dict["attention_mask"][i] = [0 for _ in range(pad_length)] + token_dict["attention_mask"][i] token_dict["labels"][i] = [-100 for _ in range(pad_length)] + token_dict["labels"][i] else: raise ValueError(f"padding_side should be either 'right' or 'left', got {padding_side}") return token_dict def tokenize_function( examples, data_args: DatasetArguments, tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast], column_names, label_columns, tokenized_column_order, add_special_tokens, use_truncation, ) -> dict: """Handels text_only and text2text datasets tokenization""" num_example = len(examples[column_names[0]]) token_dict = { "input_ids": [[] for _ in range(num_example)], "attention_mask": [[] for _ in range(num_example)], "labels": [[] for _ in range(num_example)], } with CaptureLogger(tok_logger) as cl: for column_name in tokenized_column_order: encoding = tokenizer( examples[column_name], add_special_tokens=add_special_tokens, truncation=use_truncation, ) if column_name in label_columns: labels = encoding["input_ids"].copy() else: labels = [[-100] * len(encoding["input_ids"][i]) for i in range(num_example)] for i in range(num_example): token_dict["input_ids"][i].extend(encoding["input_ids"][i]) token_dict["attention_mask"][i].extend(encoding["attention_mask"][i]) token_dict["labels"][i].extend(labels[i]) if data_args.disable_group_texts: token_dict = blocking( token_dict=token_dict, block_size=data_args.block_size, model_max_length=tokenizer.model_max_length, pad_token_id=tokenizer.pad_token_id, padding_side=tokenizer.padding_side, truncation_side=tokenizer.truncation_side, ) # clm input could be much much longer than block_size if "Token indices sequence length is longer than the" in cl.out: tok_logger.warning( "^^^^^^^^^^^^^^^^ Please ignore the warning above - this long input will be chunked into smaller bits" " before being passed to the model." ) return token_dict def conversation_tokenize_function( examples, data_args: DatasetArguments, tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast], column_names, conversation_template: Union[ConversationTemplate, str], ) -> dict: """Handels conversation datasets tokenization""" num_example = len(examples[column_names[0]]) token_dict = { "input_ids": [[] for _ in range(num_example)], "attention_mask": [[] for _ in range(num_example)], "labels": [[] for _ in range(num_example)], } with CaptureLogger(tok_logger) as cl: for i in range(len(examples["messages"])): messages = examples["messages"][i] system = examples.get("system", [None] * num_example)[i] tools = examples.get("tools", [None] * num_example)[i] if isinstance(conversation_template, str): # jinja template conversation = [{"role": "system", "content": system}] if system is not None else [] conversation.extend(messages) encoded_conversation = tokenizer.apply_chat_template( conversation=conversation, tools=tools, chat_template=conversation_template, return_assistant_tokens_mask=True, return_dict=True, ) if data_args.train_on_prompt: labels = encoded_conversation["input_ids"] else: assistant_masks = encoded_conversation.get("assistant_masks", None) if assistant_masks is None: raise RuntimeError( "Tokenizer chat template path requires `assistant_masks` for label masking when " "`train_on_prompt=False`. Please upgrade transformers/tokenizer support, " "or use an LMFlow conversation template." ) labels = [ encoded_conversation["input_ids"][index] if mask == 1 else -100 for index, mask in enumerate(assistant_masks) ] token_dict["input_ids"][i].extend(encoded_conversation["input_ids"]) token_dict["attention_mask"][i].extend(encoded_conversation["attention_mask"]) token_dict["labels"][i].extend(labels) else: # lmflow `conversation_template` if len(messages) < 2 or messages[0]["role"] != CONVERSATION_ROLE_NAMES["user"]: tok_logger.warning( "Invalid instance encountered. Either the conversation has less than " "one round or the first message is not from the user." ) continue if len(messages) % 2 != 0: logger.warning("The number of messages is not even, the last message will be ignored.") messages = messages[:-1] encoded_conversation = conversation_template.encode_conversation( tokenizer=tokenizer, messages=messages, system=system, tools=tools, ) input_ids, labels = [], [] for turn_idx, (user_input, assistant_result) in enumerate(encoded_conversation): input_ids += user_input + assistant_result if data_args.train_on_prompt: labels += user_input + assistant_result else: labels += [-100] * len(user_input) + assistant_result token_dict["input_ids"][i].extend(input_ids) token_dict["attention_mask"][i].extend([1] * len(input_ids)) token_dict["labels"][i].extend(labels) if data_args.disable_group_texts: token_dict = blocking( token_dict=token_dict, block_size=data_args.block_size, model_max_length=tokenizer.model_max_length, pad_token_id=tokenizer.pad_token_id, padding_side=tokenizer.padding_side, truncation_side=tokenizer.truncation_side, ) # clm input could be much much longer than block_size if "Token indices sequence length is longer than the" in cl.out: tok_logger.warning( "^^^^^^^^^^^^^^^^ Please ignore the warning above - this long input will be chunked into smaller bits" " before being passed to the model." ) return token_dict ================================================ FILE: src/lmflow/tokenization/hf_text_regression_model.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import logging from typing import Union import transformers from transformers import PreTrainedTokenizer, PreTrainedTokenizerFast from transformers.testing_utils import CaptureLogger from lmflow.args import DatasetArguments from lmflow.utils.constants import CONVERSATION_ROLE_NAMES from lmflow.utils.conversation_template import ConversationTemplate logger = logging.getLogger(__name__) tok_logger = transformers.utils.logging.get_logger("transformers.tokenization_utils_base") def blocking_paired( token_dict: dict, column_names: list, block_size: int, model_max_length: int, pad_token_id: int, padding_side: str, truncation_side: str = "right", ) -> dict: num_example = len(token_dict[list(token_dict.keys())[0]]) for i in range(num_example): for column_name in column_names: max_length = min(block_size, model_max_length) pad_length = max_length - len(token_dict[f"input_ids_{column_name}"][i]) if pad_length < 0: # Truncates too long samples for key in [f"input_ids_{column_name}", f"attention_mask_{column_name}"]: if truncation_side == "right": token_dict[key][i] = token_dict[key][i][:pad_length] elif truncation_side == "left": token_dict[key][i] = token_dict[key][i][-pad_length:] else: raise ValueError(f"truncation_side should be either 'right' or 'left', got {truncation_side}") else: if padding_side == "right": # Pads too short samples token_dict[f"input_ids_{column_name}"][i].extend([pad_token_id for _ in range(pad_length)]) token_dict[f"attention_mask_{column_name}"][i].extend([0 for _ in range(pad_length)]) elif padding_side == "left": # Pads too short samples token_dict[f"input_ids_{column_name}"][i] = [pad_token_id for _ in range(pad_length)] + token_dict[ f"input_ids_{column_name}" ][i] token_dict[f"attention_mask_{column_name}"][i] = [0 for _ in range(pad_length)] + token_dict[ f"attention_mask_{column_name}" ][i] else: raise ValueError(f"padding_side should be either 'right' or 'left', got {padding_side}") return token_dict def blocking( token_dict: dict, block_size: int, model_max_length: int, pad_token_id: int, padding_side: str, truncation_side: str = "right", ) -> dict: num_example = len(token_dict[list(token_dict.keys())[0]]) for i in range(num_example): max_length = min(block_size, model_max_length) pad_length = max_length - len(token_dict["input_ids"][i]) if pad_length < 0: # Truncates too long samples for key in ["input_ids", "attention_mask", "labels"]: if truncation_side == "right": token_dict[key][i] = token_dict[key][i][:pad_length] elif truncation_side == "left": token_dict[key][i] = token_dict[key][i][-pad_length:] else: raise ValueError(f"truncation_side should be either 'right' or 'left', got {truncation_side}") else: if padding_side == "right": # Pads too short samples token_dict["input_ids"][i].extend([pad_token_id for _ in range(pad_length)]) token_dict["attention_mask"][i].extend([0 for _ in range(pad_length)]) token_dict["labels"][i].extend([-100 for _ in range(pad_length)]) elif padding_side == "left": # Pads too short samples token_dict["input_ids"][i] = [pad_token_id for _ in range(pad_length)] + token_dict["input_ids"][i] token_dict["attention_mask"][i] = [0 for _ in range(pad_length)] + token_dict["attention_mask"][i] token_dict["labels"][i] = [-100 for _ in range(pad_length)] + token_dict["labels"][i] else: raise ValueError(f"padding_side should be either 'right' or 'left', got {padding_side}") return token_dict def blocking_text_to_textlist( token_dict: dict, block_size: int, model_max_length: int, pad_token_id: int, padding_side: str, truncation_side: str = "right", ) -> dict: num_example = len(token_dict[list(token_dict.keys())[0]]) max_length = min(block_size, model_max_length) for example_idx in range(num_example): for content_idx in range(len(token_dict["input_ids"][example_idx])): pad_length = max_length - len(token_dict["input_ids"][example_idx][content_idx]) if pad_length < 0: # Truncates too long samples if truncation_side == "right": token_dict["input_ids"][example_idx][content_idx] = token_dict["input_ids"][example_idx][ content_idx ][:pad_length] elif truncation_side == "left": token_dict["input_ids"][example_idx][content_idx] = token_dict["input_ids"][example_idx][ content_idx ][-pad_length:] else: raise ValueError(f"truncation_side should be either 'right' or 'left', got {truncation_side}") else: if padding_side == "right": # Pads too short samples token_dict["input_ids"][example_idx][content_idx].extend([pad_token_id for _ in range(pad_length)]) elif padding_side == "left": # Pads too short samples token_dict["input_ids"][example_idx][content_idx] = [ pad_token_id for _ in range(pad_length) ] + token_dict["input_ids"][example_idx][content_idx] else: raise ValueError(f"padding_side should be either 'right' or 'left', got {padding_side}") return token_dict def paired_conversation_tokenize_function( examples, data_args: DatasetArguments, tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast], column_names, conversation_template: ConversationTemplate, ) -> dict: num_example = len(examples[column_names[0]]) token_dict = {} for column_name in column_names: token_dict[f"input_ids_{column_name}"] = [[] for _ in range(num_example)] token_dict[f"attention_mask_{column_name}"] = [[] for _ in range(num_example)] with CaptureLogger(tok_logger) as cl: num_corrupted = 0 for i in range(num_example): try: for column_name in column_names: messages = examples[column_name][i]["messages"] system = examples[column_name][i].get("system", None) tools = examples[column_name][i].get("tools", None) if len(messages) < 2 or messages[0]["role"] != CONVERSATION_ROLE_NAMES["user"]: tok_logger.warning( "Invalid instance encountered. Either the conversation has less than " "one round or the first message is not from the user." ) continue if len(messages) % 2 != 0: logger.warning("The number of messages is not even, the last message will be ignored.") messages = messages[:-1] encoded_conversation = conversation_template.encode_conversation( tokenizer=tokenizer, messages=messages, system=system, tools=tools, ) input_ids = [] for turn_idx, (user_input, assistant_result) in enumerate(encoded_conversation): input_ids += user_input + assistant_result token_dict[f"input_ids_{column_name}"][i].extend(input_ids) token_dict[f"attention_mask_{column_name}"][i].extend([1] * len(input_ids)) except Exception: num_corrupted += 1 logger.error(f"Error in encoding conversation {i}: {column_name}") logger.error(f"Messages: {messages}") continue if num_corrupted > 0: logger.error(f"Number of corrupted examples: {num_corrupted}") if data_args.disable_group_texts: token_dict = blocking_paired( token_dict=token_dict, column_names=column_names, block_size=data_args.block_size, model_max_length=tokenizer.model_max_length, pad_token_id=tokenizer.pad_token_id, padding_side=tokenizer.padding_side, truncation_side=tokenizer.truncation_side, ) # clm input could be much much longer than block_size if "Token indices sequence length is longer than the" in cl.out: tok_logger.warning( "^^^^^^^^^^^^^^^^ Please ignore the warning above - this long input will be chunked into smaller bits" " before being passed to the model." ) return token_dict def conversation_tokenize_function( examples, data_args: DatasetArguments, tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast], column_names, conversation_template: ConversationTemplate, ) -> dict: """Handels conversation datasets tokenization""" num_example = len(examples[column_names[0]]) token_dict = { "input_ids": [[] for _ in range(num_example)], "attention_mask": [[] for _ in range(num_example)], "labels": [[] for _ in range(num_example)], } with CaptureLogger(tok_logger) as cl: for i in range(len(examples["messages"])): messages = examples["messages"][i] system = examples.get("system", [None] * num_example)[i] tools = examples.get("tools", [None] * num_example)[i] if len(messages) < 2 or messages[0]["role"] != CONVERSATION_ROLE_NAMES["user"]: tok_logger.warning( "Invalid instance encountered. Either the conversation has less than " "one round or the first message is not from the user." ) continue if len(messages) % 2 != 0: logger.warning("The number of messages is not even, the last message will be ignored.") messages = messages[:-1] encoded_conversation = conversation_template.encode_conversation( tokenizer=tokenizer, messages=messages, system=system, tools=tools, ) input_ids, labels = [], [] for turn_idx, (user_input, assistant_result) in enumerate(encoded_conversation): input_ids += user_input + assistant_result if data_args.train_on_prompt: labels += user_input + assistant_result else: labels += [-100] * len(user_input) + assistant_result token_dict["input_ids"][i].extend(input_ids) token_dict["attention_mask"][i].extend([1] * len(input_ids)) token_dict["labels"][i].extend(labels) if data_args.disable_group_texts: token_dict = blocking( token_dict=token_dict, block_size=data_args.block_size, model_max_length=tokenizer.model_max_length, pad_token_id=tokenizer.pad_token_id, padding_side=tokenizer.padding_side, truncation_side=tokenizer.truncation_side, ) # clm input could be much much longer than block_size if "Token indices sequence length is longer than the" in cl.out: tok_logger.warning( "^^^^^^^^^^^^^^^^ Please ignore the warning above - this long input will be chunked into smaller bits" " before being passed to the model." ) return token_dict def tokenize_function( examples, data_args: DatasetArguments, tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast], column_names, label_columns, tokenized_column_order, add_special_tokens, use_truncation, ) -> dict: """Handels text_only and text2text datasets tokenization""" num_example = len(examples[column_names[0]]) token_dict = { "input_ids": [[] for _ in range(num_example)], "attention_mask": [[] for _ in range(num_example)], "labels": [[] for _ in range(num_example)], } with CaptureLogger(tok_logger) as cl: for column_name in tokenized_column_order: encoding = tokenizer( examples[column_name], add_special_tokens=add_special_tokens, truncation=use_truncation, ) if column_name in label_columns: labels = encoding["input_ids"].copy() else: labels = [[-100] * len(encoding["input_ids"][i]) for i in range(num_example)] for i in range(num_example): token_dict["input_ids"][i].extend(encoding["input_ids"][i]) token_dict["attention_mask"][i].extend(encoding["attention_mask"][i]) token_dict["labels"][i].extend(labels[i]) if data_args.disable_group_texts: token_dict = blocking( token_dict=token_dict, block_size=data_args.block_size, model_max_length=tokenizer.model_max_length, pad_token_id=tokenizer.pad_token_id, padding_side=tokenizer.padding_side, truncation_side=tokenizer.truncation_side, ) # clm input could be much much longer than block_size if "Token indices sequence length is longer than the" in cl.out: tok_logger.warning( "^^^^^^^^^^^^^^^^ Please ignore the warning above - this long input will be chunked into smaller bits" " before being passed to the model." ) return token_dict def text_to_textlist_tokenize_function( examples, data_args: DatasetArguments, tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast], column_names, add_special_tokens, use_truncation, ) -> dict: """For rm inference, and don't need attn mask and labels. NOTE: input_ids here refers to the tokenized input_ids of the input **and** output """ num_example = len(examples[column_names[0]]) output_dict = {column_name: examples[column_name] for column_name in column_names} output_dict["input_ids"] = [[] for _ in range(num_example)] for example_idx in range(num_example): encoded = tokenizer( [ examples["input"][example_idx] + examples["output"][example_idx][i] for i in range(len(examples["output"][example_idx])) ], add_special_tokens=add_special_tokens, truncation=use_truncation, ) output_dict["input_ids"][example_idx] = encoded["input_ids"] if data_args.disable_group_texts: output_dict = blocking_text_to_textlist( token_dict=output_dict, block_size=data_args.block_size, model_max_length=tokenizer.model_max_length, pad_token_id=tokenizer.pad_token_id, padding_side=tokenizer.padding_side, truncation_side=tokenizer.truncation_side, ) return output_dict ================================================ FILE: src/lmflow/utils/__init__.py ================================================ ================================================ FILE: src/lmflow/utils/common.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import logging from dataclasses import Field, fields, make_dataclass from pathlib import Path from typing import Optional, Union from lmflow.utils.versioning import get_python_version logger = logging.getLogger(__name__) def make_shell_args_from_dataclass( dataclass_objects: list, format: str = "subprocess", skip_default: bool = True, ignored_args_list: Optional[list[str]] = None, ) -> Union[str, list[str]]: """Return a string or a list of strings that can be used as shell arguments. Parameters ---------- dataclass_objects : list A list of dataclass objects. format : str, optional Return format, can be "shell" or "subprocess", by default "subprocess". skip_default : bool, optional Whether to skip attributes with default values, by default True. Returns ------- Union[str, list[str]] """ assert isinstance(dataclass_objects, list), "dataclass_objects should be a list of dataclass objects." all_args = {} for dataclass_object in dataclass_objects: for k, v in dataclass_object.__dict__.items(): if ignored_args_list and k in ignored_args_list: continue if k not in dataclass_object.__dataclass_fields__: # skip attributes that added dynamically continue if not v: # skip attributes with None values continue if skip_default: if dataclass_object.__dataclass_fields__[k].default == v: continue if k not in all_args: if isinstance(v, Path): all_args[k] = str(v) elif isinstance(v, list): all_args[k] = ",".join(v) else: all_args[k] = v elif k in all_args: if all_args[k] == v: continue else: logger.warning(f"Found different values for the same key: {k}, using value: {v} instead.") all_args[k] = v if format == "shell": final_res = " ".join([f"--{k} {v}" for k, v in all_args.items()]) elif format == "subprocess": final_res = [] for k, v in all_args.items(): final_res.extend([f"--{k}", str(v)]) else: raise ValueError(f"Unknown format: {format}") return final_res def create_copied_dataclass(original_dataclass, field_prefix: str, class_prefix: str, new_default: dict = None): """Create a copied dataclass with new field names and default values. Parameters ---------- original_dataclass : dataclass field_prefix : str The prefix to add to the **field** names of the copied dataclass. class_prefix : str The prefix to add to the **class** name of the copied dataclass. new_default : dict, optional The new default values for the copied dataclass. When None, the default values of the original dataclass are used. Returns ------- dataclass """ original_fields = fields(original_dataclass) new_default = new_default or {} new_fields = [] for field in original_fields: if get_python_version().minor >= 10: new_field = ( f"{field_prefix}{field.name}", field.type, Field( default=new_default.get(f"{field_prefix}{field.name}", field.default), default_factory=field.default_factory, init=field.init, repr=field.repr, hash=field.hash, compare=field.compare, metadata=field.metadata, kw_only=False, # add in py3.10: https://docs.python.org/3/library/dataclasses.html ), ) else: new_field = ( f"{field_prefix}{field.name}", field.type, Field( default=new_default.get(f"{field_prefix}{field.name}", field.default), default_factory=field.default_factory, init=field.init, repr=field.repr, hash=field.hash, compare=field.compare, metadata=field.metadata, ), ) new_fields.append(new_field) copied_dataclass = make_dataclass(f"{class_prefix}{original_dataclass.__name__}", new_fields) return copied_dataclass def remove_dataclass_attr_prefix(data_instance, prefix: str) -> dict: """Remove the prefix from the attribute names of a dataclass instance. Parameters ---------- data_instance : dataclass prefix : str The prefix to remove from the attribute names of the dataclass instance. Returns ------- dict """ new_attributes = {} for field in fields(data_instance): attr_name = field.name attr_value = getattr(data_instance, attr_name) new_attr_name = f"{attr_name[len(prefix) :]}" new_attributes[new_attr_name] = attr_value return new_attributes def add_dataclass_attr_prefix(data_instance, prefix: str) -> dict: """Add the prefix to the attribute names of a dataclass instance. Parameters ---------- data_instance : dataclass prefix : str The prefix to add to the attribute names of the dataclass instance. Returns ------- dict """ new_attributes = {} for field in fields(data_instance): attr_name = field.name attr_value = getattr(data_instance, attr_name) new_attr_name = f"{prefix}{attr_name}" new_attributes[new_attr_name] = attr_value return new_attributes def print_banner(message: str): length = len(message) + 8 border = "#" * length logger.info(border) logger.info(f"# {message} #") logger.info(border) ================================================ FILE: src/lmflow/utils/constants.py ================================================ #!/usr/bin/env python """ Commonly used constants. """ TEXT_ONLY_DATASET_DESCRIPTION = ( """ "text_only": a dataset with only raw text instances, with following format: { "type": "text_only", "instances": [ { "text": "TEXT_1" }, { "text": "TEXT_2" }, ... ] } """ ).lstrip("\n") TEXT_TO_SCORED_TEXTLIST_DATASET_DESCRIPTION = ( """ This kind of dataset is commonly used in reward model training/prediction, as well as rl training. { "type": "text_to_scored_textlist", "instances": [ { "input": "what's your name?", "output": [ {"score": 1.0, "text": "My name is John"}, {"score": -0.8, "text": "I'm John"} ] }, { "input": "Who are you?", "output": [ {"score": 1.5, "text": "My name is Amy"}, {"score": 1.0, "text": "I'm Amy"} ] }, ] } """ ).lstrip("\n") PAIRED_TEXT_TO_TEXT_DATASET_DESCRIPTION = ( """ This kind of dataset is commonly used in reward model training as well as rl training. { "type": "paired_text_to_text", "instances": [ { "prompt": "Who are you?", "chosen": "My name is Amy.", "rejected": "I'm Amy", "margin": 0.6 }, { "prompt": "what's your name?", "chosen": "My name is John.", "rejected": "I'm John", "margin": 0.5 } ] } """ ).lstrip("\n") TEXT_ONLY_DATASET_DETAILS = ( """ For example, ```python from lmflow.datasets import Dataset data_dict = { "type": "text_only", "instances": [ { "text": "Human: Hello. Bot: Hi!" }, { "text": "Human: How are you today? Bot: Fine, thank you!" }, ] } dataset = Dataset.create_from_dict(data_dict) ``` You may also save the corresponding format to json, ```python import json from lmflow.args import DatasetArguments from lmflow.datasets import Dataset data_dict = { "type": "text_only", "instances": [ { "text": "Human: Hello. Bot: Hi!" }, { "text": "Human: How are you today? Bot: Fine, thank you!" }, ] } with open("data.json", "w") as fout: json.dump(data_dict, fout) data_args = DatasetArgument(dataset_path="data.json") dataset = Dataset(data_args) new_data_dict = dataset.to_dict() # `new_data_dict` Should have the same content as `data_dict` ``` """ ).lstrip("\n") TEXT2TEXT_DATASET_DESCRIPTION = ( """ "text2text": a dataset with input & output instances, with following format: { "type": "text2text", "instances": [ { "input": "INPUT_1", "output": "OUTPUT_1" }, { "input": "INPUT_2", "output": "OUTPUT_2" }, ... ] } """ ).lstrip("\n") CONVERSATION_DATASET_DESCRIPTION = ( """ "conversation": a dataset with conversation instances, with following format (`conversation_id`, `system` and `tools` are optional): { "type": "conversation", "instances": [ { "conversation_id": "CONVERSATION_ID", "system": "SYSTEM_PROPMT", "tools": ["TOOL_DESCRIPTION_1","TOOL_DESCRIPTION_2","TOOL_DESCRIPTION_X"], "messages": [ { "role": "user", "content": "USER_INPUT_1" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_1" }, { "role": "user", "content": "USER_INPUT_2" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_2" } ] }, { "conversation_id": "CONVERSATION_ID", "system": "SYSTEM_PROPMT", "tools": ["TOOL_DESCRIPTION_1"], "messages": [ { "role": "user", "content": "USER_INPUT_1" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_1" } ] } ] } """ ).lstrip("\n") PAIRED_CONVERSATION_DATASET_DESCRIPTION = ( """ "paired_conversation": a dataset with paired conversation instances, with following format: { "type": "paired_conversation", "instances": [ { "chosen": { "conversation_id": "CONVERSATION_ID", "system": "SYSTEM_PROPMT", "tools": ["TOOL_DESCRIPTION_1","TOOL_DESCRIPTION_2","TOOL_DESCRIPTION_3"], "messages": [ { "role": "user", "content": "USER_INPUT_1" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_1_GOOD" }, { "role": "user", "content": "USER_INPUT_2" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_2_GOOD" } ] }, "rejected": { "conversation_id": "CONVERSATION_ID", "system": "SYSTEM_PROPMT", "tools": ["TOOL_DESCRIPTION_1","TOOL_DESCRIPTION_2","TOOL_DESCRIPTION_3"], "messages": [ { "role": "user", "content": "USER_INPUT_1" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_1_BAD" }, { "role": "user", "content": "USER_INPUT_2" }, { "role": "assistant", "content": "ASSISTANT_RESPONSE_2_BAD" } ] } } ] } """ ).lstrip("\n") TEXT_TO_TEXTLIST_DATASET_DESCRIPTION = ( """ This kind of dataset is commonly used in reward model inference. { "type": "text_to_textlist", "instances": [ { "input": "what's your name?", "output": [ "My name is John", "I'm John", ] }, { "input": "Who are you?", "output": [ "My name is Amy", "I'm Amy", ] }, ] } """ ).lstrip("\n") TEXT2TEXT_DATASET_DETAILS = ( """ For example, ```python from lmflow.datasets import Dataset data_dict = { "type": "text2text", "instances": [ { "input": "Human: Hello.", "output": "Bot: Hi!", }, { "input": "Human: How are you today?", "output": "Bot: Fine, thank you! And you?", } ] } dataset = Dataset.create_from_dict(data_dict) ``` You may also save the corresponding format to json, ```python import json from lmflow.args import DatasetArguments from lmflow.datasets import Dataset data_dict = { "type": "text2text", "instances": [ { "input": "Human: Hello.", "output": "Bot: Hi!", }, { "input": "Human: How are you today?", "output": "Bot: Fine, thank you! And you?", } ] } with open("data.json", "w") as fout: json.dump(data_dict, fout) data_args = DatasetArgument(dataset_path="data.json") dataset = Dataset(data_args) new_data_dict = dataset.to_dict() # `new_data_dict` Should have the same content as `data_dict` ``` """ ).lstrip("\n") FLOAT_ONLY_DATASET_DESCRIPTION = ( """ "float_only": a dataset with only float instances, with following format: { "type": "float_only", "instances": [ { "value": "FLOAT_1" }, { "value": "FLOAT_2" }, ... ] } """ ).lstrip("\n") TEXT_ONLY_DATASET_LONG_DESCRITION = TEXT_ONLY_DATASET_DESCRIPTION + TEXT_ONLY_DATASET_DETAILS TEXT2TEXT_DATASET_LONG_DESCRITION = TEXT2TEXT_DATASET_DESCRIPTION + TEXT2TEXT_DATASET_DETAILS DATASET_DESCRIPTION_MAP = { "text_only": TEXT_ONLY_DATASET_DESCRIPTION, "text2text": TEXT2TEXT_DATASET_DESCRIPTION, "float_only": FLOAT_ONLY_DATASET_DESCRIPTION, } INSTANCE_FIELDS_MAP = { "text_only": ["text"], "text2text": ["input", "output"], "conversation": ["messages"], # system, tools and conversation_id are optional "paired_conversation": ["chosen", "rejected"], "paired_text_to_text": ["prompt", "chosen", "rejected"], "float_only": ["value"], "image_text": ["images", "text"], "text_to_textlist": ["input", "output"], "text_to_scored_textlist": ["input", "output"], } CONVERSATION_ROLE_NAMES = { "system": "system", "user": "user", "assistant": "assistant", "function": "function", "observation": "observation", } # LLAVA constants CONTROLLER_HEART_BEAT_EXPIRATION = 30 WORKER_HEART_BEAT_INTERVAL = 15 LOGDIR = "." # Model Constants IGNORE_INDEX = -100 IMAGE_TOKEN_INDEX = -200 DEFAULT_IMAGE_TOKEN = "" DEFAULT_IMAGE_PATCH_TOKEN = "" DEFAULT_IM_START_TOKEN = "" DEFAULT_IM_END_TOKEN = "" # Lora # NOTE: This work as a mapping for those models that `peft` library doesn't support yet, and will be # overwritten by peft.utils.constants.TRANSFORMERS_MODELS_TO_LORA_TARGET_MODULES_MAPPING # if the model is supported (see hf_model_mixin.py). # NOTE: When passing lora_target_modules through arg parser, the # value should be a string. Using commas to separate the module names, e.g. # "--lora_target_modules 'q_proj, v_proj'". # However, when specifying here, they should be lists. LMFLOW_LORA_TARGET_MODULES_MAPPING = { "qwen2": ["q_proj", "v_proj"], "internlm2": ["wqkv"], "hymba": ["x_proj.0", "in_proj", "out_proj", "dt_proj.0"], } # vllm inference MEMORY_SAFE_VLLM_INFERENCE_FINISH_FLAG = "MEMORY_SAFE_VLLM_INFERENCE_DONE" RETURN_CODE_ERROR_BUFFER = [134] # return code 134: # > Fatal Python error: _enter_buffered_busy: could not acquire lock for <_io.BufferedWriter name=''> # > at interpreter shutdown, possibly due to daemon threads # The above error, by our observation, is due to the kill signal with unfinished # stdout/stderr writing in the subprocess MEMORY_SAFE_VLLM_INFERENCE_ENV_VAR_TO_REMOVE = [ "OMP_NUM_THREADS", "LOCAL_RANK", "RANK", "GROUP_RANK", "ROLE_RANK", "ROLE_NAME", "LOCAL_WORLD_SIZE", "WORLD_SIZE", "GROUP_WORLD_SIZE", "ROLE_WORLD_SIZE", "MASTER_ADDR", "MASTER_PORT", "TORCHELASTIC_RESTART_COUNT", "TORCHELASTIC_MAX_RESTARTS", "TORCHELASTIC_RUN_ID", "TORCHELASTIC_USE_AGENT_STORE", "TORCH_NCCL_ASYNC_ERROR_HANDLING", "TORCHELASTIC_ERROR_FILE", ] # dpov2 align MEMORY_SAFE_DPOV2_ALIGN_ENV_VAR_TO_REMOVE = [ "OMP_NUM_THREADS", "LOCAL_RANK", "RANK", "GROUP_RANK", "ROLE_RANK", "ROLE_NAME", "LOCAL_WORLD_SIZE", "WORLD_SIZE", "GROUP_WORLD_SIZE", "ROLE_WORLD_SIZE", "MASTER_ADDR", "MASTER_PORT", "TORCHELASTIC_RESTART_COUNT", "TORCHELASTIC_MAX_RESTARTS", "TORCHELASTIC_RUN_ID", "TORCHELASTIC_USE_AGENT_STORE", "TORCH_NCCL_ASYNC_ERROR_HANDLING", "TORCHELASTIC_ERROR_FILE", ] ================================================ FILE: src/lmflow/utils/conversation_template/__init__.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import logging from lmflow.utils.versioning import is_package_version_at_least from .base import EMPTY_NO_SPECIAL_TOKENS_TEMPLATE, EMPTY_TEMPLATE, ConversationTemplate, ConversationTemplateForTool from .chatglm import CHATGLM3_TEMPLATE from .chatml import CHATML_TEMPLATE from .deepseek import DEEPSEEK_R1_DISTILL_TEMPLATE, DEEPSEEK_R1_TEMPLATE, DEEPSEEK_V2_TEMPLATE, DEEPSEEK_V3_TEMPLATE from .gemma import GEMMA3_TEMPLATE, GEMMA_TEMPLATE from .hymba import HYMBA_TEMPLATE from .internlm import INTERNLM2_TEMPLATE from .llama import LLAMA2_TEMPLATE, LLAMA3_TEMPLATE, LLAMA3_TEMPLATE_FOR_TOOL from .phi import PHI3_TEMPLATE from .qwen import ( QWEN2_5_1M_TEMPLATE, QWEN2_5_MATH_TEMPLATE, QWEN2_5_TEMPLATE, QWEN2_TEMPLATE, QWEN2_TEMPLATE_FOR_TOOL, QWEN3_TEMPLATE, QWEN_QWQ_TEMPLATE, ) from .yi import YI1_5_TEMPLATE from .zephyr import ZEPHYR_TEMPLATE __all__ = [ "ConversationTemplate", "ConversationTemplateForTool", ] logger = logging.getLogger(__name__) PRESET_TEMPLATES = { "chatglm3": CHATGLM3_TEMPLATE, "chatml": CHATML_TEMPLATE, "deepseek": DEEPSEEK_V2_TEMPLATE, "deepseek_v2": DEEPSEEK_V2_TEMPLATE, "disable": EMPTY_TEMPLATE, "empty": EMPTY_TEMPLATE, "empty_no_special_tokens": EMPTY_NO_SPECIAL_TOKENS_TEMPLATE, "gemma": GEMMA_TEMPLATE, "hymba": HYMBA_TEMPLATE, "internlm2": INTERNLM2_TEMPLATE, "llama2": LLAMA2_TEMPLATE, "llama3": LLAMA3_TEMPLATE, "llama3_for_tool": LLAMA3_TEMPLATE_FOR_TOOL, "phi3": PHI3_TEMPLATE, "qwen2": QWEN2_TEMPLATE, "qwen2_for_tool": QWEN2_TEMPLATE_FOR_TOOL, "yi": CHATML_TEMPLATE, "yi1_5": YI1_5_TEMPLATE, "zephyr": ZEPHYR_TEMPLATE, } JINJA_TEMPLATES = { "deepseek_r1": DEEPSEEK_R1_TEMPLATE, "deepseek_r1_distill": DEEPSEEK_R1_DISTILL_TEMPLATE, "deepseek_v3": DEEPSEEK_V3_TEMPLATE, "qwen2_5": QWEN2_5_TEMPLATE, "qwen2_5_1m": QWEN2_5_1M_TEMPLATE, "qwen2_5_math": QWEN2_5_MATH_TEMPLATE, "qwen_qwq": QWEN_QWQ_TEMPLATE, "qwen3": QWEN3_TEMPLATE, "gemma3": GEMMA3_TEMPLATE, } if is_package_version_at_least("transformers", "4.43.0"): for template_name, template in JINJA_TEMPLATES.items(): PRESET_TEMPLATES[template_name] = template else: logger.warning( f"The following conversation templates require transformers>=4.43.0: {JINJA_TEMPLATES.keys()}. " f"Please upgrade `transformers` to use them." ) ================================================ FILE: src/lmflow/utils/conversation_template/base.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import logging import re from abc import ABC, abstractmethod from collections.abc import Sequence from dataclasses import dataclass, field from typing import Literal, Optional, Union from transformers import PreTrainedTokenizer from lmflow.utils.constants import CONVERSATION_ROLE_NAMES logger = logging.getLogger(__name__) @dataclass class TemplateComponent: """The minimal unit of a template, which can be a token, a string, or a list of tools. Parameters ---------- type : Literal['token', 'token_id', 'string', 'tools'] - Type of the component. - When the component is a token or a string, the content should be `string`. The difference between the two is that token will be converted to token ids by the tokenizer.convert_tokens_to_ids() method, while string will be directly encoded by the tokenizer.encode() method. Specially, since the bos token and eos token are frequently used across different templates, we provide the convenience to use `'bos_token'` and `'eos_token'` to represent the actual bos and eos tokens when `type` of the `TemplateComponent` is `token`. For example: ```python TemplateComponent(type='token', content='bos_token') ``` After encoding, the content will be replaced by the actual token id of the bos token. Please do remember that if you set the `type` to `string`, the tokenizer will try to encode the string 'bos_token' instead of providing the actual bos token. - When the component is token_id, the content should be `int` or `list[int]`, and will be directly appended to the encoded token ids. - Tools are not supported yet. content : Union[str, int, list[str], list[int]] Content of the component. """ type: Literal["token", "token_id", "string", "tools"] content: Union[str, int, list[str], list[int]] mask: Optional[bool] = True # for token specific masking, work in progress def __post_init__(self): assert self.content, "Content of the component cannot be empty." if self.type == "tools": assert isinstance(self.content, list), ( f"Content of tools component must be a list, got {type(self.content)}" ) elif self.type in ["token", "string"]: assert isinstance(self.content, str), ( f"Content of string/token component must be a string, got {type(self.content)}" ) elif self.type == "token_id": assert isinstance(self.content, int) or all(isinstance(token_id, int) for token_id in self.content), ( "Content of token_id component must be an integer or a list of integers." ) else: raise ValueError(f"The type of the component must be either 'token', 'string' or 'tools', got {self.type}") def __repr__(self) -> str: return f"TemplateComponent(type={self.type}, content={self.content})".replace("\n", "\\n") def __str__(self) -> str: return f"{self.content}".replace("\n", "\\n") @dataclass class Formatter(ABC): template: list[TemplateComponent] = field(default_factory=list) @abstractmethod def format(self, **kwargs) -> list[TemplateComponent]: ... def has_placeholder(self): flag = False for component in self.template: if component.type == "string": if re.search(r"{{(.*?)}}", component.content): flag = True break return flag @dataclass class EmptyFormatter(Formatter): def __post_init__(self): if self.has_placeholder(): raise ValueError("Empty formatter should not have placeholders.") def format(self, **kwargs) -> list: """Empty formatter for when no formatting is needed. This is useful when user has already applied formatting to the dataset. Returns ------- list Original template. """ return self.template @dataclass class StringFormatter(Formatter): def __post_init__(self): if not self.has_placeholder(): raise ValueError("String formatter should have placeholders.") def format(self, **kwargs) -> list: """Format the string components with the provided keyword arguments. Mostly used for formatting system prompt, user and assistant messages. Parameters ---------- **kwargs : dict Keyword arguments containing values to replace in the template components. Returns ------- list Formatted template. """ formatted_template = [] for component in self.template: if component.type == "string": for key, value in kwargs.items(): templated = component.content.replace("{{" + key + "}}", value) if len(templated) == 0: logger.warning( "Found empty string after formatting, adding a space instead. " "If this is not intended, please check the dataset." ) templated = " " formatted_template.append(TemplateComponent(type="string", content=templated)) else: formatted_template.append(component) logger.debug(formatted_template) return formatted_template @dataclass class ConversationTemplate: user_formatter: Formatter assistant_formatter: Formatter function_formatter: Optional[Formatter] = None observation_formatter: Optional[Formatter] = None system_formatter: Optional[Formatter] = None force_system: bool = False tools_formatter: Optional[Formatter] = None separator: Optional[TemplateComponent] = None remove_last_sep: bool = False special_starter: Optional[TemplateComponent] = None special_stopper: Optional[TemplateComponent] = None template_name: Optional[str] = None system_default: Optional[str] = None def __post_init__(self): if self.separator: if self.separator.type not in ["string", "token", "token_id"]: raise NotImplementedError(f"Component type {self.separator.type} cannot be used as a separator.") if self.special_starter: if self.special_starter.type not in ["string", "token", "token_id"]: raise NotImplementedError( f"Component type {self.special_starter.type} cannot be used as a special starter." ) def encode_conversation( self, tokenizer: PreTrainedTokenizer, messages: list[dict[str, str]], system: Optional[str] = None, tools: Optional[list[str]] = None, **kwargs, ) -> Sequence[tuple[list[int], list[int]]]: r""" Messages here should be guaranteed to be in pairs, with the first message being the user message and the second message being the system message. Data example: ```json { "conversation_id": 2, "system": "sysinfo1", "tools": ["tool_1_desc"], "messages": [ { "role": "user", "content": "hi" }, { "role": "assistant", "content": "Hello!" } ] } ``` """ assert isinstance(messages, list), "Messages must be a list." if tools: logger.warning("Tools are not supported yet. Please include tools in the system message manually.") if system: if system.replace(" ", ""): if not self.system_formatter: raise ValueError( "Your dataset contains system message but no system formatter is provided. " "Consider either providing a system formatter or removing system prompt from your dataset." ) else: system = self.system_default if self.system_default else None encoded_pairs = self._encode(tokenizer, messages, system, tools, **kwargs) encoded_pairs = self.post_process_pairs(encoded_pairs=encoded_pairs, tokenizer=tokenizer) return encoded_pairs def _encode( self, tokenizer: PreTrainedTokenizer, messages: list[dict[str, str]], system: Optional[str] = None, tools: Optional[str] = None, **kwargs, ) -> Sequence[tuple[list[int], list[int]]]: # TODO: truncation according to model max length # TODO: make sure the last few tokens are "learnable", not masked with token_id = -100. res_all = [] if system: system_formatted = self.system_formatter.format(content=system) else: system_formatted = self.system_formatter.format(content="") if self.force_system else [] system_encoded = self._encode_template(system_formatted, tokenizer) for i in range(0, len(messages), 2): user_message = messages[i] assistant_message = messages[i + 1] user_formatted = self.user_formatter.format(content=user_message["content"]) assistant_formatted = self.assistant_formatter.format(content=assistant_message["content"]) user_encoded = self._encode_template(user_formatted, tokenizer) assistant_encoded = self._encode_template(assistant_formatted, tokenizer) res_all.append((system_encoded + user_encoded if i == 0 else user_encoded, assistant_encoded)) return res_all def _encode_template( self, template: list[TemplateComponent], tokenizer: PreTrainedTokenizer, **kwargs ) -> list[int]: """Encode template components into token ids. Parameters ---------- template : list[TemplateComponent] Formatted template components. tokenizer : PreTrainedTokenizer Tokenizer to convert tokens into token ids. Returns ------- list[int] Encoded token ids. """ encoded_ids = [] for component in template: if component.type == "string": if len(component.content) == 0: logger.warning("Empty string component found in the template.") continue else: encoded_ids += tokenizer.encode(component.content, add_special_tokens=False) elif component.type == "token": if component.content == "bos_token": encoded_ids += [tokenizer.bos_token_id] elif component.content == "eos_token": encoded_ids += [tokenizer.eos_token_id] else: encoded_ids += self._ensure_id_list(tokenizer.convert_tokens_to_ids(component.content)) elif component.type == "token_id": encoded_ids += self._ensure_id_list(component.content) else: raise NotImplementedError(f"Component type {component.type} is not supported yet.") return encoded_ids def post_process_pairs(self, encoded_pairs, tokenizer): if self.separator and self.remove_last_sep: # For models that require a separator between messages, # user can include the seperator at the end of each template # and specify the separator. Auto formatting will remove the # last separator once user specifies this option. encoded_pairs = self.remove_last_separator(encoded_pairs, tokenizer) if self.special_starter: # For models that has ONLY ONE bos token at the beginning of # a conversation session (not a conversation pair), user can # specify a special starter to add that starter to the very # beginning of the conversation session. # eg: # llama-2: and at every pair of conversation # v.s. # llama-3: <|begin_of_text|> only at the beginning of a session encoded_pairs = self.add_special_starter(encoded_pairs, tokenizer) if self.special_stopper: encoded_pairs = self.add_special_stopper(encoded_pairs, tokenizer) return encoded_pairs def remove_last_separator( self, encoded_pairs: Sequence[tuple[list[int], list[int]]], tokenizer: PreTrainedTokenizer ) -> Sequence[tuple[list[int], list[int]]]: last_assistant_msg = encoded_pairs[-1][1] if self.separator.type == "string": separator_ids = tokenizer.encode(self.separator.content, add_special_tokens=False) elif self.separator.type == "token": separator_ids = self._ensure_id_list(tokenizer.convert_tokens_to_ids(self.separator.content)) elif self.separator.type == "token_id": separator_ids = self._ensure_id_list(self.separator.content) else: raise ValueError(f"Component type {self.separator.type} cannot be used as a separator.") if len(separator_ids) > len(last_assistant_msg): raise ValueError("Separator is longer than the last assistant message, please check.") if last_assistant_msg[-len(separator_ids) :] == separator_ids: last_assistant_msg = last_assistant_msg[: -len(separator_ids)] encoded_pairs[-1] = (encoded_pairs[-1][0], last_assistant_msg) return encoded_pairs def add_special_starter( self, encoded_pairs: Sequence[tuple[list[int], list[int]]], tokenizer: PreTrainedTokenizer ) -> Sequence[tuple[list[int], list[int]]]: if self.special_starter.type == "string": special_starter_ids = tokenizer.encode(self.special_starter.content, add_special_tokens=False) elif self.special_starter.type == "token": if self.special_starter.content == "bos_token": special_starter_ids = [tokenizer.bos_token_id] elif self.special_starter.content == "eos_token": special_starter_ids = [tokenizer.eos_token_id] else: special_starter_ids = self._ensure_id_list( tokenizer.convert_tokens_to_ids(self.special_starter.content) ) elif self.special_starter.type == "token_id": special_starter_ids = self._ensure_id_list(self.special_starter.content) else: raise ValueError(f"Component type {self.special_starter.type} cannot be used as a special starter.") encoded_pairs[0] = (special_starter_ids + encoded_pairs[0][0], encoded_pairs[0][1]) return encoded_pairs def add_special_stopper( self, encoded_pairs: Sequence[tuple[list[int], list[int]]], tokenizer: PreTrainedTokenizer ) -> Sequence[tuple[list[int], list[int]]]: if self.special_stopper.type == "string": special_stopper_ids = tokenizer.encode(self.special_stopper.content, add_special_tokens=False) elif self.special_stopper.type == "token": if self.special_stopper.content == "bos_token": special_stopper_ids = [tokenizer.bos_token_id] elif self.special_stopper.content == "eos_token": special_stopper_ids = [tokenizer.eos_token_id] else: special_stopper_ids = self._ensure_id_list( tokenizer.convert_tokens_to_ids(self.special_stopper.content) ) elif self.special_stopper.type == "token_id": special_stopper_ids = self._ensure_id_list(self.special_stopper.content) else: raise ValueError(f"Component type {self.special_stopper.type} cannot be used as a special stopper.") encoded_pairs[-1] = (encoded_pairs[-1][0], encoded_pairs[-1][1] + special_stopper_ids) return encoded_pairs def _ensure_id_list(self, obj: Union[int, list[int]]) -> list[int]: """Make sure the object is a list of integers. Useful for handling token ids.""" if isinstance(obj, int): return [obj] elif isinstance(obj, list): return obj else: raise ValueError(f"Object type {type(obj)} is not supported yet.") @dataclass class ConversationTemplateForTool(ConversationTemplate): def encode_conversation( self, tokenizer: PreTrainedTokenizer, messages: list[dict[str, str]], system: Optional[str] = None, tools: Optional[list[str]] = None, **kwargs, ) -> Sequence[tuple[list[int], list[int]]]: r""" Messages here should be guaranteed to be in pairs, with the first message being the user message and the second message being the system message. Data example: ```json { "conversation_id": 2, "system": "sysinfo1", "tools": ["tool_1_desc"], "messages": [ { "role": "user", "content": "hi" }, { "role": "assistant", "content": "Hello!" } ] } ``` """ assert isinstance(messages, list), "Messages must be a list." tools = self._handle_tools(tools) if system is None: system = "" else: if system.replace(" ", ""): if not self.system_formatter: raise ValueError( "Your dataset contains system message but no system formatter is provided. " "Consider either providing a system formatter or removing system prompt from your dataset." ) else: system = self.system_default if self.system_default else "" encoded_pairs = self._encode(tokenizer, messages, system, tools, **kwargs) encoded_pairs = self.post_process_pairs(encoded_pairs=encoded_pairs, tokenizer=tokenizer) return encoded_pairs def _encode( self, tokenizer: PreTrainedTokenizer, messages: list[dict[str, str]], system: Optional[str] = None, tools: Optional[str] = None, **kwargs, ) -> Sequence[tuple[list[int], list[int]]]: # TODO: truncation according to model max length # TODO: make sure the last few tokens are "learnable", not masked with token_id = -100. res_all = [] # Concatenate the system and tools strings system = system + tools if system: system_formatted = self.system_formatter.format(content=system) else: system_formatted = self.system_formatter.format(content="") if self.force_system else [] system_encoded = self._encode_template(system_formatted, tokenizer) ls_for_save = [] for i in range(0, len(messages), 1): if messages[i]["role"] == CONVERSATION_ROLE_NAMES["user"]: user_message = messages[i] user_formatted = self.user_formatter.format(content=user_message["content"]) user_encoded = self._encode_template(user_formatted, tokenizer) if i == 0: user_encoded = system_encoded + user_encoded ls_for_save.append(user_encoded) elif messages[i]["role"] == CONVERSATION_ROLE_NAMES["function"]: function_message = messages[i] function_formatted = self.function_formatter.format(content=function_message["content"]) function_encoded = self._encode_template(function_formatted, tokenizer) ls_for_save.append(function_encoded) elif messages[i]["role"] == CONVERSATION_ROLE_NAMES["observation"]: observation_message = messages[i] observation_formatted = self.observation_formatter.format(content=observation_message["content"]) observation_encoded = self._encode_template(observation_formatted, tokenizer) ls_for_save.append(observation_encoded) elif messages[i]["role"] == CONVERSATION_ROLE_NAMES["assistant"]: assistant_message = messages[i] assistant_formatted = self.assistant_formatter.format(content=assistant_message["content"]) assistant_encoded = self._encode_template(assistant_formatted, tokenizer) ls_for_save.append(assistant_encoded) # res_tuple = (ls_for_save[0], ls_for_save[1], ls_for_save[2], ls_for_save[3]) res_all.append(tuple(ls_for_save)) ls_for_save = [] if ls_for_save: res_all.append(tuple(ls_for_save)) return res_all def _encode_template( self, template: list[TemplateComponent], tokenizer: PreTrainedTokenizer, **kwargs ) -> list[int]: """Encode template components into token ids. Parameters ---------- template : list[TemplateComponent] Formatted template components. tokenizer : PreTrainedTokenizer Tokenizer to convert tokens into token ids. Returns ------- list[int] Encoded token ids. """ encoded_ids = [] for component in template: if component.type == "string": if len(component.content) == 0: logger.warning("Empty string component found in the template.") continue else: encoded_ids += tokenizer.encode(component.content, add_special_tokens=False) elif component.type == "token": if component.content == "bos_token": encoded_ids += [tokenizer.bos_token_id] elif component.content == "eos_token": encoded_ids += [tokenizer.eos_token_id] else: encoded_ids += self._ensure_id_list(tokenizer.convert_tokens_to_ids(component.content)) elif component.type == "token_id": encoded_ids += self._ensure_id_list(component.content) else: raise NotImplementedError(f"Component type {component.type} is not supported yet.") return encoded_ids def _handle_tools(self, tools: Optional[list[str]]) -> str: tools_out = ",".join(tools) if tools is not None else "" return tools_out EMPTY_TEMPLATE = ConversationTemplate( template_name="empty", user_formatter=StringFormatter( template=[ TemplateComponent(type="token", content="bos_token"), TemplateComponent(type="string", content="{{content}}"), ] ), assistant_formatter=StringFormatter( template=[ TemplateComponent(type="string", content="{{content}}"), TemplateComponent(type="token", content="eos_token"), ] ), ) EMPTY_NO_SPECIAL_TOKENS_TEMPLATE = ConversationTemplate( template_name="empty_no_special_tokens", user_formatter=StringFormatter(template=[TemplateComponent(type="string", content="{{content}}")]), assistant_formatter=StringFormatter(template=[TemplateComponent(type="string", content="{{content}}")]), ) ================================================ FILE: src/lmflow/utils/conversation_template/chatglm.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. from .base import ConversationTemplate, StringFormatter, TemplateComponent CHATGLM3_TEMPLATE = ConversationTemplate( template_name="chatglm3", user_formatter=StringFormatter(template=[TemplateComponent(type="string", content="<|user|>\n {{content}}")]), assistant_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|assistant|>\n {{content}}")] ), system_formatter=StringFormatter(template=[TemplateComponent(type="string", content="<|system|>\n {{content}}")]), special_starter=TemplateComponent(type="string", content="[gMASK]sop"), ) ================================================ FILE: src/lmflow/utils/conversation_template/chatml.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. from .base import ConversationTemplate, StringFormatter, TemplateComponent CHATML_TEMPLATE = ConversationTemplate( template_name="chatml", user_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>user\n{{content}}<|im_end|>\n")] ), assistant_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>assistant\n{{content}}<|im_end|>\n")] ), system_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>system\n{{content}}<|im_end|>\n")] ), ) ================================================ FILE: src/lmflow/utils/conversation_template/deepseek.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. from .base import ConversationTemplate, StringFormatter, TemplateComponent DEEPSEEK_V2_TEMPLATE = ConversationTemplate( template_name="deepseek_v2", user_formatter=StringFormatter(template=[TemplateComponent(type="string", content="User: {{content}}\n\n")]), assistant_formatter=StringFormatter( template=[ TemplateComponent(type="string", content="Assistant: {{content}}"), TemplateComponent(type="token", content="eos_token"), ] ), system_formatter=StringFormatter(template=[TemplateComponent(type="string", content="{{content}}\n\n")]), special_starter=TemplateComponent(type="token", content="bos_token"), ) DEEPSEEK_V3_TEMPLATE = ( "{% if not add_generation_prompt is defined %}" "{% set add_generation_prompt = false %}" "{% endif %}" "{% set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt='', is_first_sp=true) %}" "{%- for message in messages %}" "{%- if message['role'] == 'system' %}" "{%- if ns.is_first_sp %}" "{% set ns.system_prompt = ns.system_prompt + message['content'] %}" "{% set ns.is_first_sp = false %}" "{%- else %}" "{% set ns.system_prompt = ns.system_prompt + '\n\n' + message['content'] %}" "{%- endif %}" "{%- endif %}" "{%- endfor %}" "{{bos_token}}" "{{ns.system_prompt}}" "{%- for message in messages %}" "{%- if message['role'] == 'user' %}" "{%- set ns.is_tool = false -%}" "{{'<|User|>' + message['content']}}" "{%- endif %}" "{%- if message['role'] == 'assistant' and message['content'] is none %}" "{%- set ns.is_tool = false -%}" "{%- for tool in message['tool_calls']%}" "{%- if not ns.is_first %}" "{{'<|Assistant|>'}}" "{% generation %}" "{{'<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}" "{% endgeneration %}" "{%- set ns.is_first = true -%}" "{%- else %}" "{% generation %}" "{{'\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}" "{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}" "{% endgeneration %}" "{%- endif %}" "{%- endfor %}" "{%- endif %}" "{%- if message['role'] == 'assistant' and message['content'] is not none %}" "{%- if ns.is_tool %}" "{{'<|tool▁outputs▁end|>'}}" "{% generation %}" "{{ message['content'] + '<|end▁of▁sentence|>'}}" "{%- set ns.is_tool = false -%}" "{% endgeneration %}" "{%- else %}" "{{'<|Assistant|>'}}" "{% generation %}" "{{ message['content'] + '<|end▁of▁sentence|>'}}" "{% endgeneration %}" "{%- endif %}" "{%- endif %}" "{%- if message['role'] == 'tool' %}" "{%- set ns.is_tool = true -%}" "{%- if ns.is_output_first %}" "{{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}" "{%- set ns.is_output_first = false %}" "{%- else %}" "{{'\n<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}" "{%- endif %}" "{%- endif %}" "{%- endfor -%}" "{% if ns.is_tool %}" "{{'<|tool▁outputs▁end|>'}}" "{% endif %}" "{% if add_generation_prompt and not ns.is_tool %}" "{{'<|Assistant|>'}}" "{% endif %}" ) DEEPSEEK_R1_TEMPLATE = ( "{% if not add_generation_prompt is defined %}" "{% set add_generation_prompt = false %}" "{% endif %}" "{% set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt='', is_first_sp=true) %}" "{%- for message in messages %}" "{%- if message['role'] == 'system' %}" "{%- if ns.is_first_sp %}" "{% set ns.system_prompt = ns.system_prompt + message['content'] %}" "{% set ns.is_first_sp = false %}" "{%- else %}" "{% set ns.system_prompt = ns.system_prompt + '\\n\\n' + message['content'] %}" "{%- endif %}" "{%- endif %}" "{%- endfor %}" "{{ bos_token }}" "{{ ns.system_prompt }}" "{%- for message in messages %}" "{%- if message['role'] == 'user' %}" "{%- set ns.is_tool = false -%}" "{{'<|User|>' + message['content']}}" "{%- endif %}" "{%- if message['role'] == 'assistant' and 'tool_calls' in message %}" "{%- set ns.is_tool = false -%}" "{%- for tool in message['tool_calls'] %}" "{%- if not ns.is_first %}" "{%- if message['content'] is none %}" " {{'<|Assistant|>'}}" " {% generation %}" " {{'<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}" " {% endgeneration %}" "{%- else %}" " {{'<|Assistant|>'}}" " {% generation %}" " {{ message['content'] + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}" " {% endgeneration %}" "{%- endif %}" "{%- set ns.is_first = true -%}" "{%- else %}" "{% generation %}" "{{'\\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}" "{% endgeneration %}" "{%- endif %}" "{%- endfor %}" "{% generation %}" "{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}" "{% endgeneration %}" "{%- endif %}" "{%- if message['role'] == 'assistant' and 'tool_calls' not in message %}" "{%- if ns.is_tool %}" "{{'<|tool▁outputs▁end|>'}}" "{% generation %}" "{{ message['content'] + '<|end▁of▁sentence|>'}}" "{% endgeneration %}" "{%- set ns.is_tool = false -%}" "{%- else %}" "{% set content = message['content'] %}" "{% if '' in content %}" "{% set content = content.split('')[-1] %}" "{% endif %}" "{{'<|Assistant|>'}}" "{% generation %}" "{{ content + '<|end▁of▁sentence|>'}}" "{% endgeneration %}" "{%- endif %}" "{%- endif %}" "{%- if message['role'] == 'tool' %}" "{%- set ns.is_tool = true -%}" "{%- if ns.is_output_first %}" "{{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}" "{%- set ns.is_output_first = false %}" "{%- else %}" "{{'<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}" "{%- endif %}" "{%- endif %}" "{%- endfor -%}" "{% if ns.is_tool %}" "{{'<|tool▁outputs▁end|>'}}" "{% endif %}" "{% if add_generation_prompt and not ns.is_tool %}" "{{'<|Assistant|>'}}" "{% endif %}" ) DEEPSEEK_R1_DISTILL_TEMPLATE = ( "{% if not add_generation_prompt is defined %}" "{% set add_generation_prompt = false %}" "{% endif %}" "{% set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt='') %}" "{%- for message in messages %}" "{%- if message['role'] == 'system' %}" "{% set ns.system_prompt = message['content'] %}" "{%- endif %}" "{%- endfor %}" "{{bos_token}}" "{{ns.system_prompt}}" "{%- for message in messages %}" "{%- if message['role'] == 'user' %}" "{%- set ns.is_tool = false -%}" "{{'<|User|>' + message['content']}}" "{%- endif %}" "{%- if message['role'] == 'assistant' and message['content'] is none %}" "{%- set ns.is_tool = false -%}" "{%- for tool in message['tool_calls']%}" "{%- if not ns.is_first %}" "{{'<|Assistant|>'}}" "{% generation %}" "{{'<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}" "{% endgeneration %}" "{%- set ns.is_first = true -%}" "{%- else %}" "{% generation %}" "{{'\\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\\n' + '```json' + '\\n' + tool['function']['arguments'] + '\\n' + '```' + '<|tool▁call▁end|>'}}" "{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}" "{% endgeneration %}" "{%- endif %}" "{%- endfor %}" "{%- endif %}" "{%- if message['role'] == 'assistant' and message['content'] is not none %}" "{%- if ns.is_tool %}" "{{'<|tool▁outputs▁end|>'}}" "{% generation %}" "{{ message['content'] + '<|end▁of▁sentence|>'}}" "{% endgeneration %}" "{%- set ns.is_tool = false -%}" "{%- else %}" "{% set content = message['content'] %}" "{% if '' in content %}" "{% set content = content.split('')[-1] %}" "{% endif %}" "{{'<|Assistant|>'}}" "{% generation %}" "{{ content + '<|end▁of▁sentence|>'}}" "{% endgeneration %}" "{%- endif %}" "{%- endif %}" "{%- if message['role'] == 'tool' %}" "{%- set ns.is_tool = true -%}" "{%- if ns.is_output_first %}" "{{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}" "{%- set ns.is_output_first = false %}" "{%- else %}" "{{'\\n<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}" "{%- endif %}" "{%- endif %}" "{%- endfor -%}" "{% if ns.is_tool %}" "{{'<|tool▁outputs▁end|>'}}" "{% endif %}" "{% if add_generation_prompt and not ns.is_tool %}" "{{'<|Assistant|>\\n'}}" "{% endif %}" ) ================================================ FILE: src/lmflow/utils/conversation_template/gemma.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import logging from dataclasses import dataclass from .base import ConversationTemplate, StringFormatter, TemplateComponent logger = logging.getLogger(__name__) @dataclass class GemmaConversationTemplate(ConversationTemplate): def encode_conversation(self, *args, **kwargs): if kwargs.get("system"): logger.warning( "As of now, Gemma does not support system messages officially. " "ConversationTemplate will add your system messages right after " "the bos token and before the user message without any special formatting. " "For more details, please refer to the [official template]" "(https://huggingface.co/google/gemma-1.1-2b-it/blob/bf4924f313df5166dee1467161e886e55f2eb4d4/tokenizer_config.json#L1507)." ) return super().encode_conversation(*args, **kwargs) GEMMA_TEMPLATE = GemmaConversationTemplate( template_name="gemma", user_formatter=StringFormatter( template=[TemplateComponent(type="string", content="user\n{{content}}\n")] ), assistant_formatter=StringFormatter( template=[TemplateComponent(type="string", content="model\n{{content}}\n")] ), system_formatter=StringFormatter(template=[TemplateComponent(type="string", content="{{content}}")]), special_starter=TemplateComponent(type="token", content="bos_token"), ) GEMMA3_TEMPLATE = """{{ bos_token }} {%- if messages[0]['role'] == 'system' -%} {%- if messages[0]['content'] is string -%} {%- set first_user_prefix = messages[0]['content'] + '\n\n' -%} {%- else -%} {%- set first_user_prefix = messages[0]['content'][0]['text'] + '\n\n' -%} {%- endif -%} {%- set loop_messages = messages[1:] -%}\n{%- else -%} {%- set first_user_prefix = \"\" -%} {%- set loop_messages = messages -%} {%- endif -%} {%- for message in loop_messages -%} {%- if (message['role'] == 'user') != (loop.index0 % 2 == 0) -%} {{ raise_exception(\"Conversation roles must alternate user/assistant/user/assistant/...\") }} {%- endif -%} {%- if (message['role'] == 'assistant') -%} {%- set role = \"model\" -%} {%- else -%} {%- set role = message['role'] -%} {%- endif -%} {{ '' + role + '\n' + (first_user_prefix if loop.first else \"\") }} {%- if (message['role'] == 'assistant') -%} {% generation %} {%- if message['content'] is string -%} {{ message['content'] | trim }} {%- elif message['content'] is iterable -%} {%- for item in message['content'] -%} {%- if item['type'] == 'image' -%} {{ '' }} {%- elif item['type'] == 'text' -%} {{ item['text'] | trim }} {%- endif -%} {%- endfor -%} {%- else -%} {{ raise_exception(\"Invalid content type\") }} {%- endif -%} {{ '\n' }} {% endgeneration %} {%- else -%} {%- if message['content'] is string -%} {{ message['content'] | trim }} {%- elif message['content'] is iterable -%} {%- for item in message['content'] -%} {%- if item['type'] == 'image' -%} {{ '' }} {%- elif item['type'] == 'text' -%} {{ item['text'] | trim }} {%- endif -%} {%- endfor -%} {%- else -%} {{ raise_exception(\"Invalid content type\") }} {%- endif -%} {{ '\n' }} {%- endif -%} {%- endfor -%} {%- if add_generation_prompt -%} {{'model\n'}} {%- endif -%} """ ================================================ FILE: src/lmflow/utils/conversation_template/hymba.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. from typing import Optional from .base import ConversationTemplateForTool, StringFormatter, TemplateComponent # NOTE: 'contexts' are not used in sft # {{'System'}} # {% for message in messages %} # {% if message['role'] == 'system' %} # {{'\n' + message['content'].strip()}} # {% if tools %} # {{'\n'}} # {% endif %} # {% endif %} # {% endfor %} # {% if tools %} # {% for tool in tools %} # {{ '\n ' + tool|tojson + ' ' }} # {% endfor %} # {% endif %} # {{'\n\n'}} # {% for message in messages %} # {% if message['role'] == 'user' %} # {{ 'User\n' + message['content'].strip() + '\n' }} # {% elif message['role'] == 'assistant' %} # {{ 'Assistant\n' + message['content'].strip() + '\n' }} # {% elif message['role'] == 'tool' %} # {{ 'Tool\n' + message['content'].strip() + '\n' }} # {% endif %} # {% endfor %} # {%- if add_generation_prompt %} # {{'Assistant\n'}} # {%- endif %} class HymbaConversationTemplate(ConversationTemplateForTool): def _handle_tools(self, tools: Optional[list[str]]) -> str: tools_out = "" if tools is not None: for tool in tools: tools_out += "\n " + tool + " " return tools_out HYMBA_TEMPLATE = HymbaConversationTemplate( template_name="hymba", user_formatter=StringFormatter( template=[TemplateComponent(type="string", content="User\n{{content}}\n")] ), assistant_formatter=StringFormatter( template=[TemplateComponent(type="string", content="Assistant\n{{content}}\n")] ), function_formatter=StringFormatter( template=[TemplateComponent(type="string", content="Assistant\n{{content}}\n")] ), observation_formatter=StringFormatter( template=[TemplateComponent(type="string", content="Tool\n{{content}}\n")] ), system_formatter=StringFormatter( template=[TemplateComponent(type="string", content="System{{content}}\n\n")] ), separator=TemplateComponent(type="token_id", content=13), remove_last_sep=True, special_stopper=TemplateComponent(type="token", content="eos_token"), force_system=True, ) ================================================ FILE: src/lmflow/utils/conversation_template/internlm.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. from .base import ConversationTemplate, StringFormatter, TemplateComponent INTERNLM2_TEMPLATE = ConversationTemplate( template_name="internlm2", user_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>user\n{{content}}<|im_end|>\n")] ), assistant_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>assistant\n{{content}}<|im_end|>\n")] ), system_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>system\n{{content}}<|im_end|>\n")] ), special_starter=TemplateComponent(type="token", content="bos_token"), ) ================================================ FILE: src/lmflow/utils/conversation_template/llama.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import logging from collections.abc import Sequence from typing import Optional from transformers import PreTrainedTokenizer from lmflow.utils.constants import CONVERSATION_ROLE_NAMES from .base import ConversationTemplate, ConversationTemplateForTool, StringFormatter, TemplateComponent logger = logging.getLogger(__name__) class Llama2ConversationTemplate(ConversationTemplate): def _encode( self, tokenizer: PreTrainedTokenizer, messages: list[dict[str, str]], system: Optional[str] = None, tools: Optional[str] = None, **kwargs, ) -> Sequence[tuple[list[int], list[int]]]: if tools: logger.warning( "Formatted tools are not supported in Llama2, thus tools will be ignored. " "If this is intended, please include tools in the system message manually." ) res_all = [] system_formatted = self.system_formatter.format(content=system) if system else [] system_formatted_text = "".join( [component.content for component in system_formatted if component.type == "string"] ) # HACK for i in range(0, len(messages), 2): user_message = messages[i] assistant_message = messages[i + 1] user_content = system_formatted_text + user_message["content"] if i == 0 else user_message["content"] user_formatted = self.user_formatter.format(content=user_content) assistant_formatted = self.assistant_formatter.format(content=assistant_message["content"]) user_encoded = self._encode_template(user_formatted, tokenizer) assistant_encoded = self._encode_template(assistant_formatted, tokenizer) res_all.append((user_encoded, assistant_encoded)) return res_all class Llama2ConversationTemplateForTool(Llama2ConversationTemplate): def _encode( self, tokenizer: PreTrainedTokenizer, messages: list[dict[str, str]], system: Optional[str] = None, tools: Optional[str] = None, **kwargs, ) -> Sequence[tuple[list[int], list[int]]]: if tools: # logger.warning("Formatted tools are not supported in Llama2, thus tools will be ignored. " # "If this is intended, please include tools in the system message manually.") system = system + tools res_all = [] system_formatted = self.system_formatter.format(content=system) if system else [] system_formatted_text = "".join( [component.content for component in system_formatted if component.type == "string"] ) # HACK ls_for_save = [] for i in range(0, len(messages), 1): if messages[i]["role"] == CONVERSATION_ROLE_NAMES["user"]: user_message = messages[i] if i == 0: user_content = system_formatted_text + user_message["content"] else: user_content = user_message["content"] user_formatted = self.user_formatter.format(content=user_content) user_encoded = self._encode_template(user_formatted, tokenizer) ls_for_save.append(user_encoded) elif messages[i]["role"] == CONVERSATION_ROLE_NAMES["function"]: function_message = messages[i] function_formatted = self.assistant_formatter.format(content=function_message["content"]) function_encoded = self._encode_template(function_formatted, tokenizer) ls_for_save.append(function_encoded) elif messages[i]["role"] == CONVERSATION_ROLE_NAMES["observation"]: observation_message = messages[i] observation_formatted = self.user_formatter.format(content=observation_message["content"]) observation_encoded = self._encode_template(observation_formatted, tokenizer) ls_for_save.append(observation_encoded) elif messages[i]["role"] == CONVERSATION_ROLE_NAMES["assistant"]: assistant_message = messages[i] assistant_formatted = self.assistant_formatter.format(content=assistant_message["content"]) assistant_encoded = self._encode_template(assistant_formatted, tokenizer) ls_for_save.append(assistant_encoded) # res_tuple = (ls_for_save[0], ls_for_save[1], ls_for_save[2], ls_for_save[3]) res_all.append(tuple(ls_for_save)) ls_for_save = [] if ls_for_save: res_all.append(tuple(ls_for_save)) return res_all LLAMA3_TEMPLATE = ConversationTemplate( template_name="llama3", user_formatter=StringFormatter( template=[ TemplateComponent( type="string", content="<|start_header_id|>user<|end_header_id|>\n\n{{content}}<|eot_id|>" ) ] ), assistant_formatter=StringFormatter( template=[ TemplateComponent( type="string", content="<|start_header_id|>assistant<|end_header_id|>\n\n{{content}}<|eot_id|>" ) ] ), system_formatter=StringFormatter( template=[ TemplateComponent( type="string", content="<|start_header_id|>system<|end_header_id|>\n\n{{content}}<|eot_id|>" ) ] ), special_starter=TemplateComponent(type="token", content="bos_token"), ) LLAMA3_TEMPLATE_FOR_TOOL = ConversationTemplateForTool( template_name="llama3_for_tool", user_formatter=StringFormatter( template=[ TemplateComponent( type="string", content="<|start_header_id|>user<|end_header_id|>\n\n{{content}}<|eot_id|>" ) ] ), function_formatter=StringFormatter( template=[ TemplateComponent( type="string", content="<|start_header_id|>assistant<|end_header_id|>\n\n{{content}}<|eot_id|>" ) ] ), observation_formatter=StringFormatter( template=[ TemplateComponent( type="string", content="<|start_header_id|>tool<|end_header_id|>\n\n{{content}}<|eot_id|>" ) ] ), assistant_formatter=StringFormatter( template=[ TemplateComponent( type="string", content="<|start_header_id|>assistant<|end_header_id|>\n\n{{content}}<|eot_id|>" ) ] ), system_formatter=StringFormatter( template=[ TemplateComponent( type="string", content="<|start_header_id|>system<|end_header_id|>\n\n{{content}}<|eot_id|>" ) ] ), special_starter=TemplateComponent(type="token", content="bos_token"), ) LLAMA2_TEMPLATE = Llama2ConversationTemplate( template_name="llama2", user_formatter=StringFormatter( template=[ TemplateComponent(type="token", content="bos_token"), TemplateComponent(type="string", content="[INST] {{content}} [/INST]"), ] ), assistant_formatter=StringFormatter( template=[ TemplateComponent(type="string", content="{{content}}"), TemplateComponent(type="token", content="eos_token"), ] ), system_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<>\n{{content}}\n<>\n\n")] ), ) LLAMA2_TEMPLATE_FOR_TOOL = Llama2ConversationTemplate( template_name="llama2_for_tool", user_formatter=StringFormatter( template=[ TemplateComponent(type="token", content="bos_token"), TemplateComponent(type="string", content="[INST] {{content}} [/INST]"), ] ), assistant_formatter=StringFormatter( template=[ TemplateComponent(type="string", content="{{content}}"), TemplateComponent(type="token", content="eos_token"), ] ), system_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<>\n{{content}}\n<>\n\n")] ), ) ================================================ FILE: src/lmflow/utils/conversation_template/phi.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. from .base import ConversationTemplate, StringFormatter, TemplateComponent PHI3_TEMPLATE = ConversationTemplate( template_name="phi3", user_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|user|>\n{{content}}<|end|>\n")] ), assistant_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|assistant|>\n{{content}}<|end|>\n")] ), system_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|system|>\n{{content}}<|end|>\n")] ), special_starter=TemplateComponent(type="token", content="bos_token"), special_stopper=TemplateComponent(type="token", content="eos_token"), ) ================================================ FILE: src/lmflow/utils/conversation_template/qwen.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. from .base import ConversationTemplate, ConversationTemplateForTool, StringFormatter, TemplateComponent QWEN2_TEMPLATE = ConversationTemplate( template_name="qwen2", user_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>user\n{{content}}<|im_end|>\n")] ), assistant_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>assistant\n{{content}}<|im_end|>\n")] ), system_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>system\n{{content}}<|im_end|>\n")] ), separator=TemplateComponent(type="string", content="\n"), ) QWEN2_TEMPLATE_FOR_TOOL = ConversationTemplateForTool( template_name="qwen2_for_tool", user_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>user\n{{content}}<|im_end|>\n")] ), function_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>assistant\n{{content}}<|im_end|>\n")] ), observation_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>tool\n{{content}}<|im_end|>\n")] ), assistant_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>assistant\n{{content}}<|im_end|>\n")] ), system_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>system\n{{content}}<|im_end|>\n")] ), separator=TemplateComponent(type="string", content="\n"), ) QWEN2_5_TEMPLATE = ( "{%- if tools %}" "{{- '<|im_start|>system\\n' }}" "{%- if messages[0]['role'] == 'system' %}" "{{- messages[0]['content'] }}" "{%- else %}" "{{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}" "{%- endif %}" '{{- "\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within XML tags:\\n" }}' "{%- for tool in tools %}" '{{- "\\n" }}' "{{- tool | tojson }}" "{%- endfor %}" '{{- "\\n\\n\\nFor each function call, return a json object with function name and arguments within XML tags:\\n\\n{\\"name\\": , \\"arguments\\": }\\n<|im_end|>\\n" }}' "{%- else %}" "{%- if messages[0]['role'] == 'system' %}" "{{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}" "{%- else %}" "{{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }}" "{%- endif %}" "{%- endif %}" "{%- for message in messages %}" '{%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}' '{%- if message.role == "assistant" %}' "{{- '<|im_start|>' + message.role + '\\n' }}" "{% generation %}" "{{ message.content + '<|im_end|>' + '\\n' }}" "{% endgeneration %}" "{%- else %}" "{{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}" "{%- endif %}" '{%- elif message.role == "assistant" %}' "{{- '<|im_start|>' + message.role }}" "{%- if message.content %}" "{% generation %}" "{{- '\\n' + message.content }}" "{% endgeneration %}" "{%- endif %}" "{%- for tool_call in message.tool_calls %}" "{%- if tool_call.function is defined %}" "{%- set tool_call = tool_call.function %}" "{%- endif %}" "{% generation %}" '{{- \'\\n\\n{"name": "\' }}' "{{- tool_call.name }}" '{{- \'", "arguments": \' }}' "{{- tool_call.arguments | tojson }}" "{{- '}\\n' }}" "{% endgeneration %}" "{%- endfor %}" "{% generation %}" "{{- '<|im_end|>\\n' }}" "{% endgeneration %}" '{%- elif message.role == "tool" %}' '{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}' "{{- '<|im_start|>user' }}" "{%- endif %}" "{{- '\\n\\n' }}" "{{- message.content }}" "{{- '\\n' }}" '{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}' "{{- '<|im_end|>\\n' }}" "{%- endif %}" "{%- endif %}" "{%- endfor %}" "{%- if add_generation_prompt %}" "{{- '<|im_start|>assistant\\n' }}" "{%- endif %}" ) QWEN2_5_1M_TEMPLATE = ( "{%- if tools %}" "{{- '<|im_start|>system\\n' }}" "{%- if messages[0]['role'] == 'system' %}" "{{- messages[0]['content'] }}" "{%- else %}" "{{- 'You are a helpful assistant.' }}" "{%- endif %}" '{{- "\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within XML tags:\\n" }}' "{%- for tool in tools %}" '{{- "\\n" }}' "{{- tool | tojson }}" "{%- endfor %}" '{{- "\\n\\n\\nFor each function call, return a json object with function name and arguments within XML tags:\\n\\n{\\"name\\": , \\"arguments\\": }\\n<|im_end|>\\n" }}' "{%- else %}" "{%- if messages[0]['role'] == 'system' %}" "{{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}" "{%- else %}" "{{- '<|im_start|>system\\nYou are a helpful assistant.<|im_end|>\\n' }}" "{%- endif %}" "{%- endif %}" "{%- for message in messages %}" '{%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}' '{%- if message.role == "assistant" %}' "{{- '<|im_start|>' + message.role + '\\n' }}" "{% generation %}" "{{ message.content + '<|im_end|>' + '\\n' }}" "{% endgeneration %}" "{%- else %}" "{{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}" "{%- endif %}" '{%- elif message.role == "assistant" %}' "{{- '<|im_start|>' + message.role }}" "{%- if message.content %}" "{% generation %}" "{{- '\\n' + message.content }}" "{% endgeneration %}" "{%- endif %}" "{%- for tool_call in message.tool_calls %}" "{%- if tool_call.function is defined %}" "{%- set tool_call = tool_call.function %}" "{%- endif %}" "{% generation %}" '{{- \'\\n\\n{"name": "\' }}' "{{- tool_call.name }}" '{{- \'", "arguments": \' }}' "{{- tool_call.arguments | tojson }}" "{{- '}\\n' }}" "{% endgeneration %}" "{%- endfor %}" "{% generation %}" "{{- '<|im_end|>\\n' }}" "{% endgeneration %}" '{%- elif message.role == "tool" %}' '{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}' "{{- '<|im_start|>user' }}" "{%- endif %}" "{{- '\\n\\n' }}" "{{- message.content }}" "{{- '\\n' }}" '{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}' "{{- '<|im_end|>\\n' }}" "{%- endif %}" "{%- endif %}" "{%- endfor %}" "{%- if add_generation_prompt %}" "{{- '<|im_start|>assistant\\n' }}" "{%- endif %}" ) QWEN2_5_MATH_TEMPLATE = ( "{%- if tools %}" "{{- '<|im_start|>system\\n' }}" "{%- if messages[0]['role'] == 'system' %}" "{{- messages[0]['content'] }}" "{%- else %}" "{{- 'Please reason step by step, and put your final answer within \\\\boxed{}.' }}" "{%- endif %}" '{{- "\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within XML tags:\\n" }}' "{%- for tool in tools %}" '{{- "\\n" }}' "{{- tool | tojson }}" "{%- endfor %}" '{{- "\\n\\n\\nFor each function call, return a json object with function name and arguments within XML tags:\\n\\n{\\"name\\": , \\"arguments\\": }\\n<|im_end|>\\n" }}' "{%- else %}" "{%- if messages[0]['role'] == 'system' %}" "{{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}" "{%- else %}" "{{- '<|im_start|>system\\nPlease reason step by step, and put your final answer within \\\\boxed{}.<|im_end|>\\n' }}" "{%- endif %}" "{%- endif %}" "{%- for message in messages %}" '{%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}' '{%- if message.role == "assistant" %}' "{{- '<|im_start|>' + message.role + '\\n' }}" "{% generation %}" "{{ message.content + '<|im_end|>' + '\\n' }}" "{% endgeneration %}" "{%- else %}" "{{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}" "{%- endif %}" '{%- elif message.role == "assistant" %}' "{{- '<|im_start|>' + message.role }}" "{%- if message.content %}" "{% generation %}" "{{- '\\n' + message.content }}" "{% endgeneration %}" "{%- endif %}" "{%- for tool_call in message.tool_calls %}" "{%- if tool_call.function is defined %}" "{%- set tool_call = tool_call.function %}" "{%- endif %}" "{% generation %}" '{{- \'\\n\\n{"name": "\' }}' "{{- tool_call.name }}" '{{- \'", "arguments": \' }}' "{{- tool_call.arguments | tojson }}" "{{- '}\\n' }}" "{% endgeneration %}" "{%- endfor %}" "{% generation %}" "{{- '<|im_end|>\\n' }}" "{% endgeneration %}" '{%- elif message.role == "tool" %}' '{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}' "{{- '<|im_start|>user' }}" "{%- endif %}" "{{- '\\n\\n' }}" "{{- message.content }}" "{{- '\\n' }}" '{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}' "{{- '<|im_end|>\\n' }}" "{%- endif %}" "{%- endif %}" "{%- endfor %}" "{%- if add_generation_prompt %}" "{{- '<|im_start|>assistant\\n' }}" "{%- endif %}" ) QWEN_QWQ_TEMPLATE = ( "{%- if tools %}" "{{- '<|im_start|>system\\n' }}" "{%- if messages[0]['role'] == 'system' %}" "{{- messages[0]['content'] }}" "{%- else %}" "{{- 'You are a helpful and harmless assistant. You are Qwen developed by Alibaba. You should think step-by-step.' }}" "{%- endif %}" '{{- "\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within XML tags:\\n" }}' "{%- for tool in tools %}" '{{- "\\n" }}' "{{- tool | tojson }}" "{%- endfor %}" '{{- "\\n\\n\\nFor each function call, return a json object with function name and arguments within XML tags:\\n\\n{\\"name\\": , \\"arguments\\": }\\n<|im_end|>\\n" }}' "{%- else %}" "{%- if messages[0]['role'] == 'system' %}" "{{- '<|im_start|>system\\n' + messages[0]['content'] + '<|im_end|>\\n' }}" "{%- else %}" "{{- '<|im_start|>system\\nYou are a helpful and harmless assistant. You are Qwen developed by Alibaba. You should think step-by-step.<|im_end|>\\n' }}" "{%- endif %}" "{%- endif %}" "{%- for message in messages %}" '{%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}' '{%- if message.role == "assistant" %}' "{{- '<|im_start|>' + message.role + '\\n' }}" "{% generation %}" "{{ message.content + '<|im_end|>' + '\\n' }}" "{% endgeneration %}" "{%- else %}" "{{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}" "{%- endif %}" '{%- elif message.role == "assistant" %}' "{{- '<|im_start|>' + message.role }}" "{%- if message.content %}" "{% generation %}" "{{- '\\n' + message.content }}" "{% endgeneration %}" "{%- endif %}" "{%- for tool_call in message.tool_calls %}" "{%- if tool_call.function is defined %}" "{%- set tool_call = tool_call.function %}" "{%- endif %}" "{% generation %}" '{{- \'\\n\\n{"name": "\' }}' "{{- tool_call.name }}" '{{- \'", "arguments": \' }}' "{{- tool_call.arguments | tojson }}" "{{- '}\\n' }}" "{% endgeneration %}" "{%- endfor %}" "{% generation %}" "{{- '<|im_end|>\\n' }}" "{% endgeneration %}" '{%- elif message.role == "tool" %}' '{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}' "{{- '<|im_start|>user' }}" "{%- endif %}" "{{- '\\n\\n' }}" "{{- message.content }}" "{{- '\\n' }}" '{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}' "{{- '<|im_end|>\\n' }}" "{%- endif %}" "{%- endif %}" "{%- endfor %}" "{%- if add_generation_prompt %}" "{{- '<|im_start|>assistant\\n' }}" "{%- endif %}" ) QWEN3_TEMPLATE = ( "{%- if tools %}" "{{- '<|im_start|>system\\n' }}" "{%- if messages[0].role == 'system' %}" "{{- messages[0].content + '\\n\\n' }}" "{%- endif %}" '{{- "# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within XML tags:\\n" }}' "{%- for tool in tools %}" '{{- "\\n" }}' "{{- tool | tojson }}" "{%- endfor %}" '{{- "\\n\\n\\nFor each function call, return a json object with function name and arguments within XML tags:\\n\\n{\\"name\\": , \\"arguments\\": }\\n<|im_end|>\\n" }}' "{%- else %}" "{%- if messages[0].role == 'system' %}" "{{- '<|im_start|>system\\n' + messages[0].content + '<|im_end|>\\n' }}" "{%- endif %}" "{%- endif %}" "{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}" "{%- for message in messages[::-1] %}" "{%- set index = (messages|length - 1) - loop.index0 %}" "{%- if ns.multi_step_tool and message.role == \"user\" and not(message.content.startswith('') and message.content.endswith('')) %}" "{%- set ns.multi_step_tool = false %}" "{%- set ns.last_query_index = index %}" "{%- endif %}" "{%- endfor %}" "{%- for message in messages %}" '{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}' "{{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}" '{%- elif message.role == "assistant" %}' "{% generation %}" "{%- set content = message.content %}" "{%- set reasoning_content = '' %}" "{%- if message.reasoning_content is defined and message.reasoning_content is not none %}" "{%- set reasoning_content = message.reasoning_content %}" "{%- else %}" "{%- if '' in message.content %}" "{%- set content = message.content.split('')[-1].lstrip('\\n') %}" "{%- set reasoning_content = message.content.split('')[0].rstrip('\\n').split('')[-1].lstrip('\\n') %}" "{%- endif %}" "{%- endif %}" "{%- if loop.index0 > ns.last_query_index %}" "{%- if loop.last or (not loop.last and reasoning_content) %}" "{{- '<|im_start|>' + message.role + '\\n\\n' + reasoning_content.strip('\\n') + '\\n\\n\\n' + content.lstrip('\\n') }}" "{%- else %}" "{{- '<|im_start|>' + message.role + '\\n' + content }}" "{%- endif %}" "{%- else %}" "{{- '<|im_start|>' + message.role + '\\n' + content }}" "{%- endif %}" "{%- if message.tool_calls %}" "{%- for tool_call in message.tool_calls %}" "{%- if (loop.first and content) or (not loop.first) %}" "{{- '\\n' }}" "{%- endif %}" "{%- if tool_call.function %}" "{%- set tool_call = tool_call.function %}" "{%- endif %}" '{{- \'\\n{"name": "\' }}' "{{- tool_call.name }}" '{{- \'", "arguments": \' }}' "{%- if tool_call.arguments is string %}" "{{- tool_call.arguments }}" "{%- else %}" "{{- tool_call.arguments | tojson }}" "{%- endif %}" "{{- '}\\n' }}" "{%- endfor %}" "{%- endif %}" "{{- '<|im_end|>\\n' }}" "{% endgeneration %}" '{%- elif message.role == "tool" %}' '{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}' "{{- '<|im_start|>user' }}" "{%- endif %}" "{{- '\\n\\n' }}" "{{- message.content }}" "{{- '\\n' }}" '{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}' "{{- '<|im_end|>\\n' }}" "{%- endif %}" "{%- endif %}" "{%- endfor %}" "{%- if add_generation_prompt %}" "{{- '<|im_start|>assistant\\n' }}" "{%- if enable_thinking is defined and enable_thinking is false %}" "{{- '\\n\\n\\n\\n' }}" "{%- endif %}" "{%- endif %}" ) ================================================ FILE: src/lmflow/utils/conversation_template/yi.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. from .base import ConversationTemplate, StringFormatter, TemplateComponent YI1_5_TEMPLATE = ConversationTemplate( template_name="yi1_5", user_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>user\n{{content}}<|im_end|>\n")] ), assistant_formatter=StringFormatter( template=[TemplateComponent(type="string", content="<|im_start|>assistant\n{{content}}<|im_end|>\n")] ), system_formatter=StringFormatter(template=[TemplateComponent(type="string", content="{{content}}")]), ) ================================================ FILE: src/lmflow/utils/conversation_template/zephyr.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import logging from collections.abc import Sequence from typing import Optional from transformers import PreTrainedTokenizer from .base import ConversationTemplate, StringFormatter, TemplateComponent logger = logging.getLogger(__name__) class ZephyrConversationTemplate(ConversationTemplate): def _encode( self, tokenizer: PreTrainedTokenizer, messages: list[dict[str, str]], system: Optional[str] = None, tools: Optional[str] = None, **kwargs, ) -> Sequence[tuple[list[int], list[int]]]: # TODO: truncation according to model max length # TODO: make sure the last few tokens are "learnable", not masked with token_id = -100. res_all = [] system_formatted = self.system_formatter.format(content=system) if system else [] system_encoded = self._encode_template(system_formatted, tokenizer) for i in range(0, len(messages), 2): user_message = messages[i] assistant_message = messages[i + 1] user_formatted = self.user_formatter.format(content=user_message["content"]) if i == 0 and not system: # when system is not provided, the first user message should not start with a newline user_formatted[0].content = user_formatted[0].content.replace("\n", "", 1) assistant_formatted = self.assistant_formatter.format(content=assistant_message["content"]) user_encoded = self._encode_template(user_formatted, tokenizer) assistant_encoded = self._encode_template(assistant_formatted, tokenizer) res_all.append((system_encoded + user_encoded if i == 0 else user_encoded, assistant_encoded)) return res_all ZEPHYR_TEMPLATE = ZephyrConversationTemplate( template_name="zephyr", user_formatter=StringFormatter( template=[ TemplateComponent(type="string", content="\n<|user|>\n{{content}}"), TemplateComponent(type="token", content="eos_token"), ] ), assistant_formatter=StringFormatter( template=[ TemplateComponent(type="string", content="\n<|assistant|>\n{{content}}"), TemplateComponent(type="token", content="eos_token"), ] ), system_formatter=StringFormatter( template=[ TemplateComponent(type="string", content="<|system|>\n{{content}}"), TemplateComponent(type="token", content="eos_token"), ] ), ) ================================================ FILE: src/lmflow/utils/data_utils.py ================================================ """The program includes several functions: setting a random seed, loading data from a JSON file, batching data, and extracting answers from generated text. """ import json import os import random import re from typing import TypedDict, Union import numpy as np import torch def set_random_seed(seed: int): """ Set the random seed for `random`, `numpy`, `torch`, `torch.cuda`. Parameters ------------ seed : int The default seed. """ random.seed(seed) np.random.seed(seed) torch.manual_seed(seed) if torch.cuda.is_available(): torch.cuda.manual_seed_all(seed) def load_data(file_name: str): """ Load data with file name. Parameters ------------ file_name : str. The dataset file name. Returns ------------ inputs : list. The input texts of the dataset. outputs : list. The output texts file datasets. len : int. The length of the dataset. """ inputs = [] outputs = [] type = "" with open(file_name, encoding="utf-8") as f: json_data = json.load(f) type = json_data["type"] for line in json_data["instances"]: inputs.append(line["input"]) outputs.append(line["output"]) print(f"load dataset {file_name} success.\n") print(f"Type : {type}, datasize : {len(outputs)}") return inputs, outputs, len(outputs) def batchlize(examples: list, batch_size: int, random_shuffle: bool): """ Convert examples to a dataloader. Parameters ------------ examples : list. Data list. batch_size : int. random_shuffle : bool If true, the dataloader shuffle the training data. Returns ------------ dataloader: Dataloader with batch generator. """ size = 0 dataloader = [] length = len(examples) if random_shuffle: random.shuffle(examples) while size < length: if length - size > batch_size: dataloader.append(examples[size : size + batch_size]) size += batch_size else: dataloader.append(examples[size : size + (length - size)]) size += length - size return dataloader def preview_file(file_path: str, chars: int = 100): """ Returns the first and last specified number of characters from a file without loading the entire file into memory, working with any file type. Args: file_path (str): Path to the file to be previewed chars (int, optional): Number of characters to show from start and end. Defaults to 100. Returns: tuple: (first_chars, last_chars) - The first and last characters from the file """ file_size = os.path.getsize(file_path) with open(file_path, encoding="utf-8") as f: first_chars = f.read(chars) if file_size <= 2 * chars: return first_chars, "" last_chunk_position = max(0, file_size - chars) f.seek(0) f.seek(last_chunk_position) last_chars = f.read(chars) return first_chars, last_chars def get_dataset_type_fast(file_path: str, max_chars: int = 100) -> Union[str, None]: """Get the type values from the first and last n lines of a large json dataset.""" file_content_preview = [] dataset_type = None dataset_type_pattern = re.compile(r'[\"\']type[\"\']:\s*[\'\"]([^"]+)[\'\"]') file_content_preview.extend(preview_file(file_path, max_chars)) for content in file_content_preview: try: dataset_type = dataset_type_pattern.search(content).group(1) break except AttributeError: continue return dataset_type def check_dataset_instances_key_fast(file_path: str, instances_key: str, max_lines: int = 100) -> bool: """Check if the dataset instances key matches the instance_key.""" file_content_preview = [] instance_key_pattern = re.compile(r"[\"\']" + instances_key + r"[\"\']") file_content_preview.extend(preview_file(file_path, max_lines)) for content in file_content_preview: if instance_key_pattern.search(content): return True return False def answer_extraction(response, answer_type=None): # use this funtion to extract answers from generated text """ Use this funtion to extract answers from generated text Parameters ------------ args : Arguments. response : str plain string response. Returns ------------ answer: Decoded answer (such as A, B, C, D, E for mutiple-choice QA). """ # temp = response["generated_text"] temp = response if answer_type in ("gsm8k", "svamp", "asdiv", "addsub", "singleeq", "multiarith", "math"): temp = temp.replace(",", "") temp = [s for s in re.findall(r"-?\d+\.?\d*", temp)] elif answer_type in ("aqua", "csqa", "multiple_choice"): temp = re.findall(r"A|B|C|D|E", temp) elif answer_type in ("strategyqa", "coin_flip"): temp = temp.lower() temp = re.sub("\"|'|\n|\.|\s|\:|\,", " ", temp) temp = temp.split(" ") temp = [i for i in temp if i in ("yes", "no")] elif answer_type in ("last_letters"): temp = re.sub("\"|'|\n|\.|\s", "", temp) temp = [temp] elif answer_type in ("pubmedqa", "binary_choice"): # pattern = "Output: (yes|no|maybe)" # sttr = re.search(pattern, temp) # answer = sttr.group(0)[8:] if sttr is not None else "N/A" pattern = "(answer|Answer|ANSWER|output|Output|OUTPUT|A): \(*(yes|Yes|YES|no|No|NO|maybe|Maybe|MAYBE)" sttr = re.search(pattern, temp) if sttr is not None: mid_answer = sttr.group(0) mid_answer = mid_answer.split(":")[-1].strip() answer = mid_answer.lower() else: pattern = "(yes|Yes|YES|no|No|NO|maybe|Maybe|MAYBE)(\.|\s)" sttr = re.search(pattern, temp) if sttr is not None: answer = sttr.group(0)[:-1].lower() else: answer = "N/A" return answer elif answer_type == "medmcqa": # pattern = "Output: (A|B|C|D)." # sttr = re.search(pattern, temp) # answer = sttr.group(0)[8:-1].lower() if sttr is not None else "N/A" pattern = "(answer|Answer|ANSWER|output|Output|OUTPUT|A): \(*(A|B|C|D|a|b|c|d)" sttr = re.search(pattern, temp) if sttr is not None: mid_answer = sttr.group(0) answer = mid_answer[-1].lower() else: pattern = "\(*(A|B|C|D|a|b|c|d)\)*(\.|\s)" sttr = re.search(pattern, temp) if sttr is not None: if "(" in sttr.group(0): answer = sttr.group(0)[1].lower() else: answer = sttr.group(0)[0].lower() else: answer = "N/A" return answer elif answer_type == "usmle": # pattern = "Output: (A|B|C|D)." # sttr = re.search(pattern, temp) # answer = sttr.group(0)[8:-1].lower() if sttr is not None else "N/A" pattern = "(Answer|Output|A): \(*(A|B|C|D|a|b|c|d)" sttr = re.search(pattern, temp) if sttr is not None: mid_answer = sttr.group(0) answer = mid_answer[-1].lower() else: pattern = "\(*(A|B|C|D|a|b|c|d)\)*(\.|\s)" sttr = re.search(pattern, temp) if sttr is not None: if "(" in sttr.group(0): answer = sttr.group(0)[1].lower() else: answer = sttr.group(0)[0].lower() else: answer = "N/A" return answer elif answer_type == "text": return response else: raise NotImplementedError(f"Unsupported answer type: {answer_type}") if len(temp) != 0: answer = temp[-1] # if there is . at the end of answer, remove it # e.g. answer = 64. if answer != "": if answer[-1] == ".": answer = answer[:-1] # round the answer to nearest integer if answer_type in ["gsm8k", "svamp"]: try: answer = str(round(float(answer))) except Exception: answer = "" # no sol or sol doesn't have valid format # elif answer_type in ["last_letters"]: # try: # answer = answer[-args.concat_length :] # TODO: args? # except: # answer = "" else: answer = "" return answer def process_image_flag(text, image_flag=""): texts = text.split(image_flag) if len(texts) > 1: image_token_indexes = [len(text) for text in texts[:-1]] else: image_token_indexes = [] # cumsun image_token_indexes = list(np.cumsum(image_token_indexes)) texts = "".join(texts) return texts, image_token_indexes class VLLMInferenceResultWithInput(TypedDict): input: str output: Union[list[str], list[list[int]]] class RewardModelInferenceResultWithInput(TypedDict): input: str output: list[dict[str, Union[str, float]]] # [{"score": 0.5, "text": "output text"}] ================================================ FILE: src/lmflow/utils/debug/profiler.py ================================================ import pprint import time class Timer: def __init__(self, name): self.name = name self.runtimes = {} self.runtimes_readable = {} def start(self, tag): self.runtimes[tag] = {"start": time.time()} def end(self, tag): self.runtimes[tag]["end"] = time.time() self.runtimes[tag]["elapsed"] = self.runtimes[tag]["end"] - self.runtimes[tag]["start"] def get_runtime(self, tag): return self.runtimes[tag]["elapsed"] def show(self): self._to_readable() pprint.pprint(self.runtimes_readable) def _to_readable(self): for tag, runtime in self.runtimes.items(): self.runtimes_readable[tag] = { "start": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(runtime["start"])) } self.runtimes_readable[tag]["end"] = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(runtime["end"])) self.runtimes_readable[tag]["elapsed"] = round(runtime["elapsed"], 5) if __name__ == "__main__": timer = Timer("profiler") timer.start("main") time.sleep(1) timer.end("main") timer.show() ================================================ FILE: src/lmflow/utils/deprecated.py ================================================ """ Utilities for handling deprecated APIs and maintaining backwards compatibility. """ import functools import inspect import warnings from typing import Any, Callable __all__ = ["deprecated_args"] def deprecated_args(**deprecated_params: dict[str, Any]): """ Decorator to handle deprecated function arguments. Args: **deprecated_params: Mapping of deprecated argument names to their configuration. Each value should be a dict with: - 'replacement': Name of the new argument (optional) - 'mapper': Function to map old value to new value (optional) - 'message': Custom deprecation message (optional) Example: @deprecated_args( use_vllm={ 'replacement': 'inference_engine', 'mapper': lambda x: 'vllm' if x else 'huggingface', 'message': "use_vllm is deprecated. Use inference_engine='vllm' instead." } ) def my_function(inference_engine='huggingface', **kwargs): pass """ def decorator(func: Callable) -> Callable: @functools.wraps(func) def wrapper(*args, **kwargs): # Get function signature to handle both args and kwargs sig = inspect.signature(func) bound_args = sig.bind_partial(*args, **kwargs) bound_args.apply_defaults() # Check for deprecated arguments in kwargs for old_arg, config in deprecated_params.items(): if old_arg in kwargs: old_value = kwargs.pop(old_arg) # Build deprecation message if "message" in config: message = config["message"] else: replacement = config.get("replacement", "a different argument") message = ( f"'{old_arg}' is deprecated and will be removed in a future version. " f"Please use '{replacement}' instead." ) warnings.warn(message, DeprecationWarning, stacklevel=2) # Map old value to new argument if specified if "replacement" in config: new_arg = config["replacement"] # Apply mapper function if provided if "mapper" in config: new_value = config["mapper"](old_value) else: new_value = old_value # Only set the new argument if it wasn't already provided if new_arg not in kwargs: kwargs[new_arg] = new_value return func(*args, **kwargs) return wrapper return decorator ================================================ FILE: src/lmflow/utils/envs.py ================================================ """ ref: https://github.com/pytorch/torchtune/blob/main/torchtune/utils/_device.py """ import os import logging import torch logger = logging.getLogger(__name__) is_cuda_available = torch.cuda.is_available() def is_accelerate_env(): for key, _ in os.environ.items(): if key.startswith("ACCELERATE_"): return True return False def get_device_name() -> str: """ Get the device name based on the current machine. """ if is_cuda_available: device = "cuda" else: device = "cpu" return device def get_torch_device() -> any: """Return the corresponding torch attribute based on the device type string. Returns: module: The corresponding torch device namespace, or torch.cuda if not found. """ device_name = get_device_name() try: return getattr(torch, device_name) except AttributeError: logger.warning(f"Device namespace '{device_name}' not found in torch, try to load torch.cuda.") return torch.cuda ================================================ FILE: src/lmflow/utils/llava_conversation_lib.py ================================================ import dataclasses from enum import Enum, auto from typing import Optional class SeparatorStyle(Enum): """Different separator style.""" SINGLE = auto() TWO = auto() MPT = auto() PLAIN = auto() LLAMA_2 = auto() @dataclasses.dataclass class Conversation: """A class that keeps all conversation history.""" system: str roles: list[str] messages: list[list[str]] offset: int sep_style: SeparatorStyle = SeparatorStyle.SINGLE sep: str = "###" sep2: Optional[str] = None version: str = "Unknown" skip_next: bool = False def get_prompt(self): messages = self.messages if len(messages) > 0 and type(messages[0][1]) is tuple: messages = self.messages.copy() init_role, init_msg = messages[0].copy() init_msg = init_msg[0].replace("", "").strip() if "mmtag" in self.version: messages[0] = (init_role, init_msg) messages.insert(0, (self.roles[0], "")) messages.insert(1, (self.roles[1], "Received.")) else: messages[0] = (init_role, "\n" + init_msg) if self.sep_style == SeparatorStyle.SINGLE: ret = self.system + self.sep for role, message in messages: if message: if type(message) is tuple: message, _, _ = message ret += role + ": " + message + self.sep else: ret += role + ":" elif self.sep_style == SeparatorStyle.TWO: seps = [self.sep, self.sep2] ret = self.system + seps[0] for i, (role, message) in enumerate(messages): if message: if type(message) is tuple: message, _, _ = message ret += role + ": " + message + seps[i % 2] else: ret += role + ":" elif self.sep_style == SeparatorStyle.MPT: ret = self.system + self.sep for role, message in messages: if message: if type(message) is tuple: message, _, _ = message ret += role + message + self.sep else: ret += role elif self.sep_style == SeparatorStyle.LLAMA_2: wrap_sys = lambda msg: f"<>\n{msg}\n<>\n\n" wrap_inst = lambda msg: f"[INST] {msg} [/INST]" ret = "" for i, (role, message) in enumerate(messages): if i == 0: assert message, "first message should not be none" assert role == self.roles[0], "first message should come from user" if message: if type(message) is tuple: message, _, _ = message if i == 0: message = wrap_sys(self.system) + message if i % 2 == 0: message = wrap_inst(message) ret += self.sep + message else: ret += " " + message + " " + self.sep2 else: ret += "" ret = ret.lstrip(self.sep) elif self.sep_style == SeparatorStyle.PLAIN: seps = [self.sep, self.sep2] ret = self.system for i, (role, message) in enumerate(messages): if message: if type(message) is tuple: message, _, _ = message ret += message + seps[i % 2] else: ret += "" else: raise ValueError(f"Invalid style: {self.sep_style}") return ret def append_message(self, role, message): self.messages.append([role, message]) def get_images(self, return_pil=False): images = [] for i, (role, msg) in enumerate(self.messages[self.offset :]): if i % 2 == 0: if type(msg) is tuple: import base64 from io import BytesIO from PIL import Image msg, image, image_process_mode = msg if image_process_mode == "Pad": def expand2square(pil_img, background_color=(122, 116, 104)): width, height = pil_img.size if width == height: return pil_img elif width > height: result = Image.new(pil_img.mode, (width, width), background_color) result.paste(pil_img, (0, (width - height) // 2)) return result else: result = Image.new(pil_img.mode, (height, height), background_color) result.paste(pil_img, ((height - width) // 2, 0)) return result image = expand2square(image) elif image_process_mode == "Crop": pass elif image_process_mode == "Resize": image = image.resize((336, 336)) else: raise ValueError(f"Invalid image_process_mode: {image_process_mode}") max_hw, min_hw = max(image.size), min(image.size) aspect_ratio = max_hw / min_hw max_len, min_len = 800, 400 shortest_edge = int(min(max_len / aspect_ratio, min_len, min_hw)) longest_edge = int(shortest_edge * aspect_ratio) W, H = image.size if H > W: H, W = longest_edge, shortest_edge else: H, W = shortest_edge, longest_edge image = image.resize((W, H)) if return_pil: images.append(image) else: buffered = BytesIO() image.save(buffered, format="PNG") img_b64_str = base64.b64encode(buffered.getvalue()).decode() images.append(img_b64_str) return images def to_gradio_chatbot(self): ret = [] for i, (role, msg) in enumerate(self.messages[self.offset :]): if i % 2 == 0: if type(msg) is tuple: import base64 from io import BytesIO msg, image, image_process_mode = msg max_hw, min_hw = max(image.size), min(image.size) aspect_ratio = max_hw / min_hw max_len, min_len = 800, 400 shortest_edge = int(min(max_len / aspect_ratio, min_len, min_hw)) longest_edge = int(shortest_edge * aspect_ratio) W, H = image.size if H > W: H, W = longest_edge, shortest_edge else: H, W = shortest_edge, longest_edge image = image.resize((W, H)) buffered = BytesIO() image.save(buffered, format="JPEG") img_b64_str = base64.b64encode(buffered.getvalue()).decode() img_str = f'user upload image' ret.append([img_str, None]) msg = msg.replace("", "").strip() if len(msg) > 0: ret.append([msg, None]) else: ret.append([msg, None]) else: ret[-1][-1] = msg return ret def copy(self): return Conversation( system=self.system, roles=self.roles, messages=[[x, y] for x, y in self.messages], offset=self.offset, sep_style=self.sep_style, sep=self.sep, sep2=self.sep2, version=self.version, ) def dict(self): if len(self.get_images()) > 0: return { "system": self.system, "roles": self.roles, "messages": [[x, y[0] if type(y) is tuple else y] for x, y in self.messages], "offset": self.offset, "sep": self.sep, "sep2": self.sep2, } return { "system": self.system, "roles": self.roles, "messages": self.messages, "offset": self.offset, "sep": self.sep, "sep2": self.sep2, } conv_vicuna_v0 = Conversation( system="A chat between a curious human and an artificial intelligence assistant. " "The assistant gives helpful, detailed, and polite answers to the human's questions.", roles=("Human", "Assistant"), messages=( ("Human", "What are the key differences between renewable and non-renewable energy sources?"), ( "Assistant", "Renewable energy sources are those that can be replenished naturally in a relatively " "short amount of time, such as solar, wind, hydro, geothermal, and biomass. " "Non-renewable energy sources, on the other hand, are finite and will eventually be " "depleted, such as coal, oil, and natural gas. Here are some key differences between " "renewable and non-renewable energy sources:\n" "1. Availability: Renewable energy sources are virtually inexhaustible, while non-renewable " "energy sources are finite and will eventually run out.\n" "2. Environmental impact: Renewable energy sources have a much lower environmental impact " "than non-renewable sources, which can lead to air and water pollution, greenhouse gas emissions, " "and other negative effects.\n" "3. Cost: Renewable energy sources can be more expensive to initially set up, but they typically " "have lower operational costs than non-renewable sources.\n" "4. Reliability: Renewable energy sources are often more reliable and can be used in more remote " "locations than non-renewable sources.\n" "5. Flexibility: Renewable energy sources are often more flexible and can be adapted to different " "situations and needs, while non-renewable sources are more rigid and inflexible.\n" "6. Sustainability: Renewable energy sources are more sustainable over the long term, while " "non-renewable sources are not, and their depletion can lead to economic and social instability.\n", ), ), offset=2, sep_style=SeparatorStyle.SINGLE, sep="###", ) conv_vicuna_v1 = Conversation( system="A chat between a curious user and an artificial intelligence assistant. " "The assistant gives helpful, detailed, and polite answers to the user's questions.", roles=("USER", "ASSISTANT"), version="v1", messages=(), offset=0, sep_style=SeparatorStyle.TWO, sep=" ", sep2="", ) conv_llama_2 = Conversation( system="""You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.""", roles=("USER", "ASSISTANT"), version="llama_v2", messages=(), offset=0, sep_style=SeparatorStyle.LLAMA_2, sep="", sep2="", ) conv_llava_llama_2 = Conversation( system="You are a helpful language and vision assistant. " "You are able to understand the visual content that the user provides, " "and assist the user with a variety of tasks using natural language.", roles=("USER", "ASSISTANT"), version="llama_v2", messages=(), offset=0, sep_style=SeparatorStyle.LLAMA_2, sep="", sep2="", ) conv_mpt = Conversation( system="""<|im_start|>system A conversation between a user and an LLM-based AI assistant. The assistant gives helpful and honest answers.""", roles=("<|im_start|>user\n", "<|im_start|>assistant\n"), version="mpt", messages=(), offset=0, sep_style=SeparatorStyle.MPT, sep="<|im_end|>", ) conv_llava_plain = Conversation( system="", roles=("", ""), messages=(), offset=0, sep_style=SeparatorStyle.PLAIN, sep="\n", ) conv_llava_v0 = Conversation( system="A chat between a curious human and an artificial intelligence assistant. " "The assistant gives helpful, detailed, and polite answers to the human's questions.", roles=("Human", "Assistant"), messages=(("Human", "Hi!"), ("Assistant", "Hi there! How can I help you today?")), offset=2, sep_style=SeparatorStyle.SINGLE, sep="###", ) conv_llava_v0_mmtag = Conversation( system="A chat between a curious user and an artificial intelligence assistant. " "The assistant is able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language." "The visual content will be provided with the following format: visual content.", roles=("Human", "Assistant"), messages=(), offset=0, sep_style=SeparatorStyle.SINGLE, sep="###", version="v0_mmtag", ) conv_llava_v1 = Conversation( system="A chat between a curious human and an artificial intelligence assistant. " "The assistant gives helpful, detailed, and polite answers to the human's questions.", roles=("USER", "ASSISTANT"), version="v1", messages=(), offset=0, sep_style=SeparatorStyle.TWO, sep=" ", sep2="", ) conv_llava_v1_mmtag = Conversation( system="A chat between a curious user and an artificial intelligence assistant. " "The assistant is able to understand the visual content that the user provides, and assist the user with a variety of tasks using natural language." "The visual content will be provided with the following format: visual content.", roles=("USER", "ASSISTANT"), messages=(), offset=0, sep_style=SeparatorStyle.TWO, sep=" ", sep2="", version="v1_mmtag", ) default_conversation = conv_vicuna_v1 # currently only support the v1 version conv_templates = { "default": conv_vicuna_v0, "v0": conv_vicuna_v0, "v1": conv_vicuna_v1, "vicuna_v1": conv_vicuna_v1, "llama_2": conv_llama_2, "plain": conv_llava_plain, "v0_plain": conv_llava_plain, "llava_v0": conv_llava_v0, "v0_mmtag": conv_llava_v0_mmtag, "llava_v1": conv_llava_v1, "v1_mmtag": conv_llava_v1_mmtag, "llava_llama_2": conv_llava_llama_2, "mpt": conv_mpt, } if __name__ == "__main__": print(default_conversation.get_prompt()) ================================================ FILE: src/lmflow/utils/model.py ================================================ #!/usr/bin/env python # Copyright 2024 Statistics and Machine Learning Research Group. All rights reserved. import logging from transformers import AutoTokenizer from lmflow.args import ModelArguments logger = logging.getLogger(__name__) def check_homogeneity(model_args_list: list[ModelArguments]) -> bool: assert all(isinstance(model_args, ModelArguments) for model_args in model_args_list), ( "model_args_list should be a list of ModelArguments objects." ) assert len(model_args_list) > 1, "model_args_list should have at least two elements." tokenizer_names = [] for model_args in model_args_list: tokenizer = AutoTokenizer.from_pretrained(model_args.model_name_or_path, use_fast=False) tokenizer_names.append(tokenizer.__class__.__name__) return len(set(tokenizer_names)) == 1 ================================================ FILE: src/lmflow/utils/multimodal.py ================================================ import glob import torch from tqdm import tqdm from transformers import LlamaConfig def update_custom_config(config, model_args): if model_args.llm_model_name_or_path is not None: text_config = LlamaConfig.from_pretrained(model_args.llm_model_name_or_path) config.text_config = text_config config.with_qformer = model_args.with_qformer config.custom_vision_model = model_args.custom_vision_model if model_args.custom_vision_model: # config.vision_model_args = model_args config.image_encoder_name_or_path = model_args.image_encoder_name_or_path config.vision_select_layer = model_args.vision_select_layer if getattr(model_args, "vision_select_feature", None) is not None: config.vision_select_feature = model_args.vision_select_feature return config def load_llava_pretrain_model(model, checkpoint_path): checkpoint_path = glob.glob(checkpoint_path) for path in tqdm(checkpoint_path): state_dict = torch.load(path, map_location="cpu") new_state_dict = adapt_llava_model_to_lmflow_type(state_dict) # modify the name of the key # import pdb; pdb.set_trace() lmflow_keys = model.state_dict().keys() for key in new_state_dict.keys(): if key not in lmflow_keys: print("key not in lmflow_keys: ", key) model.load_state_dict(new_state_dict, strict=False) return model def adapt_llava_model_to_lmflow_type(state_dict): new_state_dict = {} for key, item in state_dict.items(): key = key.replace("model.layers", "language_model.model.layers") key = key.replace("model.embed_tokens", "language_model.model.embed_tokens") key = key.replace("model.mm_projector", "language_projection") key = key.replace("lm_head", "language_model.lm_head") key = key.replace("model.norm", "language_model.model.norm") if "vision_tower" in key: continue new_state_dict[key] = item return new_state_dict ================================================ FILE: src/lmflow/utils/position_interpolation/__init__.py ================================================ ================================================ FILE: src/lmflow/utils/position_interpolation/llama_rope_scaled_monkey_patch.py ================================================ from functools import partial import torch import transformers import transformers.models.llama.modeling_llama class CondenseRotaryEmbedding(torch.nn.Module): def __init__(self, dim, pi_ratio, ntk_ratio, max_position_embeddings=2048, base=10000, device=None): super().__init__() self.ntk_ratio = ntk_ratio max_position_embeddings *= ntk_ratio base = base * ntk_ratio ** (dim / (dim - 2)) # Base change formula inv_freq = 1.0 / (base ** (torch.arange(0, dim, 2).float().to(device) / dim)) self.register_buffer("inv_freq", inv_freq) self.pi_ratio = pi_ratio max_position_embeddings *= pi_ratio self.max_seq_len_cached = max_position_embeddings t = torch.arange(self.max_seq_len_cached, device=self.inv_freq.device, dtype=self.inv_freq.dtype) / pi_ratio freqs = torch.einsum("i,j->ij", t, self.inv_freq) # Different from paper, but it uses a different permutation in order to obtain the same calculation emb = torch.cat((freqs, freqs), dim=-1) dtype = torch.get_default_dtype() self.register_buffer("cos_cached", emb.cos()[None, None, :, :].to(dtype), persistent=False) self.register_buffer("sin_cached", emb.sin()[None, None, :, :].to(dtype), persistent=False) def forward(self, x, seq_len=None): # x: [bs, num_attention_heads, seq_len, head_size] # This `if` block is unlikely to be run after we build sin/cos in `__init__`. Keep the logic here just in case. if seq_len > self.max_seq_len_cached: self.max_seq_len_cached = seq_len t = torch.arange(self.max_seq_len_cached, device=x.device, dtype=self.inv_freq.dtype) / self.pi_ratio freqs = torch.einsum("i,j->ij", t, self.inv_freq) # Different from paper, but it uses a different permutation in order to obtain the same calculation emb = torch.cat((freqs, freqs), dim=-1).to(x.device) self.register_buffer("cos_cached", emb.cos()[None, None, :, :].to(x.dtype), persistent=False) self.register_buffer("sin_cached", emb.sin()[None, None, :, :].to(x.dtype), persistent=False) return ( self.cos_cached[:, :, :seq_len, ...].to(dtype=x.dtype), self.sin_cached[:, :, :seq_len, ...].to(dtype=x.dtype), ) def replace_llama_with_condense(pi_ratio, ntk_ratio): transformers.models.llama.modeling_llama.LlamaRotaryEmbedding = partial( CondenseRotaryEmbedding, pi_ratio=pi_ratio, ntk_ratio=ntk_ratio ) ================================================ FILE: src/lmflow/utils/protocol.py ================================================ """ ref: https://github.com/volcengine/verl/blob/main/verl/protocol.py Implement base data transfer protocol between any two functions, modules. We can subclass Protocol to define more detailed batch info with specific keys """ import contextlib import copy import logging import math import pickle from dataclasses import dataclass, field from typing import Any, Dict, List, Optional, Set, Union import numpy as np import tensordict import torch from packaging import version from packaging.version import parse as parse_version from tensordict import TensorDict from tensordict.tensorclass import NonTensorData, NonTensorStack from torch.utils.data import DataLoader from lmflow.utils.envs import get_torch_device logger = logging.getLogger(__name__) with contextlib.suppress(Exception): tensordict.set_lazy_legacy(False).set() if parse_version(tensordict.__version__) < parse_version("0.10.0"): tensordict.set_list_to_stack(True).set() def union_python_dict(dict1: dict, dict2: dict): """Union two dict. Will throw an error if there is an item not the same object with the same key. Args: dict1: dict2: Returns: """ for key, val in dict2.items(): if key in dict1: assert dict2[key] == dict1[key], f"{key} in meta_dict1 and meta_dict2 are not the same object" dict1[key] = val return dict1 def union_tensor_dict(tensor_dict1: TensorDict, tensor_dict2: TensorDict) -> TensorDict: """Union two tensordicts.""" assert tensor_dict1.batch_size == tensor_dict2.batch_size, ( f"Two tensor dict must have identical batch size. Got {tensor_dict1.batch_size} and {tensor_dict2.batch_size}" ) for key in tensor_dict2.keys(): if key not in tensor_dict1.keys(): tensor_dict1[key] = tensor_dict2[key] else: assert tensor_dict1[key].equal(tensor_dict2[key]), ( f"{key} in tensor_dict1 and tensor_dict2 are not the same object" ) return tensor_dict1 def _array_equal(array1: np.ndarray, array2: np.ndarray, visited: Set[int]) -> bool: """ Recursively compares two NumPy arrays for strict equality, with special handling for object-dtype arrays, NaN values, and circular references. This function assumes that the two arguments provided are NumPy arrays. Args: array1: The first NumPy array. array2: The second NumPy array. Returns: True if the arrays' dtypes, shapes, and all elements are equal. """ # Check dtype and shape first, as this is the fastest failure path. if array1.dtype != array2.dtype or array1.shape != array2.shape: return False # For non-object dtypes, use NumPy's implementation with equal_nan=True. if array1.dtype != "object": return np.array_equal(array1, array2, equal_nan=True) # For object-dtype arrays, we must recursively compare each element. # We delegate to _deep_equal to handle elements, as they could be any # type, including other nested arrays or NaNs. return all(_deep_equal(x, y, visited) for x, y in zip(array1.flat, array2.flat, strict=False)) def _deep_equal(a: Any, b: Any, visited: Set[int]) -> bool: """ Recursively performs a deep comparison between two Python objects. - Handles NaN values correctly (NaN == NaN evaluates to True). - Handling circular references. - Dispatches to _array_equal if both objects are NumPy arrays. - Otherwise, uses standard '==' comparison. """ if type(a) is not type(b): return False # If we have seen this object ID before on this path, it's a cycle. # Since we already know the types match, we can safely assume this part # of the structure is equal. obj_id = id(a) if obj_id in visited: return True visited.add(obj_id) # Perform the specific comparison based on type result = False if isinstance(a, float) and math.isnan(a) and math.isnan(b): result = True elif isinstance(a, np.ndarray): # We know b is also an ndarray due to the initial type check result = _array_equal(a, b, visited) else: # Standard equality for all other types result = a == b # Clean up the visited set on the way out of the recursion visited.remove(obj_id) return result def union_numpy_dict(tensor_dict1: Dict[str, np.ndarray], tensor_dict2: Dict[str, np.ndarray]) -> Dict[str, np.ndarray]: for key, val in tensor_dict2.items(): if key in tensor_dict1: assert isinstance(tensor_dict2[key], np.ndarray) assert isinstance(tensor_dict1[key], np.ndarray) # to properly deal with nan and object type assert _deep_equal(tensor_dict1[key], tensor_dict2[key], visited=set()), ( f"`{key}` in tensor_dict1 and tensor_dict2 are not the same object." ) tensor_dict1[key] = val return tensor_dict1 def list_of_dict_to_dict_of_list(list_of_dict: List[dict]): if len(list_of_dict) == 0: return {} keys = list_of_dict[0].keys() output = {key: [] for key in keys} for data in list_of_dict: for key, item in data.items(): assert key in output output[key].append(item) return output def collate_fn(x: List["DataProtoItem"]): batch = [] non_tensor_batch = [] for data in x: batch.append(data.batch) non_tensor_batch.append(data.non_tensor_batch) batch = torch.stack(batch).contiguous() non_tensor_batch = list_of_dict_to_dict_of_list(non_tensor_batch) for key, val in non_tensor_batch.items(): non_tensor_batch[key] = np.array(val, dtype=object) return DataProto(batch=batch, non_tensor_batch=non_tensor_batch) def get_tensordict(tensor_dict: Dict[str, Union[torch.Tensor, list]], non_tensor_dict: dict = None) -> TensorDict: """Create a TensorDict from tensors and non-tensor data. Automatically handles nested structures in lists by converting them to NonTensorStack. This enables support for: - Lists of lists: [[], [0.5, 0.8], [0.9]] - Lists of dicts: [{"acc": 1.0}, {"acc": 0.0}] - Lists of lists of dicts: [[{"content": "...", "role": "user"}]] Args: tensor_dict: Dictionary of tensors and lists to include in the TensorDict non_tensor_dict: Dictionary of metadata to store as NonTensorData Returns: TensorDict with proper handling of nested structures Example: >>> td = get_tensordict( ... tensor_dict={ ... "obs": torch.randn(3, 4), ... "turn_scores": [[], [0.5, 0.8], [0.9]] # Nested list ... }, ... non_tensor_dict={"experiment": "test"} ... ) """ tensor_dict = tensor_dict.copy() if non_tensor_dict is None: non_tensor_dict = {} batch_size = None for key, val in tensor_dict.items(): if isinstance(val, torch.Tensor) and val.is_nested: assert val.is_contiguous(), "Nested tensors must be contiguous. Try setting layout=torch.jagged" assert val.layout == torch.jagged, "Nested tensors must be jagged." # Skip validation for NonTensorStack as it's already properly formatted if isinstance(val, NonTensorStack): if batch_size is None: batch_size = len(val) else: assert len(val) == batch_size, ( f"Batch size of NonTensorStack {key} is not consistent with other tensors. " f"Expected {batch_size}, got {len(val)}" ) continue if isinstance(val, list): for v in val: assert not isinstance(v, torch.Tensor), ( "Passing a list makes the data NonTensorStack, " "which doesn't support torch.Tensor. Please convert to numpy first" ) # Convert to NonTensorStack to handle nested structures tensor_dict[key] = NonTensorStack.from_list([NonTensorData(item) for item in val]) assert isinstance(val, (torch.Tensor, list)) if batch_size is None: batch_size = val.size(0) if isinstance(val, torch.Tensor) else len(val) else: val_batch_size = val.size(0) if isinstance(val, torch.Tensor) else len(val) assert val_batch_size == batch_size, ( f"Batch size of tensor {key} is not consistent with other tensors. " f"Expected {batch_size}, got {val_batch_size}" ) if batch_size is None: batch_size = [] else: batch_size = [batch_size] for key, val in non_tensor_dict.items(): assert key not in tensor_dict tensor_dict[key] = NonTensorData(val) return TensorDict(source=tensor_dict, batch_size=batch_size) @dataclass class DataProtoItem: batch: TensorDict = None non_tensor_batch: dict = field(default_factory=dict) meta_info: dict = field(default_factory=dict) @dataclass class DataProto: """ A DataProto is a data structure that aims to provide a standard protocol for data exchange between functions. It contains a batch (TensorDict) and a meta_info (Dict). The batch is a TensorDict https://pytorch.org/tensordict/. TensorDict allows you to manipulate a dictionary of Tensors like a single Tensor. Ideally, the tensors with the same batch size should be put inside batch. """ batch: TensorDict = None non_tensor_batch: dict = field(default_factory=dict) meta_info: dict = field(default_factory=dict) def __post_init__(self): # perform necessary checking self.check_consistency() def __len__(self): if self.batch is not None: return self.batch.batch_size[0] elif self.non_tensor_batch is not None and len(self.non_tensor_batch) > 0: random_key = list(self.non_tensor_batch.keys())[0] return self.non_tensor_batch[random_key].shape[0] else: return 0 def __getitem__(self, item): """ Enhanced indexing for DataProto objects. Args: item: Can be one of: - int: A single index - slice: A slice object (start:stop:step) - list: A list of indices - numpy.ndarray: An array of indices - torch.Tensor: A tensor of indices Returns: DataProto: For all indexing types except single integers DataProtoItem: Only for single integer indices """ # Case 1: Slice object - use the slice method if isinstance(item, slice): return self.slice(item.start, item.stop, item.step) # Case 2: List, numpy array, or torch tensor - use sel_idxs elif isinstance(item, (list, np.ndarray, torch.Tensor)): return self.select_idxs(item) # Case 3: Single integer - return DataProtoItem for backward compatibility elif isinstance(item, (int, np.integer)): tensor_data = self.batch[item] if self.batch is not None else None non_tensor_data = {key: val[item] for key, val in self.non_tensor_batch.items()} return DataProtoItem(batch=tensor_data, non_tensor_batch=non_tensor_data, meta_info=self.meta_info) # # Case 4: Unsupported type else: raise TypeError(f"Indexing with {type(item)} is not supported") def __getstate__(self): import io buffer = io.BytesIO() if tensordict.__version__ >= "0.5.0" and self.batch is not None: self.batch = self.batch.contiguous() self.batch = self.batch.consolidate() torch.save(self.batch, buffer) return buffer, self.non_tensor_batch, self.meta_info def __setstate__(self, data): batch_deserialized, non_tensor_batch, meta_info = data batch_deserialized.seek(0) batch = torch.load( batch_deserialized, weights_only=False, map_location="cpu" if not get_torch_device().is_available() else None, ) self.batch = batch self.non_tensor_batch = non_tensor_batch self.meta_info = meta_info def save_to_disk(self, filepath): with open(filepath, "wb") as f: pickle.dump(self, f) @staticmethod def load_from_disk(filepath) -> "DataProto": with open(filepath, "rb") as f: data = pickle.load(f) return data def print_size(self, prefix=""): size_of_tensordict = 0 if self.batch is not None: for _, tensor in self.batch.items(): size_of_tensordict += tensor.element_size() * tensor.numel() size_of_numpy_array = 0 for _, numpy_array in self.non_tensor_batch.items(): size_of_numpy_array += numpy_array.nbytes size_of_numpy_array /= 1024**3 size_of_tensordict /= 1024**3 message = f"Size of tensordict: {size_of_tensordict} GB, size of non_tensor_batch: {size_of_numpy_array} GB" if prefix: message = f"{prefix}, " + message print(message) def check_consistency(self): """Check the consistency of the DataProto. Mainly for batch and non_tensor_batch We expose this function as a public one so that user can call themselves directly """ if self.batch is not None: assert len(self.batch.batch_size) == 1, "only support num_batch_dims=1" if self.non_tensor_batch is not None: for key, val in self.non_tensor_batch.items(): assert isinstance(val, np.ndarray) if self.batch is not None and self.non_tensor_batch is not None and len(self.non_tensor_batch) != 0: # TODO: we can actually lift this restriction if needed assert len(self.batch.batch_size) == 1, "only support num_batch_dims=1 when non_tensor_batch is not empty." batch_size = self.batch.batch_size[0] for key, val in self.non_tensor_batch.items(): assert isinstance(val, np.ndarray), ( f"data in the non_tensor_batch must be a numpy.array with dtype=object, but for " f"{key=}, got {type(val)=}" ) assert val.shape[0] == batch_size, ( f"key {key} length {len(val)} is not equal to batch size {batch_size}" ) @classmethod def from_single_dict(cls, data: Dict[str, Union[torch.Tensor, np.ndarray]], meta_info=None): """Create a DataProto from a dict of tensors and non_tensors""" tensors = {} non_tensors = {} for key, val in data.items(): if isinstance(val, torch.Tensor): tensors[key] = val elif isinstance(val, np.ndarray): non_tensors[key] = val else: raise ValueError(f"Unsupported type in data {type(val)}") return cls.from_dict(tensors=tensors, non_tensors=non_tensors, meta_info=meta_info) @classmethod def from_dict( cls, tensors: Optional[dict[str, torch.Tensor]] = None, non_tensors=None, meta_info=None, num_batch_dims=1, ): """Create a DataProto from a dict of tensors. This assumes that 1. All the tensor in tensors have the same dim0 2. Only dim0 is the batch dim """ assert num_batch_dims > 0, "num_batch_dims must be greater than zero" if non_tensors is not None: assert num_batch_dims == 1, "only support num_batch_dims=1 when non_tensors is not None." if tensors is None: tensors = {} if meta_info is None: meta_info = {} if non_tensors is None: non_tensors = {} assert isinstance(non_tensors, dict) # get and check batch size batch_size = None pivot_key = None for key, tensor in tensors.items(): if batch_size is None: batch_size = tensor.shape[:num_batch_dims] pivot_key = key else: current_batch = tensor.shape[:num_batch_dims] assert batch_size == current_batch, ( f"Not all the tensor in tensors have the same batch size with batch_dims={num_batch_dims}. " f"Got {pivot_key} has {batch_size}, {key} has {current_batch}" ) for key, val in non_tensors.items(): if not isinstance(val, np.ndarray): non_tensors[key] = np.array(val, dtype=object) tensor_dict = TensorDict(source=tensors, batch_size=batch_size) if tensors else None return cls(batch=tensor_dict, non_tensor_batch=non_tensors, meta_info=meta_info) @classmethod def from_tensordict( cls, tensor_dict: TensorDict = None, meta_info=None, num_batch_dims=1, ): """Create a DataProto from a TensorDict. This assumes that 1. All the tensor in tensor_dict have the same dim0 2. Only dim0 is the batch dim """ assert version.parse(tensordict.__version__) >= version.parse("0.10.0"), ( "Build DataProto from TensorDict at least requires tensordict version 0.10.0" ) from tensordict import NonTensorData, NonTensorStack assert num_batch_dims > 0, "num_batch_dims must be greater than zero" if not all(isinstance(val, torch.Tensor) for val in tensor_dict.values()): assert num_batch_dims == 1, "only support num_batch_dims=1 when tensor_dict contains non tensor data." if meta_info is None: meta_info = {} batch = {} non_tensor_batch = {} batch_size = None for key, val in tensor_dict.items(): if isinstance(val, torch.Tensor): batch[key] = val if batch_size is None: batch_size = val.shape[:num_batch_dims] elif isinstance(val, NonTensorStack): non_tensor_batch[key] = np.array([elem.data for elem in val], dtype=object) elif isinstance(val, NonTensorData): meta_info[key] = val.data return cls( batch=TensorDict(batch, batch_size=batch_size), non_tensor_batch=non_tensor_batch, meta_info=meta_info, ) def to(self, device) -> "DataProto": """move the batch to device Args: device (torch.device, str): torch device Returns: DataProto: the current DataProto """ if self.batch is not None: self.batch = self.batch.to(device) return self def select(self, batch_keys=None, non_tensor_batch_keys=None, meta_info_keys=None, deepcopy=False) -> "DataProto": """Select a subset of the DataProto via batch_keys and meta_info_keys Args: batch_keys (list, optional): a list of strings indicating the keys in batch to select meta_info_keys (list, optional): a list of keys indicating the meta info to select Returns: DataProto: the DataProto with the selected batch_keys and meta_info_keys """ # TODO (zhangchi.usc1992) whether to copy if batch_keys is not None: batch_keys = tuple(batch_keys) sub_batch = self.batch.select(*batch_keys) else: sub_batch = self.batch if non_tensor_batch_keys is not None: non_tensor_batch = {key: val for key, val in self.non_tensor_batch.items() if key in non_tensor_batch_keys} else: non_tensor_batch = self.non_tensor_batch if deepcopy: non_tensor_batch = copy.deepcopy(non_tensor_batch) if meta_info_keys is not None: sub_meta_info = {key: val for key, val in self.meta_info.items() if key in meta_info_keys} else: sub_meta_info = self.meta_info if deepcopy: sub_meta_info = copy.deepcopy(sub_meta_info) return type(self)(batch=sub_batch, non_tensor_batch=non_tensor_batch, meta_info=sub_meta_info) def select_idxs(self, idxs): """ Select specific indices from the DataProto. Args: idxs (torch.Tensor or numpy.ndarray or list): Indices to select Returns: DataProto: A new DataProto containing only the selected indices """ if isinstance(idxs, list): idxs = torch.tensor(idxs) if idxs.dtype != torch.bool: idxs = idxs.type(torch.int32) if isinstance(idxs, np.ndarray): idxs_np = idxs idxs_torch = torch.from_numpy(idxs) else: # torch.Tensor idxs_torch = idxs idxs_np = idxs.detach().cpu().numpy() batch_size = int(idxs_np.sum()) if idxs_np.dtype == bool else idxs_np.shape[0] if self.batch is not None: # Use TensorDict's built-in indexing capabilities selected_batch = TensorDict( source={key: tensor[idxs_torch] for key, tensor in self.batch.items()}, batch_size=(batch_size,), device=self.batch.device, ) else: selected_batch = None selected_non_tensor = {} for key, val in self.non_tensor_batch.items(): selected_non_tensor[key] = val[idxs_np] return type(self)(batch=selected_batch, non_tensor_batch=selected_non_tensor, meta_info=self.meta_info) def slice(self, start=None, end=None, step=None): """ Slice the DataProto and return a new DataProto object. This is an improved version of direct slicing which returns a DataProtoItem. Args: start (int, optional): Start index. Defaults to None (start from beginning). end (int, optional): End index (exclusive). Defaults to None (go to end). step (int, optional): Step size. Defaults to None (step=1). Returns: DataProto: A new DataProto containing the sliced data Examples: # Using the slice method directly sliced_data = data_proto.slice(10, 20) # Using enhanced indexing (returns DataProto) sliced_data = data_proto[10:20] sliced_data = data_proto[::2] # Every other element # Using list indexing (returns DataProto) indices = [1, 5, 10] selected_data = data_proto[indices] # Single index still returns DataProtoItem single_item = data_proto[5] """ # Create a slice object slice_obj = slice(start, end, step) # Handle the batch data if self.batch is not None: # Use TensorDict's built-in slicing capabilities sliced_batch = self.batch[slice_obj] else: sliced_batch = None # Handle the non-tensor batch data sliced_non_tensor = {} for key, val in self.non_tensor_batch.items(): sliced_non_tensor[key] = val[slice_obj] # Return a new DataProto object return type(self)(batch=sliced_batch, non_tensor_batch=sliced_non_tensor, meta_info=self.meta_info) def pop(self, batch_keys=None, non_tensor_batch_keys=None, meta_info_keys=None) -> "DataProto": """Pop a subset of the DataProto via `batch_keys` and `meta_info_keys` Args: batch_keys (list, optional): a list of strings indicating the keys in batch to pop meta_info_keys (list, optional): a list of keys indicating the meta info to pop Returns: DataProto: the DataProto with the poped batch_keys and meta_info_keys """ if batch_keys is None: batch_keys = [] if meta_info_keys is None: meta_info_keys = [] if non_tensor_batch_keys is None: non_tensor_batch_keys = [] tensors = {} # tensor batch for key in batch_keys: assert key in self.batch.keys() tensors[key] = self.batch.pop(key) non_tensors = {} # non tensor batch for key in non_tensor_batch_keys: assert key in self.non_tensor_batch.keys() non_tensors[key] = self.non_tensor_batch.pop(key) meta_info = {} for key in meta_info_keys: assert key in self.meta_info.keys() meta_info[key] = self.meta_info.pop(key) return DataProto.from_dict(tensors=tensors, non_tensors=non_tensors, meta_info=meta_info) def rename(self, old_keys=None, new_keys=None) -> "DataProto": """ Note that this function only rename the key in the batch """ def validate_input(keys): if keys is not None: if isinstance(keys, str): keys = [keys] elif isinstance(keys, list): pass else: raise TypeError(f"keys must be a list or a string, but got {type(keys)}") return keys old_keys = validate_input(old_keys) new_keys = validate_input(new_keys) if len(new_keys) != len(old_keys): raise ValueError( f"new_keys and old_keys must have the same length, but got {len(new_keys)} and {len(old_keys)}" ) self.batch.rename_key_(tuple(old_keys), tuple(new_keys)) return self def union(self, other: "DataProto") -> "DataProto": """Union with another DataProto. Union batch and meta_info separately. Throw an error if - there are conflict keys in batch and they are not equal - the batch size of two data batch is not the same - there are conflict keys in meta_info and they are not the same. Args: other (DataProto): another DataProto to union Returns: DataProto: the DataProto after union """ self.batch = union_tensor_dict(self.batch, other.batch) self.non_tensor_batch = union_numpy_dict(self.non_tensor_batch, other.non_tensor_batch) self.meta_info = union_python_dict(self.meta_info, other.meta_info) return self def make_iterator(self, mini_batch_size, epochs, seed=None, dataloader_kwargs=None): r"""Make an iterator from the DataProto. This is built upon that TensorDict can be used as a normal Pytorch dataset. See https://pytorch.org/tensordict/tutorials/data_fashion for more details. Args: mini_batch_size (int): mini-batch size when iterating the dataset. We require that ``batch.batch_size[0] % mini_batch_size == 0``. epochs (int): number of epochs when iterating the dataset. dataloader_kwargs (Any): internally, it returns a DataLoader over the batch. The dataloader_kwargs is the kwargs passed to the DataLoader. Returns: Iterator: an iterator that yields a mini-batch data at a time. The total number of iteration steps is ``self.batch.batch_size * epochs // mini_batch_size`` """ assert self.batch.batch_size[0] % mini_batch_size == 0, f"{self.batch.batch_size[0]} % {mini_batch_size} != 0" # we can directly create a dataloader from TensorDict if dataloader_kwargs is None: dataloader_kwargs = {} if seed is not None: generator = torch.Generator() generator.manual_seed(seed) else: generator = None assert isinstance(dataloader_kwargs, dict) train_dataloader = DataLoader( dataset=self, batch_size=mini_batch_size, collate_fn=collate_fn, generator=generator, **dataloader_kwargs ) def get_data(): for _ in range(epochs): for d in train_dataloader: d.meta_info = self.meta_info yield d return iter(get_data()) def padding(self, padding_size, padding_candidate=""): """Pad the DataProto by concating with padding_candidate.repeat(padding_size) Args: padding_size (int): the number of repeated padding_candidate padding_candidate: the item to be repeated and appended to the DataProto, only supporting ["first", "last"] """ if padding_size == 0: return padding_candidate = self.select_idxs([0 if padding_candidate == "first" else len(self) - 1]) padding_part = padding_candidate.repeat(padding_size) padded_dp = DataProto.concat([self, padding_part]) self.batch = padded_dp.batch self.non_tensor_batch = padded_dp.non_tensor_batch def chunk(self, chunks: int) -> list["DataProto"]: """Split the batch among dim=0 into chunks. The meta_info is passed to each DataProto after split. Args: chunks (int): the number of chunks to split on dim=0 Returns: List[DataProto]: a list of DataProto after splitting """ if not self.is_padding_enabled(): assert len(self) % chunks == 0, ( f"only support equal chunk. Got size of DataProto {len(self)} and chunk {chunks}." ) bsz_in_batch = None if self.batch is not None: batch_lst = self.batch.chunk(chunks=chunks, dim=0) bsz_in_batch = np.array([batch.batch_size[0] for batch in batch_lst]) chunk_indices = np.cumsum(bsz_in_batch)[:-1] else: batch_lst = [None for _ in range(chunks)] non_tensor_batch_lst = [{} for _ in range(chunks)] for key, val in self.non_tensor_batch.items(): assert isinstance(val, np.ndarray) if bsz_in_batch is not None: non_tensor_lst = np.array_split(val, chunk_indices.tolist()) else: non_tensor_lst = np.array_split(val, chunks) assert len(non_tensor_lst) == chunks for i in range(chunks): non_tensor_batch_lst[i][key] = non_tensor_lst[i] output = [] for i in range(chunks): output.append( type(self)(batch=batch_lst[i], non_tensor_batch=non_tensor_batch_lst[i], meta_info=self.meta_info) ) return output def split(self, split_size: int) -> list["DataProto"]: """Split the batch among dim=0 into chunks. The meta_info is passed to each DataProto after split. Args: split_size (int): the size of each split Returns: List[DataProto]: a list of DataProto after splitting """ return [self[i : i + split_size] for i in range(0, len(self), split_size)] @staticmethod def concat(data: list["DataProto"]) -> "DataProto": """Concat a list of DataProto. The batch is concatenated among dim=0. The meta_info is merged, with special handling for metrics from different workers. Args: data (List[DataProto]): list of DataProto Returns: DataProto: concatenated DataProto """ batch_lst = [] for batch in data: batch_lst.append(batch.batch) new_batch = torch.cat(batch_lst, dim=0) if batch_lst[0] is not None else None non_tensor_batch = list_of_dict_to_dict_of_list(list_of_dict=[d.non_tensor_batch for d in data]) for key, val in non_tensor_batch.items(): non_tensor_batch[key] = np.concatenate(val, axis=0) # Merge meta_info with special handling for metrics merged_meta_info = {} if data: # Merge non-metric meta_info and aggregate metrics from all workers. all_metrics = [] for d in data: for k, v in d.meta_info.items(): if k == "metrics": if v is not None: if isinstance(v, list): all_metrics.extend(v) else: all_metrics.append(v) else: if k in merged_meta_info: # Ensure consistency for overlapping non-metric keys assert merged_meta_info[k] == v, f"Conflicting values for meta_info key '{k}'" else: merged_meta_info[k] = v # Flatten list of dicts to dict of lists for consistent metrics structure if all_metrics: merged_meta_info["metrics"] = list_of_dict_to_dict_of_list(all_metrics) cls = type(data[0]) if len(data) > 0 else DataProto return cls(batch=new_batch, non_tensor_batch=non_tensor_batch, meta_info=merged_meta_info) def reorder(self, indices): """ Note that this operation is in-place """ indices_np = indices.detach().numpy() self.batch = self.batch[indices] self.non_tensor_batch = {key: val[indices_np] for key, val in self.non_tensor_batch.items()} def repeat(self, repeat_times=2, interleave=True): """ Repeat the batch data a specified number of times. Args: repeat_times (int): Number of times to repeat the data. interleave (bool): Whether to interleave the repeated data. Returns: DataProto: A new DataProto with repeated data. """ if self.batch is not None: if interleave: # Interleave the data repeated_tensors = { key: tensor.repeat_interleave(repeat_times, dim=0) for key, tensor in self.batch.items() } else: # Stack the data repeated_tensors = { key: tensor.unsqueeze(0).expand(repeat_times, *tensor.shape).reshape(-1, *tensor.shape[1:]) for key, tensor in self.batch.items() } repeated_batch = TensorDict( source=repeated_tensors, batch_size=(self.batch.batch_size[0] * repeat_times,), ) else: repeated_batch = None repeated_non_tensor_batch = {} for key, val in self.non_tensor_batch.items(): if interleave: repeated_non_tensor_batch[key] = np.repeat(val, repeat_times, axis=0) else: repeated_non_tensor_batch[key] = np.tile(val, (repeat_times,) + (1,) * (val.ndim - 1)) return type(self)( batch=repeated_batch, non_tensor_batch=repeated_non_tensor_batch, meta_info=self.meta_info, ) def unfold_column_chunks(self, n_split: int, split_keys: Optional[list[str]] = None): """Split along the second dim into `n_split`, unfold it to the first dim (batch dim) Useful in passing grouped tensors that doesn't want to be shuffled in dataset. keys not in split_keys are repeated to match the shape Note that if the `split_keys` is not provided, it will repeat all the keys in the second dim. """ if self.batch is not None: unfolded_batch = {} for key in self.batch.keys(): if key in split_keys if split_keys is not None else False: shape = list(self.batch[key].shape) shape[0] = self.batch[key].shape[0] * n_split shape[1] = self.batch[key].shape[1] // n_split unfolded_batch[key] = self.batch[key].reshape(*shape) else: unfolded_batch[key] = torch.repeat_interleave(self.batch[key], n_split, dim=0) # locate the `unfolded_batch` as a TensorDict on the same device as the original batch unfolded_batch = TensorDict( source=unfolded_batch, batch_size=(self.batch.batch_size[0] * n_split,), device=self.batch.device ) else: unfolded_batch = None repeated_non_tensor_batch = {} for key, val in self.non_tensor_batch.items(): if key in split_keys: shape = list(val.shape) shape[0] = val.shape[0] * n_split shape[1] = val.shape[1] // n_split repeated_non_tensor_batch[key] = val.reshape(*shape) else: repeated_non_tensor_batch[key] = np.repeat(val, n_split, axis=0) return type(self)( batch=unfolded_batch, non_tensor_batch=repeated_non_tensor_batch, meta_info=self.meta_info, ) def sample_level_repeat(self, repeat_times): """ Repeat each row of the batch data a specified number of times. Args: repeat_times (torch.tensor, list, tuple, ndarray): Number of times to repeat the data. Returns: DataProto: A new DataProto with repeated data. """ if isinstance(repeat_times, tuple): repeat_times = list(repeat_times) elif isinstance(repeat_times, torch.Tensor): assert len(repeat_times.shape) == 1 repeat_times = repeat_times.tolist() elif isinstance(repeat_times, np.ndarray): assert len(repeat_times.shape) == 1 repeat_times = repeat_times.tolist() else: assert isinstance(repeat_times, list), ( f"repeat_times type must be in [list, torch.Tensor, np.ndarray, tuple], got {type(repeat_times)}" ) repeat_times = torch.tensor(repeat_times) if self.batch is not None: # Interleave the data repeated_tensors = { key: tensor.repeat_interleave(repeat_times, dim=0) for key, tensor in self.batch.items() } repeated_batch = TensorDict( source=repeated_tensors, batch_size=(repeat_times.sum().item(),), device=self.batch.device, ) else: repeated_batch = None repeated_non_tensor_batch = {} for key, val in self.non_tensor_batch.items(): repeated_non_tensor_batch[key] = np.repeat(val, repeat_times, axis=0) return type(self)( batch=repeated_batch, non_tensor_batch=repeated_non_tensor_batch, meta_info=self.meta_info, ) def to_tensordict(self) -> TensorDict: """Convert this DataProto to TensorDict. Note that this requires tensordict version at least 0.10 Returns: """ assert parse_version(tensordict.__version__) >= parse_version("0.10"), ( "Convert DataProto to TensorDict at least requires tensordict version 0.10" ) tensor_batch = self.batch.to_dict() non_tensor_batch = self.non_tensor_batch from tensordict.tensorclass import NonTensorData, NonTensorStack common_keys = set(tensor_batch.keys()) & set(non_tensor_batch.keys()) assert len(common_keys) == 0, f"tensor_batch and non_tensor_batch have common keys {common_keys}" for key, val in non_tensor_batch.items(): assert isinstance(val, np.ndarray) # Convert to NonTensorStack instead of plain list to handle nested structures tensor_batch[key] = NonTensorStack.from_list([NonTensorData(item) for item in val]) output = get_tensordict(tensor_dict=tensor_batch, non_tensor_dict=self.meta_info) return output def get_data_info(self) -> str: """Return formatted information about stored data with nested type details. Returns: str: Formatted string showing tensor details and recursive metadata types """ info = ["batch"] for key, tensor in self.batch.items(): if hasattr(tensor, "shape") and hasattr(tensor, "dtype") and hasattr(tensor, "device"): info.append(f" {key}: {tuple(tensor.shape)} ({tensor.dtype}) {tensor.device}") elif hasattr(tensor, "shape") and hasattr(tensor, "dtype"): info.append(f" {key}: {tuple(tensor.shape)} ({tensor.dtype})") else: info.append(f" {key}: {type(tensor).__name__}") info.append("non_tensor_batch") for key, array in self.non_tensor_batch.items(): info.append(f" {key}: ndarray{array.shape} ({array.dtype})") info.append("meta_info") for k, v in self.meta_info.items(): type_info = self._get_type_info(v) info.append(f" {k}: {type_info}") return "\n".join(info) def _get_type_info(self, value): """Recursively get type information for nested structures""" if isinstance(value, list): elem_types = {self._get_type_info(v) for v in value[:3]} return f"list[{'|'.join(elem_types) if elem_types else '...'}]" if isinstance(value, tuple): elem_types = [self._get_type_info(v) for v in value] return f"tuple({', '.join(elem_types)})" if isinstance(value, dict): if not value: return "dict" k, v = next(iter(value.items())) return f"dict[{self._get_type_info(k)}: {self._get_type_info(v)}]" if isinstance(value, np.ndarray): return f"ndarray{value.shape} ({value.dtype})" return type(value).__name__ ================================================ FILE: src/lmflow/utils/test_utils.py ================================================ from typing import Optional import torch import torch.nn as nn def compare_model( model_ref: "nn.Module", model_trained: "nn.Module", module_trained: Optional[list[str]] = None ) -> None: state_dict_ref = model_ref.state_dict() state_dict_trained = model_trained.state_dict() assert set(state_dict_ref.keys()) == set(state_dict_trained.keys()) for name in state_dict_ref.keys(): if module_trained is not None: if any([module in name for module in module_trained]): assert torch.allclose(state_dict_ref[name], state_dict_trained[name], rtol=1e-4, atol=1e-5) is False else: assert torch.allclose(state_dict_ref[name], state_dict_trained[name], rtol=1e-4, atol=1e-5) is True ================================================ FILE: src/lmflow/utils/versioning.py ================================================ import importlib import logging import sys from importlib import metadata from pathlib import Path from typing import Union, List, Tuple from packaging.version import Version, InvalidVersion logger = logging.getLogger(__name__) def get_python_version(): return sys.version_info def _is_package_available(package_name: str, skippable: bool = False): assert isinstance(package_name, str), f"Invalid type of package_name: {type(package_name)}" try: importlib.import_module(package_name) return True except Exception as e: if isinstance(e, ModuleNotFoundError): return False else: if skippable: logger.warning(f"An error occurred when importing {package_name}:\n{e}\n{package_name} is disabled.") return False else: raise e def _is_packages_available(packages: Union[List[str], List[Tuple[str, bool]]]): if isinstance(packages[0], str): return all([_is_package_available(package) for package in packages]) elif isinstance(packages[0], tuple): return all([_is_package_available(package, skippable) for package, skippable in packages]) else: raise ValueError(f"Invalid type of packages: {type(packages[0])}") def is_package_version_at_least(package_name, min_version): try: package_version = metadata.version(package_name) if Version(package_version) < Version(min_version): return False except (metadata.PackageNotFoundError, InvalidVersion): return False return True def is_gradio_available(): return _is_package_available("gradio") def is_ray_available(): return _is_package_available("ray") def is_vllm_available(): return _is_package_available("vllm") def is_sglang_available(): return _is_package_available("sglang") def is_flash_attn_available(): return _is_package_available("flash_attn", skippable=True) def is_flask_available(): return _is_packages_available(["flask", "flask_cors"]) def is_trl_available(): return _is_package_available("trl") def is_multimodal_available(): return _is_packages_available(["PIL"]) def is_deepspeed_available(): return _is_package_available("deepspeed") def get_lmflow_dir(return_src_dir: bool = False) -> Path: try: from importlib.util import find_spec spec = find_spec("lmflow") if spec is None: return None origin = Path(spec.origin) if origin is None: return None if origin.name == "__init__.py": if return_src_dir: return origin.parent else: return origin.parent.parent.parent else: return None except (ImportError, AttributeError): return None ================================================ FILE: src/lmflow/version.py ================================================ __version__ = "1.1.0" ================================================ FILE: tests/__init__.py ================================================ ================================================ FILE: tests/conftest.py ================================================ import pytest def pytest_configure(config: pytest.Config): config.addinivalue_line("markers", "gpu: requires gpu") config.addinivalue_line("markers", "slow: marks tests as slow") config.addinivalue_line("markers", "lmflow_core: tests for core lmflow functionality") config.addinivalue_line("markers", "dothis: mark for dev to do the specified tests only") ================================================ FILE: tests/datasets/__init__.py ================================================ ================================================ FILE: tests/datasets/conftest.py ================================================ import pytest from lmflow.args import DatasetArguments from lmflow.datasets.dataset import Dataset @pytest.fixture def dataset_inference_conversation() -> Dataset: dataset = Dataset(DatasetArguments(dataset_path=None)) dataset = dataset.from_dict( {"type": "conversation", "instances": [{"messages": [{"role": "user", "content": "Hello, how are you?"}]}]} ) return dataset @pytest.fixture def dataset_inference_conversation_batch() -> Dataset: dataset = Dataset(DatasetArguments(dataset_path=None)) dataset = dataset.from_dict( { "type": "conversation", "instances": [ {"messages": [{"role": "user", "content": "Hello, how are you?"}]}, {"messages": [{"role": "user", "content": "What's the capital of France?"}]}, ], } ) return dataset ================================================ FILE: tests/datasets/test_dataset.py ================================================ #!/bin/env/python3 """A one-line summary of the module or program, terminated by a period. Leave one blank line. The rest of this docstring should contain an overall description of the module or program. Optionally, it may also contain a brief description of exported classes and functions and/or usage examples. Typical usage example: foo = ClassFoo() bar = foo.FunctionBar() """ import json import os import unittest from pathlib import Path from lmflow.args import DatasetArguments from lmflow.datasets.dataset import Dataset class DatasetTest(unittest.TestCase): def test_init(self): dataset_dir = "data/example_dataset/train" data_args = DatasetArguments(dataset_path=dataset_dir) dataset = Dataset(data_args, backend="huggingface") hf_dataset = dataset.get_backend_dataset() with open(os.path.join(Path(dataset_dir), "train_50.json")) as fin: json_obj = json.load(fin) for i in range(len(hf_dataset)): self.assertEqual(json_obj["instances"][i], hf_dataset[i]) def test_create_from_dict(self): data_dict = { "type": "text2text", "instances": [ {"input": "INPUT 1", "output": "OUTPUT 1"}, {"input": "INPUT 2", "output": "OUTPUT 2"}, ], } dataset = Dataset.create_from_dict(data_dict) self.assertEqual(dataset.to_dict(), data_dict) def test_create_from_dict_bad_type(self): data_dict = { "type": "non-supported", "instances": [ {"input": "INPUT 1", "output": "OUTPUT 1"}, {"input": "INPUT 2", "output": "OUTPUT 2"}, ], } with self.assertRaises(ValueError): dataset = Dataset.create_from_dict(data_dict) ================================================ FILE: tests/models/__init__.py ================================================ ================================================ FILE: tests/models/test_auto_model.py ================================================ import unittest from lmflow.args import ModelArguments from lmflow.models.auto_model import AutoModel from lmflow.models.hf_decoder_model import HFDecoderModel # from lmflow.models.hf_encoder_decoder_model import HFEncoderDecoderModel MODEL_NAME = "gpt2" class AutoModelTest(unittest.TestCase): def test_get_decoder_model(self): model_args = ModelArguments(arch_type="decoder_only", model_name_or_path=MODEL_NAME) model = AutoModel.get_model(model_args) self.assertTrue(isinstance(model, HFDecoderModel)) # This unit test is commented out since the encoder decoder model has not been fully implemented """ def test_get_text_regression_model(self): model_args = ModelArguments( arch_type="text_regression", model_name_or_path=MODEL_NAME) model = AutoModel.get_model(model_args) self.assertTrue(isinstance(model, TextRegressionModel)) """ # This unit test is commented out since the encoder decoder model has not been fully implemented """ def test_get_encoder_decoder(self): model_args = ModelArguments( arch_type="encoder_decoder", model_name_or_path=MODEL_NAME) model = AutoModel.get_model(model_args) self.assertTrue(isinstance(model, HFEncoderDecoderModel)) """ def test_get_unsupported_model(self): model_args = ModelArguments(arch_type="unsupported model", model_name_or_path=MODEL_NAME) with self.assertRaises(NotImplementedError): model = AutoModel.get_model(model_args) ================================================ FILE: tests/models/test_hf_decoder_model.py ================================================ #!/bin/env/python3 # coding=utf-8 """A one-line summary of the module or program, terminated by a period. Leave one blank line. The rest of this docstring should contain an overall description of the module or program. Optionally, it may also contain a brief description of exported classes and functions and/or usage examples. Typical usage example: foo = ClassFoo() bar = foo.FunctionBar() """ from __future__ import absolute_import import unittest import torch import json import os from pathlib import Path from lmflow.args import DatasetArguments, ModelArguments from lmflow.datasets.dataset import Dataset from lmflow.models.hf_decoder_model import HFDecoderModel from lmflow.utils.constants import ( TEXT_ONLY_DATASET_DESCRIPTION, TEXT2TEXT_DATASET_DESCRIPTION, ) from lmflow.utils.conversation_template import PRESET_TEMPLATES SAMPLE_TEXT = "Defintion: In this task, we ask you to write an answer to a question that involves events that may be stationary (not changing over time) or transient (changing over time). For example, the sentence \"he was born in the U.S.\" contains a stationary event since it will last forever; however, \"he is hungry\" contains a transient event since it will remain true for a short period of time. Note that a lot of the questions could have more than one correct answer. We only need a single most-likely answer. Please try to keep your \"answer\" as simple as possible. Concise and simple \"answer\" is preferred over those complex and verbose ones. \\n Input: Sentence: It's hail crackled across the comm, and Tara spun to retake her seat at the helm. \nQuestion: Will the hail storm ever end? \\n Output: NA \\n\\n" SAMPLE_TOKENS = [ 7469, 600, 295, 25, 554, 428, 4876, 11, 356, 1265, 345, 284, 3551, 281, 3280, 284, 257, 1808, 326, 9018, 2995, 326, 743, 307, 31607, 357, 1662, 5609, 625, 640, 8, 393, 32361, 357, 22954, 625, 640, 737, 1114, 1672, 11, 262, 6827, 366, 258, 373, 4642, 287, 262, 471, 13, 50, 526, 4909, 257, 31607, 1785, 1201, 340, 481, 938, 8097, 26, 2158, 11, 366, 258, 318, 14720, 1, 4909, 257, 32361, 1785, 1201, 340, 481, 3520, 2081, 329, 257, 1790, 2278, 286, 640, 13, 5740, 326, 257, 1256, 286, 262, 2683, 714, 423, 517, 621, 530, 3376, 3280, 13, 775, 691, 761, 257, 2060, 749, 12, 40798, 3280, 13, 4222, 1949, 284, 1394, 534, 366, 41484, 1, 355, 2829, 355, 1744, 13, 13223, 786, 290, 2829, 366, 41484, 1, 318, 9871, 625, 883, 3716, 290, 15942, 577, 3392, 13, 3467, 77, 23412, 25, 11352, 594, 25, 632, 338, 32405, 8469, 992, 1973, 262, 725, 11, 290, 37723, 26843, 284, 41754, 607, 5852, 379, 262, 18030, 13, 220, 198, 24361, 25, 2561, 262, 32405, 6388, 1683, 886, 30, 3467, 77, 25235, 25, 11746, 3467, 77, 59, 77 ] SAMPLE_ATTENTION_MASKS = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] CONVERSATION_SINGLETURN = { "system": "sysinfo", "messages": [ { "role": "user", "content": "Hello" }, { "role": "assistant", "content": "Hi!" } ] } CONVERSATION_SINGLETURN_LLAMA2 = { "messages": [ { "role": "user", "content": "[INST] <>\nsysinfo\n<>\n\nHello [/INST]" }, { "role": "assistant", "content": "Hi!" } ] } CONVERSATION_SINGLETURN_CHATGLM3_IDS = [ ( [64790, 64792, 906, 31007, 13361, 31007, 30994, 13, 15184, 6607, 64795, 30910, 13, 13755, ], [64796, 30910, 13, 8686, 30992,] ) ] CONVERSATION_SINGLETURN_DEEPSEEK_IDS = [ ( [100000, 10183, 4904, 185, 185, 5726, 25, 37727, 185, 185], [77398, 25, 11598, 0, 100001] ) ] CONVERSATION_SINGLETURN_GEMMA_IDS = [ ( [2, 9052, 3296, 106, 1645, 108, 4521, 107, 108], [106, 2516, 108, 2151, 235341, 107, 108] ) ] CONVERSATION_SINGLETURN_INTERNLM2_IDS = [ ( [1, 333, 352, 449, 5064, 352, 330, 9081, 364, 7930, 2896, 333, 352, 449, 6368, 352, 527, 333, 352, 449, 5064, 352, 330, 1008, 364, 9843, 333, 352, 449, 6368, 352, 527,], [333, 352, 449, 5064, 352, 330, 525, 11353, 364, 13195, 346, 333, 352, 449, 6368, 352, 527, ] ) ] CONVERSATION_SINGLETURN_LLAMA2_IDS = [ ( [1, 518, 25580, 29962, 3532, 14816, 29903, 6778, 13, 9675, 3888, 13, 29966, 829, 14816, 29903, 6778, 13, 13, 10994, 518, 29914, 25580, 29962], [6324, 29991, 2] ) ] CONVERSATION_SINGLETURN_LLAMA3_IDS = [ ( [128000, 128006, 9125, 128007, 271, 7947, 2801, 128009, 128006, 882, 128007, 271, 9906, 128009], [128006, 78191, 128007, 271, 13347, 0, 128009] ) ] CONVERSATION_SINGLETURN_PHI3_IDS = [ ( [1, 32006, 10876, 3888, 32007, 32010, 15043, 32007], [32001, 6324, 29991, 32007, 32000] ) ] CONVERSATION_SINGLETURN_YI1_5_IDS = [ ( [15692, 5885, 59666, 59705, 622, 59593, 5858, 46826, 3903, 144, 25102, 59666, 59705, 622, 59593, 701, 46826, 144 ], [59666, 59705, 622, 59593, 5858, 46826, 765, 13611, 144, 25070, 99, 59666, 59705, 622, 59593, 701, 46826, 144, ] ) ] CONVERSATION_SINGLETURN_ZEPHYR_IDS = [ ( [523, 28766, 6574, 28766, 28767, 13, 6609, 1817, 2, 28705, 13, 28789, 28766, 1838, 28766, 28767, 13, 16230, 2], [28705, 13, 28789, 28766, 489, 11143, 28766, 28767, 13, 23809, 28808, 2] ) ] CONVERSATION_MULTITURN = { "system": "sysinfo", "messages": [ { "role": "user", "content": "Hello" }, { "role": "assistant", "content": "Hi!" }, { "role": "user", "content": "How are you?" }, { "role": "assistant", "content": "I'm good, thanks!" } ] } CONVERSATION_MULTITURN_LLAMA2 = { "messages": [ { "role": "user", "content": "[INST] <>\nsysinfo\n<>\n\nHello [/INST]" }, { "role": "assistant", "content": "Hi!" }, { "role": "user", "content": "[INST] How are you? [/INST]" }, { "role": "assistant", "content": "I'm good, thanks!" } ] } CONVERSATION_MULTITURN_DEEPSEEK_IDS = [ ( [100000, 10183, 4904, 185, 185, 5726, 25, 37727, 185, 185], [77398, 25, 11598, 0, 100001] ), ( [5726, 25, 1724, 418, 340, 30, 185, 185], [77398, 25, 304, 6, 76, 1207, 11, 7749, 0, 100001] ) ] CONVERSATION_MULTITURN_CHATGLM3_IDS = [ ( [64790, 64792, 906, 31007, 13361, 31007, 30994, 13, 15184, 6607, 64795, 30910, 13, 13755, ], [64796, 30910, 13, 8686, 30992,] ), ( [64795, 30910, 13, 1072, 383, 344, 30987, ], [64796, 30910, 13, 307, 30953, 30924, 878, 30932, 4772, 30992] ) ] CONVERSATION_MULTITURN_GEMMA_IDS = [ ( [2, 9052, 3296, 106, 1645, 108, 4521, 107, 108], [106, 2516, 108, 2151, 235341, 107, 108] ), ( [106, 1645, 108, 2299, 708, 692, 235336, 107, 108], [106, 2516, 108, 235285, 235303, 235262, 1426, 235269, 6402, 235341, 107, 108] ) ] CONVERSATION_MULTITURN_INTERNLM2_IDS = [ ( [1, 333, 352, 449, 5064, 352, 330, 9081, 364, 7930, 2896, 333, 352, 449, 6368, 352, 527, 333, 352, 449, 5064, 352, 330, 1008, 364, 9843, 333, 352, 449, 6368, 352, 527,], [333, 352, 449, 5064, 352, 330, 525, 11353, 364, 13195, 346, 333, 352, 449, 6368, 352, 527, ] ), ( [333, 352, 449, 5064, 352, 330, 1008, 364, 4500, 657, 629, 345, 333, 352, 449, 6368, 352, 527, ], [333, 352, 449, 5064, 352, 330, 525, 11353, 364, 295, 2940, 1811, 328, 9467, 346, 333, 352, 449, 6368, 352, 527] ) ] CONVERSATION_MULTITURN_LLAMA2_IDS = [ ( [1, 518, 25580, 29962, 3532, 14816, 29903, 6778, 13, 9675, 3888, 13, 29966, 829, 14816, 29903, 6778, 13, 13, 10994, 518, 29914, 25580, 29962], [6324, 29991, 2] ), ( [1, 518, 25580, 29962, 1128, 526, 366, 29973, 518, 29914, 25580, 29962], [306, 29915, 29885, 1781, 29892, 3969, 29991, 2] ) ] CONVERSATION_MULTITURN_LLAMA3_IDS = [ ( [128000, 128006, 9125, 128007, 271, 7947, 2801, 128009, 128006, 882, 128007, 271, 9906, 128009], [128006, 78191, 128007, 271, 13347, 0, 128009] ), ( [128006, 882, 128007, 271, 4438, 527, 499, 30, 128009], [128006, 78191, 128007, 271, 40, 2846, 1695, 11, 9523, 0, 128009] ) ] CONVERSATION_MULTITURN_PHI3_IDS = [ ( [1, 32006, 10876, 3888, 32007, 32010, 15043, 32007], [32001, 6324, 29991, 32007] ), ( [32010, 1128, 526, 366, 29973, 32007], [32001, 306, 29915, 29885, 1781, 29892, 3969, 29991, 32007, 32000] ) ] CONVERSATION_MULTITURN_YI1_5_IDS = [ ( [15692, 5885, 59666, 59705, 622, 59593, 5858, 46826, 3903, 144, 25102, 59666, 59705, 622, 59593, 701, 46826, 144 ], [59666, 59705, 622, 59593, 5858, 46826, 765, 13611, 144, 25070, 99, 59666, 59705, 622, 59593, 701, 46826, 144, ] ), ( [59666, 59705, 622, 59593, 5858, 46826, 3903, 144, 6546, 678, 641, 100, 59666, 59705, 622, 59593, 701, 46826, 144,], [59666, 59705, 622, 59593, 5858, 46826, 765, 13611, 144, 59597, 59610, 59583, 1226, 97, 5867, 99, 59666, 59705, 622, 59593, 701, 46826, 144] ) ] CONVERSATION_MULTITURN_ZEPHYR_IDS = [ ( [523, 28766, 6574, 28766, 28767, 13, 6609, 1817, 2, 28705, 13, 28789, 28766, 1838, 28766, 28767, 13, 16230, 2], [28705, 13, 28789, 28766, 489, 11143, 28766, 28767, 13, 23809, 28808, 2] ), ( [28705, 13, 28789, 28766, 1838, 28766, 28767, 13, 5660, 460, 368, 28804, 2], [28705, 13, 28789, 28766, 489, 11143, 28766, 28767, 13, 28737, 28742, 28719, 1179, 28725, 8196, 28808, 2] ) ] test_encode_input = "Question: Which of the following is not true for myelinated nerve fibers: (A) Impulse through myelinated fibers is slower than non-myelinated fibers (B) Membrane currents are generated at nodes of Ranvier (C) Saltatory conduction of impulses is seen (D) Local anesthesia is effective only when the nerve is not covered by myelin sheath." test_encode_output = [24361, 25, 9022, 286, 262, 1708, 318, 407, 2081, 329, 616, 417, 3898, 16384, 26742, 25, 357, 32, 8, 9855, 9615, 832, 616, 417, 3898, 26742, 318, 13611, 621, 1729, 12, 1820, 417, 3898, 26742, 357, 33, 8, 4942, 1671, 1531, 28629, 389, 7560, 379, 13760, 286, 23075, 49663, 357, 34, 8, 13754, 2870, 369, 11124, 286, 37505, 318, 1775, 357, 35, 8, 10714, 49592, 318, 4050, 691, 618, 262, 16384, 318, 407, 5017, 416, 616, 27176, 673, 776, 13] test_decode_input = [24361, 25, 9022, 286, 262, 1708, 318, 407, 2081, 329, 616, 417, 3898, 16384, 26742, 25, 357, 32, 8, 9855, 9615, 832, 616, 417, 3898, 26742, 318, 13611, 621, 1729, 12, 1820, 417, 3898, 26742, 357, 33, 8, 4942, 1671, 1531, 28629, 389, 7560, 379, 13760, 286, 23075, 49663, 357, 34, 8, 13754, 2870, 369, 11124, 286, 37505, 318, 1775, 357, 35, 8, 10714, 49592, 318, 4050, 691, 618, 262, 16384, 318, 407, 5017, 416, 616, 27176, 673, 776, 13] test_decode_output = "Question: Which of the following is not true for myelinated nerve fibers: (A) Impulse through myelinated fibers is slower than non-myelinated fibers (B) Membrane currents are generated at nodes of Ranvier (C) Saltatory conduction of impulses is seen (D) Local anesthesia is effective only when the nerve is not covered by myelin sheath." test_inference_output = "The following is a list of the most common causes of myelinated nerve fibers." def make_gt_from_conversation_ids(conversation_ids): res = {"input_ids": [], "attention_mask": [], "labels": []} for turn_idx, turn_content in enumerate(conversation_ids): user_content = turn_content[0] assistant_content = turn_content[1] res["input_ids"].extend(user_content) res["input_ids"].extend(assistant_content) res['attention_mask'].extend([1] * len(user_content) + [1] * len(assistant_content)) res['labels'].extend([-100] * len(user_content)) res['labels'].extend(assistant_content) return res def make_gt_from_conversation_ids_batch(batched_conversation_ids): res = {"input_ids": [], "attention_mask": [], "labels": []} for conversation_ids in batched_conversation_ids: this_res = make_gt_from_conversation_ids(conversation_ids) res["input_ids"].append(this_res["input_ids"]) res["attention_mask"].append(this_res["attention_mask"]) res["labels"].append(this_res["labels"]) return res class HFDecoderModelTest(unittest.TestCase): def _test_tokenize( self, model_name, groundtruth_dataset, groundtruth_tokenized_dataset, **kwargs ): data_args = DatasetArguments( dataset_path=None, disable_group_texts=False, conversation_template=kwargs.get("conversation_template", None), ) dataset = Dataset(data_args, backend="huggingface") dataset = dataset.from_dict(groundtruth_dataset) self.assertEqual(dataset.to_dict(), groundtruth_dataset) model_args = ModelArguments( model_name_or_path=model_name, trust_remote_code=kwargs.get("trust_remote_code", False) ) model = HFDecoderModel(model_args) tokenized_dataset = model.tokenize(dataset, **kwargs) self.assertEqual( tokenized_dataset.get_backend_dataset().to_dict(), groundtruth_tokenized_dataset, ) def test_tokenize_text_only(self): text_only_dataset = { "type": "text_only", "instances": [ { "text": SAMPLE_TEXT }, ], } text_only_tokenized_dataset = { 'input_ids': [SAMPLE_TOKENS], 'attention_mask': [SAMPLE_ATTENTION_MASKS], 'labels': [SAMPLE_TOKENS], } self._test_tokenize( model_name="gpt2", groundtruth_dataset=text_only_dataset, groundtruth_tokenized_dataset=text_only_tokenized_dataset, ) def test_tokenize_text_only_multiple(self): text_only_dataset = { "type": "text_only", "instances": [ { "text": SAMPLE_TEXT }, { "text": SAMPLE_TEXT }, ], } text_only_tokenized_dataset = { 'input_ids': [SAMPLE_TOKENS, SAMPLE_TOKENS], 'attention_mask': [SAMPLE_ATTENTION_MASKS, SAMPLE_ATTENTION_MASKS], 'labels': [SAMPLE_TOKENS, SAMPLE_TOKENS], } self._test_tokenize( model_name="gpt2", groundtruth_dataset=text_only_dataset, groundtruth_tokenized_dataset=text_only_tokenized_dataset, ) def test_tokenize_text2text(self): text2text_dataset = { "type": "text2text", "instances": [ { "input": SAMPLE_TEXT, "output": SAMPLE_TEXT, }, ], } text2text_tokenized_dataset = { 'input_ids': [SAMPLE_TOKENS + SAMPLE_TOKENS], 'attention_mask': [SAMPLE_ATTENTION_MASKS + SAMPLE_ATTENTION_MASKS], 'labels': [ [-100] * len(SAMPLE_TOKENS) + SAMPLE_TOKENS ], } self._test_tokenize( model_name="gpt2", groundtruth_dataset=text2text_dataset, groundtruth_tokenized_dataset=text2text_tokenized_dataset, ) def test_tokenize_conversation(self): conversation_dataset = { "type": "conversation", "instances": [ { "messages": [ { "role": "user", "content": SAMPLE_TEXT }, { "role": "assistant", "content": SAMPLE_TEXT } ] }, ], } conversation_tokenized_dataset = { 'input_ids': [SAMPLE_TOKENS + SAMPLE_TOKENS], 'attention_mask': [SAMPLE_ATTENTION_MASKS + SAMPLE_ATTENTION_MASKS], 'labels': [ [-100] * len(SAMPLE_TOKENS) + SAMPLE_TOKENS ], } self._test_tokenize( model_name="gpt2", groundtruth_dataset=conversation_dataset, groundtruth_tokenized_dataset=conversation_tokenized_dataset, conversation_template='empty_no_special_tokens' ) self._test_tokenize( model_name='meta-llama/Llama-2-7b-hf', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_SINGLETURN_LLAMA2]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_SINGLETURN_LLAMA2_IDS]), conversation_template='empty' ) self._test_tokenize( model_name='meta-llama/Llama-2-7b-hf', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_SINGLETURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_SINGLETURN_LLAMA2_IDS]), conversation_template='llama2' ) self._test_tokenize( model_name='meta-llama/Meta-Llama-3-8B-Instruct', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_SINGLETURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_SINGLETURN_LLAMA3_IDS]), conversation_template='llama3' ) self._test_tokenize( model_name='microsoft/Phi-3-mini-4k-instruct', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_SINGLETURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_SINGLETURN_PHI3_IDS]), conversation_template='phi3', trust_remote_code=True ) self._test_tokenize( model_name='deepseek-ai/deepseek-llm-7b-base', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_SINGLETURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_SINGLETURN_DEEPSEEK_IDS]), conversation_template='deepseek' ) self._test_tokenize( model_name='internlm/internlm2-1_8b', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_SINGLETURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_SINGLETURN_INTERNLM2_IDS]), conversation_template='internlm2', trust_remote_code=True ) self._test_tokenize( model_name='THUDM/chatglm3-6b', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_SINGLETURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_SINGLETURN_CHATGLM3_IDS]), conversation_template='chatglm3', trust_remote_code=True ) self._test_tokenize( model_name='01-ai/Yi-1.5-6B', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_SINGLETURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_SINGLETURN_YI1_5_IDS]), conversation_template='yi1_5', ) self._test_tokenize( model_name='google/gemma-1.1-2b-it', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_SINGLETURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_SINGLETURN_GEMMA_IDS]), conversation_template='gemma', ) self._test_tokenize( model_name='HuggingFaceH4/zephyr-7b-beta', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_SINGLETURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_SINGLETURN_ZEPHYR_IDS]), conversation_template='zephyr', ) def test_tokenize_conversation_multiple(self): conversation_dataset = { "type": "conversation", "instances": [ { "messages": [ { "role": "user", "content": SAMPLE_TEXT }, { "role": "assistant", "content": SAMPLE_TEXT } ] }, { "messages": [ { "role": "user", "content": SAMPLE_TEXT }, { "role": "assistant", "content": SAMPLE_TEXT } ] }, ], } conversation_tokenized_dataset = { 'input_ids': [SAMPLE_TOKENS + SAMPLE_TOKENS, SAMPLE_TOKENS + SAMPLE_TOKENS], 'attention_mask': [SAMPLE_ATTENTION_MASKS + SAMPLE_ATTENTION_MASKS, SAMPLE_ATTENTION_MASKS + SAMPLE_ATTENTION_MASKS], 'labels': [ [-100] * len(SAMPLE_TOKENS) + SAMPLE_TOKENS , [-100] * len(SAMPLE_TOKENS) + SAMPLE_TOKENS ], } self._test_tokenize( model_name="gpt2", groundtruth_dataset=conversation_dataset, groundtruth_tokenized_dataset=conversation_tokenized_dataset, conversation_template='empty_no_special_tokens' ) self._test_tokenize( model_name='meta-llama/Llama-2-7b-hf', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_MULTITURN_LLAMA2]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_MULTITURN_LLAMA2_IDS]), conversation_template='empty' ) self._test_tokenize( model_name='meta-llama/Llama-2-7b-hf', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_MULTITURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_MULTITURN_LLAMA2_IDS]), conversation_template='llama2' ) self._test_tokenize( model_name='meta-llama/Meta-Llama-3-8B-Instruct', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_MULTITURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_MULTITURN_LLAMA3_IDS]), conversation_template='llama3' ) self._test_tokenize( model_name='microsoft/Phi-3-mini-4k-instruct', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_MULTITURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_MULTITURN_PHI3_IDS]), conversation_template='phi3', trust_remote_code=True ) self._test_tokenize( model_name='deepseek-ai/deepseek-llm-7b-base', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_MULTITURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_MULTITURN_DEEPSEEK_IDS]), conversation_template='deepseek', ) self._test_tokenize( model_name='internlm/internlm2-1_8b', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_MULTITURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_MULTITURN_INTERNLM2_IDS]), conversation_template='internlm2', trust_remote_code=True ) self._test_tokenize( model_name='THUDM/chatglm3-6b', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_MULTITURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_MULTITURN_CHATGLM3_IDS]), conversation_template='chatglm3', trust_remote_code=True ) self._test_tokenize( model_name='01-ai/Yi-1.5-6B', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_MULTITURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_MULTITURN_YI1_5_IDS]), conversation_template='yi1_5', ) self._test_tokenize( model_name='google/gemma-1.1-2b-it', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_MULTITURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_MULTITURN_GEMMA_IDS]), conversation_template='gemma', ) self._test_tokenize( model_name='HuggingFaceH4/zephyr-7b-beta', groundtruth_dataset={"type": "conversation", "instances": [CONVERSATION_MULTITURN]}, groundtruth_tokenized_dataset=make_gt_from_conversation_ids_batch([CONVERSATION_MULTITURN_ZEPHYR_IDS]), conversation_template='zephyr', ) def test_encode(self): model_name = 'gpt2' model_args = ModelArguments(model_name_or_path=model_name) model = HFDecoderModel(model_args) self.assertEqual(model.encode(test_encode_input), test_encode_output) batch_encode_input = [test_encode_input] * 2 batch_encode_output = [test_encode_output] * 2 self.assertEqual(model.encode(batch_encode_input)['input_ids'], batch_encode_output) def test_decode(self): model_name = 'gpt2' model_args = ModelArguments(model_name_or_path=model_name) model = HFDecoderModel(model_args) self.assertEqual(model.decode(test_decode_input), test_decode_output) batch_decode_input = [test_decode_input] * 2 batch_decode_output = [test_decode_output] * 2 self.assertEqual(model.decode(batch_decode_input), batch_decode_output) def test_inference(self): ds_config_path = "examples/ds_config.json" with open (ds_config_path, "r") as f: ds_config = json.load(f) model_name = 'gpt2' model_args = ModelArguments( model_name_or_path=model_name, use_ram_optimized_load=False ) model = HFDecoderModel(model_args, do_train=False, ds_config=ds_config) self.local_rank = int(os.getenv("LOCAL_RANK", "0")) self.world_size = int(os.getenv("WORLD_SIZE", "1")) torch.cuda.set_device(self.local_rank) inputs = model.encode(test_encode_input, return_tensors="pt").to(device=self.local_rank) outputs = model.inference(inputs,min_length=5, max_length=100,temperature=0.0, do_sample=False) text_out = model.decode(outputs[0], skip_special_tokens=True) prompt_length = len(model.decode(inputs[0], skip_special_tokens=True,)) text_out = text_out[prompt_length:].strip("\n") self.assertEqual(text_out, test_inference_output) if __name__ == "__main__": unittest.main() ================================================ FILE: tests/models/test_tool_inferencer.py ================================================ import unittest from lmflow.args import DatasetArguments, InferencerArguments, ModelArguments from lmflow.pipeline.inferencer import ToolInferencer CODE_1 = 'print("hello world")' RES_1 = "hello world\n" CODE_2 = "b=a+1\nprint(b)" RES_2 = """Traceback (most recent call last): File "", line 1, in NameError: name 'a' is not defined """ class ToolInferencerTest(unittest.TestCase): def set_up(self): model_args = ModelArguments(model_name_or_path="codellama/CodeLlama-7b-instruct-hf") inferencer_args = InferencerArguments() data_args = DatasetArguments() self.toolinf = ToolInferencer(model_args, data_args, inferencer_args) def test_code_exec_1(self, code=CODE_1, expected_output=RES_1): toolinf_res = self.toolinf.code_exec(code) self.assertEqual(toolinf_res, expected_output) def test_code_exec_2(self, code=CODE_2): toolinf_res = self.toolinf.code_exec(code) self.assertNotEqual(toolinf_res.returncode, 0) ================================================ FILE: tests/pipeline/test_auto_pipeline.py ================================================ import unittest from lmflow.args import DatasetArguments, EvaluatorArguments, FinetunerArguments, InferencerArguments, ModelArguments from lmflow.pipeline.auto_pipeline import AutoPipeline from lmflow.pipeline.evaluator import Evaluator from lmflow.pipeline.finetuner import Finetuner from lmflow.pipeline.inferencer import Inferencer MODEL_NAME = "gpt2" class AutoPipelineTest(unittest.TestCase): def test_get_evaluator_pipeline(self): model_args = ModelArguments(model_name_or_path=MODEL_NAME) dataset_args = DatasetArguments() evaluator_args = EvaluatorArguments() pipeline = AutoPipeline.get_pipeline("evaluator", model_args, dataset_args, evaluator_args) self.assertTrue(isinstance(pipeline, Evaluator)) def test_get_finetuner_pipeline(self): model_args = ModelArguments(model_name_or_path=MODEL_NAME) dataset_args = DatasetArguments() finetuner_args = FinetunerArguments(output_dir="~/tmp") pipeline = AutoPipeline.get_pipeline("finetuner", model_args, dataset_args, finetuner_args) self.assertTrue(isinstance(pipeline, Finetuner)) def test_get_inferencer_pipeline(self): model_args = ModelArguments(model_name_or_path=MODEL_NAME) dataset_args = DatasetArguments() inferencer_args = InferencerArguments() pipeline = AutoPipeline.get_pipeline("inferencer", model_args, dataset_args, inferencer_args) self.assertTrue(isinstance(pipeline, Inferencer)) def test_get_unsupported_pipeline(self): model_args = ModelArguments(model_name_or_path=MODEL_NAME) dataset_args = DatasetArguments() with self.assertRaisesRegex(NotImplementedError, 'Pipeline "unsupported" is not supported'): pipeline = AutoPipeline.get_pipeline("unsupported", model_args, dataset_args, None) ================================================ FILE: tests/pipeline/test_finetuner_distributed_loss.py ================================================ import json import os from datetime import datetime from enum import Enum from typing import Optional import pytest import torch from transformers.testing_utils import ( TestCasePlus, _RunOutput, execute_subprocess_async, get_torch_dist_unique_port, ) from lmflow.utils.versioning import get_lmflow_dir, is_deepspeed_available TEST_START_TIME = datetime.now().strftime("%Y%m%d_%H%M%S") KEEP_TEST_FILES = os.environ.get("LMFLOW_KEEP_TEST_FILES", "1") == "1" LOG_TEST_STD = os.environ.get("LMFLOW_LOG_TEST_STD", "1") == "1" TEST_MODEL_NAME_OR_PATH = os.getenv("LMFLOW_TEST_MODEL_NAME_OR_PATH", "Qwen/Qwen2.5-0.5B-Instruct") TEST_STEPS = int(os.getenv("LMFLOW_TEST_STEPS", 100)) # python subprocess takes list of strings as command, don't forget to split ACCELERATE_ARGS = f""" --machine_rank 0 --main_training_function main --num_machines 1 --num_processes {torch.cuda.device_count()} --rdzv_backend static --same_network --mixed_precision no --dynamo_backend no --main_process_port {get_torch_dist_unique_port()} """.split() ACCELERATE_DSZ3_ARGS = """ --use_deepspeed --deepspeed_multinode_launcher standard --offload_optimizer_device none --offload_param_device none --zero3_init_flag true --zero3_save_16bit_model true --zero_stage 3 """.split() ACCELERATE_FSDP_ARGS = """ --use_fsdp --fsdp_auto_wrap_policy TRANSFORMER_BASED_WRAP --fsdp_min_num_params 1000000 --fsdp_backward_prefetch BACKWARD_PRE --fsdp_forward_prefetch false --fsdp_cpu_ram_efficient_loading true --fsdp_offload_params false --fsdp_sharding_strategy FULL_SHARD --fsdp_state_dict_type FULL_STATE_DICT --fsdp_sync_module_states true --fsdp_use_orig_params true """.split() DEEPSPEED_BASE_ARGS = f""" --master_port {get_torch_dist_unique_port()} --num_gpus {torch.cuda.device_count()} """.split() DEEPSPEED_ZERO3_CONFIG_ARGS = """ --deepspeed configs/deepspeed/zero3.json """.split() LMFLOW_BASE_ARGS = f""" --model_name_or_path {TEST_MODEL_NAME_OR_PATH} --trust_remote_code 0 --dataset_path {get_lmflow_dir() / "data/alpaca/train_conversation"} --overwrite_output_dir --conversation_template qwen2 --disable_group_texts 1 --num_train_epochs 1 --per_device_train_batch_size 1 --gradient_accumulation_steps 1 --block_size 512 --learning_rate 2e-5 --lr_scheduler_type cosine --validation_split_percentage 0 --logging_steps 1 --max_steps {TEST_STEPS} --do_train --ddp_timeout 72000 --save_steps 5000 --use_flash_attention 0 --gradient_checkpointing 0 --dataloader_num_workers 8 --report_to wandb --seed 42 --save_strategy no """.split() LMFLOW_FP32_ARGS = """ --torch_dtype float32 """.split() LMFLOW_BF16_ARGS = """ --bf16 --torch_dtype bfloat16 """.split() LMFLOW_LORA_ARGS = """ --use_lora 1 --lora_r 8 --lora_alpha 32 --lora_dropout 0.1 """.split() LMFLOW_QLORA_ARGS = """ --use_qlora 1 --quant_bit 4 --lora_r 8 --lora_alpha 32 --lora_dropout 0.1 """.split() LMFLOW_LISA_ARGS = """ --lisa_activated_layers 1 --lisa_interval_steps 20 """.split() LMFLOW_CUSTOM_OPTIM_ARGS = """ --use_customized_optim 1 --customized_optim adabelief --optim_beta1 0.9 --optim_beta2 0.99 --optim_weight_decay 0 """.split() class AccelerateBackend(Enum): FSDP = "fsdp" DEEPSPEED_ZERO3 = "deepspeed_zero3" class DeepSpeedZeroStage(Enum): ZERO3 = "zero3" class PeftMethod(Enum): NO = "full" LORA = "lora" QLORA = "qlora" LISA = "lisa" class TestDtype(Enum): FP32 = "fp32" BF16 = "bf16" ACCELERATE_BACKEND_ARGS_MAPPING = { AccelerateBackend.FSDP: ACCELERATE_FSDP_ARGS, AccelerateBackend.DEEPSPEED_ZERO3: ACCELERATE_DSZ3_ARGS, } DEEPSPEED_ZERO_CONFIG_MAPPING = { DeepSpeedZeroStage.ZERO3: DEEPSPEED_ZERO3_CONFIG_ARGS, } LMFLOW_PEFT_ARGS_MAPPING = { PeftMethod.LORA: LMFLOW_LORA_ARGS, PeftMethod.QLORA: LMFLOW_QLORA_ARGS, PeftMethod.LISA: LMFLOW_LISA_ARGS, } class TestFinetunerBase(TestCasePlus): """Full finetune, and other base functionality tests""" def setUp(self): os.environ["WANDB_PROJECT"] = "lmflow-pytest" self.lmflow_dir = get_lmflow_dir() self.lmflow_examples_dir = self.lmflow_dir / "examples" return super().setUp() def _make_cmd(self, run_name: str, args: list[list[str]]) -> list[str]: cmd = [] for arg in args: assert isinstance(arg, list) cmd.extend(arg) self.output_dir = self.get_auto_remove_tmp_dir( tmp_dir=f"./tests_out/{run_name}", before=True, after=not KEEP_TEST_FILES, ) logging_args = f""" --run_name {TEST_START_TIME}_{run_name} --output_dir {self.output_dir} """.split() return cmd + logging_args def _log_std(self, res: _RunOutput): if LOG_TEST_STD: with open(f"{self.output_dir}/stdout.log", "w") as f: for line in res.stdout: f.write(line + "\n") with open(f"{self.output_dir}/stderr.log", "w") as f: for line in res.stderr: f.write(line + "\n") def _load_trainer_state(self, output_dir: str) -> dict: with open(f"{output_dir}/trainer_state.json") as f: trainer_state = json.load(f) return trainer_state def _run_with_accelerate( self, backend: AccelerateBackend, *, dtype: Optional[TestDtype] = TestDtype.FP32, extra_args: Optional[list[str]] = None, run_name_note: Optional[str] = None, ) -> dict: assert isinstance(backend, AccelerateBackend) run_name = f"test_finetuner_accelerate_{backend.value}" if run_name_note: run_name += f"_{str(run_name_note)}" all_args = [ ["accelerate", "launch"], ACCELERATE_ARGS, ACCELERATE_BACKEND_ARGS_MAPPING[backend], [f"{self.lmflow_examples_dir}/finetune.py"], LMFLOW_BASE_ARGS, ] if dtype == TestDtype.FP32: all_args.append(LMFLOW_FP32_ARGS) elif dtype == TestDtype.BF16: all_args.append(LMFLOW_BF16_ARGS) else: raise ValueError(f"Unsupported dtype: {dtype}") if extra_args and len(extra_args) > 0: all_args.append(extra_args) cmd = self._make_cmd(run_name, all_args) res = execute_subprocess_async(cmd) self._log_std(res) return self._load_trainer_state(self.output_dir) def _run_with_deepspeed( self, zero_stage: DeepSpeedZeroStage, *, dtype: Optional[TestDtype] = TestDtype.FP32, extra_args: Optional[list[str]] = None, run_name_note: Optional[str] = None, ) -> dict: assert isinstance(zero_stage, DeepSpeedZeroStage) run_name = f"test_finetuner_deepspeed_{zero_stage.value}" if run_name_note: run_name += f"_{str(run_name_note)}" all_args = [ ["deepspeed"], DEEPSPEED_BASE_ARGS, [f"{self.lmflow_examples_dir}/finetune.py"], DEEPSPEED_ZERO_CONFIG_MAPPING[zero_stage], LMFLOW_BASE_ARGS, ] if dtype == TestDtype.FP32: all_args.append(LMFLOW_FP32_ARGS) elif dtype == TestDtype.BF16: all_args.append(LMFLOW_BF16_ARGS) else: raise ValueError(f"Unsupported dtype: {dtype}") if extra_args and len(extra_args) > 0: all_args.append(extra_args) cmd = self._make_cmd(run_name, all_args) res = execute_subprocess_async(cmd) self._log_std(res) return self._load_trainer_state(self.output_dir) def _compare_loss(self, trainer_state1: dict, trainer_state2: dict): loss1 = [] loss2 = [] for step_idx in range(TEST_STEPS): assert trainer_state1["log_history"][step_idx]["step"] == trainer_state2["log_history"][step_idx]["step"], ( "log_history step mismatch, check traner_state.json" ) loss1.append(trainer_state1["log_history"][step_idx]["loss"]) loss2.append(trainer_state2["log_history"][step_idx]["loss"]) self.assertTrue(torch.allclose(torch.tensor(loss1), torch.tensor(loss2), rtol=1e-2, atol=0)) @pytest.mark.lmflow_core @pytest.mark.gpu @pytest.mark.slow @pytest.mark.skipif(not is_deepspeed_available(), reason="Deepspeed is not available") def test_loss_accelerate_dsz3_vs_fsdp(self): dsz3_trainer_state = self._run_with_accelerate( backend=AccelerateBackend.DEEPSPEED_ZERO3, run_name_note=PeftMethod.NO.value ) fsdp_trainer_state = self._run_with_accelerate( backend=AccelerateBackend.FSDP, run_name_note=PeftMethod.NO.value ) self._compare_loss(dsz3_trainer_state, fsdp_trainer_state) @pytest.mark.lmflow_core @pytest.mark.gpu @pytest.mark.slow @pytest.mark.skipif(not is_deepspeed_available(), reason="Deepspeed is not available") def test_loss_deepspeed_z3_vs_accelerate_dsz3(self): deepspeed_z3_trainer_state = self._run_with_deepspeed( zero_stage=DeepSpeedZeroStage.ZERO3, run_name_note=PeftMethod.NO.value ) accelerate_dsz3_train_state = self._run_with_accelerate( backend=AccelerateBackend.DEEPSPEED_ZERO3, run_name_note=PeftMethod.NO.value ) self._compare_loss(deepspeed_z3_trainer_state, accelerate_dsz3_train_state) class TestFinetunerLora(TestFinetunerBase): @pytest.mark.lmflow_core @pytest.mark.gpu @pytest.mark.slow @pytest.mark.skipif(not is_deepspeed_available(), reason="Deepspeed is not available") def test_loss_accelerate_dsz3_vs_fsdp(self): dsz3_trainer_state = self._run_with_accelerate( backend=AccelerateBackend.DEEPSPEED_ZERO3, extra_args=LMFLOW_PEFT_ARGS_MAPPING[PeftMethod.LORA], run_name_note=PeftMethod.LORA.value, ) fsdp_trainer_state = self._run_with_accelerate( backend=AccelerateBackend.FSDP, extra_args=LMFLOW_PEFT_ARGS_MAPPING[PeftMethod.LORA], run_name_note=PeftMethod.LORA.value, ) self._compare_loss(dsz3_trainer_state, fsdp_trainer_state) @pytest.mark.lmflow_core @pytest.mark.gpu @pytest.mark.slow @pytest.mark.skipif(not is_deepspeed_available(), reason="Deepspeed is not available") def test_loss_deepspeed_z3_vs_accelerate_dsz3(self): deepspeed_z3_trainer_state = self._run_with_deepspeed( zero_stage=DeepSpeedZeroStage.ZERO3, extra_args=LMFLOW_PEFT_ARGS_MAPPING[PeftMethod.LORA], run_name_note=PeftMethod.LORA.value, ) accelerate_dsz3_train_state = self._run_with_accelerate( backend=AccelerateBackend.DEEPSPEED_ZERO3, extra_args=LMFLOW_PEFT_ARGS_MAPPING[PeftMethod.LORA], run_name_note=PeftMethod.LORA.value, ) self._compare_loss(deepspeed_z3_trainer_state, accelerate_dsz3_train_state) class TestFinetunerQlora(TestFinetunerBase): """Currently only supports in bf16""" @pytest.mark.lmflow_core @pytest.mark.gpu @pytest.mark.slow @pytest.mark.skipif(not is_deepspeed_available(), reason="Deepspeed is not available") def test_loss_accelerate_dsz3_vs_fsdp(self): dsz3_trainer_state = self._run_with_accelerate( backend=AccelerateBackend.DEEPSPEED_ZERO3, dtype=TestDtype.BF16, extra_args=LMFLOW_PEFT_ARGS_MAPPING[PeftMethod.QLORA], run_name_note=PeftMethod.QLORA.value, ) fsdp_trainer_state = self._run_with_accelerate( backend=AccelerateBackend.FSDP, dtype=TestDtype.BF16, extra_args=LMFLOW_PEFT_ARGS_MAPPING[PeftMethod.QLORA], run_name_note=PeftMethod.QLORA.value, ) self._compare_loss(dsz3_trainer_state, fsdp_trainer_state) @pytest.mark.lmflow_core @pytest.mark.gpu @pytest.mark.slow @pytest.mark.skipif(not is_deepspeed_available(), reason="Deepspeed is not available") def test_loss_deepspeed_z3_vs_accelerate_dsz3(self): deepspeed_z3_trainer_state = self._run_with_deepspeed( zero_stage=DeepSpeedZeroStage.ZERO3, dtype=TestDtype.BF16, extra_args=LMFLOW_PEFT_ARGS_MAPPING[PeftMethod.QLORA], run_name_note=PeftMethod.QLORA.value, ) accelerate_dsz3_train_state = self._run_with_accelerate( backend=AccelerateBackend.DEEPSPEED_ZERO3, dtype=TestDtype.BF16, extra_args=LMFLOW_PEFT_ARGS_MAPPING[PeftMethod.QLORA], run_name_note=PeftMethod.QLORA.value, ) self._compare_loss(deepspeed_z3_trainer_state, accelerate_dsz3_train_state) class TestFinetunerCustomOptim(TestFinetunerBase): @pytest.mark.lmflow_core @pytest.mark.gpu @pytest.mark.slow @pytest.mark.skipif(not is_deepspeed_available(), reason="Deepspeed is not available") def test_loss_accelerate_dsz3_vs_fsdp(self): dsz3_trainer_state = self._run_with_accelerate( backend=AccelerateBackend.DEEPSPEED_ZERO3, extra_args=LMFLOW_CUSTOM_OPTIM_ARGS, run_name_note="custom_optim" ) fsdp_trainer_state = self._run_with_accelerate( backend=AccelerateBackend.FSDP, extra_args=LMFLOW_CUSTOM_OPTIM_ARGS, run_name_note="custom_optim" ) self._compare_loss(dsz3_trainer_state, fsdp_trainer_state) @pytest.mark.lmflow_core @pytest.mark.gpu @pytest.mark.slow @pytest.mark.skipif(not is_deepspeed_available(), reason="Deepspeed is not available") def test_loss_deepspeed_z3_vs_accelerate_dsz3(self): deepspeed_z3_trainer_state = self._run_with_deepspeed( zero_stage=DeepSpeedZeroStage.ZERO3, extra_args=LMFLOW_CUSTOM_OPTIM_ARGS, run_name_note="custom_optim" ) accelerate_dsz3_train_state = self._run_with_accelerate( backend=AccelerateBackend.DEEPSPEED_ZERO3, extra_args=LMFLOW_CUSTOM_OPTIM_ARGS, run_name_note="custom_optim" ) self._compare_loss(deepspeed_z3_trainer_state, accelerate_dsz3_train_state) ================================================ FILE: tests/pipeline/test_memory_safe_vllm_inferencer.py ================================================ # cannot use unittest, since memory safe vllm inference uses stdout, # which has conflicts with unittest stdout. import logging import pytest vllm = pytest.importorskip("vllm") from lmflow.args import DatasetArguments, InferencerArguments, ModelArguments from lmflow.datasets import Dataset from lmflow.models.hf_decoder_model import HFDecoderModel from lmflow.pipeline.vllm_inferencer import MemorySafeVLLMInferencer logger = logging.getLogger(__name__) model_args = ModelArguments( "Qwen/Qwen2-0.5B", torch_dtype="auto", ) data_args = DatasetArguments( "./data/alpaca/test_conversation", preprocessing_num_workers=4, ) inferencer_args = InferencerArguments( random_seed=42, apply_chat_template=True, num_output_sequences=2, temperature=1.0, max_new_tokens=1024, save_results=True, results_path="./data/mem_safe_vllm_res.json", use_vllm=True, enable_decode_inference_result=False, inference_gpu_memory_utilization=0.95, inference_tensor_parallel_size=2, ) class MemorySafeVLLMInferencerTest: def test_init(self): self.dataset = Dataset(data_args) self.model = HFDecoderModel(model_args) self.inferencer = MemorySafeVLLMInferencer( model_args=model_args, data_args=data_args, inferencer_args=inferencer_args, ) self.status = [] def test_inference(self): res = self.inferencer.inference() test_res = all( [ isinstance(res, list), isinstance(res[0], list), isinstance(res[0][0], list), isinstance(res[0][0][0], int), ] ) self.status.append(test_res) logger.warning(f"test_inference: {test_res}") def test_inference_detokenize(self): inferencer_args.enable_decode_inference_result = True self.inferencer = MemorySafeVLLMInferencer( model_args=model_args, data_args=data_args, inferencer_args=inferencer_args, ) res = self.inferencer.inference() test_res = all( [ isinstance(res, list), isinstance(res[0], list), isinstance(res[0][0], str), ] ) self.status.append(test_res) logger.warning(f"test_inference_detokenize: {test_res}") def summary(self): logger.warning(f"MemorySafeVLLMInferencerTest: {all(self.status)}") if __name__ == "__main__": test = MemorySafeVLLMInferencerTest() test.test_init() test.test_inference() test.test_inference_detokenize() test.summary() ================================================ FILE: tests/pipeline/test_sglang_infernecer.py ================================================ import numpy as np import pytest from sglang.srt.entrypoints.engine import Engine from sglang.srt.server_args import ServerArgs from lmflow.args import InferencerArguments, ModelArguments from lmflow.datasets.dataset import Dataset from lmflow.models.hf_decoder_model import HFDecoderModel from lmflow.pipeline.sglang_inferencer import SGLangInferencer from tests.datasets.conftest import dataset_inference_conversation_batch # noqa: F401 @pytest.fixture def sglang_test_model_args() -> ModelArguments: return ModelArguments(model_name_or_path="Qwen/Qwen3-4B-Instruct-2507") @pytest.fixture def sglang_test_inferencer_args() -> InferencerArguments: return InferencerArguments( inference_engine="sglang", inference_gpu_memory_utilization=0.8, num_output_sequences=2, enable_deterministic_inference=True, attention_backend="fa3", return_logprob=True, ) def test_sglang_inferencer( dataset_inference_conversation_batch: Dataset, # noqa: F811 sglang_test_model_args: ModelArguments, sglang_test_inferencer_args: InferencerArguments, ): def parse_logprob(logprob_list: list[tuple[float, int, None]]) -> list[float]: return np.array([logprob for logprob, _, _ in logprob_list]) model = HFDecoderModel(model_args=sglang_test_model_args) sglang_inferencer = SGLangInferencer( data_args=dataset_inference_conversation_batch.data_args, model_args=sglang_test_model_args, inferencer_args=sglang_test_inferencer_args, ) res = sglang_inferencer.inference( model=model, dataset=dataset_inference_conversation_batch, release_gpu=True, ) assert len(res) == 4 assert res[0]["input"] == dataset_inference_conversation_batch.backend_dataset[0]["templated"] assert res[1]["input"] == dataset_inference_conversation_batch.backend_dataset[0]["templated"] assert res[2]["input"] == dataset_inference_conversation_batch.backend_dataset[1]["templated"] assert res[3]["input"] == dataset_inference_conversation_batch.backend_dataset[1]["templated"] # test consistency sgl_server_args = ServerArgs( model_path=sglang_test_model_args.model_name_or_path, mem_fraction_static=sglang_test_inferencer_args.inference_gpu_memory_utilization, tp_size=sglang_test_inferencer_args.inference_tensor_parallel_size, enable_deterministic_inference=sglang_test_inferencer_args.enable_deterministic_inference, attention_backend=sglang_test_inferencer_args.attention_backend, ) llm = Engine(server_args=sgl_server_args) model_input = [ sample for sample in dataset_inference_conversation_batch.backend_dataset["templated"] for _ in range(sglang_test_inferencer_args.num_output_sequences) ] sglang_outputs = llm.generate( prompt=model_input, sampling_params=sglang_inferencer.sampling_params.copy().update({"n": 1}), return_logprob=sglang_test_inferencer_args.return_logprob, ) logprobs_lmflow = [parse_logprob(x["meta_info"]["output_token_logprobs"]) for x in res] logprobs_sglang = [parse_logprob(x["meta_info"]["output_token_logprobs"]) for x in sglang_outputs] assert all( np.allclose(logprobs_lmflow, logprobs_sglang, atol=1e-10) for logprobs_lmflow, logprobs_sglang in zip(logprobs_lmflow, logprobs_sglang) ) ================================================ FILE: tests/utils/__init__.py ================================================ ================================================ FILE: tests/utils/test_conversation_formatter.py ================================================ import unittest from lmflow.utils.conversation_template.base import StringFormatter, TemplateComponent class StringFormatterTest(unittest.TestCase): def test_format_string_component(self): formatter = StringFormatter( template=[ TemplateComponent(type="token", content="bos_token"), TemplateComponent(type="string", content="[INST] {{content}} [/INST]"), TemplateComponent(type="token", content="eos_token"), ] ) formatted_components = formatter.format(content="Who are you?") expected_components = [ TemplateComponent(type="token", content="bos_token"), TemplateComponent(type="string", content="[INST] Who are you? [/INST]"), TemplateComponent(type="token", content="eos_token"), ] self.assertEqual(formatted_components, expected_components) if __name__ == "__main__": unittest.main() ================================================ FILE: tests/utils/test_conversation_template.py ================================================ import unittest from transformers import AutoTokenizer from lmflow.utils.conversation_template import PRESET_TEMPLATES CONVERSATION_SINGLETURN = { "system": "sysinfo", "messages": [{"role": "user", "content": "Hello"}, {"role": "assistant", "content": "Hi!"}], } CONVERSATION_SINGLETURN_LLAMA2 = [ {"role": "user", "content": "[INST] <>\nsysinfo\n<>\n\nHello [/INST]"}, {"role": "assistant", "content": "Hi!"}, ] CONVERSATION_SINGLETURN_LLAMA2_IDS = [ ( [ 1, 518, 25580, 29962, 3532, 14816, 29903, 6778, 13, 9675, 3888, 13, 29966, 829, 14816, 29903, 6778, 13, 13, 10994, 518, 29914, 25580, 29962, ], [6324, 29991, 2], ) ] CONVERSATION_MULTITURN = { "system": "sysinfo", "messages": [ {"role": "user", "content": "Hello"}, {"role": "assistant", "content": "Hi!"}, {"role": "user", "content": "How are you?"}, {"role": "assistant", "content": "I'm good, thanks!"}, ], } CONVERSATION_MULTITURN_LLAMA2 = [ {"role": "user", "content": "[INST] <>\nsysinfo\n<>\n\nHello [/INST]"}, {"role": "assistant", "content": "Hi!"}, {"role": "user", "content": "[INST] How are you? [/INST]"}, {"role": "assistant", "content": "I'm good, thanks!"}, ] CONVERSATION_MULTITURN_LLAMA2_IDS = [ ( [ 1, 518, 25580, 29962, 3532, 14816, 29903, 6778, 13, 9675, 3888, 13, 29966, 829, 14816, 29903, 6778, 13, 13, 10994, 518, 29914, 25580, 29962, ], [6324, 29991, 2], ), ( [1, 518, 25580, 29962, 1128, 526, 366, 29973, 518, 29914, 25580, 29962], [306, 29915, 29885, 1781, 29892, 3969, 29991, 2], ), ] class EmptyConversationTemplateTest(unittest.TestCase): def setUp(self): MODEL_PATH = "meta-llama/Llama-2-7b-hf" self.tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, use_fast=False) self.conversation_template = PRESET_TEMPLATES["empty"] def test_encode_conversation_singleturn_llama2(self): res = self.conversation_template.encode_conversation( tokenizer=self.tokenizer, messages=CONVERSATION_SINGLETURN_LLAMA2, system=None, tools=None ) self.assertEqual(res, CONVERSATION_SINGLETURN_LLAMA2_IDS) def test_encode_conversation_multiturn_llama2(self): res = self.conversation_template.encode_conversation( tokenizer=self.tokenizer, messages=CONVERSATION_MULTITURN_LLAMA2, system=None, tools=None ) self.assertEqual(res, CONVERSATION_MULTITURN_LLAMA2_IDS) class Llama2ConversationTemplateTest(unittest.TestCase): def setUp(self): MODEL_PATH = "meta-llama/Llama-2-7b-hf" self.tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, use_fast=False) self.conversation_template = PRESET_TEMPLATES["llama2"] def test_encode_conversation_singleturn(self): res = self.conversation_template.encode_conversation( tokenizer=self.tokenizer, messages=CONVERSATION_SINGLETURN["messages"], system=CONVERSATION_SINGLETURN["system"], tools=None, ) self.assertEqual(res, CONVERSATION_SINGLETURN_LLAMA2_IDS) def test_encode_conversation_multiturn(self): res = self.conversation_template.encode_conversation( tokenizer=self.tokenizer, messages=CONVERSATION_MULTITURN["messages"], system=CONVERSATION_MULTITURN["system"], tools=None, ) self.assertEqual(res, CONVERSATION_MULTITURN_LLAMA2_IDS) class Qwen2ConversationTemplateTest(unittest.TestCase): def setUp(self): MODEL_PATH = "Qwen/Qwen1.5-0.5B-Chat" self.tokenizer = AutoTokenizer.from_pretrained(MODEL_PATH, use_fast=False) self.conversation_template = PRESET_TEMPLATES["qwen2"] def test_encode_conversation_singleturn(self): res = self.conversation_template.encode_conversation( tokenizer=self.tokenizer, messages=CONVERSATION_SINGLETURN["messages"], system=CONVERSATION_SINGLETURN["system"], tools=None, ) print(res) def test_encode_conversation_multiturn(self): res = self.conversation_template.encode_conversation( tokenizer=self.tokenizer, messages=CONVERSATION_MULTITURN["messages"], system=CONVERSATION_MULTITURN["system"], tools=None, ) print(res) print("===") print( self.tokenizer.apply_chat_template( CONVERSATION_MULTITURN["messages"], tokenize=True, add_generation_prompt=False ) ) print("===") print( self.tokenizer.apply_chat_template( CONVERSATION_MULTITURN["messages"], tokenize=False, add_generation_prompt=False ) ) print("===") if __name__ == "__main__": unittest.main() ================================================ FILE: tests/utils/test_data_utils.py ================================================ #!/bin/env/python3 import unittest from lmflow.utils.data_utils import answer_extraction, batchlize, load_data groundtruth_inputs = [ "The Transformer architecture [START_REF]", "The Schwarzschild radius is defined as: \\[", "A force of 0.6N is applied to an object, which accelerates at 3m/s. What is its mass? ", "[START_I_SMILES]", "[START_AMINO]GHMQSITAGQKVISKHKNGRFYQCEVVRLTTETFYEVNFDDGSFSDNLYPEDIVSQDCLQFGPPAEGEVVQVRWTDGQVYGAKFVASHPIQMYQVEFEDGSQLVVKRDDVYTLDEELP[END_AMINO] ## Keywords", "The reason why Transformers replaced RNNs was because", "Question: What is the notch signaling pathway?\n\nAnswer:", "# Multi-Head Attention\n\n", "Title: Self-Supervised Learning, A Survey\n\nAuthors: John Smith\n\n", "Lecture 1: The Ising Model\n\n", "Information overload is a major obstacle to scientific progress. The explosive growth in scientific literature and data has made it ever harder to discover useful insights in a large mass of information. Today scientific knowledge is accessed through search engines, but they are unable to organize scientific knowledge alone. In this paper we introduce Galactica: a large language model that can store, combine and reason about scientific knowledge. We train on a large scientific corpus of papers, reference material, knowledge bases and many other sources. We outperform existing models on a range of scientific tasks. On technical knowledge probes such as LaTeX equations, Galactica outperforms the latest GPT-3 by 68.2% versus 49.0%. Galactica also performs well on reasoning, outperforming Chinchilla on mathematical MMLU by 41.3% to 35.7%, and PaLM 540B on MATH with a score of 20.4% versus 8.8%. It also sets a new state-of-the-art on downstream tasks such as PubMedQA and MedMCQA dev of 77.6% and 52.9%. And despite not being trained on a general corpus, Galactica outperforms BLOOM and OPT-175B on BIG-bench. We believe these results demonstrate the potential for language models as a new interface for science. We open source the model for the benefit of the scientific community.\n\nTLDR:", "[START_I_SMILES]C(C(=O)O)N[END_I_SMILES]\n\n## Chemical and Physical Properties\n\nThe following are chemical properties for", "what is the capital of US?", ] groundtruth_outputs = ["NA"] * 13 mc_output = [ "Answer: (C) Generation of free radicals", "Answer: C Generation of free radicals", "Answer: C", "Answer: (C)", "A: C", "A: (C)", "Output: (C) Generation of free radicals", "Output: C Generation of free radicals", "Output: C", "Output: (C)", ] mc_answer = ["c"] * 10 qa_output = [ "Yes.", "Answer: Yes", "Answer: Yes.", "Yes ", "No.", "Answer: No", "Answer: No.", "No ", "Maybe.", "Answer: Maybe", "Answer: Maybe.", "Maybe ", ] qa_answer = ["yes"] * 4 + ["no"] * 4 + ["maybe"] * 4 class DataUtilsTest(unittest.TestCase): def test_load_data(self): file_name = "data/example_dataset/test/test_13.json" inputs, outputs, datasize = load_data(file_name=file_name) # Test for inputs for i in range(0, len(inputs)): self.assertEqual(inputs[i], groundtruth_inputs[i]) # Test for outputs for i in range(0, len(outputs)): self.assertEqual(outputs[i], groundtruth_outputs[i]) # Test for datasize self.assertEqual(datasize, 13) def test_batchlize(self): file_name = "data/example_dataset/test/test_13.json" inputs, outputs, datasize = load_data(file_name=file_name) dataset = [] for idx in range(len(outputs)): dataset.append({"input": inputs[idx], "output": outputs[idx], "input_idx": idx}) # TODO: add test for random shuffle case dataloader = batchlize(dataset, 4, random_shuffle=False) self.assertEqual(len(dataloader), 13 // 4 + 1) def test_answer_extraction(self): # Test for medmcqa dataset for i in range(0, len(mc_output)): self.assertEqual(answer_extraction(mc_output[i], answer_type="medmcqa"), mc_answer[i]) # Test for usmle dataset for i in range(0, len(mc_output)): self.assertEqual(answer_extraction(mc_output[i], answer_type="usmle"), mc_answer[i]) # Test for pubmedqa dataset for i in range(0, len(qa_output)): self.assertEqual(answer_extraction(qa_output[i], answer_type="pubmedqa"), qa_answer[i])