-
Notifications
You must be signed in to change notification settings - Fork 137
Putting LazyTensor components together #294
Conversation
inputs = inputs.map { maybeMaterialized(input: $0) } | ||
} | ||
|
||
private static func materializeLiveTensors(_ lazyOp: LazyTensorOperation) { |
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.
Since this takes a Self
, why not define it as an instance method?
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.
Done.
func maybeMaterialized(lazyTensor: LazyTensor) -> LazyTensor { | ||
let handle = lazyTensor.handle | ||
if case let LazyTensor.Handle.symbolic(lazyOp, index, _) = handle { | ||
if let outputs = lazyOp.outputs { |
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.
if
accepts multiple conditions and optional binding clauses separated by a comma.
if let outputs = lazyOp.outputs { | |
let outputs = lazyOp.outputs { |
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.
Done.
private func maybeMaterializeInputs() { | ||
func maybeMaterialized(lazyTensor: LazyTensor) -> LazyTensor { | ||
let handle = lazyTensor.handle | ||
if case let LazyTensor.Handle.symbolic(lazyOp, index, _) = handle { |
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.
if case let LazyTensor.Handle.symbolic(lazyOp, index, _) = handle { | |
if case let LazyTensor.Handle.symbolic(lazyOp, index, _) = handle, |
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.
done.
func maybeMaterialized(input: Input) -> Input { | ||
switch input { | ||
case .single(let h): | ||
return Input.single(maybeMaterialized(lazyTensor: h)) |
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.
return Input.single(maybeMaterialized(lazyTensor: h)) | |
return .single(maybeMaterialized(lazyTensor: h)) |
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.
done.
case .single(let h): | ||
return Input.single(maybeMaterialized(lazyTensor: h)) | ||
case .list(let elements): | ||
return Input.list(elements.map { maybeMaterialized(lazyTensor: $0) }) |
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.
return Input.list(elements.map { maybeMaterialized(lazyTensor: $0) }) | |
return .list(elements.map { maybeMaterialized(lazyTensor: $0) }) |
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.
done.
return lazyTensor | ||
} | ||
|
||
func maybeMaterialized(input: Input) -> Input { |
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.
Could you elaborate on what "maybe" stands for here?
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.
Added a brief comment to the function. Basically, if any symbolic value in the input has been materialized, the input is rewritten by replacing the symbolic value with the corresponding concrete value.
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.
How about materializedAsNeeded(_:)
?
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.
SG. Done!
0e5a963
to
43c7e1a
Compare
Extracted traces are evaluated and used for materializing lazy tensors.
Use extracted traces to evaluate and materializing lazy tensors.