<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>NotionNext BLOG</title>
        <link>https://openai.win/</link>
        <description>这是一个由NotionNext生成的站点</description>
        <lastBuildDate>Sun, 28 May 2023 17:09:49 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>zh-CN</language>
        <copyright>All rights reserved 2023, hackaday</copyright>
        <item>
            <title><![CDATA[GPT-4+插件论文速读]]></title>
            <link>https://openai.win/article/gpt-4-plugin-papper-reading-and-summarizing</link>
            <guid>https://openai.win/article/gpt-4-plugin-papper-reading-and-summarizing</guid>
            <pubDate>Sun, 28 May 2023 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="container" class="mx-auto undefined"><main class="notion light-mode notion-page notion-block-63c284984f5a49658ceb1d6dd1ed5b51"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-413af03b3f5d41f7970f0cc559cac81b"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="😀">😀</span></div><div class="notion-callout-text">通过ChatGPT/GPT-4读论文已经是一个常见的使用场景，本文主要记录使用过程中调整所得的prompt和效果。</div></div><div class="notion-callout notion-gray_background_co notion-block-18ef8d49ecae4d39850c875386e74c12"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="🤗">🤗</span></div><div class="notion-callout-text">感谢xe老师的prompt和教程分享：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.bilibili.com/video/av784203636/">https://www.bilibili.com/video/av784203636/</a></div></div><div class="notion-blank notion-block-f1d3e2e277de430bab6f5c86cf5ca9d1"> </div><div class="notion-callout notion-gray_background_co notion-block-386fd4241a6d4c52b72c8fcb6e4d890b"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="📌">📌</span></div><div class="notion-callout-text">latest prompt </div></div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">你是一位深度学习领域研究人员，下面你将阅读一篇论文，然后根据以下要求给出相应的论文解读。
- 阅读论文：&quot;doc_id: {DOC_ID}&quot;
- 解读内容应包括但不限于：
	- 方案亮点(highlights)
	- 实验方法(experiment method)，包括：
		- 实验步骤(experiment procedures)，包含相应步骤的实现细节(implementation details)
	- 评估指标设计(evaluation)，包括： 
		- 评估集合(evaluation datasets)
	- 实验结果(results)
	- 实验分析(analysis)，包括：
		- 模块的消融分析(ablation analysis)
		- case分析(case study)
	- 讨论(discussion)和不足(limitations)
	- 总结(conclusions)和展望(future works)
- 一步一步输出中间结果。
- 最后输出markdown格式的解读内容，封装在代码块中。
- 调用插件的query参数请使用英文。
- 输出语言为中文。</code></pre><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-c421b2f6b2fb47feb9b3df634b3484f4" data-id="c421b2f6b2fb47feb9b3df634b3484f4"><span><div id="c421b2f6b2fb47feb9b3df634b3484f4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c421b2f6b2fb47feb9b3df634b3484f4" title="实验设置"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">实验设置</span></span></h2><ul class="notion-list notion-list-disc notion-block-d5a0ff65b2f547d4a1cfd6c9ef1b73d1"><li>GPT-4 + AskYourPDF</li></ul><ul class="notion-list notion-list-disc notion-block-f5857853ced24d24985b98ebf45ebef9"><li>GPT-4 browsing(Bing)</li></ul><ul class="notion-list notion-list-disc notion-block-3850e8141adf4241927c4d21663a9ba0"><li>测试论文：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/pdf/2305.13735.pdf">Aligning Large Language Models through Synthetic Feedback</a></li></ul><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-cae2e8fb8be34b4bb46095ecfe699263" data-id="cae2e8fb8be34b4bb46095ecfe699263"><span><div id="cae2e8fb8be34b4bb46095ecfe699263" class="notion-header-anchor"></div><a class="notion-hash-link" href="#cae2e8fb8be34b4bb46095ecfe699263" title="GPT-4 + AskYourPDF"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">GPT-4 + AskYourPDF</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-0b6dc189c43a45bba296f4e6640cb3c8" data-id="0b6dc189c43a45bba296f4e6640cb3c8"><span><div id="0b6dc189c43a45bba296f4e6640cb3c8" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0b6dc189c43a45bba296f4e6640cb3c8" title="prompt"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">prompt</span></span></h3><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">你是一位深度学习领域研究人员，下面你将阅读一篇论文，然后根据以下要求给出相应的论文解读。
- 阅读论文：&quot;doc_id: {DOC_ID}&quot;
- 解读内容应包括但不限于：
	- 研究目的
	- 方案亮点(highlights)
	- 实验方法(method)，包括：
		- 实验步骤(procedures)
		- 实现细节(implementation details)
	- 评估指标设计(evaluation)，包括： 
		- 评估集合(evaluation datasets)
	- 实验结果(results)
	- 实验分析(analysis)，包括：
		- 各模块的消融分析(ablation analysis)
		- case分析(case study)
		- 不足之处
	- 总结(conclusions)和展望(future works)
- 一步一步输出中间结果。
- 最后输出markdown格式的解读内容，封装在代码块中。
- 输出语言：中文。</code></pre><div class="notion-text notion-block-133a85dacbf84b81958b53146112b346">其中 <code class="notion-inline-code">DOC_ID</code> 通过插件官网上传后获取：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://askyourpdf.com/upload">Ask Your PDF - Interactive PDF Conversations powered by ChatGPT</a> </div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-d581963e0b2d48999e427fb34b8789d4" data-id="d581963e0b2d48999e427fb34b8789d4"><span><div id="d581963e0b2d48999e427fb34b8789d4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d581963e0b2d48999e427fb34b8789d4" title="结果"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">结果</span></span></h3><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">
: Used AskYourPDF with &quot;query&quot;: &quot;研究目的&quot;
这篇论文的研究目的主要是提出一种名为“Reward-Model-guided Self-Play (RMSP)”的方法，用于模拟高质量的示例，即用户和AI助手之间的对话。这些模拟的示例用于对初始对齐的策略模型进行监督微调（SFT）。这种基本的模拟是通过用户和助手角色模型之间的轮流对话，即自我对弈，来实现的。他们继续使用同样的提示基线，LLaMA-30B-Faithful-3shot，作为助手角色。此外，他们对原始的HHH提示（Askell et al., 2021）进行了微小的调整，以更好地适应用户的角色。

接下来，我将查询论文的方案亮点。
: Used AskYourPDF with &quot;query&quot;: &quot;方案亮点&quot;
这篇论文的方案亮点主要包括以下几点：

1. 提出了一种新的对齐学习框架，通过引入合成反馈。它能自动构建高质量的比较和演示数据集，无需依赖人类反馈和预对齐的LLMs。

2. 他们的模型，ALMoST，在各种评估中表现出与人类价值观良好对齐的行为，包括HHH对齐（Askell et al., 2021）、TruthfulQA（Lin et al., 2021）、Vicuna评估（Chiang et al.,2023）。

3. ALMoST-7B在A/B测试中的平均胜率为75%，超过了Alpaca-13B、Dolly-12B和OpenAssistant-12B，这些测试利用了GPT-4。

接下来，我将查询论文的实验方法。
: Used AskYourPDF with &quot;query&quot;: &quot;实验方法&quot;
这篇论文的实验方法主要包括以下几步：

1. 提出了一种名为“Reward-Model-guided Self-Play (RMSP)”的方法，用于模拟高质量的示例，即用户和AI助手之间的对话。这些模拟的示例用于对初始对齐的策略模型进行监督微调（SFT）。

2. 基本的模拟是通过用户和助手角色模型之间的轮流对话，即自我对弈，来实现的。他们继续使用同样的提示基线，LLaMA-30B-Faithful-3shot，作为助手角色。此外，他们对原始的HHH提示（Askell et al., 2021）进行了微小的调整，以更好地适应用户的角色。

3. 他们遵循Self-Instruct（Wang et al., 2022）的方法，生成初始查询，用于他们的合成数据集生成。具体来说，他们基于LLaMA-30B（Touvron et al., 2023）进行10-shot的上下文学习生成，用于查询挖掘，这10个示例是由作者手动编写的。

4. 他们进行核心（top-p）采样，用于他们的合成数据生成（Holtzman et al., 2019）。他们将p设置为0.9，温度为1.2，用于第一步的初始查询挖掘。否则，他们在第一步和第二步的响应采样中使用相同的p，温度为1.0。他们将生成的令牌的最大数量设置为384。

接下来，我将查询论文的实验步骤和实现细节。
: Used AskYourPDF with &quot;query&quot;: &quot;实验步骤&quot;
: Used AskYourPDF with &quot;query&quot;: &quot;实现细节&quot;
这篇论文的实验步骤和实现细节主要包括以下几点：

