Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Use ChainRules for operators

Đang mở
#22 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

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ái cấu trúc
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
julia
Lĩnh vực
machine-learning

Hướng nghiên cứu

Bắt đầu bằng cách đọc src/Nonlinear/univariate_expressions_generator.jl và phần dispatch toán tử xung quanh src/Nonlinear/operators.jl:570-582. Theo dõi cách ReverseAD biểu diễn các toán tử cổ điển, đã đăng ký và do người dùng định nghĩa, sau đó so sánh luồng đó với dispatch và fallback được đề xuất theo phong cách ChainRules. Công việc được xem là hoàn tất khi đã quyết định thiết kế, cập nhật phần xử lý toán tử và có bằng chứng cho thấy các trường hợp được hỗ trợ tránh được những lo ngại hiện tại về tính không ổn định kiểu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Currently, the approach in ReverseAD is to generate the symbolic expression of the first and second-order derivatives for classical univariate functions using Calculus
https://github.com/jump-dev/MathOptInterface.jl/blob/100eab2e669e73689e1dc214391d97c24402e35c/src/Nonlinear/univariate_expressions_generator.jl
Then, given a representation of the operator as an Int, we do an hard-coded binary search to evaluate a O(log(n)) number of Int comparison instead of a O(n) number of comparison:
https://github.com/jump-dev/MathOptInterface.jl/blob/100eab2e669e73689e1dc214391d97c24402e35c/src/Nonlinear/operators.jl#L570-L582
I'm wondering whether we could get closer to ChainRules instead like other Julia AD framework.
The naive way to do this would be

op = :tanh
f = eval(op)
value_and_derivative(f, 1)

The issue is that, because the value of op is discovered at run-time, the type of f is type-unstable.
But we can use the same trick with the if-else and do

if op == :tanh
    value_and_derivative(tanh, x)
elseif op == :tan
    value_and_derivative(tan, x)
elseif ...
else
   value_and_derivative(eval(op), x)
end

Again, we can do a binary search instead of just a list of if-else.
So, for a fixed number of symbols, we avoid the type-instability thanks to the if-else and we have a fallback for the other ones with the eval.
That would also mean that for registered functions, we need to implement a method and just rely on multiple dispatch instead of adding an operators to the list of user-defined operators, user-defined operators already trigger a type-instability when they are called anyway.

Ngôn ngữ chính
Julia
Star
6
Fork
0
Merge trung bình
2 ngày 8 giờ
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của blegat/ArrayDiff.jl

Tất cả issue của blegat/ArrayDiff.jl

Issue tương tự

Thêm issue về Julia

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.