### Install Transformers Library Source: https://github.com/keyhsw/chemllm/blob/main/README.md Install the necessary transformers library to use the ChemLLM model. This is a prerequisite for loading and running the model. ```bash pip install transformers ``` -------------------------------- ### Load and Run ChemLLM-7B-Chat Model Source: https://github.com/keyhsw/chemllm/blob/main/README.md Load the ChemLLM-7B-Chat model and tokenizer using the transformers library. This snippet demonstrates how to set up the model for inference and generate text based on a prompt. ```python from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig import torch model_name_or_id = "AI4Chem/ChemLLM-7B-Chat" model = AutoModelForCausalLM.from_pretrained(model_name_or_id, torch_dtype=torch.float16, device_map="auto",trust_remote_code=True) tokenizer = AutoTokenizer.from_pretrained(model_name_or_id,trust_remote_code=True) prompt = "What is Molecule of Ibuprofen?" inputs = tokenizer(prompt, return_tensors="pt").to("cuda") generation_config = GenerationConfig( do_sample=True, top_k=1, temperature=0.9, max_new_tokens=500, repetition_penalty=1.5, pad_token_id=tokenizer.eos_token_id ) outputs = model.generate(**inputs, generation_config=generation_config) print(tokenizer.decode(outputs[0], skip_special_tokens=True)) ``` -------------------------------- ### Format Prompt for InternLM2 Dialogue Source: https://github.com/keyhsw/chemllm/blob/main/README.md A Python function to format user inputs into the InternLM2 dialogue format. This is useful for structuring conversations with the model, especially when using history. ```python def InternLM2_format(instruction,prompt,answer,history): prefix_template=[ "<|system|>:", "{}" ] prompt_template=[ "<|user|>:", "{} ", "<|Bot|>:\n" ] system = f'{prefix_template[0]}\n{prefix_template[-1].format(instruction)}\n' history = "\n".join([f'{prompt_template[0]}\n{prompt_template[1].format(qa[0])}{prompt_template[-1]}{qa[1]}' for qa in history]) prompt = f'\n{prompt_template[0]}\n{prompt_template[1].format(prompt)}{prompt_template[-1]}' return f"{system}{history}{prompt}" ``` -------------------------------- ### Iframe Styling within Space Source: https://github.com/keyhsw/chemllm/blob/main/index.html Ensures the iframe has minimum width and height of 100% and sets its background to white. ```css .iframe { min-width: 100%; min-height: 100%; background: white; } ``` -------------------------------- ### ChemLLM Citation Source: https://github.com/keyhsw/chemllm/blob/main/README.md This is the BibTeX entry for citing the ChemLLM work. Use this in your academic papers to reference the model. ```bibtex @misc{zhang2024chemllm, title={ChemLLM: A Chemical Large Language Model}, author={Di Zhang and Wei Liu and Qian Tan and Jingdan Chen and Hang Yan and Yuliang Yan and Jiatong Li and Weiran Huang and Xiangyu Yue and Dongzhan Zhou and Shufei Zhang and Mao Su and Hansen Zhong and Yuqiang Li and Wanli Ouyang}, year={2024}, eprint={2402.06852}, archivePrefix={arXiv}, primaryClass={cs.AI} } ``` -------------------------------- ### Space Component Styling Source: https://github.com/keyhsw/chemllm/blob/main/index.html Defines the maximum width and height, sets the width and height to viewport units, and enables hidden overflow for the space element. ```css .space { max-width: 100%; max-height: 100%; width: 100vw; height: 100vh; overflow: hidden; } ``` -------------------------------- ### Static Space Body Styling Source: https://github.com/keyhsw/chemllm/blob/main/index.html Sets the margin for the static Space body to 0. ```css body { margin: 0; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.