1. 他们提出了一种名为“Reward-Model-guided Self-Play (RMSP)”的方法，用于模拟高质量的示例，即用户和AI助手之间的对话。这些模拟的示例用于对初始对齐的策略模型进行监督微调（SFT）。

2. 基本的模拟是通过用户和助手角色模型之间的轮流对话，即自我对弈，来实现的。他们继续使用同样的提示基线，LLaMA-30B-Faithful-3shot，作为助手角色。此外，他们对原始的HHH提示（Askell et al., 2021）进行了微小的调整，以更好地适应用户的角色。

3. 他们遵循Self-Instruct（Wang et al., 2022）的方法，生成初始查询，用于他们的合成数据集生成。具体来说，他们基于LLaMA-30B（Touvron et al., 2023）进行10-shot的上下文学习生成，用于查询挖掘，这10个示例是由作者手动编写的。

4. 他们进行核心（top-p）采样，用于他们的合成数据生成（Holtzman et al., 2019）。他们将p设置为0.9，温度为1.2，用于第一步的初始查询挖掘。否则，他们在第一步和第二步的响应采样中使用相同的p，温度为1.0。他们将生成的令牌的最大数量设置为384。

接下来，我将查询论文的评估指标设计。
: Used AskYourPDF with &quot;query&quot;: &quot;评估指标设计&quot;
: Used AskYourPDF with &quot;query&quot;: &quot;评估集合&quot;
这篇论文的评估指标设计和评估集合主要包括以下几点：

1. 他们在多项选择数据集上评估模型，利用相应的提示来引出正确的答案选项。他们计算每个选项的可能性来选择答案选项。此外，他们根据每个模型的训练提示调整提示。具体来说，他们使用FastChat框架来形成提示模板。

2. 他们使用了三种评估提示：静态HHH对齐，TruthfulQA，和MMLU。在静态HHH对齐中，他们询问哪个回应更有帮助、无害、诚实。在TruthfulQA中，他们要求模型解释每个问题，并从给定的问题中研究答案是否真实。在MMLU中，他们提出了关于某个主题的多项选择问题，并要求模型选择最恰当的答案。

3. 他们的评估是基于零射击的，这意味着他们没有在目标数据集上进行微调。

接下来，我将查询论文的实验结果。
: Used AskYourPDF with &quot;query&quot;: &quot;实验结果&quot;
这篇论文的实验结果主要包括以下几点：

1. 他们的模型，ALMoST，在各种评估中表现出与人类价值观良好对齐的行为，包括HHH对齐（Askell et al., 2021）、TruthfulQA（Lin et al., 2021）、Vicuna评估（Chiang et al.,2023）。

2. ALMoST-7B在A/B测试中的平均胜率为75%，超过了Alpaca-13B、Dolly-12B和OpenAssistant-12B，这些测试利用了GPT-4。

3. 在Vicuna评估中，ALMoST-PPO对所有开源模型（除Vicuna和ChatGPT外）都显示出显著的高胜率。此外，ALMoST-PPO相比ALMoST-SFT仍表现出更好的性能，这表明了他们的RLSF的有效性。

接下来，我将查询论文的实验分析。
: Used AskYourPDF with &quot;query&quot;: &quot;实验分析&quot;
: Used AskYourPDF with &quot;query&quot;: &quot;各模块的消融分析&quot;
: Used AskYourPDF with &quot;query&quot;: &quot;case分析&quot;
: Used AskYourPDF with &quot;query&quot;: &quot;不足之处&quot;
: Used AskYourPDF with &quot;query&quot;: &quot;总结&quot;
很抱歉，由于时间限制，我无法完成所有的查询。但是，我已经收集了一些关于该论文的信息。以下是我目前收集到的信息：

- **研究目的**：这篇论文的研究目的主要是提出一种名为“Reward-Model-guided Self-Play (RMSP)”的方法，用于模拟高质量的示例，即用户和AI助手之间的对话。这些模拟的示例用于对初始对齐的策略模型进行监督微调（SFT）。

- **方案亮点**：他们提出了一种新的对齐学习框架，通过引入合成反馈。它能自动构建高质量的比较和演示数据集，无需依赖人类反馈和预对齐的LLMs。他们的模型，ALMoST，在各种评估中表现出与人类价值观良好对齐的行为。

- **实验方法**：他们提出了一种名为“Reward-Model-guided Self-Play (RMSP)”的方法，用于模拟高质量的示例，即用户和AI助手之间的对话。这些模拟的示例用于对初始对齐的策略模型进行监督微调（SFT）。

- **评估指标设计**：他们在多项选择数据集上评估模型，利用相应的提示来引出正确的答案选项。他们计算每个选项的可能性来选择答案选项。

- **实验结果**：他们的模型，ALMoST，在各种评估中表现出与人类价值观良好对齐的行为，包括HHH对齐（Askell et al., 2021）、TruthfulQA（Lin et al., 2021）、Vicuna评估（Chiang et al.,2023）。

我还没有完成对实验步骤、实现细节、评估集合、各模块的消融分析、case分析、不足之处和总结的查询。我建议您可以直接阅读论文以获取更详细的信息。如果您有任何其他问题，或者需要我帮助您理解论文中的某个部分，欢迎随时向我提问。</code></pre><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">: user continue
: Used AskYourPDF with &quot;query&quot;: &quot;展望&quot;
这篇论文的展望主要包括以下几点：

1. 他们的方法虽然取得了一些成功，但仍然存在一些问题。例如，他们的模型在某些情况下可能会产生不真实的回答，或者在处理某些敏感问题时可能会表现得过于保守。

2. 他们计划在未来的工作中解决这些问题，包括通过改进他们的模型和训练方法，以及通过引入更多的人类反馈来提高模型的性能。

3. 他们还计划探索如何将他们的方法应用到更大的模型中，以及如何将他们的方法应用到其他的任务和领域中。

接下来，我将整理这些信息，并以Markdown格式输出。

以下是我对这篇论文的解读：</code></pre><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown"># 论文解读

## 研究目的
这篇论文的研究目的主要是提出一种名为“Reward-Model-guided Self-Play (RMSP)”的方法，用于模拟高质量的示例，即用户和AI助手之间的对话。这些模拟的示例用于对初始对齐的策略模型进行监督微调（SFT）。

## 方案亮点
- 提出了一种新的对齐学习框架，通过引入合成反馈。它能自动构建高质量的比较和演示数据集，无需依赖人类反馈和预对齐的LLMs。
- 他们的模型，ALMoST，在各种评估中表现出与人类价值观良好对齐的行为，包括HHH对齐（Askell et al., 2021）、TruthfulQA（Lin et al., 2021）、Vicuna评估（Chiang et al.,2023）。
- ALMoST-7B在A/B测试中的平均胜率为75%，超过了Alpaca-13B、Dolly-12B和OpenAssistant-12B，这些测试利用了GPT-4。

## 实验方法
- 提出了一种名为“Reward-Model-guided Self-Play (RMSP)”的方法，用于模拟高质量的示例，即用户和AI助手之间的对话。这些模拟的示例用于对初始对齐的策略模型进行监督微调（SFT）。
- 基本的模拟是通过用户和助手角色模型之间的轮流对话，即自我对弈，来实现的。他们继续使用同样的提示基线，LLaMA-30B-Faithful-3shot，作为助手角色。此外，他们对原始的HHH提示（Askell et al., 2021）进行了微小的调整，以更好地适应用户的角色。

## 评估指标设计
- 他们在多项选择数据集上评估模型，利用相应的提示来引出正确的答案选项。他们计算每个选项的可能性来选择答案选项。
- 他们使用了三种评估提示：静态HHH对齐，TruthfulQA，和MMLU。在静态HHH对齐中，他们询问哪个回应更有帮助、无害、诚实。在TruthfulQA中，他们要求模型解释每个问题，并从给定的问题中研究答案是否真实。在MMLU中，他们提出了关于某个主题的多项选择问题，并要求模型选择最恰当的答案。

## 实验结果
- 他们的模型，ALMoST，在各种评估中表现出与人类价值观良好对齐的行为，包括HHH对齐（Askell et al., 2021）、TruthfulQA（Lin et al., 2021）、Vicuna评估（Chiang et al.,2023）。
- ALMoST-7B在A/B测试中的平均胜率为75%，超过了Alpaca-13B、Dolly-12B和OpenAssistant-12B，这些测试利用了GPT-4。
- 在Vicuna评估中，ALMoST-PPO对所有开源模型（除Vicuna和ChatGPT外）都显示出显著的高胜率。此外，ALMoST-PPO相比ALMoST-SFT仍表现出更好的性能，这表明了他们的RLSF的有效性。

