Skip to content

Commit 8b6e5f9

Browse files
author
Giovanni Amorim
committed
change place to check time limit on GradientMode and implements on GradientMPIMode
1 parent 06229d6 commit 8b6e5f9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/optimizers/gradient.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ function train_with_gradient!(
7171
best_C = C
7272
best_θ = extract_params(model.forecast)
7373
end
74+
end
7475

75-
# check time limit reach
76-
if time() - start_time > time_limit
77-
break
78-
end
76+
# check time limit reach
77+
if time() - start_time > time_limit
78+
break
7979
end
8080

8181
# take gradient step

src/optimizers/gradient_mpi.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ function train_with_gradient_mpi!(
1717
verbose = get(params, :verbose, true)
1818
compute_cost_every = get(params, :compute_cost_every, 1)
1919
mpi_finalize = get(params, :mpi_finalize, true)
20+
time_limit = get(params, :time_limit, Inf)
2021

2122
JQM.mpi_init()
2223

2324
# init parameters
25+
start_time = time()
2426
is_done = false
2527
best_C = Inf
2628
best_θ = []
@@ -111,7 +113,12 @@ function train_with_gradient_mpi!(
111113
best_θ = curr_θ
112114
end
113115
end
114-
116+
117+
# check time limit reach
118+
if time() - start_time > time_limit
119+
break
120+
end
121+
115122
# take gradient step (if not last epoch)
116123
apply_gradient!(model.forecast, dCdy, epochx, rule)
117124
end

0 commit comments

Comments
 (0)