惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Troy Hunt's Blog
F
Fortinet All Blogs
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
The Register - Security
The Register - Security
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
月光博客
月光博客
V
Vulnerabilities – Threatpost
S
Securelist
S
SegmentFault 最新的问题
T
Threat Research - Cisco Blogs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Privacy International News Feed
S
Schneier on Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
GbyAI
GbyAI
Apple Machine Learning Research
Apple Machine Learning Research
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
美团技术团队
Cyberwarzone
Cyberwarzone
C
Cisco Blogs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google Online Security Blog
Google Online Security Blog
M
MIT News - Artificial intelligence
U
Unit 42
V
V2EX
C
CERT Recently Published Vulnerability Notes
云风的 BLOG
云风的 BLOG
B
Blog
博客园 - 叶小钗
Attack and Defense Labs
Attack and Defense Labs
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Hacker News: Ask HN
Hacker News: Ask HN
博客园 - Franky
Engineering at Meta
Engineering at Meta
Schneier on Security
Schneier on Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Blog of Author Tim Ferriss
IT之家
IT之家
W
WeLiveSecurity
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
Martin Fowler
Martin Fowler
SecWiki News
SecWiki News

Benson's blog

Enjoy life Internship AI on academic research How AI Will Change the Mobile Ecosystem Look ahead Goodbye 2025 Hacker News to Kindle Another project How to imporve english Introduction of Fraud detection PopTranslate Last day in netease Better idea between Copilot-typed and CLI-typed assistant Gemini-cli LLM Post-Training experience Papers I readed recently about LLM application Difference between LLMs and traditional computer technology GRPO Weekly-#26 AI Application Weekly-#25 AI infra and application Weekly-#24 First week as LLM inference engineer Weekly-#23 seeking job Weekly-#22 2025 New Year AutoSwitch Translate Goodbye 2024 Weekly-#20 Breaking of glass Cross Entropy Loss of Triton Weekly-#18 Cross Entropy Loss of Triton Weekly-#17 Triton Puzzles Weekly-#16 AutoBuilder Weekly-#15 Starting of tanble tennis Weekly-#14 Accident in life Weekly-#13 Trying of xiaohongshu Weekly-#12 summary of LLM acceleration Outline of LLM acceleration Weekly-#11 Copilot-type products Weekly-#10 Preparation for next journey Weekly-#9 Startup of YouTube Notes of flash-attention How to learn knowledge in new fields? Weekly-#8 Start Reading Notes of LoRA Acceleration of LLM - Matrix Multiplication Weekly-#8 Summary for two month Weekly-#7 Staying home Weekly-#6 Cost of PopTranslate Weekly-#5 Updating of PopTranslate Validated example of LLM acceleration Weekly-#4 First insight of LLM accelerate Weekly-#3 PopTranslate Weekly-#2 The fail of first product Weekly-#1 First week of indie develop slack迁移discord 雅思备考 2024Q3 中文博客合集 English Diary in May 五一游记 开始休假 离职前的状态 2024-01-01 duckdb 看懂的第一个PR learning english in October learning english in September learning english in August top hack news 收集 大模型调研 自动驾驶的小玩具 旅游 扬州+苏州 small talk of learning english 新年新气象-碎碎念 刷剧 感染新冠 强化学习简介 神经网络解释性 全局的模型无关解释方法合集 社区发现算法概览 图神经网络入门(GNN) 我的第一款 iOS APP AtCoder Beginner Contest 268 人的信息输入方式对比 重叠社区检测 人穷极一生到底在追求什么 重拾生活规划 社区发现算法 - Louvain 《幸福的方法》 读《人类简史》有感 妙峰山骑行 黑客帝国 特征交互 特征工程 累计局部效应图 模型解释性-PDP 模型解释性 Web3 入门科普 总结 2022.4 孪生网络做 query 相似度任务 学习 2022.4 Imagen 读论文 用CNN做query相似度任务
DeBERTa
Benson · 2022-05-31 · via Benson's blog

