-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Eager mode #491
WIP: Eager mode #491
Conversation
src/eager.jl
Outdated
end | ||
|
||
|
||
mutable struct TensorHandle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't need to be mutable does it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does so that it can have a finalizer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might be right there.
Though IIRC you can hook the Finalizer directly to the Ptr
Codecov Report
@@ Coverage Diff @@
## master #491 +/- ##
==========================================
- Coverage 49.04% 48.56% -0.48%
==========================================
Files 79 80 +1
Lines 2659 2685 +26
==========================================
Hits 1304 1304
- Misses 1355 1381 +26
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #491 +/- ##
==========================================
+ Coverage 49.04% 53.17% +4.13%
==========================================
Files 79 83 +4
Lines 2661 2642 -19
==========================================
+ Hits 1305 1405 +100
+ Misses 1356 1237 -119
Continue to review full report at Codecov.
|
src/eager.jl
Outdated
end | ||
|
||
function setindex!(op::EagerOp, dtype::DataType, attr_name) | ||
@tfcall(:TFE_OpSetAttrType, Cvoid, (Ptr{Cvoid}, Cstring, TF_DataType), op, attr_name, dtype|>jl_to_df_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tfcall(:TFE_OpSetAttrType, Cvoid, (Ptr{Cvoid}, Cstring, TF_DataType), op, attr_name, dtype|>jl_to_df_type) | |
tf_dtype = jl_to_df_type(dtype) | |
@tfcall(:TFE_OpSetAttrType, Cvoid, (Ptr{Cvoid}, Cstring, TF_DataType), op, attr_name, tf_dtype) |
src/eager.jl
Outdated
end | ||
|
||
function set_attr_list(op::EagerOp, attr_name, list::Vector{<:Integer}) | ||
list = Int64[Int64(x) for x in list] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list = Int64[Int64(x) for x in list] | |
list = Int64.(list) |
src/eager.jl
Outdated
end | ||
|
||
function set_attr_list(op::EagerOp, attr_name, list::Vector{<:AbstractFloat}) | ||
list = Float32[Float32(x) for x in list] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list = Float32[Float32(x) for x in list] | |
list = Float32.(x) |
function set_attr_shape_list(op::EagerOp, attr_name, list::Vector) | ||
dims = Vector{Int64}[] | ||
for shape in list | ||
push!(dims, Int64[shape...]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't thiis an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's right? At least Keno's PR 9325475 touched this code to make it what it is now.
src/eager.jl
Outdated
ptr = @tfcall(:TFE_ContextListDevices, Ptr{Cvoid}, (Ptr{Cvoid}, Ptr{Cvoid}), ctx, status) | ||
check_status(status) | ||
count = @tfcall(:TF_DeviceListCount, Cint, (Ptr{Cvoid},), ptr) | ||
this = new(ptr, count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't call new
outside of a inner constructor?
Ya all that setattr stuff was jsut copy-pasted from core.jl and blindly tweaked. I suspect a lot of code on this branch will be ugly/buggy as I just try to get a basic system working, at which point I'll worry more about code quality. |
OK, I'll stop bugging about it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, cool cool.
A first heavy pass.
I'ld like to take a closer look still at the import ops generation code.
and also the tape/grads code.
Ideally eager mode would not be a state, but just the result of using eager types.
And I think the gradient code really wants rewriting to be more dispatch based. Since we can dispatch on function types.
So it is like https://github.com/JuliaDiff/DiffRules.jl
return new_tape | ||
end | ||
|
||
function get_tape() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can and thus should be a 1 line function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not applicable anymore since it's no longer a single expression. although if there's a way to write it more compactly, then we should do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I responded to some comments. I'll apply some of your patches now, then push a patch, then pick this up a little later. Thanks again for the great feedback.
src/summary_writer.jl
Outdated
local path | ||
for i in Iterators.countfrom(1) | ||
path = joinpath(log_dir, "events.out.tfevents.$i") | ||
isfile(path) || break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want is isfile
here? The events file is a file, not a directory. Maybe the variable name should be changed from 'path' if that's confusing.
src/show.jl
Outdated
@@ -40,12 +40,19 @@ function Base.show(io::IO, t::RawTensor) | |||
end | |||
end | |||
|
|||
function Base.show(io::IO, t::TensorHandle) | |||
raw_tensor = resolve(t) | |||
jl_array = convert(Array, raw_tensor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/keras.jl
Outdated
lr::TensorHandle | ||
end | ||
|
||
SGD(;lr=1e-3)= SGD(convert(TensorHandle, lr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mirroring keras. Let's make on-boarding easy :)
Co-Authored-By: malmaud <malmaud@gmail.com>
Oh ya, good point.
…On Sat, Mar 16, 2019 at 10:57 AM Lyndon White ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/summary_writer.jl
<#491 (comment)>:
> mkpath(log_dir)
- path = joinpath(log_dir, "events")
- pyo = @py_proc pywrap_tensorflow[][:EventsWriter](py_bytes($path))
- writer = FileWriter(pyo, String(log_dir))
+ local path
+ for i in Iterators.countfrom(1)
+ path = joinpath(log_dir, "events.out.tfevents.$i")
+ isfile(path) || break
As I understand it
What we are actually looking for is the first available name that we can
use without overwriting anything.
The normal thing to be getting in the way is old log files.
But it is also not strictly impossible the user has put a directory, a
symlink, a mount point or something else there.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#491 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA8SvcJrN6FYp44afCPyxXkuqrTb9dhMks5vXQZUgaJpZM4aJz7O>
.
|
OK, ready for another review. Not everything is ideal, but as long as it's good enough, I would like to merge soon. |
I will try and review this week |
I think I'll just merge for now, but I still welcome comments if you get a chance/have the motivation sometime. |
Fair, sorry I didn't get back to this |
No description provided.