styler00dollar / VSGAN-tensorrt-docker

Using VapourSynth with super resolution and interpolation models and speeding them up with TensorRT.
BSD 3-Clause "New" or "Revised" License
274 stars 30 forks source link

Getting Illegal instruction error while using the no_avx512 image #58

Closed AlexMF26 closed 7 months ago

AlexMF26 commented 8 months ago

Hello, thanks for putting this together !

I'm getting an illegal instruction error using the no_avx512 image on intel 13th gen and nvidia 4000 series using the following command:

f"vspipe -c y4m inference_batch.py --arg source='{file_path_in}' - | ffmpeg -y -i '{file_path_in}' -thread_queue_size 100 -i pipe: -map 1 -map 0 -map -0:v -max_interleave_delta 0 -scodec copy -crf 5 -preset slow '{file_path_out}'"

the input file has been converted from vfr to cfr before running.

this is the error:

frame= 1348 fps= 12 q=13.0 size=  952320kB time=00:00:28.06 bitrate=277929.7kbits/s speed=0.255x
Illegal instruction q=10.0 size= 3444224kB time=00:01:50.90 bitrate=254413.5kbits/s speed=0.347x
Error: fwrite() call failed when writing frame: 5433, plane: 0, errno: 32
Output 5440 frames in 320.48 seconds (16.97 fps)
sys:1: RuntimeWarning: An environment is getting collected without calling EnvironmentPolicyAPI.destroy_environment(). This skips some lifecycle callbacks (e.g. register_on_destroy). This might cause libraries to misbehave.
root@3a52f8c13d81:/workspace/tensorrt#

I don't know if it helps you debug but I'll leave the chain I'm using here just in case:

    interp_scale = 2

    clip = core.bs.VideoSource(source=video_path)

    clip_metric = vs.core.resize.Bicubic(
        clip, width=224, height=224, format=vs.YUV420P8, matrix_s="709"
    )
    clip_metric = metrics_func(clip_metric)

    clip = vs.core.resize.Bicubic(clip, format=vs.RGBH, matrix_in_s="709")

    clip_sc = scene_detect(
        clip,
        thresh=0.98,
        onnx_path="/workspace/tensorrt/sc_efficientnetv2b0+rife46_flow_1362_256_CHW_6ch_clamp_softmax_op17_fp16_sim.onnx",
        resolution=256,
    )

    clip_orig = vs.core.std.Interleave([clip] * interp_scale)
    clip_sc = vs.core.std.Interleave([clip_sc] * interp_scale)
    clip_metric = vs.core.std.Interleave([clip_metric] * interp_scale)

    clip = rife_trt(
        clip,
        multi=interp_scale,
        scale=1.0,
        device_id=0,
        num_streams=2,
        engine_path="/workspace/tensorrt/rife414_ensembleTrue_op18_fp16_clamp_sim.engine",
    )

    clip = core.akarin.Select([clip, clip_orig], clip_metric, "x.float_ssim 0.999 >")
    clip = core.akarin.Select([clip, clip_orig], clip_sc, "x._SceneChangeNext 1 0 ?")

    clip = core.trt.Model(
        clip,
        engine_path="/workspace/tensorrt/2x_AnimeJaNai_HD_V3_Compact_583k_op18_fp16_clamp.engine",
        num_streams=2,
    )

    clip = vs.core.resize.Bicubic(clip, format=vs.YUV420P8, matrix_s="709")
    return clip

The engines are generated like this:

trtexec --fp16 --bf16 --onnx=2x_AnimeJaNai_HD_V3_Compact_583k_op18_fp16_clamp.onnx --minShapes=input:1x3x8x8 --optShapes=input:1x3x1080x1920 --maxShapes=input:1x3x1080x1920 --saveEngine=2x_AnimeJaNai_HD_V3_Compact_583k_op18_fp16_clamp.engine --tacticSources=+CUDNN,-CUBLAS,-CUBLAS_LT --skipInference --infStreams=4 --builderOptimizationLevel=4
trtexec --fp16 --bf16 --onnx=rife414_ensembleTrue_op18_fp16_clamp_sim.onnx --minShapes=input:1x8x64x64 --optShapes=input:1x8x1080x1920 --maxShapes=input:1x8x1080x1920 --saveEngine=rife414_ensembleTrue_op18_fp16_clamp_sim.engine --tacticSources=+CUDNN,-CUBLAS,-CUBLAS_LT --skipInference --infStreams=4 --builderOptimizationLevel=4 --preview=+fasterDynamicShapes0805
styler00dollar commented 8 months ago

Since that error happens during inference and not on startup, make sure that your hardware is properly working via memtest and you don't have out of memory errors (drive, ram, etc). With that error message alone, it is hard to say what is happening.

The non-avx docker was build on a i5-8265U and it has following support via lscpu:

Markierungen:                  fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm 
                                   pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid ap
                                   erfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic mov
                                   be popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single ssbd
                                    ibrs ibpb stibp tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rd
                                   seed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_wind
                                   ow hwp_epp vnmi md_clear flush_l1d arch_capabilities