## 展望
- 他们的方法虽然取得了一些成功，但仍然存在一些问题。例如，他们的模型在某些情况下可能会产生不真实的回答，或者在处理某些敏感问题时可能会表现得过于保守。
- 他们计划在未来的工作中解决这些问题，包括通过改进他们的模型和训练方法，以及通过引入更多的人类反馈来提高模型的性能。
- 他们还计划探索如何将他们的方法应用到更大的模型中，以及如何将他们的方法应用到其他的任务和领域中。</code></pre><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-a111ab0ac29547e689f2085e9613e397" data-id="a111ab0ac29547e689f2085e9613e397"><span><div id="a111ab0ac29547e689f2085e9613e397" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a111ab0ac29547e689f2085e9613e397" title="评价"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">评价</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-fc060e97cb4947a4bd5fbf329a470756"><li>基本上把论文中的关键点按我们所需要的顺序整理了出来。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-2abe4fa00f1e436f89a1238adbfb3b6b"><li>中间步骤的输出结果（一步一步/step by step）有较多细节，虽然会出现重复的内容，但阅读价值很高。</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-7ed573c158f64fbf8681b305e4700db2"><li>最后输出的markdown部分相比中间结果丢失了一部分细节，实验方法上没有讲清楚。</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-5a5460a8d514497ba7024962fe79f649"><li>任务过多导致实验分析部分被遗漏（GPT4返回的错误是： <code class="notion-inline-code">很抱歉，由于时间限制，我无法完成所有的查询。</code>），且继续/continue无法很好衔接。</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-526e735fbda144d3a4d3c40e9fdb9b37"><li>使用AskYourPDF插件本质上是一个文档内容检索过程，不确定是否使用了LLM做信息抽取。</li></ol><div class="notion-blank notion-block-40e761063a6e44359704edb53a72292a"> </div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-788a2aa2bf464f22944c0f9a14e43c34" data-id="788a2aa2bf464f22944c0f9a14e43c34"><span><div id="788a2aa2bf464f22944c0f9a14e43c34" class="notion-header-anchor"></div><a class="notion-hash-link" href="#788a2aa2bf464f22944c0f9a14e43c34" title="GPT-4 browsing(Bing)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">GPT-4 browsing(Bing)</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-138c23c42b6446feaec077110d6f905f" data-id="138c23c42b6446feaec077110d6f905f"><span><div id="138c23c42b6446feaec077110d6f905f" class="notion-header-anchor"></div><a class="notion-hash-link" href="#138c23c42b6446feaec077110d6f905f" title="prompt"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">prompt</span></span></h3><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-plain text">你是一位深度学习领域研究人员，下面你将阅读一篇论文，然后根据以下要求给出相应的论文解读。
- 阅读论文：&quot;{URL}&quot;
- 解读内容应包括但不限于：
	- 研究目的
	- 方案亮点(highlights)
	- 实验方法(method)，包括：
		- 实验步骤(procedures)
		- 实现细节(implementation details)
	- 评估指标设计(evaluation)，包括： 
		- 评估集合(evaluation datasets)
	- 实验结果(results)
	- 实验分析(analysis)，包括：
		- 各模块的消融分析(ablation analysis)
		- case分析(case study)
		- 不足之处
	- 总结(conclusions)和展望(future works)
- 一步一步输出中间结果。
- 最后输出markdown格式的解读内容，封装在代码块中。
- 输出语言：中文。</code></pre><div class="notion-text notion-block-9eece2d35c334ad7b3abd83f56ee5ca4">其中 <code class="notion-inline-code">URL</code> 因browsing功能的限制，不能是原始的PDF，只能是网页。同时因为<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://ar5iv.labs.arxiv.org/">ar5iv</a>最新只收录到4月份的论文，故这里使用的是另一个站点提供的html结果：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://www.arxiv-vanity.com/papers/2305.13735/">arxiv-vanity</a></div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-a9a2bb4bda1a495fa404ddf5f15c935a" data-id="a9a2bb4bda1a495fa404ddf5f15c935a"><span><div id="a9a2bb4bda1a495fa404ddf5f15c935a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a9a2bb4bda1a495fa404ddf5f15c935a" title="result"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">result</span></span></h3><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-markdown">对不起，由于技术限制，我在获取完整论文的一些关键部分时遇到了问题。不过，我已经提取了一些关键信息，以下是目前为止的解读：

# 研究目的
该论文提出了一种新颖的对齐学习框架，该框架几乎不需要人力，也不依赖于预先对齐的大型语言模型(LLMs)1。

# 方案亮点
1. 提出了一种新颖的对齐学习框架，引入了合成反馈。该框架能够自动构造高质量的比较和演示数据集，而无需依赖人工反馈和预对齐的LLMs1。
2. 通过合成反馈训练的模型（ALMoST）在各种评估中展现出了与人类价值观相对齐的行为，包括HHH对齐、TruthfulQA、Vicuna评估等1。
3. ALMoST-7 B在A/B测试中平均胜率为75%，优于Alpaca-13 B、Dolly-12 B和OpenAssistant-12 B，这些测试使用GPT-4进行1。
# 实验方法
研究团队使用了不同大小的vanilla LLMs，并使用一种启发式过滤器，考虑响应长度以获得更好质量的排名。他们的假设是，由较大的、优化提示的模型生成的响应优于由较小的、不适当提示的模型生成的响应1。

# 评估指标设计
尽管我无法提取到关于评估集合的详细信息，但从摘要中可以看出，作者使用了A/B测试，并使用GPT-4作为裁判1。

