有没有办法减少 Julia Flux 梯度调用的垃圾收集和/或动态调度?
有谁知道是否有任何方法可以减少通量中梯度调用的 gc 和/或动态调度量?我尝试使用 FastClosures.jl ,以及将损失包装到可调用结构中以防止闭包以及随后的 Core.Box 调用,但似乎没有什么明显的区别。
MWE:
using Flux
function get_grad(dnn, x, y)
p = params(dnn)
g = gradient(p) do
Flux.mse(dnn(x),y)
end
return g
end
const DNN = Dense(3, 2)
const X = rand(Float32, 3)
const Y = rand(Float32, 2)
@profiler for _ in 1:10_000; get_grad(DNN, X, Y); end
配置文件(橙色 - 动态调度,红色 - 垃圾收集,动态调度)
Does anyone know if there's any way to reduce the amount of gc and/or dynamic dispatch for a gradient call in flux? I've tried using FastClosures.jl, as well as wrapping loss into a callable struct to prevent closures and consequently Core.Box calls, but nothing seems to make an appreciable difference.
MWE:
using Flux
function get_grad(dnn, x, y)
p = params(dnn)
g = gradient(p) do
Flux.mse(dnn(x),y)
end
return g
end
const DNN = Dense(3, 2)
const X = rand(Float32, 3)
const Y = rand(Float32, 2)
@profiler for _ in 1:10_000; get_grad(DNN, X, Y); end
Profile (orange - dynamic dispatch, red - garbage collection, dynamic dispatch)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论