Reducing Impact of deepcopies in callbacks/batched CPU interface
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- julia
- Lĩnh vực
- performance
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện kết quả profiling cho bài kiểm tra CSMC và truy vết nơi các state được deep-copy vào callback container. Đọc callback interface và batched CPU interface, sau đó so sánh với GPU interface hiện có. Được xem là hoàn tất khi một phương án đã thống nhất được triển khai và có bằng chứng cho thấy tính an toàn của callback state cũng như hiệu năng smoothing/PG đã được xử lý.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I have been profiling some of our unit tests to see if we can reduce the runtime of our CI pipeline (and learn more about the bottlenecks of our implementation.
I was surprised to find that for the CSMC test, a surprising amount of time is taken deepcopying the states over to the callback container.
This currently needs to be done because we make no promises that the state you save in the callback container will not later be modified by predict/update.
This is probably something we should address since this will make smoothing/PG much slower than it needs to be.
There are two options:
- We start to provide some guarantees that we won't modify states (or have a safe non in-place, plus an in-place version if we want)
- We provide a batched CPU interface
To elaborate on the latter point, the reason why the deepcopies are so slow is because we're copying a load of tiny vectors/matrices. This has two problems:
- If the vectors are small (less than 16 Float64s), they will be padded in memory so are not adjacent, making reading slower
- Many read operations are needed rather than one.
If instead, these were stored compactly in a matrix, copies are 100–1000x faster
julia> x = [rand(2) for _ in 1:10000];
julia> y = rand(2, 10000);
julia> @benchmark deepcopy($x)
BenchmarkTools.Trial: 2095 samples with 1 evaluation per sample.
Range (min … max): 1.910 ms … 8.215 ms ┊ GC (min … max): 0.00% … 67.91%
Time (median): 2.185 ms ┊ GC (median): 0.00%
Time (mean ± σ): 2.385 ms ± 807.511 μs ┊ GC (mean ± σ): 7.41% ± 13.06%
▂▇██▇▇▆▅▃▂ ▁
██████████▇▆▄▅▅▄▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▄▅▅▆▇▆█▇▇█▇▆█▇ █
1.91 ms Histogram: log(frequency) by time 5.99 ms <
Memory estimate: 3.38 MiB, allocs estimate: 69001.
julia> @benchmark deepcopy($y)
BenchmarkTools.Trial: 10000 samples with 8 evaluations per sample.
Range (min … max): 6.404 μs … 255.764 μs ┊ GC (min … max): 0.00% … 96.48%
Time (median): 7.296 μs ┊ GC (median): 0.00%
Time (mean ± σ): 9.726 μs ± 14.747 μs ┊ GC (mean ± σ): 21.57% ± 13.47%
█▅ ▁
██▇▄▁▃▁▁▁▁▁▃▃▁▁▁▁▁▁▁▄▁▁▁▁▃▁▃▃▁▃▄▃▃▆▆▃▁▁▁▁▁▁▁▁▁▁▁▃▁▃▄▅▅▆▇▇▇▇ █
6.4 μs Histogram: log(frequency) by time 96.8 μs <
Memory estimate: 156.67 KiB, allocs estimate: 6.
julia> x = [rand(32) for _ in 1:1000];
julia> y = rand(32, 1000);
julia> @benchmark deepcopy($x)
BenchmarkTools.Trial: 10000 samples with 1 evaluation per sample.
Range (min … max): 139.110 μs … 10.880 ms ┊ GC (min … max): 0.00% … 97.60%
Time (median): 156.897 μs ┊ GC (median): 0.00%
Time (mean ± σ): 207.138 μs ± 374.546 μs ┊ GC (mean ± σ): 18.86% ± 10.30%
█
█▃▃▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▂▂▂▂▂ ▂
139 μs Histogram: frequency by time 2.97 ms <
Memory estimate: 517.55 KiB, allocs estimate: 5997.
julia> @benchmark deepcopy($y)
BenchmarkTools.Trial: 10000 samples with 4 evaluations per sample.
Range (min … max): 9.720 μs … 430.233 μs ┊ GC (min … max): 0.00% … 96.79%
Time (median): 11.256 μs ┊ GC (median): 0.00%
Time (mean ± σ): 15.797 μs ± 28.136 μs ┊ GC (mean ± σ): 21.13% ± 11.88%
█▃ ▁
██▄▃▁▄▃▃▃▅▁▁▁▁▁▄▄▁▁▄▄▁▄▃▁▆▆▇▇▆▄▁▃▃▄▄▃▃▁▁▁▁▁▁▁▁▁▁▁▃▁▁▁▃▃▄▅▆▇▇ █
9.72 μs Histogram: log(frequency) by time 188 μs <
Memory estimate: 250.42 KiB, allocs estimate: 6.
This is similar to the GPU interface so it will be not be much work to create similar wrappers to describe how to translate a regular KF into this batched form (I can provide more details at a later point).
- Ngôn ngữ chính
- Julia
- Star
- 12
- Fork
- 7
- Merge trung bình
- 42 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TuringLang/SSMProblems.jl
-
Updating model parameters in a Gibbs sampler with CSMCCó thể làm lại được @THargreaves đã nhận 95 ngày trước và không có pull request nào đang mở. Đang mở
TuringLang/SSMProblems.jl#186 · 1 bình luận · 1 người được giao ·
-
Naming Convention ConsistencyĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
TuringLang/SSMProblems.jl#150 · 1 bình luận ·
-
Implemented CI-based unit testsĐang mởpriority-high testing
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
TuringLang/SSMProblems.jl#126 ·
-
Add an example for Levy SSM problemCó thể làm lại được @THargreaves đã nhận 292 ngày trước và không có pull request nào đang mở. Đang mở
TuringLang/SSMProblems.jl#68 · 1 người được giao ·
Tất cả issue của TuringLang/SSMProblems.jl
Issue tương tự
-
Release CorleoneInverse as 0.1.1Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
SciML/Corleone.jl#200 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
JuliaAI/MLJTransforms.jl#120 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
exercism/julia#1205 · 3 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
SciML/OrdinaryDiffEq.jl#5175 ·
Maintainer thường phản hồi trong vòng 1 ngày