参考原 bert 参数,A100 机器上跑一轮得3个小时,算力是在顶不住,放弃了。 所以就只用 paddle 实现一下 DeBERTa,跑通 demo 锻炼下编码能力,过程中主要是 disentangled attention 实现起来有点复杂。

class="highlight">

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def _process_qkv(self, x):
    x = paddle.reshape(x = x, shape = [0, 0, self.nhead, self.dim_head])
    x = paddle.transpose(x = x, perm = [0, 2, 1, 3])
    return x

def MultiHeadAttention(self, input, p, ptq):
    qr = self._process_qkv(self.wqr(p))
    kr = self._process_qkv(self.wkr(p))
    qc = self._process_qkv(self.wqc(input))
    kc = self._process_qkv(self.wkc(input))
    vc = self._process_qkv(self.wvc(input))

    qc_kr = paddle.matmul(qc, paddle.transpose(x = kr, perm = [0, 1, 3, 2]))
    qc_kr_ = []
    for i in range(self.max_len):
        qc_kr_.append(paddle.gather(qc_kr[:, :, i, :], axis = 2, index = ptq[i, :]))
    qc_kr = paddle.to_tensor(qc_kr_)
    qc_kr = paddle.transpose(qc_kr, perm = [1, 2, 0, 3])

    kc_qr = paddle.matmul(kc, paddle.transpose(x = qr, perm = [0, 1, 3, 2]))
    kc_qr = paddle.transpose(kc_qr, perm = [0, 1, 3, 2])
    kc_qr_ = []
    ptk = paddle.transpose(x = ptq, perm = [1, 0])
    for i in range(self.max_len):
        kc_qr_.append(paddle.gather(kc_qr[:, :, :, i], axis = 2, index = ptk[:, i]))
    kc_qr = paddle.to_tensor(kc_qr_)
    kc_qr = paddle.transpose(kc_qr, perm = [1, 2, 0, 3])

    weight = paddle.matmul(qc, paddle.transpose(x = kc, perm = [0, 1, 3, 2])) + qc_kr + kc_qr

    val = paddle.matmul(F.softmax(weight * ((self.dim_head*3)**0.5)), vc)
    val = paddle.transpose(x = val, perm = [0, 2, 1, 3])
    val = paddle.reshape(x = val, shape = [0, 0, self.d_model])
    return val

其他

数据集过大

可以逐行读入,代码中自己设置随机

class="highlight">

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
def __iter__(self):
    azip = zipfile.ZipFile(self.intpus)
    self.cache = []
    self.cache_cnt = 10000 # 缓存池大小
    for fi in azip.namelist():
        if fi.endswith('/'): continue
        for line in azip.open(fi):
            line = json.loads(line.decode("utf-8", "ignore"))
            text = line['title'].strip('\n') + ' ' + line['text'].strip('\n')
            self.cache.append(text)
            if len(self.cache) > self.cache_cnt:
                text = random.choice(self.cache)
                self.cache.remove(text)
                idx, mask_token, mask_idx = self.__process__(text)
                yield idx, mask_token, mask_idx
    while len(self.cache) > 0:
        text = random.choice(self.cache)
        self.cache.remove(text)
        idx, mask_token, mask_idx = self.__process__(text)
        yield idx, mask_token, mask_idx

逐行读入:DataLoader提供了IterableDataset 自己写随机逻辑:感谢神秘网友的答案

gather 问题

DeBERTa 实现起来比较复杂的两个步骤

75179-kcyduoy5fb.png

pytorch 中有对应的 gather 接口可以简单实现,但 paddle 的 gather 函数实现原理不同,paddle 中的 index 只能是一个一维函数,重定向 index 时无法参考其他维度的值,这样实现起来就更复杂一些。详细对比

其他优化

绝对位置编码:attention中引入了相对位置编码,除此之外,mlm 预测时还引入了绝对位置编码,缺一不可。 样本扰动:传统机器学习实验时可以添加输入扰动提升模型鲁棒性,但 nlp 中 word太多、参数量太大(个人觉得主要还是 word多的原因)导致扰动的试验效果不稳定,原文发现在 layer normalized 之后的 embedding 上添加扰动,对提升扰动训练的稳定性很有帮助。

Trending Tags