Check whether the block already has feed operators. Return false if the block does not have any feed operators. If some feed operators have been prepended to the block, check that the info contained in these feed operators matches the feed_targets and feed_holder_name. Raise excepti
(block, feed_targets, feed_holder_name)
| 338 | |
| 339 | |
| 340 | def has_feed_operators(block, feed_targets, feed_holder_name): |
| 341 | """Check whether the block already has feed operators. |
| 342 | |
| 343 | Return false if the block does not have any feed operators. |
| 344 | If some feed operators have been prepended to the block, check that |
| 345 | the info contained in these feed operators matches the feed_targets |
| 346 | and feed_holder_name. Raise exception when any mismatch is found. |
| 347 | Return true when the block has feed operators with matching info. |
| 348 | |
| 349 | Args: |
| 350 | block: a block instance (typically global block of a program) |
| 351 | feed_targets: a dictionary of {feed_target_name: feed_target_data} |
| 352 | feed_holder_name: the name of the variable that holds the data of |
| 353 | all feed targets. The type of this feed_holder variable is |
| 354 | FEED_MINIBATCH, which is essentially vector<DenseTensor>. |
| 355 | |
| 356 | Returns: |
| 357 | A boolean value that indicates whether a block has feed operators |
| 358 | that match the info contained in feed_targets and feed_holder_name. |
| 359 | """ |
| 360 | |
| 361 | feed_count = 0 |
| 362 | for op in block.ops: |
| 363 | if op.desc.type() == 'feed': |
| 364 | feed_count += 1 |
| 365 | assert op.desc.input('X')[0] == feed_holder_name |
| 366 | feed_target_name = op.desc.output('Out')[0] |
| 367 | if feed_target_name not in feed_targets: |
| 368 | raise Exception( |
| 369 | f"'feed_targets' does not have {feed_target_name} variable" |
| 370 | ) |
| 371 | else: |
| 372 | break |
| 373 | if feed_count > 0 and feed_count != len(feed_targets): |
| 374 | raise Exception( |
| 375 | "Feed operators in program desc do not match 'feed_targets'" |
| 376 | ) |
| 377 | return feed_count > 0 |
| 378 | |
| 379 | |
| 380 | def has_fetch_operators( |
no test coverage detected