Comments (5)
Hi @mrclovvn,
As @awolant stated, the behavior is up to the external_source
itself. So your callable should control this, or in parallel mode, you need to pad samples on your own without the ability to return only partial results. We have an appropriate improvement on our ToDo list.
from dali.
Hello @JoostvDoorn, thank you for creating the issue and thanks for the repro you provided.
The behavior you are seeing is not controlled by the DALIGenericIterator
parameters. That's why you see now difference in the output when you change them. You could remove the iterator layer from your repro you would get the same result:
import numpy as np
from nvidia.dali import pipeline_def
import nvidia.dali.fn as fn
import nvidia.dali.types as types
batch_size = 32
class ExternalInputCallable:
def __init__(self, batch_size):
self.batch_size = batch_size
self.length = 100
self.full_iterations = self.length // batch_size
def __call__(self, sample_info):
sample_idx = sample_info.idx_in_epoch
if sample_idx >= self.length:
print("STOPPED", sample_idx)
# Indicate end of the epoch
raise StopIteration
return np.array([1], dtype=np.int32), np.array([sample_idx], dtype=np.int32)
@pipeline_def(batch_size=batch_size, num_threads=1, device_id=0)
def callable_pipeline():
data, label = fn.external_source(source=ExternalInputCallable(batch_size), num_outputs=2, batch=False,
dtype=[types.INT32, types.INT32])
return data, label
call_pipe = callable_pipeline()
call_pipe.build()
max_label = -1
for i in range(10):
batch = call_pipe.run()
max_label = max(batch[1].as_array().flatten().max().item(), max_label)
print(max_label)
Output:
31
63
STOPPED 100
95
Traceback (most recent call last):
File "/home/awolant/Projects/DALI/dev/issue/5199.py", line 46, in <module>
batch = call_pipe.run()
File "/home/awolant/.local/lib/python3.10/site-packages/nvidia/dali/pipeline.py", line 1176, in run
return self.outputs()
File "/home/awolant/.local/lib/python3.10/site-packages/nvidia/dali/pipeline.py", line 1015, in outputs
raise StopIteration
StopIteration
What happens here is controlled by the pipeline
and ExternalInputCallable
you created. Note, how it is configured:
self.batch_size = batch_size
self.length = 100
self.full_iterations = self.length // batch_size
In your example, with batch_size == 32
you get full_iterations == 3
. That is why your pipeline returns only 3 iterations and you loose samples beyond. So to make this work as you intend you need to support it in ExternalInputCallable
. With current implementation all DALI facilities see full_iterations == 3
and try to act accordingly which in conclusion gives the result that we see.
Just one more note on this: if you plan to use the parallel external source for your use case, you have to implement batch padding rather than partial batch as it is a requirement to make it work in parallel and is mentioned in
Parallel External Source docs
Hope that helps
from dali.
In your example, with
batch_size == 32
you getfull_iterations == 3
. That is why your pipeline returns only 3 iterations and you loose samples beyond. So to make this work as you intend you need to support it inExternalInputCallable
. With current implementation all DALI facilities seefull_iterations == 3
and try to act accordingly which in conclusion gives the result that we see.
I don't actually use the full_iterations, I use the self.length
to raise the StopIteration if the length is exceeded. But I see your point that it is documented in the Parallel External Source docs that this is a restrictions, I didn't see this in the specific API docs, so wasn't able to find out this behavior. I suppose what I should do is extend it with a padding, and mask output to be able to return partial batches. It would seem reasonable to support this on the library side since the sample_info
anyway is produced by the library it should be able to control the partial batch generation.
from dali.
Right, I misread the code, apologies.
I agree, it would be good to support this. In the meantime I can extend the docs of source
argument to include this information.
from dali.
Hi~
I've encountered the same issue with the fn.external_source
callable not returning the last batch. I've also tried using LastBatchPolicy.PARTIAL
, but it seems to have no effect on external_source. Have you found a solution to this problem, or is there an alternative workaround? I look forward to your response.
Best regards.
from dali.
Related Issues (20)
- Numpy reader test (GDS) HOT 4
- How to add a scalar value to the loader? HOT 1
- Can DALI be integrated into HuggingFace Trainer? HOT 9
- Bug in creating `TensorGPU` when `stream` key is `None` in CUDA array interface HOT 3
- Configure max image size HOT 3
- Webdataset reader behavior with many sources HOT 1
- ModuleNotFoundError: No module named 'nvidia.dali.python_function_plugin' HOT 3
- Speed up Dino with DALI HOT 3
- error using webdataset
- webdataset cannot stop cycling at end of epoch HOT 11
- Get audio data from external data sources and start iteration HOT 7
- Encountered some issues when using mirror flip HOT 2
- Can AArch64 Numba tests be re-renabled? HOT 2
- Cannot access CUDA GPU on WSL HOT 1
- When decoding RTSP streams using DALI, I encountered the following issues: HOT 8
- TypeError: 'DataNode' object does not support item assignment HOT 14
- DALI is slower than PyTorch DataLoader only when encountering large dataset HOT 11
- Request for msoco Dataset Reader for Multimodal Model Training HOT 1
- The correct way of using rand_augment HOT 1
- Dealing with corrupt videos using experimental video decoder HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dali.