/usr/local/lib/python3.6/site-packages/transformers/benchmark/__pycache__
NameSizeModeActions
benchmark.cpython-36.pyc75450644editdlrm
benchmark_args.cpython-36.pyc31820644editdlrm
benchmark_args_tf.cpython-36.pyc36920644editdlrm
benchmark_args_utils.cpython-36.pyc52300644editdlrm
benchmark_tf.cpython-36.pyc98360644editdlrm
benchmark_utils.cpython-36.pyc303540644editdlrm
__init__.cpython-36.pyc1560644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/transformers/benchmark/__pycache__/benchmark.cpython-36.pyc (7545B)
3 Eg)@sdZddlZddlmZmZddlmZddlmZm Z ddl m Z m Z m Z dd lmZmZmZmZmZmZe rddlZdd lmZe rddljZe jeZGd d d eZdS) zD Benchmarking the library on inference and training in PyTorch. N)CallableOptional)PretrainedConfig) MODEL_MAPPINGMODEL_WITH_LM_HEAD_MAPPING)is_py3nvml_availableis_torch_availablelogging) BenchmarkMemory MemorySummarymeasure_peak_memory_cpustart_memory_tracingstop_memory_tracing)PyTorchBenchmarkArgumentsc@seZdZUeedZee ddZ ee e e dddZ ee e eeegdddZee e e dd d Zee e eeegdd d Zee e egd fdddZee e egd fdddZe dddZegd feegdddZd S)PyTorchBenchmarkZPyTorchcCstjS)N)torch __version__)selfrJ/usr/local/lib/python3.6/site-packages/transformers/benchmark/benchmark.pyframework_version8sz"PyTorchBenchmark.framework_version) model_name batch_sizesequence_lengthreturncCs|j|||}|j|S)N)_prepare_inference_func_measure_speed)rrrr _inferencerrr_inference_speed<sz!PyTorchBenchmark._inference_speedcCs|j|||}|j|S)N)r_measure_memory)rrrrr rrr_inference_memory@sz"PyTorchBenchmark._inference_memorycCs|j|||}|j|S)N)_prepare_train_funcr)rrrr_trainrrr _train_speedFszPyTorchBenchmark._train_speedcCs|j|||}|j|S)N)r$r")rrrrr%rrr _train_memoryJszPyTorchBenchmark._train_memoryNcs|j|}|jjrd|_t|do:t|jto:t|jdk}|jj r|ry.|jd}t d|gd}t ||}||} Wqt k rt |dYqXnt |j |} | j| j|jjt|dr|jn|jj} tj| ||ftj|jjd|jjr$tjd |jjstd | j|jjrRtjtjj| WdQRXn| fd d } fd d} |jr~| n| } | S)NT architecturesr transformers)fromlistz does not exist. If you just want to test the pretrained model, you might want to set `--only_pretrain_model` or `args.only_pretrain_model=True`. vocab_size)dtypedevicez&Running training in Mixed Precision...z)Mixed precision is possible only for GPU.c s$tjd}WdQRX|S)N)decoder_input_ids)rno_grad)outputs)inference_model input_idsrrencoder_decoder_forward}s zIPyTorchBenchmark._prepare_inference_func..encoder_decoder_forwardc s tj}WdQRX|S)N)rr/)r0)r1r2rrencoder_forwards zAPyTorchBenchmark._prepare_inference_func..encoder_forward) config_dictargs torchscripthasattr isinstancer(listlenonly_pretrain_model __import__getattr ImportErrorr __class__evaltor-r+encoderrrandintlongfp16loggerinfois_gpu ValueErrorhalfr/Zjittraceis_encoder_decoder)rrrrconfighas_model_class_in_config model_classtransformers_module model_clsmodelr+r3r4Z_forwardr)r1r2rrPsB           z(PyTorchBenchmark._prepare_inference_funccs\|j|}t|do,t|jto,t|jdk}|jj r|ry.|jd}td|gd}t ||}||} Wqt k rt |dYqXnt |j |} |jj rtdn| | j| j|jjt|dr|jn|jj} tj| ||ftj|jjd|jjr,tjd |jjs$td | jfd d } fd d} |jrT| n| } | S)Nr(rr))r*z does not exist. If you just want to test the pretrained model, you might want to set `--only_pretrain_model` or `args.only_pretrain_model=True`.z5Training for torchscript is currently not implementedr+)r,r-z&Running training in Mixed Precision...z)Mixed precision is possible only for GPU.csdd}|j|S)N)labelsr)backward)loss)r2 train_modelrr!compute_loss_and_backprob_encoderszOPyTorchBenchmark._prepare_train_func..compute_loss_and_backprob_encodercsdd}|j|S)N)r.rTr)rU)rV)r2rWrr)compute_loss_and_backprob_encoder_decoderszWPyTorchBenchmark._prepare_train_func..compute_loss_and_backprob_encoder_decoder)r5r8r9r(r:r;r6r<r=r>r?rr@r7NotImplementedErrorZtrainrBr-r+rCrrDrErFrGrHrIrJrKrM)rrrrrNrOrPrQrRrSr+rXrYr%r)r2rWrr$s>           z$PyTorchBenchmark._prepare_train_func)rcCsyt|jjs|jjr,tjdtj|dddtj||jjdd}|jjrj|jjrjddlj j }|j |j t |dStk r}z|j d|d Sd}~XnXdS) NzRDo inference on TPU or torchscript. Running model 5 times to stabilize compilationr )repeatnumber rg$@zDoesn't fit on GPU. zN/A)r6is_tpur7rGrHtimeitr\Ztorch_xla_tpu_print_metricsZtorch_xla.debug.metricsdebugZmetricsprint_fnZmetrics_reportmin RuntimeError)rfuncZruntimesZmeterrrrs$   zPyTorchBenchmark._measure_speed)rerc Csy|jjrtd}|jjr$tdn|jjrtsBtjdd}qtj dt j |t j |jj }t j|}|j}t|}t jnt|}t|trt|n|}|jjrt|}nd}||fStk r} z|jd| dSd} ~ XnXdS)Nr)zMemory Benchmarking is currently not implemented for TPU. Please disable memory benchmarking with `--no-memory` or `args.memory=False`zypy3nvml not installed, we won't log GPU memory usage. Install py3nvml (pip install py3nvml) to log information about GPU.N/AzlMeasuring total GPU usage on GPU device. Make sure to not have additional processes running on the same GPU.zDoesn't fit on GPU. )rgN)r6Ztrace_memory_line_by_linerr_rZrIrrGwarningrHnvmlZnvmlInitZnvmlDeviceGetHandleByIndexZ device_idxZnvmlDeviceGetMemoryInfousedr Z nvmlShutdownrr9intrrdrb) rrerLZmemoryhandleZmeminfoZmax_bytes_in_useZ memory_bytessummaryrfrrrr"s:   z PyTorchBenchmark._measure_memory)__name__ __module__ __qualname__rr6rZconfigs frameworkstrpropertyrrkfloatr!r rrr#r&r'rrr$rr"rrrrr2s  :;r)__doc__r`typingrrZconfiguration_utilsrZmodels.auto.modeling_autorrutilsrr r Zbenchmark_utilsr r rrrrrZbenchmark_argsrZpy3nvml.py3nvmlZpy3nvmlri get_loggerrnrGrrrrrs