def get_node_tree(target):
    """
    Blender stores the node tree as a either 'node_group' or 'node_tree' depending on what the target is
    """

    if hasattr(target, "bl_idname") and target.bl_idname.endswith("NodeGroup"):
        return target.node_tree
    elif isinstance(target, bpy.types.NodesModifier):
        return target.node_group
    elif isinstance(target, (bpy.types.Material, bpy.types.World, bpy.types.Scene)):
        return target.node_tree
    else:
        raise ValueError(
            f"Couldnt infer node tree from {target=}, {type(target)=}, please contact the developer"
        )

    Blender stores the node tree as a either 'node_group' or 'node_tree' depending on what the target is
    
infinigen/core/nodes/node_transpiler/transpiler.py