@mcmcjs/julia 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fitlib.jl +15 -3
- package/package.json +1 -1
package/dist/fitlib.jl
CHANGED
|
@@ -501,11 +501,23 @@ end
|
|
|
501
501
|
# Resolve the model entry function: use the requested name, falling back to the
|
|
502
502
|
# conventional build_model. This lets a request leave the entry implicit, or name a
|
|
503
503
|
# custom entry that a given model file does not define (then build_model is used).
|
|
504
|
+
# Load the user's model file into a throwaway module. Isolation keeps repeated
|
|
505
|
+
# requests in the persistent worker from colliding on names (e.g. two models each
|
|
506
|
+
# defining `const model_def`), and confines the model's globals to their own scope.
|
|
507
|
+
function load_model_module(path)
|
|
508
|
+
mod = Module(gensym(:UserModel))
|
|
509
|
+
Base.include(mod, abspath(path))
|
|
510
|
+
return mod
|
|
511
|
+
end
|
|
512
|
+
|
|
504
513
|
function resolve_entry(mod, requested)
|
|
505
514
|
for name in (requested, "build_model")
|
|
506
515
|
name === nothing && continue
|
|
507
516
|
sym = Symbol(name)
|
|
508
|
-
|
|
517
|
+
# The model was just include'd, so its bindings live in a newer world than
|
|
518
|
+
# this frame; resolve them in the latest world to avoid a Julia 1.12
|
|
519
|
+
# world-age warning on the access.
|
|
520
|
+
Base.invokelatest(isdefined, mod, sym) && return Base.invokelatest(getfield, mod, sym)
|
|
509
521
|
end
|
|
510
522
|
error("model file defines no entry function (looked for $(requested) and build_model)")
|
|
511
523
|
end
|
|
@@ -520,8 +532,8 @@ function handle_request(request)
|
|
|
520
532
|
try
|
|
521
533
|
Random.seed!(Int(request["seed"]))
|
|
522
534
|
rng = StableRNG(Int(request["seed"]))
|
|
523
|
-
|
|
524
|
-
entry = resolve_entry(
|
|
535
|
+
modelmod = load_model_module(request["model"]["file"])
|
|
536
|
+
entry = resolve_entry(modelmod, get(request["model"], "entry", nothing))
|
|
525
537
|
|
|
526
538
|
wire = if mode == "predict"
|
|
527
539
|
if backend == "juliabugs"
|