forked from alibaba/pipcook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize the time cost to go into training (alibaba#410)
- Loading branch information
1 parent
2d3b416
commit fd4041d
Showing
40 changed files
with
513 additions
and
370 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { DataLoader, Sample } from './common'; | ||
|
||
class LocalDataLoader extends DataLoader { | ||
async len(): Promise<number> { | ||
return 10; | ||
} | ||
|
||
async getItem(): Promise<Sample> { | ||
return { | ||
data: Math.random(), | ||
label: Math.random | ||
}; | ||
} | ||
|
||
setItem(): Promise<void> { | ||
return null; | ||
} | ||
} | ||
|
||
describe('test dataloder', () => { | ||
it('should return data immediately when data is ready', async () => { | ||
const dataLoader = new LocalDataLoader(); | ||
dataLoader.processIndex = 5; | ||
const nextData = await dataLoader.next(); | ||
const nextDataBatch = await dataLoader.nextBatch(2); | ||
expect(nextData?.data).not.toBeNull(); | ||
expect(nextData?.label).not.toBeNull(); | ||
expect(nextDataBatch?.length).toBe(2); | ||
}); | ||
|
||
it('should wait until data is processed', async () => { | ||
const dataLoader = new LocalDataLoader(); | ||
dataLoader.processIndex = 1; | ||
setTimeout(() => { | ||
dataLoader.processIndex = 5; | ||
dataLoader.notifyProcess(); | ||
}, 1000); | ||
const nextDataBatch = await dataLoader.nextBatch(3); | ||
expect(nextDataBatch?.length).toBe(3); | ||
}, 3000); | ||
|
||
it('should read data from beginning when it reaches end', async () => { | ||
const dataLoader = new LocalDataLoader(); | ||
dataLoader.processIndex = 5; | ||
await dataLoader.nextBatch(4); | ||
expect(dataLoader.getFetchIndex()).toBe(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.