But ffmpeg probably would just instantly crash if it would be related to instruction sets, so I kind of doubt that this is the reason here like it was in https://github.com/styler00dollar/VSGAN-tensorrt-docker/issues/48.

If nothing helps, try to build the docker image on your system from scratch and set avx512 to false prior to doing so.

https://github.com/styler00dollar/VSGAN-tensorrt-docker/blob/0f3f0a9e262ed409e9891c17a669d7a2dd80d627/Dockerfile#L663

styler00dollar commented 7 months ago

Any updates?

AlexMF26 commented 7 months ago

To remove the risk of a hardware error I disabled XMP, efficiency cores, and every auto OC feature I could find. Also run memtest and OCCT's VRAM test for 1h.

It failed to build the image from during the ffmpeg compilation: https://github.com/styler00dollar/VSGAN-tensorrt-docker/blob/0f3f0a9e262ed409e9891c17a669d7a2dd80d627/Dockerfile#L357 I'll attach the full logs as a file: full-log.txt Screenshot:

image
styler00dollar commented 7 months ago

Mentioned in https://github.com/styler00dollar/VSGAN-tensorrt-docker/issues/61 to use the trt9.3 branch for now to avoid build errors. Didn't finish building the images myself, so it is not in master yet.

AlexMF26 commented 7 months ago

Switched to the trt9.3 branch but I am still failing to build the image, this time with a different error:

image

Full log: full_log.txt The line with the error: https://github.com/styler00dollar/VSGAN-tensorrt-docker/blob/2d9bb90f50a37cd8065cbfd7e77e9402bdfa05e1/Dockerfile#L730

styler00dollar commented 7 months ago

I did not expect that filename to change, but that is easy to solve.

Guess I have to make it more generic or use a specific commit to avoid crashes on different torch whl filenames.

styler00dollar commented 7 months ago

Adjusted the docker file so it builds without the torch whl filename and merged code into master branch. Uploaded avx and non-avx docker images onto dockerhub. There shouldn't be errors left.

yuvraj108c commented 7 months ago

Trying to build the new docker image on master, getting this error: I managed to build the image while it was still on the other branch trt9.3 2 days ago (on same machine)

Edit: setting avx512 to false worked, hmmm, was it set to false on the other branch??

8.383 Run-time dependency CUDA (modules: cudart_static, rt, pthread, dl) found: YES 12.1 (/usr/local/cuda)
8.383 src/meson.build:168: WARNING: add_languages is missing native:, assuming languages are wanted for both host and build.
8.383
8.383 src/meson.build:168:4: ERROR: Executables created by cuda compiler nvcc are not runnable.
8.383
8.383 A full log can be found at /workspace/vmaf-3.0.0/libvmaf/build/meson-logs/meson-log.txt
8.383 WARNING: Running the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.
------
Dockerfile:670
--------------------
 669 |     # VMAF
 670 | >>> RUN apt install nasm xxd -y && wget https://github.com/Netflix/vmaf/archive/refs/tags/v3.0.0.tar.gz && \
 671 | >>>   tar -xzf v3.0.0.tar.gz && cd vmaf-3.0.0/libvmaf/ && \
 672 | >>>   meson build --buildtype release -Denable_cuda=true -Denable_avx512=true && ninja -C build && \
 673 | >>>   ninja -C build install && cd /workspace && rm -rf v3.0.0.tar.gz vmaf-3.0.0 && \
 674 | >>>   git clone https://github.com/HomeOfVapourSynthEvolution/VapourSynth-VMAF && cd VapourSynth-VMAF && meson build && \
 675 | >>>   ninja -C build && ninja -C build install
 676 |
--------------------
ERROR: failed to solve: process "/bin/sh -c apt install nasm xxd -y && wget https://github.com/Netflix/vmaf/archive/refs/tags/v3.0.0.tar.gz &&   tar -xzf v3.0.0.tar.gz && cd vmaf-3.0.0/libvmaf/ &&   meson build --buildtype release -Denable_cuda=true -Denable_avx512=true && ninja -C build &&   ninja -C build install && cd /workspace && rm -rf v3.0.0.tar.gz vmaf-3.0.0 &&   git clone https://github.com/HomeOfVapourSynthEvolution/VapourSynth-VMAF && cd VapourSynth-VMAF && meson build &&   ninja -C build && ninja -C build install" did not complete successfully: exit code: 1
styler00dollar commented 7 months ago

It should be always be true since I mainly only compile on my ryzen system. Some other parts of the docker seemingly do automatic detection of cpu instruction sets, but that line is the only place where I explicitly turn avx512 on.

styler00dollar commented 7 months ago

Can this issue be considered done or is there still something left to do?

AlexMF26 commented 7 months ago

Just tested now with styler00dollar/vsgan_tensorrt:latest_no_avx512 from dockerhub and it seems to work now. From my point of view this issue can be considered done. I haven't tried building the image locally again but I think it should work.

styler00dollar commented 7 months ago

Thanks.