{"action":"created","issue":{"url":"https://api.github.com/repos/google/swift/issues/36","repository_url":"https://api.github.com/repos/google/swift","labels_url":"https://api.github.com/repos/google/swift/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/google/swift/issues/36/comments","events_url":"https://api.github.com/repos/google/swift/issues/36/events","html_url":"https://github.com/google/swift/issues/36","id":321013985,"number":36,"title":"Non-data dependent code with side effects within a tensor computation should be blocking","user":{"login":"rxwei","id":856507,"avatar_url":"https://avatars0.githubusercontent.com/u/856507?v=4","gravatar_id":"","url":"https://api.github.com/users/rxwei","html_url":"https://github.com/rxwei","followers_url":"https://api.github.com/users/rxwei/followers","following_url":"https://api.github.com/users/rxwei/following{/other_user}","gists_url":"https://api.github.com/users/rxwei/gists{/gist_id}","starred_url":"https://api.github.com/users/rxwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rxwei/subscriptions","organizations_url":"https://api.github.com/users/rxwei/orgs","repos_url":"https://api.github.com/users/rxwei/repos","events_url":"https://api.github.com/users/rxwei/events{/privacy}","received_events_url":"https://api.github.com/users/rxwei/received_events","type":"User","site_admin":false},"labels":[{"id":749479360,"url":"https://api.github.com/repos/google/swift/labels/question","name":"question","color":"cc317c","default":true},{"id":915157936,"url":"https://api.github.com/repos/google/swift/labels/tensorflow","name":"tensorflow","color":"f6921e","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-05-08T01:41:52Z","updated_at":"2018-05-11T04:13:11Z","closed_at":null,"author_association":"MEMBER","body":"Here's a long-standing issue that we haven't yet visited. The following code results in unexpected behavior.\r\n\r\n```swift\r\nimport Foundation\r\nimport TensorFlow\r\n\r\nvar x = Tensor([[1, 2], [3, 4]])\r\n\r\nprint(\"start time\", Date())\r\n\r\nfor _ in 0...100000 {\r\n  x += x ⊗ x\r\n}\r\n\r\nprint(\"finished a big loop at\", Date())\r\n\r\nfor _ in 0...9 {\r\n  x += x ⊗ x\r\n}\r\n\r\nprint(\"end time\", Date())\r\n```\r\n\r\nWhen you run this program, the print statement in the middle does not block async execution, so \"middle\" gets printed immediately after \"start\". This is because of async execution and that print doesn't have any data dependency. This goes against the mental model for writing such imperative code.\r\n\r\n```console\r\n$ swift -O test.swift\r\nstart time 2018-05-08 01:26:30 +0000\r\nfinished a big loop at 2018-05-08 01:26:30 +0000\r\nend time 2018-05-08 01:26:34 +0000\r\n```\r\n\r\nIn the programming model, users should not be aware of \"there is a graph\" or \"graph running asynchronously\". The expected model should block the async execution (without send/receive) when there's a side-effectful statement in the middle of a graph like print. Blocking for a print like this within tensor code is slow for performance, but it's an expected feature for any imperative code and is important for debugging."},"comment":{"url":"https://api.github.com/repos/google/swift/issues/comments/388254701","html_url":"https://github.com/google/swift/issues/36#issuecomment-388254701","issue_url":"https://api.github.com/repos/google/swift/issues/36","id":388254701,"user":{"login":"rxwei","id":856507,"avatar_url":"https://avatars0.githubusercontent.com/u/856507?v=4","gravatar_id":"","url":"https://api.github.com/users/rxwei","html_url":"https://github.com/rxwei","followers_url":"https://api.github.com/users/rxwei/followers","following_url":"https://api.github.com/users/rxwei/following{/other_user}","gists_url":"https://api.github.com/users/rxwei/gists{/gist_id}","starred_url":"https://api.github.com/users/rxwei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rxwei/subscriptions","organizations_url":"https://api.github.com/users/rxwei/orgs","repos_url":"https://api.github.com/users/rxwei/repos","events_url":"https://api.github.com/users/rxwei/events{/privacy}","received_events_url":"https://api.github.com/users/rxwei/received_events","type":"User","site_admin":false},"created_at":"2018-05-11T04:13:11Z","updated_at":"2018-05-11T04:13:11Z","author_association":"MEMBER","body":"> Even in the eager execution mode, we're really waiting for each individual asynchronous operation to complete.\r\n\r\nYes, but that feels like an implementation detail to me. The actual behavior and the user expectation in eager execution are still sync-per-statement.\r\n\r\n> But to keep the program synced when necessary we would need some form of wait/callback so we know operations have completed.\r\n\r\nAgreed. That's something we can start with. When too many users complain about debuggability, we can then evaluate whether debug mode expose the same behavior as eager execution."}}
{"actor":{"display_login":"rxwei"}}