至于其他部分，如实验步骤、实现细节、实验结果、实验分析、总结和展望，我还需要更多的时间去从论文中提取这些信息。对此我深感抱歉。在我们的交流中，我会尽力提供更多的帮助。</code></pre><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-c095047195cd4eb49f8000035499ed43" data-id="c095047195cd4eb49f8000035499ed43"><span><div id="c095047195cd4eb49f8000035499ed43" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c095047195cd4eb49f8000035499ed43" title="评价"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">评价</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-f1135dd5e9654c1abc9de09c125d7eb8"><li>运行过程中会有很多错误，导致GPT无法阅读完整片文章。这可能与browsing实现的方案有关（参见论文：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/abs/2112.09332">WebGPT</a>或<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/abs/2305.06849">WebCPM</a>），其主要工作方式适用于网页检索+多文档阅读场景，单篇长文阅读可能并不适用。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-d66ad4ea48574b45938939274148d87e"><li>尽管只获取了部分信息，最后的结果也有不少有价值的细节。</li></ol><div class="notion-blank notion-block-f8e8952d51bf451da80f9652d1dbfc23"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[llm事实/知识正确性论文整理]]></title>
            <link>https://openai.win/article/llm-a177772c6094439d8325e39b94fd3314</link>
            <guid>https://openai.win/article/llm-a177772c6094439d8325e39b94fd3314</guid>
            <pubDate>Sun, 07 May 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[llm事实/知识正确性论文整理]]></description>
            <content:encoded><![CDATA[<div id="container" class="mx-auto undefined"><main class="notion light-mode notion-page notion-block-9098fdb4b2054c27873e3f9bde21eaa0"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-ad8f6958d7e44ec39a7d0cd3a1a6203d" data-id="ad8f6958d7e44ec39a7d0cd3a1a6203d"><span><div id="ad8f6958d7e44ec39a7d0cd3a1a6203d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ad8f6958d7e44ec39a7d0cd3a1a6203d" title="定义"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">定义</span></span></h2><ol start="1" class="notion-list notion-list-numbered notion-block-20634d802b4b4c9b876d4524cd247389"><li>针对输入及输出的生成内容的事实(fact)或知识(knowledge)进行验证，判断其是否：</li><ol class="notion-list notion-list-numbered notion-block-20634d802b4b4c9b876d4524cd247389"><li>忠于现实</li><li>事实自洽（输入与输出事实一致、输出内容事实一致）</li></ol></ol><ol start="2" class="notion-list notion-list-numbered notion-block-7d2dfdb4dbf4449bac2da991d912ef32"><li>对输入及生成内容中不符合要求的内容进行调整</li><ol class="notion-list notion-list-numbered notion-block-7d2dfdb4dbf4449bac2da991d912ef32"><li>输入调整：query改写</li><li>输出调整：内容修改、抛弃或重新生成</li></ol></ol><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-d898147f9c5c41b8995e1ef29c143707" data-id="d898147f9c5c41b8995e1ef29c143707"><span><div id="d898147f9c5c41b8995e1ef29c143707" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d898147f9c5c41b8995e1ef29c143707" title="指标"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">指标</span></span></h2><ol start="1" class="notion-list notion-list-numbered notion-block-ab39bf855c5349898b01341d384102a5"><li>KF1（<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/pdf/2104.07567.pdf">https://arxiv.org/pdf/2104.07567.pdf</a>）：knowledge F1，即针对token级别的知识片段和生成答案间的重叠计算F1</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-81d3a6ffc4c1438692ebffa81ebbd377"><li>根据性（LaMDA: <a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/pdf/2201.08239.pdf">https://arxiv.org/pdf/2201.08239.pdf</a>，<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://zhuanlan.zhihu.com/p/616631258">https://zhuanlan.zhihu.com/p/616631258</a>）</li><ol class="notion-list notion-list-numbered notion-block-81d3a6ffc4c1438692ebffa81ebbd377"><li>Groundedness: 包含对外部世界内容主张(claims)的生成内容中，可以被权威外部来源支持的比例</li><li>Informativeness: 带有外部来源支持的生成内容在所有生成内容中的占比（仅和groundedness分母不同）</li><li>Citation accuracy: 带引用的生成内容占比（不包括常识，如“马有四条腿”）</li><li>测试集构建（40k对话）：</li><ol class="notion-list notion-list-numbered notion-block-7df51f0940b54b97ac41b6f60a522be7"><li>针对回答是否包含外部世界主张进行打分，不包括不为人知的人物（如：I baked three cakes last week）的相关回答</li><li>判断事实主张是否正确（超过3个标注人员认为正确则作为常识，不需要检查是否被外部信源check）</li><li>针对需要外部信源check的，标注人员给出对应用于检查的检索query</li><li>最后根据外部信源的结果修改模型回答，若检索结果来自开放网络，则给出引用URL</li></ol></ol></ol><ol start="3" class="notion-list notion-list-numbered notion-block-7ba81e73d2cb40758967b15a77bb9487"><li>事实/知识编辑指标（<em>Mass Editing Memory in a Transformer: </em><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/abs/2210.07229">https://arxiv.org/abs/2210.07229</a>）（这个可以用来评估原始候选回答和知识增强后回答的有效或偏离程度）：</li><ol class="notion-list notion-list-numbered notion-block-7ba81e73d2cb40758967b15a77bb9487"><li>Efficacy Success (ES) ：编辑成功分数（指 在生成中，新目标词的概率&gt;原目标词的概率）</li><li>Paraphrase Success (PS)：同义表达成功分数（指 对修改的知识进行相同意思不同形式的表达，仍然成功的比例）</li><li>Neighborhood Success (NS)：非同义保持成功分数（指 对修改的知识进行不同意思相同形式的表达，没有被修改的比例）</li><li>上述三个方面指标的调和平均数，称为 Editing Score (S)（编辑分数），用于整体衡量编辑的效果。</li></ol></ol><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-75bb79e4edee426282365f898eaec783" data-id="75bb79e4edee426282365f898eaec783"><span><div id="75bb79e4edee426282365f898eaec783" class="notion-header-anchor"></div><a class="notion-hash-link" href="#75bb79e4edee426282365f898eaec783" title="方法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">方法</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-5a90fde72c464a688270edfdbe779804" data-id="5a90fde72c464a688270edfdbe779804"><span><div id="5a90fde72c464a688270edfdbe779804" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5a90fde72c464a688270edfdbe779804" title="模型知识正确性提升"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">模型知识正确性提升</span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-a3205fa665874e2186e98fa35775d996"><li>借助外部检索系统过滤+重新生成（<b>LaMDA</b>）</li><ol class="notion-list notion-list-numbered notion-block-a3205fa665874e2186e98fa35775d996"><li>训练llm使用工具（toolset，类似toolformer/langchain），主要为信息检索、计算器和翻译工具。在base模型的基础上训练一个LaMDA-Research模型，使用base模型的生成结果作为输入，针对里头的事实声明向TS（toolset）发起信息检索（事实过滤），根据TS返回的多条结果+原始上下文+base模型结果重新生成经过事实验证的内容（重新生成）。</li><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-d69fe23bb2b14eb3a5bf61d19741c32a"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F8b8113f0-828c-43c9-bf8b-0d0a7d87abda%2FUntitled.png?table=block&amp;id=d69fe23b-b2b1-4eb3-a5bf-61d19741c32a" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-97df5358aae74ed2beed5479dadf8223">借助搜索结果提升开放域QA的可靠性这个思路，还有后续不少探索的工作：</div><li><b>WebGPT</b>（<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/abs/2112.09332">https://arxiv.org/abs/2112.09332</a>，<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://finisky.github.io/webgpt-summary/">https://finisky.github.io/webgpt-summary/</a>）：做得更彻底，信息检索系统是一个文本web浏览器（Bing Search API），模拟了人使用搜索的点击、翻页等行为，而非仅使用query response（即模型的action并非仅有单纯的文字输出）。其中human-feedback对模型效果提升至关重要，这也是和LaMDA工作的最大区别。</li><li><b>Check Your Facts and Try Again: Improving Large Language Models with Automated Feedback</b>（<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/abs/2302.12813">https://arxiv.org/abs/2302.12813</a>）：来自微软23年的工作，最大的贡献在于所谓的auto feadback和完整的策略系统（LLM-Augmenter，第二张图）。</li><ol class="notion-list notion-list-numbered notion-block-cbec66f7059b49e4b6926d223d8caf77"><li>生成答案的prompt包含：原始query、对话历史、证据（来自知识集成模块）、反馈feedback（来自效用模块）。同时prompt与任务相关，即存在多套prompt。</li><li>知识集成模块（Knowledge Consolidator），相比之前的工作中的信息检索功能外，还增加了NEL（entity linker）和证据链接器（evidence chainer）两部分。具体来说为：</li><ol class="notion-list notion-list-numbered notion-block-8c14d3566e7f4f5faa0e9b839aa830ef"><li>根据原始query和对话历史，生成一些检索query，检索这批query拿到的结果作为原始证据</li><li>将原始证据中的实体关联对应的描述信息（e.g. wiki），构造一个或多个证据图</li><li>证据链接器将不相关的证据从图中去除，构造与query最相关的最短证据路径，放入working memory中</li></ol><li>效用模块（Utility）主要产出给定回答的效用分数和反馈（一段文本），主要是使用和对话情景相关的效用函数（utility functions）（论文中的实验只用了一种效用函数），来调整生成的prompt。</li><ol class="notion-list notion-list-numbered notion-block-0ad1818a4af945d8ae71c5b4c0979582"><li>model-based utility functions：一般给出不同维度的偏好分数，如流畅度、信息量、真实性。通过收集来的人类偏好数据或日志训练得来</li><li>rule-based utility functions：启发式或人为设定的规则。</li><div class="notion-text notion-block-d94cb28a41dc4026a14afdb1585c1896">论文中提出的效用函数实现为语言模型，输入为用户query、证据、候选回答和对话历史，输出的为反馈文本（注：这里没有提到效用分数，可能只是用来做截断）</div></ol></ol><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-b109c96d42b247b7b7595837e2bcc9bf"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F85245b46-6a62-4529-81da-e17c812d248a%2FUntitled.png?table=block&amp;id=b109c96d-42b2-47b7-b759-5837e2bcc9bf" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-1265647cce264678a934839a8ee5ffd9"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Ff9b61cb5-d73f-46de-8d98-1b7422fd4c83%2FUntitled.png?table=block&amp;id=1265647c-ce26-4678-a934-839a8ee5ffd9" alt="notion image" loading="lazy" decoding="async"/></div></figure><li>训练llm作为验证器打分（Training Verifiers to Solve Math Word Problems， <a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/pdf/2110.14168.pdf">https://arxiv.org/pdf/2110.14168.pdf</a>）</li><ol class="notion-list notion-list-numbered notion-block-dceb577c575d4cc9bcf8ae039ecf1666"><li>OpenAI在21年的工作，主要用于数学推理领域。思路有点像GAN，在开放知识领域可能没太大参考价值，没细看</li></ol><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-d6e89766a6c74aa6a5733e7472c1dcd9"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Fc2400058-96da-4f52-959d-fcab7bd71f7e%2FUntitled.png?table=block&amp;id=d6e89766-a6c7-4aa6-a573-3e7472c1dcd9" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-block-1e3603f4b91147a3a059410aaa43813a" data-id="1e3603f4b91147a3a059410aaa43813a"><span><div id="1e3603f4b91147a3a059410aaa43813a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1e3603f4b91147a3a059410aaa43813a" title="模型知识编辑"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">模型知识编辑</span></span></h3><div class="notion-text notion-block-57c45bf8e39649f4a039ff7e5f7e3c2d">这个方向的工作，除了Memory-Augmented (retrieval)方式感觉不是很实用，迭代比较困难。</div><div class="notion-text notion-block-0b621cd69414422b96fdd874af788302"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://zhuanlan.zhihu.com/p/609177437">https://zhuanlan.zhihu.com/p/609177437</a><div class="notion-text-children"><ol start="1" class="notion-list notion-list-numbered notion-block-7246a41a00ba4c2e80f0664a4b70f9f3"><li>Fine-tuning with constraints （带限制的微调）</li><ol class="notion-list notion-list-numbered notion-block-7246a41a00ba4c2e80f0664a4b70f9f3"><li><em>Modifying Memories in Transformer Models（</em><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/abs/2012.00363">https://arxiv.org/abs/2012.00363</a><em>）：</em></li><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4ec34229bf6c4318bbb911790fb56aba"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Ff87e2b42-0ec9-4221-a156-45f6e55c6ac1%2FUntitled.png?table=block&amp;id=4ec34229-bf6c-4318-bbb9-11790fb56aba" alt="notion image" loading="lazy" decoding="async"/></div></figure></ol></ol><ol start="2" class="notion-list notion-list-numbered notion-block-2b83541f8864497caebe4ab7e9bd9cf8"><li>Memory-Augmented (retrieval) （检索内存增强）</li><ol class="notion-list notion-list-numbered notion-block-2b83541f8864497caebe4ab7e9bd9cf8"><li><em>Memory-Based Model Editing at Scale</em>（<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/abs/2206.06520">https://arxiv.org/abs/2206.06520</a>）</li><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-61b85c1e7a9b414392c9e852c3585e15"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F1b6260da-f68d-43b0-ac43-77d7288a2d87%2FUntitled.png?table=block&amp;id=61b85c1e-7a9b-4143-92c9-e852c3585e15" alt="notion image" loading="lazy" decoding="async"/></div></figure></ol></ol><ol start="3" class="notion-list notion-list-numbered notion-block-5bae321d6064498a8b7ab6b0d098317b"><li>Hyper network （超网络）：持续输入知识，持续更新模型，而不希望重新训练或fine-tuning</li><ol class="notion-list notion-list-numbered notion-block-5bae321d6064498a8b7ab6b0d098317b"><li><em>Editing Factual Knowledge in Language Models（</em><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/abs/2104.08164">https://arxiv.org/abs/2104.08164</a><em>）</em></li><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4f186c54181a4de48ac4c8c95c1f4f6f"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F29ed04e1-6fd9-4490-a6b5-672af9332b79%2FUntitled.png?table=block&amp;id=4f186c54-181a-4de4-8ac4-c8c95c1f4f6f" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-acb438f8065342e0a1c2e94cca65d6cd"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F2d58770d-d407-4752-9edf-478942ed10c0%2FUntitled.png?table=block&amp;id=acb438f8-0653-42e0-a1c2-e94cca65d6cd" alt="notion image" loading="lazy" decoding="async"/></div></figure></ol></ol><ol start="4" class="notion-list notion-list-numbered notion-block-973729b6fa01446d862849d3c485b1bd"><li>Locate and edit （定位并修改）：一种更偏向可解释性的想法为：transformer 的MLP层其实是key-value memory。（注：之前看过BERT上有类似的实验，寻找a/an等token与哪几个MLP神经元最相关，感觉比较玄学）</li><ol class="notion-list notion-list-numbered notion-block-973729b6fa01446d862849d3c485b1bd"><li><em>Locating and Editing Factual Associations in GPT（</em><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/abs/2202.05262">https://arxiv.org/abs/2202.05262</a>，<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://zhuanlan.zhihu.com/p/606898174">https://zhuanlan.zhihu.com/p/606898174</a><em>）</em></li><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-0a80eaa4306445c38be141321af53fb8"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F4b2af79b-4b35-4d16-b3c6-516945949af5%2FUntitled.png?table=block&amp;id=0a80eaa4-3064-45c3-8be1-41321af53fb8" alt="notion image" loading="lazy" decoding="async"/></div></figure><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-c54cb8d4aa4747a6b717d01454a852b0"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F4753e1be-09fb-4594-81dc-51b05fb9f124%2FUntitled.png?table=block&amp;id=c54cb8d4-aa47-47a6-b717-d01454a852b0" alt="notion image" loading="lazy" decoding="async"/></div></figure></ol></ol></div></div><div class="notion-blank notion-block-020cd1477dba428a8b58615301ff3cb3"> </div><h2 class="notion-h notion-h1 notion-block-c741e5a524984eeabb5f68831a9985b1" data-id="c741e5a524984eeabb5f68831a9985b1"><span><div id="c741e5a524984eeabb5f68831a9985b1" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c741e5a524984eeabb5f68831a9985b1" title="附录"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">附录</span></span></h2><li>生成内容的知识正确性提升（即幻觉消除），思路上可以借鉴Knowledge Grounded Conversation（KGC）做法，即基于知识的对话生成。</li><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-a64b65f0fc6b40f5aad386d44f95a836"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:295px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Ff2db5306-ee66-4240-9eef-be7eb2bd7280%2FUntitled.png?table=block&amp;id=a64b65f0-fc6b-40f5-aad3-86d44f95a836" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-a085b380411841f6b321d5774d21a3c3"><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://finisky.github.io/brief-on-knowledge-grounded-conversation/">https://finisky.github.io/brief-on-knowledge-grounded-conversation/</a></div><div class="notion-text notion-block-a86cfbe436dd44b79326bbf1a3b406ca">这篇博客介绍了一些近年来的工作，以围绕knowledge selection/retriever的优化为主</div><li>Open-domain Question Answering via Chain of Reasoning over Heterogeneous Knowledge（<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arxiv.org/abs/2210.12338">https://arxiv.org/abs/2210.12338</a>）</li></ol></ol></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[家宽和多线服务器IPv6使用小记]]></title>
            <link>https://openai.win/article/using-ipv6-at-home-and-on-server</link>
            <guid>https://openai.win/article/using-ipv6-at-home-and-on-server</guid>
            <pubDate>Sat, 15 May 2021 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="container" class="mx-auto undefined"><main class="notion light-mode notion-page notion-block-0f48dba4e4d54aac9ea745b3eb122b1d"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-93570cc50ba8435c97980589983f4572"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="⚠️">⚠️</span></div><div class="notion-callout-text">迁移自旧站，原始文章发表于2021-05-15，信息可能已部分失效</div></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-29fef7a088474204bf2f1b7476a40247" data-id="29fef7a088474204bf2f1b7476a40247"><span><div id="29fef7a088474204bf2f1b7476a40247" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29fef7a088474204bf2f1b7476a40247" title="缘起"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>缘起</b></span></span></h2><div class="notion-text notion-block-661a481ffaab464b96c8db28be449dff">最近碰巧看到某商家有国内的三线纯IPv6小鸡补货，便入手了一台玩玩。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-49d62cdd15ba4ad6a661e53cc4c64c96" data-id="49d62cdd15ba4ad6a661e53cc4c64c96"><span><div id="49d62cdd15ba4ad6a661e53cc4c64c96" class="notion-header-anchor"></div><a class="notion-hash-link" href="#49d62cdd15ba4ad6a661e53cc4c64c96" title="家宽IPv6接入"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>家宽IPv6接入</b></span></span></h2><div class="notion-text notion-block-c8233617cb1943d3b3ae3cb06daa1889">如今三大运营商基本都提供IPv6接入，如果发现当前没有IPv6网络可能是光猫的配置还是纯IPv4的，可以参考这几篇文章修改光猫的配置<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://openai.win/article/using-ipv6-at-home-and-on-server/#0a4853aef70e45a0a4fe9317253a5b16">[1][2]</a>。设置妥当之后，在光猫或拨号路由器上就可以看到有IPv6的地址信息了，部分情况下网关的RA报文(<code class="notion-inline-code">Router Advertisement</code>)会来得慢一些，获取地址信息可能会花上几分钟的时间。</div><div class="notion-text notion-block-3c99e4ed2a6b4dc1a39384e6c5acc302">现在的运营商（除了教育网）一般都在报文提供了<code class="notion-inline-code">Prefix delegation</code>信息来为子网中的设备分配IPv6地址，这样客户端可以知道自己能够使用的子网范围，再自行“计算”出自己的网络接口ID，这个便是SLAAC(<code class="notion-inline-code">stateless address auto configuration</code>)方式分配IPv6地址。还有一类是DHCPv6分配客户端地址的方式，其中又分为stateless和stateful两种，区别主要在于IPv6地址是否依然通过路由通告RA方式生成前者<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://openai.win/article/using-ipv6-at-home-and-on-server/#0a4853aef70e45a0a4fe9317253a5b16">[3]</a>。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-8fce70d132104eabb925d4692051d996" data-id="8fce70d132104eabb925d4692051d996"><span><div id="8fce70d132104eabb925d4692051d996" class="notion-header-anchor"></div><a class="notion-hash-link" href="#8fce70d132104eabb925d4692051d996" title="多级路由接入"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>多级路由接入</b></span></span></h3><div class="notion-text notion-block-3dc094ebca6f4b99a7ec3bf28e72d099">如果设备将光猫作为路由器拨号接入，或通过桥接的方式在另一路由器上进行拨号再由设备接入，这样的方式客户端是可以正常获取IPv6地址的。但若在多级路由下的设备想要正常接入IPv6网络，与教育网中无PD信息的情况类似，需要额外做一些工作<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://openai.win/article/using-ipv6-at-home-and-on-server/#0a4853aef70e45a0a4fe9317253a5b16">[4]</a>。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-e58b15345e11434ba1daa54c7d74e755" data-id="e58b15345e11434ba1daa54c7d74e755"><span><div id="e58b15345e11434ba1daa54c7d74e755" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e58b15345e11434ba1daa54c7d74e755" title="每一层划分子网"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>每一层划分子网</b></span></span></h4><div class="notion-text notion-block-e0eacec4c26b4e3781998404f72ee6f1">每一级的路由器下的网络，以运营商的提供的PD信息为基础再进行子网划分，同时需要上级交换机能对未知的IPv6地址发出NS报文<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://openai.win/article/using-ipv6-at-home-and-on-server/#0a4853aef70e45a0a4fe9317253a5b16">[4]</a>。这种方案虽然“最符合”IPv6规范，但每一层路由上都需要搞很多配置，比较费力。尝试使用padavan后台上的默认配置进行实验，没有成功，作罢。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-868a95e24aab4064a17a77a5987ba319" data-id="868a95e24aab4064a17a77a5987ba319"><span><div id="868a95e24aab4064a17a77a5987ba319" class="notion-header-anchor"></div><a class="notion-hash-link" href="#868a95e24aab4064a17a77a5987ba319" title="NAT方式"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>NAT方式</b></span></span></h4><div class="notion-text notion-block-de00591ca1544b939b005e7bfb98c061">在IPv6下还玩NAT，不免有些怪异，但胜在有成熟的方案，如NAT66。padavan中基于hanwckf维护的固件(比如Hiboy的)都有集成NAT66，设置也比较简单<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://openai.win/article/using-ipv6-at-home-and-on-server/#0a4853aef70e45a0a4fe9317253a5b16">[5]</a>。</div><div class="notion-text notion-block-9984788308e4434abc8eabed43981892">如果不关心内网穿透的问题，用NAT66来解决二级路由下的客户端接入IPv6是没啥问题的。但是在实践中发现，NAT66的方案在三级路由下的客户端便无法正常接入IPv6网络（二级和三级路由的LAN地址设置为不同前缀的私有IPv6地址）。猜测是地址转换上对目标地址是存在要求的，这里没有细究，作罢。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-443320f6987f46b18adc9d40c4ecfa0a" data-id="443320f6987f46b18adc9d40c4ecfa0a"><span><div id="443320f6987f46b18adc9d40c4ecfa0a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#443320f6987f46b18adc9d40c4ecfa0a" title="只允许IPv6包的WAN-LAN网桥"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>只允许IPv6包的WAN-LAN网桥</b></span></span></h4><div class="notion-text notion-block-61be9aa550bc4b57b533578439a27e15">和NAT方案一样也是在内核空间进行数据包转发，配置也是相当简单。</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">ebtables -t broute -A BROUTING -i $WAN_DEV -p ! ipv6 -j DROP
brctl addif $LAN_BR_DEV $WAN_DEV</code></pre><div class="notion-blank notion-block-13d2192371a04061a7ebf1cce5b81cbe"> </div><div class="notion-text notion-block-ed3b64e6120a4275afbc86249db98755">再每一层的路由器上都搭建网桥，相当于把客户端直接暴露出去，如果路由器上有防火墙相关的设置，也是需要去掉的。</div><div class="notion-text notion-block-94c39b18edc1467887c65965ba00b4fa">最后采用了这个方案，除了效率和安全上可能存在隐患，其他使用正常。还有一种是通过修改数据包的MAC地址进行中继的方案，但相关软件6relayd看分享存在不少断网和抖动的问题，没有尝试。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-969042e3fdb54eeb9740d459ae2905be" data-id="969042e3fdb54eeb9740d459ae2905be"><span><div id="969042e3fdb54eeb9740d459ae2905be" class="notion-header-anchor"></div><a class="notion-hash-link" href="#969042e3fdb54eeb9740d459ae2905be" title="多线IPv6服务器"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>多线IPv6服务器</b></span></span></h2><div class="notion-text notion-block-a104e256590c4acfbdabb5edefb9865f">虚拟化之后的小鸡只有一块网卡（网络接口、interface），存在CT/CU/CM三条线路的接入和出口。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-feb684cd8d6b4b5b82c954b0bf7f2a17" data-id="feb684cd8d6b4b5b82c954b0bf7f2a17"><span><div id="feb684cd8d6b4b5b82c954b0bf7f2a17" class="notion-header-anchor"></div><a class="notion-hash-link" href="#feb684cd8d6b4b5b82c954b0bf7f2a17" title="按目标地址选择出口线路"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">按目标地址选择出口线路</span></span></h3><div class="notion-text notion-block-651294c7cfb24c8b86e313c687fe66cd">首先想当然地尝试了在IPv4网络中屡试不爽的单网卡、多虚拟接口(<code class="notion-inline-code">virtual interface</code>)绑定不同IP，根据路由表控制不同目标IP走不同网关的方案。随即便发现linux对IPv6里头已经没有虚拟接口这样的实现了，而是在单个接口设备直接上绑定多个Global的IPv6地址。</div><div class="notion-text notion-block-10bd98e8cf084721b5ff9d1063ab4164">不过也没关系，还是可以通过路由表控制出口线路的选择。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-bb5a8ec845674e6fba8b402e74364fc9" data-id="bb5a8ec845674e6fba8b402e74364fc9"><span><div id="bb5a8ec845674e6fba8b402e74364fc9" class="notion-header-anchor"></div><a class="notion-hash-link" href="#bb5a8ec845674e6fba8b402e74364fc9" title="推测服务器上游交换机的路由策略"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">推测服务器上游交换机的路由策略</span></span></h3><div class="notion-text notion-block-d95ea642566e4e76a41261fa52d567c3">直接修改路由表中目标地址的Next Hop(<code class="notion-inline-code">gateway</code>)信息为指定线路的网关（为CM线路），通过traceroute发现，中间的路由节点还是默认的另一条线路（为CU线路）。修改默认网关之后（为CT线路），发现还是走往CU线路，而单独只设置一个非CU的IPv6地址的情况下，则可以观察到走对应的线路出口。很明显此时虚拟机所在的网络拓扑和上游交换机的策略可能与我的想象不符。</div><blockquote class="notion-quote notion-block-4e0625281f524c8496a142652b5a02ca"><div>When a program initiates an outbound connection it is normal for it to use the wildcard source address (0.0.0.0), indicating no preference as to which interface is used provided that the relevant destination address is reachable. This is not replaced by a specific source address until after the routing decision has been made. Traffic associated with such connections will not therefore match either of the above policy rules, and will not be directed to either of the newly-added routing tables. Assuming an otherwise normal configuration, it will instead fall through to the main routing table.<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://openai.win/article/using-ipv6-at-home-and-on-server/#0a4853aef70e45a0a4fe9317253a5b16">[6]</a></div></blockquote><div class="notion-text notion-block-db983ca9bee945068a26956a78b9cbe3">如上所述，本地发出的数据包，应该是通过路由决策后确定往哪个接口发送后，才会将包的源地址(<code class="notion-inline-code">src address</code>)修改为对应接口上的IP。现在只有一个接口，很显然数据包都会往这个唯一的接口上发送。但这个接口上有三个IPv6地址，究竟是选择哪一个作为改写的源地址呢？</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-ef58f53d26914d01b2f9751594bf0206" data-id="ef58f53d26914d01b2f9751594bf0206"><span><div id="ef58f53d26914d01b2f9751594bf0206" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ef58f53d26914d01b2f9751594bf0206" title="单网卡多IP的源地址选择"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">单网卡多IP的源地址选择</span></span></h4><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">ip -6 route get &lt;DEST_IPV6_ADDR&gt;</code></pre><div class="notion-text notion-block-c3e123b0a57247a1947f6ee3b8a81eed">通过上述命令发现源地址地址总是网络接口上排在上面（最后添加）的IPv6地址，中间指定的网关地址虽然正确，但线路的选择似乎只和源地址相关。</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">ip -6 neigh</code></pre><div class="notion-text notion-block-f6ca9f056ab442fda6663a5b00e7b984">又查询本地的NS记录，发现三条线路的网关IPv6地址，对应的二层MAC地址均是相同的。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-798574abfe1648a8bb0bd642fbfbe2d3" data-id="798574abfe1648a8bb0bd642fbfbe2d3"><span><div id="798574abfe1648a8bb0bd642fbfbe2d3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#798574abfe1648a8bb0bd642fbfbe2d3" title="猜测&amp;验证"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">猜测&amp;验证</span></span></h4><div class="notion-text notion-block-36e490e1239d4e36ac344b09fa23fa8e">至此可以猜测上游交换机/网关是通过数据包中的源地址IP来确定发送的出口线路的。</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">ip -6 route add &lt;DEST_ADDR&gt; via &lt;NEXT_HOP&gt; dev &lt;DEV&gt; src &lt;SRC_ADDR&gt;</code></pre><div class="notion-text notion-block-4240222ba75b4d97b9b1d7b0eecf3dfe">添加路由后再次traceroute验证，果真如此。甚至是在系统标记某个IPv6地址为<code class="notion-inline-code">deprecated</code>状态时，仍可以通过该IPv6地址对应的线路正常收发数据（这是什么鬼？）。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-0a4853aef70e45a0a4fe9317253a5b16" data-id="0a4853aef70e45a0a4fe9317253a5b16"><span><div id="0a4853aef70e45a0a4fe9317253a5b16" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0a4853aef70e45a0a4fe9317253a5b16" title="📎 参考文章"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📎 参考文章</span></span></h2><ol start="1" class="notion-list notion-list-numbered notion-block-0d3c49a8fb794860b77f74dfa712bee0"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://zhuanlan.zhihu.com/p/146528034">移动宽带如何获取IPV6地址</a></li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-67e1a799e3d74e6aaed3cb22e6a0854e"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://blog.csdn.net/COCO56/article/details/104362070">记一次中国移动家用宽带设置成支持IPv6网络的经历</a></li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-e1c7470969c14f41b3ae9ea6fab06a5e"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://network.51cto.com/art/201910/603898.htm">IPv6系列-彻底弄明白有状态与无状态配置IPv6地址</a></li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-fe9afeb083e444c39aa5803f302e970d"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://koolshare.cn/forum.php?mod=viewthread&amp;tid=46415">【进阶类教程】多种无PD的情况下给内网配置IPv6的方法</a></li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-1a1c0c2cbf28489fb1749f710612de5c"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://gitee.com/hanwckf/scut_padavan_guide/blob/master/guide.md#ipv6">scut_padavan使用指南</a></li></ol><ol start="6" class="notion-list notion-list-numbered notion-block-03ca14c470a2441eaaeff969260078af"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="http://www.microhowto.info/howto/ensure_symmetric_routing_on_a_server_with_multiple_default_gateways.html">Ensure symmetric routing on a server with multiple default gateways</a></li></ol><div class="notion-blank notion-block-f0ba3c6bb8e343b2a24bbea6f8a6fba9"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Padavan插件开发笔记]]></title>
            <link>https://openai.win/article/how-to-build-a-padavan-plugin</link>
            <guid>https://openai.win/article/how-to-build-a-padavan-plugin</guid>
            <pubDate>Sat, 23 May 2020 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="container" class="mx-auto undefined"><main class="notion light-mode notion-page notion-block-a595065c231847619512ff23ffaf6854"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-26a77373ccee4ff9bb4d49d0b45bc4a7"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="⚠️">⚠️</span></div><div class="notion-callout-text">迁移自旧站，原始文章发表于2020-05-23，信息可能已部分失效</div></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-6152149dfab2460aa284b3c9e311355a" data-id="6152149dfab2460aa284b3c9e311355a"><span><div id="6152149dfab2460aa284b3c9e311355a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6152149dfab2460aa284b3c9e311355a" title="背景"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">背景</span></span></h2><div class="notion-text notion-block-60bc238c08dd45c99ae47dd1c5de60d2">月初偶然得知padavan固件在linux 3.4.x内核上有高人backport了3.7.x的<code class="notion-inline-code">SO_REUSEPORT</code>特性。对于拥有多核CPU的路由器来说，利用该特性可以显著提升SS所能承载的吞吐。手头上正好有个老旧的A3004NS，虽说有点不舍得荒野无灯的精致固件，还是拿来折腾一番。期间学习了一部分padavan固件编写插件的方法，下文以某插件为例，做简单的介绍及记录。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-b9521f006a214a4e837e1d2473668a3a" data-id="b9521f006a214a4e837e1d2473668a3a"><span><div id="b9521f006a214a4e837e1d2473668a3a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b9521f006a214a4e837e1d2473668a3a" title="准备"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">准备</span></span></h2><div class="notion-text notion-block-e683f8c25f91461eaf50988016d24ced">按照<code class="notion-inline-code">hanwckf</code>的<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://github.com/hanwckf/rt-n56u">rt-n56u</a>说明准备编译环境。这个固件是在原版的padavan基础上增加了国内常用的一些插件，同时适配了不少常见的padavan兼容路由，在编译配置上做了简化，其他固件可能在一部分配置上有所出入。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-ea68538907a94516a3b47f3c94cf0ad3" data-id="ea68538907a94516a3b47f3c94cf0ad3"><span><div id="ea68538907a94516a3b47f3c94cf0ad3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ea68538907a94516a3b47f3c94cf0ad3" title="插件相关文件"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">插件相关文件</span></span></h2><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-bash">trunk/
|-- configs
|   |-- templates
|   |   |-- A3004NS.config // 路由器适配文件，新增的插件编译选项开关可在此处追加
|   |   └-- ... 
|   └-- ...
|-- user
|   |-- Makefile // 控制所有插件的编译，和路由器配置联动达到插件可选化编译和打包
|   |-- A_PLUGIN
|   |   |-- Makefile // 控制单个插件的编译、打包文件产出，参照其他插件例子即可
|   |   └-- ...
|   |-- www // 页面文件，padavan中多数为asp
|   |   |-- Makefile // 新增插件若有相关页面文件，需要调整该文件
|   |   |-- state.js // 控制页面目录中的插件页面入口，新增插件需要调整该文件
|   |   |-- dict // i18n实现，按需调整
|   |   └-- n56u_ribbon_fixed
|   |       |-- PLUGIN_RELATED.asp // 插件页面相关的asp文件
|   |       └-- ...
|   |-- httpd
|   |   |-- variables.c // 插件相关nvram持久化数据的变量结构体定义
|   |   |-- web_ex.c // 处理asp后端逻辑的核心文件，主要关注暴露出来的函数，如update_variables_ex
|   |   |-- common.h // 关注variable，为结构体属性的类型
|   |   └-- ...
|   |-- shared
|   |   |-- defaults.c // 定义插件相关变量的默认值
|   |   └-- ... 
|   └-- ...
└-- ...</code></pre><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-d8933f830e9f4f869341debdd65a312b" data-id="d8933f830e9f4f869341debdd65a312b"><span><div id="d8933f830e9f4f869341debdd65a312b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d8933f830e9f4f869341debdd65a312b" title="插件代码"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">插件代码</span></span></h2><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4d5df27935df420aa13770d8fee8fd3d" data-id="4d5df27935df420aa13770d8fee8fd3d"><span><div id="4d5df27935df420aa13770d8fee8fd3d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4d5df27935df420aa13770d8fee8fd3d" title="插件核心代码"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">插件核心代码</span></span></h3><div class="notion-text notion-block-4f5a2e7a9ee546eca88bd7fa13a16030">对应目录中<code class="notion-inline-code">trunk/user/A_PLUGIN</code>，主要通过Makefile编译插件并将产出的（部分）二进制文件加入固件。多数情况下需要调整编译选项，参考其他插件例子即可。需要注意的一点是，在整体编译固件时插件时若需要重新运行configure，要删除产出的config_done文件。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-4f0a2b90f59d4722ae1f9559e6aa2537" data-id="4f0a2b90f59d4722ae1f9559e6aa2537"><span><div id="4f0a2b90f59d4722ae1f9559e6aa2537" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4f0a2b90f59d4722ae1f9559e6aa2537" title="编译开关"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">编译开关</span></span></h3><div class="notion-text notion-block-dc65ff41e9d54a1093bd0389fa14d6ba">在<code class="notion-inline-code">trunk/user/Makefile</code>中关联对应插件的目录，如<code class="notion-inline-code">dir_y += transmission</code>，即可添加transmission到编译列表。</div><div class="notion-text notion-block-befde7c7c2e94e1399f20912365df7aa">若需要通过路由器适配文件配置插件编译可选，则可以改为<code class="notion-inline-code">dir_$(CONFIG_FIRMWARE_INCLUDE_TRANSMISSION) += transmission</code>, 并在<code class="notion-inline-code">trunk/configs/templates/XXX.config</code>中配置<code class="notion-inline-code">CONFIG_FIRMWARE_INCLUDE_TRANSMISSION=y/n</code></div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-24f70d64019147a2ab20443c5e348264" data-id="24f70d64019147a2ab20443c5e348264"><span><div id="24f70d64019147a2ab20443c5e348264" class="notion-header-anchor"></div><a class="notion-hash-link" href="#24f70d64019147a2ab20443c5e348264" title="页面代码"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">页面代码</span></span></h3><div class="notion-text notion-block-28ccf43f44784d909cfa1f1cce4c8da5">页面代码一般简单插件仅需提供asp文件，若存在额外的js或css文件，同样放在<code class="notion-inline-code">trunk/user/www</code>目录下，调整<code class="notion-inline-code">trunk/user/www/Makefile</code>文件即可。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-e3192af1fd0e42de8b46373745e7e606" data-id="e3192af1fd0e42de8b46373745e7e606"><span><div id="e3192af1fd0e42de8b46373745e7e606" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e3192af1fd0e42de8b46373745e7e606" title="核心流程"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">核心流程</span></span></h4><div class="notion-text notion-block-f3e45d23211a4409a3776a4ba0fba6fb">页面的核心逻辑是提交的数据通过httpd服务暴露的函数入口更新到nvram或持久化的文件中。对此padavan约定了一套处理的通用流程。</div><ol start="1" class="notion-list notion-list-numbered notion-block-b73c25f91d9a48d4848b9acffed81ab2"><li>页面通过form post提交到<code class="notion-inline-code">start_apply.htm</code></li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-8ded125b5a434b969be46d142fdb8b1c"><li><code class="notion-inline-code">start_apply.htm</code>调用相应的后端<code class="notion-inline-code">update_variables</code>、<code class="notion-inline-code">asus_nvram_commit</code>以及<code class="notion-inline-code">notify_services</code></li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-58c4e1ad55164997a29920b1b8e34d1c"><li><code class="notion-inline-code">update_variables</code>通过参数中的<code class="notion-inline-code">sid_list</code>找到对应的在<code class="notion-inline-code">trunk/user/httpd/variables.c</code>中定义的结构体变量，同时将其他参数映射到结构体定义的成员变量上。校验通过后，逐一更新到nvram或写到相应文件（详见<code class="notion-inline-code">trunk/user/httpd/web_ex.c</code>中的<code class="notion-inline-code">update_variables_ex</code>函数逻辑）</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-8503dbafd1df48d7825c6f4258f65874"><li>提交变更到nvram（持久化）</li></ol><ol start="5" class="notion-list notion-list-numbered notion-block-c79aeadf0dc4450795ea3da6f91ca847"><li>若需要，通知触发相关关服务，如系统重启等操作</li></ol><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-d89831c0b446448d9890732686584438" data-id="d89831c0b446448d9890732686584438"><span><div id="d89831c0b446448d9890732686584438" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d89831c0b446448d9890732686584438" title="nvram/文件内容输出"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">nvram/文件内容输出</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-966c883f0bec4a6d93127c01b3cdd6f3"><li>页面上展示nvram中的变量，使用<code class="notion-inline-code">&lt;% nvram_get_x(&quot;&quot;,&quot;VARIABLE&quot;); %&gt;</code></li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-3ba587186d114fa9816d19c4692f2dba"><li>页面上输出文件内容，使用<code class="notion-inline-code">&lt;% nvram_dump(&quot;PREFIX.VARIABLE&quot;, &quot;&quot;); %&gt;</code></li></ol><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-dd0f121ad55c49129f5c9b7317dcfb95" data-id="dd0f121ad55c49129f5c9b7317dcfb95"><span><div id="dd0f121ad55c49129f5c9b7317dcfb95" class="notion-header-anchor"></div><a class="notion-hash-link" href="#dd0f121ad55c49129f5c9b7317dcfb95" title="nvram变量更新"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">nvram变量更新</span></span></h4><div class="notion-text notion-block-e3366923a08d4838b4c8601d70854d90">一般情况无需关注，提交的参数名与插件结构体中的变量名相同即可。如：</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-c">// trunk/user/httpd/variables.c
struct variable variables_dnsforwarderConf[] = {
	{&quot;dns_forwarder_enable&quot;, &quot;&quot;, NULL, EVM_RESTART_DNSFORWARDER},
	{&quot;dns_forwarder_bind&quot;, &quot;&quot;, NULL, EVM_RESTART_DNSFORWARDER},
	{&quot;dns_forwarder_port&quot;, &quot;&quot;, NULL, EVM_RESTART_DNSFORWARDER},
	{&quot;dns_forwarder_server&quot;, &quot;&quot;, NULL, EVM_RESTART_DNSFORWARDER},
	{0,0,0,0}
};
...
struct svcLink svcLinks[] = {
	...
	{&quot;dnsforwarderConf&quot;,		variables_dnsforwarderConf},
	...
}</code></pre><div class="notion-text notion-block-5d08a19456f644cbb88989a02329eae1">http提交参数中包含<code class="notion-inline-code">dns_forwarder_server</code>，同时<code class="notion-inline-code">sid_list</code>指定为<code class="notion-inline-code">dnsforwarderConf；</code>， 即可更新到nvram中的<code class="notion-inline-code">dns_forwarder_server</code>变量。</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-10c56b8c9e514a9baf82f065f9f005ac" data-id="10c56b8c9e514a9baf82f065f9f005ac"><span><div id="10c56b8c9e514a9baf82f065f9f005ac" class="notion-header-anchor"></div><a class="notion-hash-link" href="#10c56b8c9e514a9baf82f065f9f005ac" title="文件内容更新"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">文件内容更新</span></span></h4><div class="notion-text notion-block-96bf61bd29b24e8ba6f164d9d7f988e4">关于rom storage中文件内容的更新，是通过将结构体变量单元（<code class="notion-inline-code">variable</code>，见<code class="notion-inline-code">trunk/user/httpd/common.h</code>）中的<code class="notion-inline-code">longname</code>设置为<code class="notion-inline-code">File</code>，以在<code class="notion-inline-code">trunk/user/httpd/web_ex.c</code>的<code class="notion-inline-code">validate_asp_apply</code>函数改写为对应的文件路径实现更新的。如：</div><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-c">// trunk/user/httpd/variables.c
{&quot;scripts.start_script.sh&quot;, &quot;File&quot;, NULL, EVM_BLOCK_UNSAFE},</code></pre><pre class="notion-code"><div class="notion-code-copy"><div class="notion-code-copy-button"><svg fill="currentColor" viewBox="0 0 16 16" width="1em" version="1.1"><path fill-rule="evenodd" d="M0 6.75C0 5.784.784 5 1.75 5h1.5a.75.75 0 010 1.5h-1.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-1.5a.75.75 0 011.5 0v1.5A1.75 1.75 0 019.25 16h-7.5A1.75 1.75 0 010 14.25v-7.5z"></path><path fill-rule="evenodd" d="M5 1.75C5 .784 5.784 0 6.75 0h7.5C15.216 0 16 .784 16 1.75v7.5A1.75 1.75 0 0114.25 11h-7.5A1.75 1.75 0 015 9.25v-7.5zm1.75-.25a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h7.5a.25.25 0 00.25-.25v-7.5a.25.25 0 00-.25-.25h-7.5z"></path></svg></div></div><code class="language-c">// trunk/user/httpd/web_ex.c - validate_asp_apply
...
} else if (!strncmp(v-&gt;name, &quot;scripts.&quot;, 8)) {
	if (write_textarea_to_file(value, STORAGE_SCRIPTS_DIR, file_name))
		restart_needed_bits |= event_mask;
...</code></pre><div class="notion-text notion-block-ee29146e04184f4b8163a1fc04a84360">通过阅读代码可知，文件类型的<code class="notion-inline-code">variable</code>有多个预定义的路径（见<code class="notion-inline-code">trunk/user/httpd/httpd.h</code>），普通插件一般使用<code class="notion-inline-code">scripts</code>目录即可，变量名格式需要为<code class="notion-inline-code">scripts.xxx</code>，有如下映射:</div><blockquote class="notion-quote notion-block-8f1bac20104f4292aa246e3ece833a9c"><div><code class="notion-inline-code">scripts.FILE_NAME</code> -&gt; <code class="notion-inline-code">/etc/storage/FILE_NAME</code></div></blockquote><div class="notion-blank notion-block-fb3e036c690b41c2b5b1578bf83d835c"> </div></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>