question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow direct contruction of `Batch`

See original GitHub issue

🚀 The feature, motivation and pitch

I’m working on GANs for graphs that generates multiple graphs at once. The output of the generator is a feature matrix and a vector in the form of Batch.batch. I would like to pass it on to the discriminator directly as a Batch, without splitting the matrix first, creating Data objects and then calling from_data_list. After the construction .__getitem__ and .num_graphs should be available.

Cheers!

Alternatives

No response

Additional context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
rusty1scommented, Feb 18, 2022

Glad that it’s working.

I think it is not really possible to allow this in a generic case, as we usually cannot utilize any assumptions on _slice_dict and _inc_dict layouts. How they look like is really task-dependent.

0reactions
movacommented, Feb 17, 2022

Hey, thanks for your help. The following code works for now.

def batch_construct_direct(pcs: torch.Tensor, batch_idxs: torch.Tensor) -> Batch:
    device = pcs.device
    batch = Batch(x=pcs, batch=batch_idxs)
    batch._num_graphs = int(batch.batch.max() + 1)

    _slice_dict = defaultdict(dict)
    out = torch_scatter.scatter_add(
        torch.ones(len(batch.x), dtype=torch.long, device=device), batch_idxs, dim=0
    )
    out = out.cumsum(dim=0)
    _slice_dict["x"] = torch.cat(
        [torch.zeros(1, dtype=torch.long, device=device), out], dim=0
    )

    batch._slice_dict = _slice_dict

    _inc_dict = defaultdict(dict)
    _inc_dict["x"] = torch.zeros(batch._num_graphs, dtype=torch.long, device=device)
    batch._inc_dict = _inc_dict
    return batch
    ```
Do you think it would be worth a having a constructor of the `Batch` class could take care of this?  If not feel free to close this.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Batch build buildspec reference - AWS CodeBuild
Learn about buildspec entries for batch builds in AWS CodeBuild. ... This topic contains the buildspec reference for batch build properties.
Read more >
Accounts Payable Batch Processing: A Tactical How-To Guide
In short, accounts payable batch processing allows companies to manage invoices, and process business-to-business (B2B) payments, and adjustments in bulk.
Read more >
Batch Processing | MuleSoft Documentation
You can apply filters by adding accept expressions within each batch step to prevent the step from processing certain records; for example, you...
Read more >
Standard Permit for Concrete Batch Plants: Learning More
Plants producing smaller amounts are authorized either by a Concrete Batch Plant Standard Permit or a Concrete Batch Plant Standard Permit with ...
Read more >
General Permit Regulation for Concrete Batch Plants - EPA
A Concrete Batch Plant General Permit Number (GPN) for each unit may be obtained by submitting an application with Notification of Intent to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found