Skip to content

Commit de451c9

Browse files
committed
feat(julia): load trained Flux weights in gnn_endpoint.jl, cosine as fallback
load_gnn_model() now tries three candidate directories in order: gnn_ranker/ → best_model/ → final_model/ (all under models/neural/, written by run_training*.jl) The cosine similarity path (rank_with_cosine) is kept intact and reachable but only runs when all candidate directories are absent or fail to deserialise — it is the genuine missing-model fallback for CI smoke runs, not the default. The warning message now explains how to produce real weights (just train-cpu). https://claude.ai/code/session_01YPqu7gti4azBach6ZvpRFJ
1 parent 06324d8 commit de451c9

1 file changed

Lines changed: 21 additions & 11 deletions

File tree

src/julia/api/gnn_endpoint.jl

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,37 @@ const TOTAL_TRAINING_RECORDS = Ref{Int}(0)
4242
"""
4343
load_gnn_model(models_dir::String)
4444
45-
Load the GNN premise ranker model from disk.
46-
Falls back to creating a fresh (untrained) model if no checkpoint exists.
45+
Load the GNN premise ranker model from disk. Tries, in order:
46+
1. `models/neural/gnn_ranker/` — directory written by run_training*.jl
47+
2. `models/neural/best_model/` — early-stopping checkpoint
48+
3. `models/neural/final_model/` — last epoch checkpoint
49+
50+
Only falls back to the cosine path (GNN_MODEL[] = nothing) when none of
51+
the above directories exist or all fail to deserialise. The cosine path
52+
is the genuine missing-model fallback for CI smoke runs.
4753
"""
4854
function load_gnn_model(models_dir::String)
49-
model_path = joinpath(models_dir, "neural", "gnn_ranker")
50-
51-
if isdir(model_path)
52-
@info "Loading GNN model from $model_path"
55+
candidate_dirs = [
56+
joinpath(models_dir, "neural", "gnn_ranker"),
57+
joinpath(models_dir, "neural", "best_model"),
58+
joinpath(models_dir, "neural", "final_model"),
59+
]
60+
61+
for model_path in candidate_dirs
62+
isdir(model_path) || continue
63+
@info "Trying to load GNN model from $model_path"
5364
try
5465
solver = load_solver(model_path)
5566
GNN_MODEL[] = solver
56-
@info "GNN model loaded successfully"
67+
@info "GNN model loaded successfully from $model_path"
5768
return true
5869
catch e
59-
@warn "Failed to load GNN model: $e"
70+
@warn "Failed to load GNN model from $model_path: $e"
6071
end
6172
end
6273

63-
@info "No trained GNN model found — creating fresh model for inference"
64-
# Create a minimal model with default configuration for the endpoint
65-
# to respond (scores will be random until training completes)
74+
# All candidates exhausted — cosine fallback is genuine missing-model path.
75+
@warn "No trained GNN model found in $(joinpath(models_dir, "neural")) — ranking will use cosine similarity until weights are trained (run: just train-cpu)"
6676
GNN_MODEL[] = nothing
6777
return false
6878
end

0 commit comments

Comments
 (0)