# access docstore and docstore id for 100 random chunks vs = db.__dict__.get("docstore") docstore_id_list = list(db.__dict__.get("index_to_docstore_id").values()) rand_doc_id_list = random.choices(docstore_id_list, k=200)
query = ''' Please generate two questions about SteelHead based on the provided context. The question should be around SteelHead WAN acceleration and its related concepts only. The questions should start with any of the following: "What", "How', "Is there a", "What are the", "How do I", "When is it", "Does SteelHead have", "How to", "What is the difference", "Which", "List". You do not need to provide an answer or category to each question. ''' qfile = open("instructions.txt", "w") start_gen = timeit.default_timer() for i,doc_id in enumerate(rand_doc_id_list): start = timeit.default_timer() a_doc = vs.search(doc_id) result = chain.invoke({"question": query, "context": a_doc.page_content}) resp_time = timeit.default_timer() - start # seconds print(f'{"-"*50}\nQ #{i}: {result}\nTime: {resp_time}\n{"-"*50}\n') qfile.write(result) qfile.close() # total time for generation gen_time = timeit.default_timer() - start_gen # seconds print(f'Total generation time => {timedelta(seconds=gen_time)}')
为了允许轻松调用任一生成函数,让我们使用命令行选项。函数最多接受两个布尔参数,这些参数将由提供的命令行选项控制。要决定要启动的指令或训练数据集生成任务,命令行选项 or 将分别与库一起使用。main-i-targparse
以下列表捕获了这些命令行选项处理以及函数。main
def main(is_gen_instruct=False,is_gen_training=False): # Prompt template qa_template = """<s>[INST] You are a helpful assistant. Use the following context to answer the question below accurately and concisely: {context} [/INST] </s>{question} """
# Create a prompt instance QA_PROMPT = PromptTemplate.from_template(qa_template)
if __name__ == "__main__": # Initialize parser parser = argparse.ArgumentParser("Script to generate instruction or training data for LLM fine-tuning") group = parser.add_mutually_exclusive_group()
# Adding optional mutually-exclusive arguments group.add_argument("-i", "--instructions", action='store_true', help = "Generate Instructions") group.add_argument("-t", "--training", action='store_true', help = "Generate Training and Validation Data")
# Read arguments from command line args = parser.parse_args() if args.instructions: main(is_gen_instruct=args.instructions) elif args.training: main(is_gen_training=args.training)
这样就完成了数据生成系统的实现。此系统的完整代码可在以下 GitHub 存储库中找到:
https://github.com/drskennedy/instruction_gen
现在就让我们去兜风吧!
3.0 指令生成运行
在本练习中,将使用命令行选项启动代码以启动指令生成过程。以下控制台输出数据提取表示生成 200 个问题的运行。整个过程在我的 Mac 上只花了 2 个多小时。-i
$ python main.py -i
-------------------------------------------------- Q #0: 1. Where do I find the QoS settings in SteelHead? 2. Is there a difference between MX-TCP and TCP in terms of handling packet loss? Time: 57.88847145799991 --------------------------------------------------
-------------------------------------------------- Q #1: 1. Where do I find information about configuring SSL on SteelHead? 2. Is there a requirement for a trust relationship between Client Accelerators for SSL configuration on SteelHead? Time: 47.30005858300001 --------------------------------------------------
-------------------------------------------------- Q #2: 1. Where is the configuration for enabling Connection Forwarding between SteelHeads in a cluster? 2. Is there a difference between using multiple interfaces on the same SteelHead versus using multiple SteelHeads for ITD high availability deployment? Time: 70.70811329100025 --------------------------------------------------
-------------------------------------------------- Q #3: 1. Where do I enable CDP on the SteelHead that is used in the PBR deployment? 2. Is there a specific command that I need to use to enable CDP on the SteelHead? Time: 68.81058954199989 -------------------------------------------------- ...
Q #99: 1. What is correct addressing in the context of SteelHead WAN acceleration? 2. How does correct addressing enable connection pooling acceleration in SteelHead? Time: 63.51242004099913 --------------------------------------------------
现在,使用命令行选项启动相同的脚本,以启动训练和验证数据集生成。在我资源有限的机器上,这需要很长时间。幸运的是,控制台输出很好地了解了其通过指令列表的进度。由于在运行过程中会产生大量热量,我不得不将 Mac 部分悬浮在空气中以改善其冷却效果。以下是此运行的控制台输出提取:-t
$ python main.py -t
Handling (1/150): -------------------------------------------------- Q #1: Is there a difference between MX-TCP and TCP in terms of handling packet loss? A: Yes, there is a difference between MX-TCP and TCP in terms of handling packet loss. MX-TCP is designed to handle packet loss without a decrease in throughput, while TCP typically experiences a decrease in throughput when there is packet loss. MX-TCP effectively handles packet loss without error correction packets over the WAN through forward error correction (FEC). Time: 152.08327770899996
Handling (2/150): -------------------------------------------------- Q #2: Where is the configuration for enabling Connection Forwarding between SteelHeads in a cluster? A: To enable Connection Forwarding between SteelHeads in a cluster, you need to configure the in-path0_0 IP address of the two SteelHeads as neighbors in the CLI of each SteelHead. Then, you can enter the following commands in each SteelHead's CLI:
enable configure terminal SteelHead communication enable SteelHead communication multi-interface enable SteelHead name <SteelHead name> main-ip <SteelHead IP address>
Once you have enabled Connection Forwarding, you can configure fail-to-block and allow-failure commands to provide greater resiliency and redundancy in your ITD deployment. Time: 215.70585895799923
Handling (3/150): -------------------------------------------------- Q #3: Is there a difference between using multiple interfaces on the same SteelHead versus using multiple SteelHeads for ITD high availability deployment? A: Yes, there is a difference between using multiple interfaces on the same SteelHead versus using multiple SteelHeads for ITD high availability deployment. Using multiple interfaces on the same SteelHead can provide greater acceleration throughput capacity beyond a single SteelHead, but it may not provide the same level of redundancy or resiliency as using multiple SteelHeads. On the other hand, using multiple SteelHeads can provide greater redundancy and resiliency, but it may not provide the same level of acceleration throughput capacity as using multiple interfaces on the same SteelHead. Time: 179.73986179200074
...
Handling (150/150): -------------------------------------------------- Q #150: How does correct addressing enable connection pooling acceleration in SteelHead?
A:
Correct addressing enables connection pooling acceleration in SteelHead by allowing it to create several TCP connections between each other before they are needed. This is because correct addressing uses specific values in the TCP/IP packet headers, which allows SteelHeads to detect what types of client and server IP addresses and ports are needed. When transparent addressing is enabled, SteelHeads cannot create the TCP connections in advance because they cannot detect what types of client and server IP addresses and ports are needed. If the number of connections that you want to accelerate exceeds the limit of the SteelHead model, the excess connections are passed through unaccelerated by the SteelHead. Time: 159.28865737500018 --------------------------------------------------
Total training generation time => 9:20:06.321521
这个训练数据集的生成花了 9 个多小时!对于其中一些指令,语言模型无法生成任何答案。为了便于全面覆盖包含 1,200 多个块的所选文档,它可能需要 2,000 多条指令,这显然需要很多天才能完成运行。话虽如此,只有我的 Mac 在训练生成期间持续高温下幸存下来,才有可能!为了演示整个端到端过程,接下来我们将对有限的训练数据集进行微调。
$ python mlx-examples/lora/lora.py \ --train \ --model ./mlx_model \ --data ./ \ --batch-size 1 \ --lora-layers 2 \ --iters 1000 Loading pretrained model Total parameters 1242.550M Trainable parameters 0.213M Loading datasets Training Iter 1: Val loss 3.565, Val took 32.649s Iter 10: Train loss 3.008, It/sec 0.401, Tokens/sec 80.419 Iter 20: Train loss 3.195, It/sec 0.358, Tokens/sec 75.043 Iter 30: Train loss 2.830, It/sec 0.425, Tokens/sec 72.879 Iter 40: Train loss 2.817, It/sec 0.456, Tokens/sec 71.241 Iter 50: Train loss 2.235, It/sec 0.328, Tokens/sec 73.343 Iter 60: Train loss 2.383, It/sec 0.337, Tokens/sec 74.361 Iter 70: Train loss 2.249, It/sec 0.371, Tokens/sec 74.073 Iter 80: Train loss 2.353, It/sec 0.342, Tokens/sec 72.922 Iter 90: Train loss 2.027, It/sec 0.413, Tokens/sec 74.373 Iter 100: Train loss 2.091, It/sec 0.362, Tokens/sec 74.554 Iter 100: Saved adapter weights to adapters.npz. ... Iter 200: Train loss 1.955, It/sec 0.395, Tokens/sec 74.250 Iter 200: Val loss 1.893, Val took 31.658s Iter 200: Saved adapter weights to adapters.npz. Iter 210: Train loss 1.695, It/sec 0.324, Tokens/sec 75.333 Iter 220: Train loss 1.856, It/sec 0.420, Tokens/sec 71.344 ... ter 600: Train loss 1.584, It/sec 0.330, Tokens/sec 67.831 Iter 600: Val loss 1.771, Val took 35.813s Iter 600: Saved adapter weights to adapters.npz. Iter 610: Train loss 1.487, It/sec 0.368, Tokens/sec 64.815 ... Iter 990: Train loss 1.503, It/sec 0.437, Tokens/sec 71.288 Iter 1000: Train loss 1.511, It/sec 0.361, Tokens/sec 74.861 Iter 1000: Val loss 1.777, Val took 31.679s Iter 1000: Saved adapter weights to adapters.npz.
$ python mlx-examples/lora/lora.py --model ./mlx_model --max-tokens 1000 --prompt 'What is the purpose of SteelHead path selection?' Loading pretrained model Total parameters 1244.041M Trainable parameters 1.704M Loading datasets Generating What is the purpose of SteelHead path selection?
The purpose of the path selection feature in a WAN optimization solution is to reduce the amount of data that is transmitted over the network by minimizing the number of round-trips between the data source and the client. This is achieved by minimizing the number of round-trips required for data to be transmitted, as each round-trip takes time and represents additional network traffic... ==========
### Fine-Tuned Model
$ python mlx-examples/lora/lora.py --model ./mlx_model --adapter-file ./adapters.npz --max-tokens 1000 --prompt 'What is the purpose of SteelHead path selection?' Loading pretrained model Total parameters 1244.041M Trainable parameters 1.704M Loading datasets Generating What is the purpose of SteelHead path selection?
The purpose of the network path selection feature is to selectively choose the most efficient path between two locations based on SaaS application traffic. SteelHead network path selection allows network traffic to use a specific path, either a network path or a WAN path connection, to access a specific application, and can prioritize traffic to ensure network performance. This feature is particularly beneficial in environments where multiple paths are available, such as multiple WAN links, MPLS connections, and LANs.