|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928 |
- # Copyright 2020 Huawei Technologies Co., Ltd
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- # ==============================================================================
- """
- Testing cache operator with non-mappable datasets
- """
- import os
- import itertools
- import pytest
- import mindspore.common.dtype as mstype
- import mindspore.dataset as ds
- import mindspore.dataset.text as text
- import mindspore.dataset.vision.c_transforms as c_vision
- from mindspore import log as logger
-
- DATA_DIR = ["../data/dataset/test_tf_file_3_images/train-0000-of-0001.data"]
- SCHEMA_DIR = "../data/dataset/test_tf_file_3_images/datasetSchema.json"
-
- TEXT_TF_DATA_DIR = ["../data/dataset/testTextTFRecord/text.tfrecord"]
- SCHEMA_DIR2 = "../data/dataset/testTextTFRecord/datasetSchema.json"
-
- TRAIN_DATA_DIR = ["../data/dataset/test_tf_file_3_images2/train-0000-of-0001.data",
- "../data/dataset/test_tf_file_3_images2/train-0000-of-0002.data",
- "../data/dataset/test_tf_file_3_images2/train-0000-of-0003.data",
- "../data/dataset/test_tf_file_3_images2/train-0000-of-0004.data"]
- TRAIN_SCHEMA_DIR = "../data/dataset/test_tf_file_3_images2/datasetSchema.json"
-
- IMAGE_FOLDER_DATA_DIR = "../data/dataset/testImageNetData/train/"
- CLUE_DATA_DIR = '../data/dataset/testCLUE/afqmc/train.json'
- CSV_DATA_DIR = '../data/dataset/testCSV/1.csv'
- TEXT_FILE_DATA_DIR = "../data/dataset/testTextFileDataset/1.txt"
-
- GENERATE_GOLDEN = False
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_basic1():
- """
- A random dataset (a non mappable dataset) with a cache over it just after the leaf
- """
-
- logger.info("Test cache nomap basic 1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- schema = ds.Schema()
- schema.add_column('image', de_type=mstype.uint8,
- shape=[640, 480, 3]) # 921600 bytes (a bit less than 1 MB per image)
- schema.add_column('label', de_type=mstype.uint8, shape=[1])
-
- # create a cache. arbitrary session_id for now
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # User-created sampler here
- ds1 = ds.RandomDataset(schema=schema, total_rows=10, num_parallel_workers=4, cache=some_cache)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for data in ds1.create_dict_iterator(num_epochs=1):
- logger.info("printing the label: {}".format(data["label"]))
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 40
- logger.info("test_cache_nomap_basic1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_basic2():
- """
- A random dataset (a non mappable dataset) with a cache over it just after the leaf
- """
-
- logger.info("Test cache nomap basic 2")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- schema = ds.Schema()
- schema.add_column('image', de_type=mstype.uint8,
- shape=[640, 480, 3]) # 921600 bytes (a bit less than 1 MB per image)
- schema.add_column('label', de_type=mstype.uint8, shape=[1])
-
- # create a cache. arbitrary session_id for now
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # sampler arg not given directly, however any of these args will auto-generate an appropriate sampler:
- # num_samples, shuffle, num_shards, shard_id
- # In this case, the presence of num_samples chooses a sampler.
- ds1 = ds.RandomDataset(schema=schema, total_rows=20, num_samples=20, num_parallel_workers=4, cache=some_cache)
- ds1 = ds1.repeat(2)
-
- num_iter = 0
- for data in ds1.create_dict_iterator(num_epochs=1):
- logger.info("printing the label: {}".format(data["label"]))
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 40
- logger.info("test_cache_nomap_basic2 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_basic3():
- """
- A TF reader dataset (a non mappable dataset) with a cache over it just after the leaf
-
- Repeat
- |
- Map(decode)
- |
- Cache
- |
- TFReader
- """
-
- logger.info("Test cache nomap basic 3")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False, cache=some_cache)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(operations=decode_op, input_columns=["image"])
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
-
- # Contact the server to get the statistics
- stat = some_cache.GetStat()
- cache_sz = stat.avg_cache_sz
- num_mem_cached = stat.num_mem_cached
- num_disk_cached = stat.num_disk_cached
-
- logger.info("Number of rows cached in memory: {}".format(num_mem_cached))
- logger.info("Number of rows spilled to disk: {}".format(num_disk_cached))
- logger.info("Average row cache size: {}".format(cache_sz))
-
- logger.info("test_cache_nomap_basic3 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_basic4():
- """
- A TF reader dataset (a non mappable dataset) with a map decode and cache after it
- Since a global shuffle is used for the tf reader, it will inject a shuffle op over the tf.
- But, if there's a cache later, that shuffle becomes invalid and should be removed.
-
- Repeat
- |
- Cache
- |
- Map(decode)
- |
- TFReader
- """
-
- logger.info("Test cache nomap basic 4")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- # This dataset has 3 records in it only
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
- # With shuffle not being set, TF defaults to a "global" shuffle when there is no cache
- # in the picture. This causes a shuffle-injection over the TF. For clarify, this test will
- # explicitly give the global option, even though it's the default in python.
- # But, when caching is added in the ascendent tree above TF, we do global shuffling
- # through the sampler over the cache, not by the shuffle op. In that case, tree prepare
- # will remove the shuffle op that got injected by the initial tree creation.
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=ds.Shuffle.GLOBAL)
- decode_op = c_vision.Decode()
-
- ds1 = ds1.map(operations=decode_op, input_columns=["image"], cache=some_cache)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
- logger.info("test_cache_nomap_basic4 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_basic5():
- """
- A TF reader dataset (a non mappable dataset) with a cache over it just after the leaf
- Same as test 3, but this one does not have shuffle arg, causing tf to default to global
- shuffle which attempts to inject a shuffle operator. However, since there is a cache
- we do not need global shuffle, so the shuffle will not be built. It ends up being
- identical to test basic 3, however we arrive at the same tree in different codepaths
- (if there was no cache, then the shuffle IS built)
-
- Repeat
- |
- Map(decode)
- |
- Cache
- |
- TFReader
- """
-
- logger.info("Test cache nomap basic 5")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- # This dataset has 3 records in it only
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], cache=some_cache)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(operations=decode_op, input_columns=["image"])
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
- logger.info("test_cache_nomap_basic5 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_basic6():
- """
- A TF reader dataset (a non mappable dataset) with a cache over it just after the leaf
- In this one, the tf dataset will be given sharding configuration, however since a cache is
- used, the tree prepare should undo the sharding configuration and instead, a distributed
- sampler will be chosen with the same shard config.
-
- Repeat
- |
- Map(decode)
- |
- Cache
- |
- TFReader
- """
-
- logger.info("Test cache nomap basic 6")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- # This dataset has 3 records in it only
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # With only 3 records shard into 3, we expect only 1 record returned for this shard
- # However, the sharding will be done by the sampler, not by the tf record leaf node
- # In this case, it is a row-based sharding, not the file-based sharding that would happen if
- # there was not any cache.
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], num_shards=3, shard_id=1, cache=some_cache)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(operations=decode_op, input_columns=["image"])
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 4
- logger.info("test_cache_nomap_basic6 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_basic7():
- """
- A TF reader dataset (a non mappable dataset) that uses global shuffle, and is cached followed by
- map.
- In this one, the tf dataset with global shuffle might want to inject a shuffle op over top of the
- tf reader, but since a cache is given, it will choose not to.
-
- Repeat
- |
- Map(decode)
- |
- cache
- |
- TFReader
- """
-
- logger.info("Test cache nomap basic 7")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=ds.Shuffle.GLOBAL, cache=some_cache)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(operations=decode_op, input_columns=["image"])
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
- logger.info("test_cache_nomap_basic7 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_basic8():
- """
- Test cache as root node
-
- cache
- |
- TFReader
- """
- logger.info("Test cache basic 8")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, cache=some_cache)
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- logger.info("get data from dataset")
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 3
- logger.info('test_cache_basic8 Ended.\n')
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_basic9():
- """
- Testing the GetStat interface for getting some info from server, but this should fail if the cache is not created
- in a pipeline.
- """
-
- logger.info("Test cache nomap basic 9")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # Contact the server to get the statistics, this should fail because we have not used this cache in any pipeline
- # so there will not be any cache to get stats on.
- with pytest.raises(RuntimeError) as e:
- stat = some_cache.GetStat()
- cache_sz = stat.avg_cache_sz
- logger.info("Average row cache size: {}".format(cache_sz))
- assert "Unexpected error" in str(e.value)
-
- logger.info("test_cache_nomap_basic9 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_allowed_share1():
- """
- It is allowed to share the cache between the following two trees:
-
- Repeat Shuffle
- | |
- Cache Cache
- | |
- TFReader TFReader
- """
-
- logger.info("Test cache nomap allowed share 1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- ds.config.set_seed(1)
- # This dataset has 3 records in it only
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True, prefetch_size=32)
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False, cache=some_cache)
- ds1 = ds1.repeat(4)
-
- ds2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False, cache=some_cache)
- ds2 = ds2.shuffle(buffer_size=2)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
- assert num_iter == 12
- logger.info("Number of data in ds1: {} ".format(num_iter))
-
- num_iter = 0
- for _ in ds2.create_dict_iterator(num_epochs=1):
- num_iter += 1
- assert num_iter == 3
- logger.info("test_cache_nomap_allowed_share1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_allowed_share2():
- """
- It is allowed to share the cache between the following two trees (with map decode):
-
- Repeat Shuffle
- | |
- Cache Cache
- | |
- Map(decode) Map(decode)
- | |
- TFReader TFReader
- """
-
- logger.info("Test cache nomap allowed share 2")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- ds.config.set_seed(1)
- # This dataset has 3 records in it only
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
- decode_op = c_vision.Decode()
-
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
- ds1 = ds1.map(operations=decode_op, input_columns=["image"], cache=some_cache)
- ds1 = ds1.repeat(4)
-
- ds2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
- ds2 = ds2.map(operations=decode_op, input_columns=["image"], cache=some_cache)
- ds2 = ds2.shuffle(buffer_size=2)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
-
- num_iter = 0
- for _ in ds2.create_dict_iterator(num_epochs=1):
- num_iter += 1
- assert num_iter == 3
- logger.info("test_cache_nomap_allowed_share2 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_allowed_share3():
- """
- It is allowed to share the cache between the following two trees (different shard ids):
-
- Repeat Repeat
- | |
- Cache Cache
- | |
- TFReader(shard_id = 0) TFReader(shard_id = 1)
- """
-
- logger.info("Test cache nomap allowed share 3")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- tf_files = ["../data/dataset/tf_file_dataset/test1.data", "../data/dataset/tf_file_dataset/test2.data"]
- ds1 = ds.TFRecordDataset(tf_files, num_shards=2, shard_id=0, num_samples=3, shuffle=False, cache=some_cache)
- ds1 = ds1.repeat(4)
-
- ds2 = ds.TFRecordDataset(tf_files, num_shards=2, shard_id=1, num_samples=3, shuffle=False, cache=some_cache)
- ds2 = ds2.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
-
- num_iter = 0
- for _ in ds2.create_dict_iterator(num_epochs=1):
- num_iter += 1
- assert num_iter == 12
- logger.info("test_cache_nomap_allowed_share3 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_allowed_share4():
- """
- It is allowed to share the cache between the following two trees:
-
- Cache Cache
- | |
- Map(decode, num_parallel_workers=1) Map(decode, num_parallel_workers=2)
- | |
- TFReader TFReader
- """
-
- logger.info("Test cache nomap allowed share 4")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- # This dataset has 3 records in it only
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
- decode_op = c_vision.Decode()
-
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
- ds1 = ds1.map(operations=decode_op, input_columns=["image"], cache=some_cache, num_parallel_workers=1)
-
- ds2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
- ds2 = ds2.map(operations=decode_op, input_columns=["image"], cache=some_cache, num_parallel_workers=2)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 3
-
- num_iter = 0
- for _ in ds2.create_dict_iterator(num_epochs=1):
- num_iter += 1
- logger.info("Number of data in ds2: {} ".format(num_iter))
- assert num_iter == 3
-
- logger.info("test_cache_nomap_allowed_share4 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_disallowed_share1():
- """
- It is not allowed to share the cache between the following two trees:
-
- Cache Cache
- | |
- Map(decode) Map(rescale)
- | |
- TFReader TFReader
- """
-
- logger.info("Test cache nomap disallowed share1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- # This dataset has 3 records in it only
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
- decode_op = c_vision.Decode()
- rescale_op = c_vision.Rescale(1.0 / 255.0, -1.0)
-
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
- ds1 = ds1.map(operations=decode_op, input_columns=["image"], cache=some_cache)
-
- ds2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
- ds2 = ds2.map(operations=rescale_op, input_columns=["image"], cache=some_cache)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 3
-
- with pytest.raises(RuntimeError) as e:
- sum([1 for _ in ds2])
- assert "Cannot re-use a cache for a different tree!" in str(e.value)
-
- logger.info("test_cache_nomap_disallowed_share1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_running_twice1():
- """
- Executing the same pipeline for twice (from python), with cache injected after map
-
- Repeat
- |
- Cache
- |
- Map(decode)
- |
- TFRecord
- """
-
- logger.info("Test cache nomap running twice 1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op, cache=some_cache)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator():
- num_iter += 1
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
-
- num_iter = 0
- for _ in ds1.create_dict_iterator():
- num_iter += 1
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
-
- logger.info("test_cache_nomap_running_twice1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_running_twice2():
- """
- Executing the same pipeline for twice (from shell), with cache injected after leaf
-
- Repeat
- |
- Map(decode)
- |
- Cache
- |
- TFRecord
- """
-
- logger.info("Test cache nomap running twice 2")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, cache=some_cache)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator():
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
- logger.info("test_cache_nomap_running_twice2 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_extra_small_size1():
- """
- Test running pipeline with cache of extra small size and spilling true
-
- Repeat
- |
- Map(decode)
- |
- Cache
- |
- TFRecord
- """
-
- logger.info("Test cache nomap extra small size 1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
- some_cache = ds.DatasetCache(session_id=session_id, size=1, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, cache=some_cache)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator():
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
- logger.info("test_cache_nomap_extra_small_size1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_extra_small_size2():
- """
- Test running pipeline with cache of extra small size and spilling false (failure)
-
- Repeat
- |
- Cache
- |
- Map(decode)
- |
- TFRecord
- """
-
- logger.info("Test cache nomap extra small size 2")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
- some_cache = ds.DatasetCache(session_id=session_id, size=1, spilling=False)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op, cache=some_cache)
- ds1 = ds1.repeat(4)
-
- with pytest.raises(RuntimeError) as e:
- sum([1 for _ in ds1])
- assert "Out of memory" in str(e.value)
- logger.info("test_cache_nomap_extra_small_size2 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_parallel_pipeline1(shard):
- """
- Test running two parallel pipelines (sharing cache) with cache injected after leaf op
-
- Repeat
- |
- Map(decode)
- |
- cache
- |
- TFReader
- """
-
- logger.info("Test cache nomap parallel pipeline 1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, num_shards=3, shard_id=int(shard), cache=some_cache)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 4
- logger.info("test_cache_nomap_parallel_pipeline1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_parallel_pipeline2(shard):
- """
- Test running two parallel pipelines (sharing cache) with cache injected after map op
-
- Repeat
- |
- cache
- |
- Map(decode)
- |
- TFReader
- """
-
- logger.info("Test cache nomap parallel pipeline 2")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, num_shards=3, shard_id=int(shard))
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op, cache=some_cache)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 4
- logger.info("test_cache_nomap_parallel_pipeline2 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_parallel_workers():
- """
- Test cache with num_parallel_workers > 1 set for map op and leaf op
-
- Repeat
- |
- Map(decode)
- |
- cache
- |
- TFReader
- """
-
- logger.info("Test cache nomap parallel workers")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, num_parallel_workers=4)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op, num_parallel_workers=4, cache=some_cache)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
- logger.info("test_cache_nomap_parallel_workers Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_server_workers_1():
- """
- start cache server with --workers 1 and then test cache function
-
- Repeat
- |
- cache
- |
- Map(decode)
- |
- TFRecord
- """
-
- logger.info("Test cache nomap server workers 1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op, cache=some_cache)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator():
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
- logger.info("test_cache_nomap_server_workers_1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_server_workers_100():
- """
- start cache server with --workers 100 and then test cache function
-
- Repeat
- |
- Map(decode)
- |
- cache
- |
- TFRecord
- """
-
- logger.info("Test cache nomap server workers 100")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, cache=some_cache)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator():
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
- logger.info("test_cache_nomap_server_workers_100 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_num_connections_1():
- """
- Test setting num_connections=1 in DatasetCache
-
- Repeat
- |
- cache
- |
- Map(decode)
- |
- TFRecord
- """
-
- logger.info("Test cache nomap num_connections 1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True, num_connections=1)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op, cache=some_cache)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator():
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
- logger.info("test_cache_nomap_num_connections_1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_num_connections_100():
- """
- Test setting num_connections=100 in DatasetCache
-
- Repeat
- |
- Map(decode)
- |
- cache
- |
- TFRecord
- """
-
- logger.info("Test cache nomap num_connections 100")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True, num_connections=100)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, cache=some_cache)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator():
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
- logger.info("test_cache_nomap_num_connections_100 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_prefetch_size_1():
- """
- Test setting prefetch_size=1 in DatasetCache
-
- Repeat
- |
- cache
- |
- Map(decode)
- |
- TFRecord
- """
-
- logger.info("Test cache nomap prefetch_size 1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True, prefetch_size=1)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op, cache=some_cache)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator():
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
- logger.info("test_cache_nomap_prefetch_size_1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_prefetch_size_100():
- """
- Test setting prefetch_size=100 in DatasetCache
-
- Repeat
- |
- Map(decode)
- |
- cache
- |
- TFRecord
- """
-
- logger.info("Test cache nomap prefetch_size 100")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True, prefetch_size=100)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, cache=some_cache)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op)
- ds1 = ds1.repeat(4)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator():
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 12
- logger.info("test_cache_nomap_prefetch_size_100 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_to_device():
- """
- Test cache with to_device
-
- DeviceQueue
- |
- EpochCtrl
- |
- Repeat
- |
- Map(decode)
- |
- cache
- |
- TFReader
- """
-
- logger.info("Test cache nomap to_device")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op, cache=some_cache)
- ds1 = ds1.repeat(4)
- ds1 = ds1.to_device()
- ds1.send()
-
- logger.info("test_cache_nomap_to_device Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_session_destroy():
- """
- Test executing cache_admin -d while the pipeline is running
-
- Repeat
- |
- Cache
- |
- RandomDataset
- """
-
- logger.info("Test cache nomap session destroy")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- schema = ds.Schema()
- schema.add_column('image', de_type=mstype.uint8,
- shape=[640, 480, 3]) # 921600 bytes (a bit less than 1 MB per image)
- schema.add_column('label', de_type=mstype.uint8, shape=[1])
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # User-created sampler here
- ds1 = ds.RandomDataset(schema=schema, num_parallel_workers=4, cache=some_cache)
- ds1 = ds1.repeat()
-
- with pytest.raises(RuntimeError) as e:
- num_iter = 0
- for _ in ds1.create_dict_iterator():
- num_iter += 1
- assert "Unexpected error" in str(e.value)
-
- logger.info("test_cache_nomap_session_destroy Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_server_stop():
- """
- Test executing cache_admin --stop while the pipeline is running
-
- Repeat
- |
- Cache
- |
- RandomDataset
- """
-
- logger.info("Test cache nomap server stop")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- schema = ds.Schema()
- schema.add_column('image', de_type=mstype.uint8,
- shape=[640, 480, 3]) # 921600 bytes (a bit less than 1 MB per image)
- schema.add_column('label', de_type=mstype.uint8, shape=[1])
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # User-created sampler here
- ds1 = ds.RandomDataset(schema=schema, num_parallel_workers=4, cache=some_cache)
- ds1 = ds1.repeat()
-
- with pytest.raises(RuntimeError) as e:
- num_iter = 0
- for _ in ds1.create_dict_iterator():
- num_iter += 1
- assert "Network error. Cache server with port 50052 is unreachable. Make sure the server is running." in \
- str(e.value)
-
- logger.info("test_cache_nomap_server_stop Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_epoch_ctrl1():
- """
- Test using two-loops method to run several epochs
-
- Map(decode)
- |
- cache
- |
- TFRecord
- """
-
- logger.info("Test cache nomap epoch ctrl1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, cache=some_cache)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op)
-
- num_epoch = 5
- iter1 = ds1.create_dict_iterator(num_epochs=num_epoch)
-
- epoch_count = 0
- for _ in range(num_epoch):
- row_count = 0
- for _ in iter1:
- row_count += 1
- logger.info("Number of data in ds1: {} ".format(row_count))
- assert row_count == 3
- epoch_count += 1
- assert epoch_count == num_epoch
- logger.info("test_cache_nomap_epoch_ctrl1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_epoch_ctrl2():
- """
- Test using two-loops method with infinite epochs
-
- cache
- |
- Map(decode)
- |
- TFRecord
- """
-
- logger.info("Test cache nomap epoch ctrl2")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op, cache=some_cache)
-
- num_epoch = 5
- # iter1 will always assume there is a next epoch and never shutdown
- iter1 = ds1.create_dict_iterator()
-
- epoch_count = 0
- for _ in range(num_epoch):
- row_count = 0
- for _ in iter1:
- row_count += 1
- logger.info("Number of data in ds1: {} ".format(row_count))
- assert row_count == 3
- epoch_count += 1
- assert epoch_count == num_epoch
-
- # manually stop the iterator
- iter1.stop()
- logger.info("test_cache_nomap_epoch_ctrl2 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_epoch_ctrl3():
- """
- Test using two-loops method with infinite epochs over repeat
-
- repeat
- |
- Map(decode)
- |
- cache
- |
- TFRecord
- """
-
- logger.info("Test cache nomap epoch ctrl3")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, cache=some_cache)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op)
- ds1 = ds1.repeat(2)
-
- num_epoch = 5
- # iter1 will always assume there is a next epoch and never shutdown
- iter1 = ds1.create_dict_iterator()
-
- epoch_count = 0
- for _ in range(num_epoch):
- row_count = 0
- for _ in iter1:
- row_count += 1
- logger.info("Number of data in ds1: {} ".format(row_count))
- assert row_count == 6
- epoch_count += 1
- assert epoch_count == num_epoch
-
- # reply on garbage collector to destroy iter1
-
- logger.info("test_cache_nomap_epoch_ctrl3 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_epoch_ctrl4():
- """
- Test using two-loops method with repeat under cache
-
- cache
- |
- Map(decode)
- |
- repeat
- |
- TFRecord
- """
-
- logger.info("Test cache nomap epoch ctrl4")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- ds1 = ds1.repeat(2)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(input_columns=["image"], operations=decode_op, cache=some_cache)
-
- num_epoch = 5
- iter1 = ds1.create_dict_iterator(num_epochs=num_epoch)
-
- epoch_count = 0
- for _ in range(num_epoch):
- row_count = 0
- for _ in iter1:
- row_count += 1
- logger.info("Number of data in ds1: {} ".format(row_count))
- assert row_count == 6
- epoch_count += 1
- assert epoch_count == num_epoch
-
- logger.info("test_cache_nomap_epoch_ctrl4 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_multiple_cache1():
- """
- Test multiple cache in the same python script
-
- cache cache
- | |
- Map(decode) Map(decode)
- | |
- TFRecord(train) TFRecord(eval)
- """
-
- logger.info("Test cache nomap multiple cache 1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- train_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
- eval_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 12 records in it
- train_dataset = ds.TFRecordDataset(TRAIN_DATA_DIR, TRAIN_SCHEMA_DIR)
- decode_op = c_vision.Decode()
- train_dataset = train_dataset.map(input_columns=["image"], operations=decode_op, cache=train_cache)
-
- # This dataset has 3 records in it only
- eval_dataset = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- eval_dataset = eval_dataset.map(input_columns=["image"], operations=decode_op, cache=eval_cache)
-
- num_epoch = 5
- train_iter = train_dataset.create_dict_iterator(num_epochs=num_epoch)
- eval_iter = eval_dataset.create_dict_iterator(num_epochs=num_epoch)
-
- epoch_count = 0
- for _ in range(num_epoch):
- assert sum([1 for _ in train_iter]) == 12
- assert sum([1 for _ in eval_iter]) == 3
- epoch_count += 1
- assert epoch_count == num_epoch
-
- logger.info("test_cache_nomap_multiple_cache1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_multiple_cache2():
- """
- Test multiple cache in the same python script
-
- cache
- |
- Map(decode) cache
- | |
- TFRecord(image) TFRecord(text)
- """
-
- logger.info("Test cache nomap multiple cache 2")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- image_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
- text_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- image_dataset = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- decode_op = c_vision.Decode()
- image_dataset = image_dataset.map(input_columns=["image"], operations=decode_op, cache=image_cache)
-
- # This dataset has 3 records in it only
- text_dataset = ds.TFRecordDataset(TEXT_TF_DATA_DIR, SCHEMA_DIR2, cache=text_cache)
-
- num_epoch = 5
- image_iter = image_dataset.create_dict_iterator(num_epochs=num_epoch)
- text_iter = text_dataset.create_dict_iterator(num_epochs=num_epoch, output_numpy=True)
-
- epoch_count = 0
- for _ in range(num_epoch):
- row_count = 0
- for _, _ in itertools.zip_longest(image_iter, text_iter):
- row_count += 1
- assert row_count == 3
- epoch_count += 1
- assert epoch_count == num_epoch
-
- logger.info("test_cache_nomap_multiple_cache2 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_multiple_cache3():
- """
- Test multiple cache in the same python script
-
- cache cache
- | |
- Map(decode) Map(decode)
- | |
- TFRecord ImageFolder
- """
-
- logger.info("Test cache nomap multiple cache 3")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- tf_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
- image_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- tf_dataset = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- decode_op = c_vision.Decode()
- tf_dataset = tf_dataset.map(input_columns=["image"], operations=decode_op, cache=tf_cache)
-
- # This DATA_DIR only has 2 images in it
- image_dataset = ds.ImageFolderDataset(dataset_dir=IMAGE_FOLDER_DATA_DIR)
- image_dataset = image_dataset.map(input_columns=["image"], operations=decode_op, cache=image_cache)
-
- num_epoch = 5
- tf_iter = tf_dataset.create_dict_iterator(num_epochs=num_epoch)
- image_iter = image_dataset.create_dict_iterator(num_epochs=num_epoch)
-
- epoch_count = 0
- for _ in range(num_epoch):
- assert sum([1 for _ in tf_iter]) == 3
- assert sum([1 for _ in image_iter]) == 2
- epoch_count += 1
- assert epoch_count == num_epoch
-
- logger.info("test_cache_nomap_multiple_cache3 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_multiple_cache_train():
- """
- Test multiple cache in different python scripts. This test case is going to run concurrently with
- test_cache_nomap_multiple_cache_eval.
-
- cache
- |
- Map(decode)
- |
- TFRecord(train)
- """
-
- logger.info("Test cache nomap multiple cache train")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- train_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 12 records in it
- train_dataset = ds.TFRecordDataset(TRAIN_DATA_DIR, TRAIN_SCHEMA_DIR)
- decode_op = c_vision.Decode()
- train_dataset = train_dataset.map(input_columns=["image"], operations=decode_op, cache=train_cache)
-
- num_epoch = 5
- train_iter = train_dataset.create_dict_iterator(num_epochs=num_epoch)
-
- epoch_count = 0
- for _ in range(num_epoch):
- assert sum([1 for _ in train_iter]) == 12
- epoch_count += 1
- assert epoch_count == num_epoch
-
- logger.info("test_cache_nomap_multiple_cache_train Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_multiple_cache_eval():
- """
- Test multiple cache in different python scripts. This test case is going to run concurrently with
- test_cache_nomap_multiple_cache_train.
-
- cache
- |
- Map(decode)
- |
- TFRecord(eval)
- """
-
- logger.info("Test cache nomap multiple cache eval")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- eval_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset only has 3 records in it
- eval_dataset = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- decode_op = c_vision.Decode()
- eval_dataset = eval_dataset.map(input_columns=["image"], operations=decode_op, cache=eval_cache)
-
- num_epoch = 5
- eval_iter = eval_dataset.create_dict_iterator(num_epochs=num_epoch)
-
- epoch_count = 0
- for _ in range(num_epoch):
- assert sum([1 for _ in eval_iter]) == 3
- epoch_count += 1
- assert epoch_count == num_epoch
-
- logger.info("test_cache_nomap_multiple_cache_eval Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_clue1():
- """
- A clue dataset (a non mappable dataset) with a cache over it just after the leaf
- In this one, the clue dataset will be given sharding configuration, however since a cache is
- used, the tree prepare should undo the sharding configuration and instead, a distributed
- sampler will be chosen with the same shard config.
-
- Cache
- |
- CLUE
- """
-
- logger.info("Test cache nomap clue 1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # With only 3 records shard into 3, we expect only 1 record returned for this shard
- # However, the sharding will be done by the sampler, not by the clue leaf node
- # In this case, it is a row-based sharding, not the file-based sharding that would happen if
- # there was not any cache.
- ds1 = ds.CLUEDataset(CLUE_DATA_DIR, task='AFQMC', usage='train', num_shards=3, shard_id=1, cache=some_cache)
-
- num_epoch = 4
- iter1 = ds1.create_dict_iterator(num_epochs=num_epoch, output_numpy=True)
-
- epoch_count = 0
- for _ in range(num_epoch):
- assert sum([1 for _ in iter1]) == 1
- epoch_count += 1
- assert epoch_count == num_epoch
-
- logger.info("test_cache_nomap_clue1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_clue2():
- """
- A clue dataset (a non mappable dataset) with a cache over it after map
- In this one, a num_samples argument is given
-
- Cache
- |
- map(lambda x: x)
- |
- CLUE
- """
-
- logger.info("Test cache nomap clue 2")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- ds1 = ds.CLUEDataset(CLUE_DATA_DIR, task='AFQMC', usage='train', num_samples=2)
- ds1 = ds1.map((lambda x: x), ["label"], cache=some_cache)
-
- num_epoch = 4
- iter1 = ds1.create_dict_iterator(num_epochs=num_epoch, output_numpy=True)
-
- epoch_count = 0
- for _ in range(num_epoch):
- assert sum([1 for _ in iter1]) == 2
- epoch_count += 1
- assert epoch_count == num_epoch
-
- logger.info("test_cache_nomap_clue2 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_csv1():
- """
- A csv dataset (a non mappable dataset) with a cache over it just after the leaf
- In this one, the csv dataset will be given sharding configuration, however since a cache is
- used, the tree prepare should undo the sharding configuration and instead, a distributed
- sampler will be chosen with the same shard config.
-
- Cache
- |
- CSV
- """
-
- logger.info("Test cache nomap csv 1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # With only 3 records shard into 3, we expect only 1 record returned for this shard
- # However, the sharding will be done by the sampler, not by the clue leaf node
- # In this case, it is a row-based sharding, not the file-based sharding that would happen if
- # there was not any cache.
- ds1 = ds.CSVDataset(CSV_DATA_DIR, column_defaults=["1", "2", "3", "4"],
- column_names=['col1', 'col2', 'col3', 'col4'], num_shards=3, shard_id=1, cache=some_cache)
-
- num_epoch = 4
- iter1 = ds1.create_dict_iterator(num_epochs=num_epoch, output_numpy=True)
-
- epoch_count = 0
- for _ in range(num_epoch):
- assert sum([1 for _ in iter1]) == 1
- epoch_count += 1
- assert epoch_count == num_epoch
-
- logger.info("test_cache_nomap_csv1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_csv2():
- """
- A csv dataset (a non mappable dataset) with a cache over it after map
- In this one, a num_samples argument is given
-
- Cache
- |
- map(lambda x: x)
- |
- CSV
- """
-
- logger.info("Test cache nomap csv 2")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- ds1 = ds.CSVDataset(CSV_DATA_DIR, column_defaults=["1", "2", "3", "4"],
- column_names=['col1', 'col2', 'col3', 'col4'], num_samples=2)
- ds1 = ds1.map((lambda x: x), ["col1"], cache=some_cache)
-
- num_epoch = 4
- iter1 = ds1.create_dict_iterator(num_epochs=num_epoch, output_numpy=True)
-
- epoch_count = 0
- for _ in range(num_epoch):
- assert sum([1 for _ in iter1]) == 2
- epoch_count += 1
- assert epoch_count == num_epoch
-
- logger.info("test_cache_nomap_csv2 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_textfile1():
- """
- A text file dataset (a non mappable dataset) with a cache over it just after the leaf
- In this one, the text file dataset will be given sharding configuration, however since a cache is
- used, the tree prepare should undo the sharding configuration and instead, a distributed
- sampler will be chosen with the same shard config.
-
- Cache
- |
- TextFile
- """
-
- logger.info("Test cache nomap textfile 1")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # With only 3 records shard into 3, we expect only 1 record returned for this shard
- # However, the sharding will be done by the sampler, not by the clue leaf node
- # In this case, it is a row-based sharding, not the file-based sharding that would happen if
- # there was not any cache.
- ds1 = ds.TextFileDataset(TEXT_FILE_DATA_DIR, num_shards=3, shard_id=1, cache=some_cache)
-
- num_epoch = 4
- iter1 = ds1.create_dict_iterator(num_epochs=num_epoch, output_numpy=True)
-
- epoch_count = 0
- for _ in range(num_epoch):
- assert sum([1 for _ in iter1]) == 1
- epoch_count += 1
- assert epoch_count == num_epoch
-
- logger.info("test_cache_nomap_textfile1 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_textfile2():
- """
- A text file dataset (a non mappable dataset) with a cache over it after map
- In this one, a num_samples argument is given
-
- Cache
- |
- Map(tokenizer)
- |
- TextFile
- """
-
- def my_tokenizer(line):
- words = line.split()
- if not words:
- return [""]
- return words
-
- logger.info("Test cache nomap textfile 2")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- ds1 = ds.TextFileDataset(TEXT_FILE_DATA_DIR, num_samples=2)
- tokenizer = text.PythonTokenizer(my_tokenizer)
- ds1 = ds1.map(operations=tokenizer, cache=some_cache)
-
- num_epoch = 4
- iter1 = ds1.create_dict_iterator(num_epochs=num_epoch, output_numpy=True)
-
- epoch_count = 0
- for _ in range(num_epoch):
- assert sum([1 for _ in iter1]) == 2
- epoch_count += 1
- assert epoch_count == num_epoch
-
- logger.info("test_cache_nomap_textfile2 Ended.\n")
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_nested_repeat():
- """
- Test cache on pipeline with nested repeat ops
-
- Repeat
- |
- Cache
- |
- Map(decode)
- |
- Repeat
- |
- TFRecord
- """
-
- logger.info("Test cache nomap nested repeat")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR)
- decode_op = c_vision.Decode()
- ds1 = ds1.repeat(4)
- ds1 = ds1.map(operations=decode_op, input_columns=["image"], cache=some_cache)
- ds1 = ds1.repeat(2)
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- logger.info("get data from dataset")
- num_iter += 1
-
- logger.info("Number of data in ds1: {} ".format(num_iter))
- assert num_iter == 24
- logger.info('test_cache_nomap_nested_repeat Ended.\n')
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_get_repeat_count():
- """
- Test get_repeat_count() for a pipeline with cache and nested repeat ops
-
- Cache
- |
- Map(decode)
- |
- Repeat
- |
- TFRecord
- """
-
- logger.info("Test cache nomap get_repeat_count")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=0, spilling=True)
-
- # This dataset has 3 records in it only
- ds1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
- ds1 = ds1.repeat(4)
- decode_op = c_vision.Decode()
- ds1 = ds1.map(operations=decode_op, input_columns=["image"], cache=some_cache)
-
- repeat_count = ds1.get_repeat_count()
- logger.info("repeat_count: {}".format(repeat_count))
- assert repeat_count == 4
-
- num_iter = 0
- for _ in ds1.create_dict_iterator(num_epochs=1):
- logger.info("get data from dataset")
- num_iter += 1
- assert num_iter == 12
-
-
- @pytest.mark.skipif(os.environ.get('RUN_CACHE_TEST') != 'TRUE', reason="Require to bring up cache server")
- def test_cache_nomap_long_file_list():
- """
- Test cache after TFRecord with a long list of files as arguments
-
- Cache
- |
- TFRecord
- """
-
- logger.info("Test cache nomap long file list")
- if "SESSION_ID" in os.environ:
- session_id = int(os.environ['SESSION_ID'])
- else:
- raise RuntimeError("Testcase requires SESSION_ID environment variable")
-
- some_cache = ds.DatasetCache(session_id=session_id, size=1, spilling=False)
-
- ds1 = ds.TFRecordDataset([DATA_DIR[0] for _ in range(0, 1000)], SCHEMA_DIR, columns_list=["image"],
- cache=some_cache)
-
- with pytest.raises(RuntimeError) as e:
- sum([1 for _ in ds1])
- assert "Out of memory" in str(e.value)
- logger.info("test_cache_nomap_long_file_list Ended.\n")
-
-
- if __name__ == '__main__':
- test_cache_nomap_basic1()
- test_cache_nomap_basic2()
- test_cache_nomap_basic3()
- test_cache_nomap_basic4()
- test_cache_nomap_basic5()
- test_cache_nomap_basic6()
- test_cache_nomap_basic7()
- test_cache_nomap_allowed_share1()
- test_cache_nomap_allowed_share2()
- test_cache_nomap_allowed_share3()
- test_cache_nomap_allowed_share4()
- test_cache_nomap_disallowed_share1()
|