Help Forcing farm to use All GPU Devices

We’re trying to get our farm to use blender 2.8 as a renderer, but right now blender is only picking up the CPU. Is there a command line ‘command’ we could add? Or a registered script inside the .blend? I’ve tried using a script I found on here https://developer.blender.org/T54099. But I think that’s for the 2.7x API and isn’t executing even from inside blender. (To note on the latter, if I put a registered script inside a blender file onto the farm, the output log will always say “scripts disabled for ###.blend, skipping” even though I’ve added it as a trusted script.)

Is the hardware setup on the farm consistent? In other words, exact same GPU model in all nodes, same amount, same retailer?

Yeah all machines have 2x 1060 6GB, same brand. If I run the script inside blender it works, but if I run it on the farm with autoexec enabled it still only uses the cpu, no errors are thrown either.

The script needs only a minor update, the API path to the preferences has changed:

import bpy

scene = bpy.context.scene
scene.cycles.device = 'GPU'

prefs = bpy.context.preferences
cprefs = prefs.addons['cycles'].preferences

# Attempt to set GPU device types if available
for compute_device_type in ('CUDA', 'OPENCL', 'NONE'):
    try:
        cprefs.compute_device_type = compute_device_type
        break
    except TypeError:
        pass

# Enable all CPU and GPU devices
for device in cprefs.devices:
    device.use = True

Regarding the auto execution on scripts, this can be enabled by modifying the command line arguments which run Blender. Just add the -y flag to the command (make sure it is lower case):

blender -b -y myscene.blend -a    # this should render all frames in the animation of myscene.blend

However you’ll need to make sure that script is present in every file. Another approach would be to turn the GPU switch into an Add-on operator, place that in the scripts/startup folder of your Blender installation on the server, and run said Add-on operator using a script expression, something like this:

blender -b -y myscene.blend --python-expr "import bpy;bpy.ops.render.my_gpu_switcher();" -a