Hotswaping one of two Nvidia GPUs from host to guest, can it be done?

To preface this, my setup: Ryzen 1700, kernel 5.0.10 with ACS patch on Debian Sid, a GTX 970 & 980ti both under the proprietary drivers.
I’ve been trying to get a VM running under libvirt that will passthrough the 980ti (which has no displays connected) and use it
for looking glass, then after shutting down the VM return the 980ti to the host for extra CUDA rendering horsepower, preferably without Xorg restart.
So far what i have tried is having scripts run before and after libvirt startup using this (yes i have also tested that the scripts actually work by touching an unrelated file). These scripts try to detach the gpu from the nvidia driver to vfio-pci using echo calls to files in /sys/bus/pci suggested in this thread. But I have no clue what calls will work, and the ones i have tryed in that thread and others (of course modifying the PCI ids for to one for my card) will lead to Xorg freezing and the system becoming totally unresponsive (not even Ctrl-Alt-F* terminals work). And i know this isnt a problem with vfio because i can passthrough one of my pci wireless cards just fine. I’ve also tried this guide and adapted it for my setup.
My scripts looks like this:
VM Startup
VM Shutdown
I cannot find any good documentation on how to do this or even if this is possible. This is driving me crazy, any help would be appreciated.

My libvirt xml too: https://hastebin.com/idotemikuy.xml

so you want to swap the secondary card from guest to host, no isolation?

should be possible but you probably want to use nvidia-xrun instead of trying to do it in qemu command line if managed mode isn’t working. Not ideal to restart X but it’s the way to do that right now as far as we know.

might even work with virt-manager, they’ve supported passthrough dynamically without vfio-pci for a while now via managed mode. Kinda supplanted the need for it.

check these for details:

IIRC though you’re gonna need to restart X if you need the proprietary drivers

EDIT: I forgot, prime/bbswitch is also an option but that means you have to explicitly offload processes to use the 980ti while the guest is off and bumblebee setup is a pain