Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Putting LazyTensor components together #294

Merged
merged 6 commits into from
Jun 26, 2019

Conversation

bgogul
Copy link
Contributor

@bgogul bgogul commented Jun 25, 2019

Use extracted traces to evaluate and materializing lazy tensors.

@bgogul bgogul requested a review from pschuh June 25, 2019 22:48
inputs = inputs.map { maybeMaterialized(input: $0) }
}

private static func materializeLiveTensors(_ lazyOp: LazyTensorOperation) {
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Suggested change
if let outputs = lazyOp.outputs {
let outputs = lazyOp.outputs {

Copy link
Contributor Author

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if case let LazyTensor.Handle.symbolic(lazyOp, index, _) = handle {
if case let LazyTensor.Handle.symbolic(lazyOp, index, _) = handle,

Copy link
Contributor Author

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Input.single(maybeMaterialized(lazyTensor: h))
return .single(maybeMaterialized(lazyTensor: h))

Copy link
Contributor Author

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) })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Input.list(elements.map { maybeMaterialized(lazyTensor: $0) })
return .list(elements.map { maybeMaterialized(lazyTensor: $0) })

Copy link
Contributor Author

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@rxwei rxwei Jun 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about materializedAsNeeded(_:)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SG. Done!

@bgogul bgogul force-pushed the materialization branch 3 times, most recently from 0e5a963 to 43c7e1a Compare June 25, 2019 23:41
@bgogul bgogul force-pushed the materialization branch from 43c7e1a to d38ffc5 Compare June 26, 2019 05:10
@bgogul bgogul merged commit 76a69b7 into tensorflow:master Jun 26, 2019
@bgogul bgogul deleted the materialization branch June 26, 2019 06:09
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants