[BUG]: TemplateExpressionSpec and loss_function_expression not compatible with multiprocessing #939
-
What happened?Combining TemplateExpressionSpec and a custom loss function ( Version1.5.8 Operating SystemmacOS Package Managerpip InterfaceScript (i.e., Relevant log outputExtra InfoA minimal example: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Ah. This error is not due to multiprocessing. It's actually due to a couple unrelated issues:
You can fix it with the following patch: - function eval_loss(tree, dataset::Dataset{T,L}, options, idx)::L where {T,L}
+ function my_custom_loss(tree, dataset::Dataset{T,L}, options, idx=nothing)::L where {T,L}Also, in the latest PySR/SymbolicRegression.jl, you don't need the - function eval_loss(tree, dataset::Dataset{T,L}, options, idx)::L where {T,L}
+ function my_custom_loss(tree, dataset::Dataset{T,L}, options)::L where {T,L}
- x = idx === nothing ? dataset.X : view(dataset.X, :, idx)
- y = idx === nothing ? dataset.y : view(dataset.y, idx)
+ x = dataset.X
+ y = dataset.y
prediction, flag = eval_tree_array(tree, x, options)
if !flag
return L(Inf)
end
errors = (prediction .- y) .^2
return mean(errors)
end |
Beta Was this translation helpful? Give feedback.
Ah. This error is not due to multiprocessing. It's actually due to a couple unrelated issues:
eval_lossis already used as the internal name, and this appears to be overwriting it somehow (I think). And it seems like it is not overwriting it on the worker process, which leads to a conflict.idx=nothingrather than justidx.You can fix it with the following patch:
Also, in the latest PySR/SymbolicRegression.jl,…