-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #491 from malmaud/eager_mode
Eager mode
- Loading branch information
Showing
25 changed files
with
111,326 additions
and
2,559 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using DifferentialEquations | ||
|
||
f(u,p,t)=1.01 .* u | ||
|
||
u0=constant(0.5) | ||
tspan=(0.0,1.0) | ||
prob=ODEProblem(f, u0, tspan) | ||
s=solve(prob) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using TensorFlow | ||
tf=TensorFlow | ||
tf.enable_eager_execution() | ||
m = tf.Sequential() | ||
|
||
tf.add(m, tf.Dense(3,10)) | ||
tf.add(m, tf.Relu()) | ||
tf.add(m, tf.Dense(10, 3)) | ||
|
||
x=constant(randn(5,3)) | ||
y=3x+5 | ||
tf.compile(m, optimizer=tf.SGD(lr=1e-4), loss=tf.mse) | ||
tf.fit(m, x, y, n_epochs=200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
abstract type Context | ||
end | ||
|
||
struct ContextStack | ||
contexts::Vector{Context} | ||
end | ||
|
||
ContextStack() = ContextStack(Context[]) | ||
|
||
function Base.push!(stack::ContextStack, context::Context) | ||
push!(stack.contexts, context) | ||
end | ||
|
||
function Base.pop!(stack::ContextStack) | ||
pop!(stack.contexts) | ||
end | ||
|
||
function default_context() | ||
return [ExecutionMode(eager=false)] | ||
end | ||
|
||
function context_value(context_type) | ||
return global_context[context_type] | ||
end | ||
|
||
function Base.getindex(c::ContextStack, context_type) | ||
value = nothing | ||
for context in c.contexts | ||
if isa(context, context_type) | ||
value = context | ||
end | ||
end | ||
return value | ||
end | ||
|
||
function with_context(block, ctx) | ||
push!(global_context, ctx) | ||
res = block() | ||
# This assumes the block doesn't adjust the context. We should pop explicitly the pushed context. | ||
pop!(global_context) | ||
return res | ||
end | ||
|
||
const global_context = ContextStack() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.