We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[Bug] FileExistsError when sometimes importing dgl from multiprocess training
## 🐛 Bug
Sometimes, when I launch my Pytorch distributed trainer (which spawns multiple trainer processes, eg once for each GPU for multi-gpu model training), my training job fails with the following error:

```
# pardon the possibly out-of-order stack trace, multiple processes are interleaving the stdout
    import dgl
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/dgl/__init__.py", line 13, in <module>
    from .backend import load_backend, backend_name
  File "/usr/local/lib/python3.7/os.py", line 221, in makedirs
    mkdir(name, mode)
  File "trainer/utils/cli.py", line 137, in <module>
    locals()["run_" + args.which](args, extra)
  File "/usr/local/lib/python3.7/site-packages/dgl/backend/__init__.py", line 107, in <module>
    load_backend(get_preferred_backend())
  File "trainer/utils/cli.py", line 27, in run_local
    trainer_class = locate(args.trainer)
FileExistsError: [Errno 17] File exists: '/root/.dgl'
  File "/usr/local/lib/python3.7/site-packages/dgl/backend/__init__.py", line 103, in get_preferred_backend
    set_default_backend(default_dir, 'pytorch')
FileExistsError: [Errno 17] File exists: '/root/.dgl'
```

I see this occur fairly often, say ~10-20% of the time. Usually, retrying the train command fixes things.

For what it's worth: I am running this within a Docker container, using a DGL nightly build from `2021-10-18`

## To Reproduce

Steps to reproduce the behavior:

I don't have a repro script. But, hopefully this stack trace can point out a diagnosis + fix.

## Expected behavior

Importing dgl shouldn't cause an error.

## Environment

 - DGL Version (e.g., 1.0): >0.7 (Nightly build from 2021-10-18).
 - Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3):
 - OS (e.g., Linux): Linux
 - How you installed DGL (`conda`, `pip`, source): From nightly
 - Build command you used (if compiling from source):
 - Python version: 3.7
 - CUDA/cuDNN version (if applicable):
 - GPU models and configuration (e.g. V100):
 - Any other relevant information:

## Additional context


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `python/dgl/backend/set_default_backend.py`
Content:
```
1 import argparse
2 import os
3 import json
4 
5 def set_default_backend(default_dir, backend_name):
6     if not os.path.exists(default_dir):
7         os.makedirs(default_dir)
8     config_path = os.path.join(default_dir, 'config.json')
9     with open(config_path, "w") as config_file: 
10         json.dump({'backend': backend_name.lower()}, config_file)
11     print('Setting the default backend to "{}". You can change it in the '
12           '~/.dgl/config.json file or export the DGLBACKEND environment variable.  '
13           'Valid options are: pytorch, mxnet, tensorflow (all lowercase)'.format(
14               backend_name))
15 
16 if __name__ == "__main__":
17     parser = argparse.ArgumentParser()
18     parser.add_argument("default_dir", type=str, default=os.path.join(os.path.expanduser('~'), '.dgl'))
19     parser.add_argument("backend", nargs=1, type=str, choices=[
20                         'pytorch', 'tensorflow', 'mxnet'], help="Set default backend")
21     args = parser.parse_args()
22     set_default_backend(args.default_dir, args.backend[0])
23
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/python/dgl/backend/set_default_backend.py b/python/dgl/backend/set_default_backend.py
--- a/python/dgl/backend/set_default_backend.py
+++ b/python/dgl/backend/set_default_backend.py
@@ -3,8 +3,8 @@
 import json
 
 def set_default_backend(default_dir, backend_name):
-    if not os.path.exists(default_dir):
-        os.makedirs(default_dir)
+    # the exists_ok requires python >= 3.2
+    os.makedirs(default_dir, exists_ok=True)
     config_path = os.path.join(default_dir, 'config.json')
     with open(config_path, "w") as config_file: 
         json.dump({'backend': backend_name.lower()}, config_file)

{"golden_diff": "diff --git a/python/dgl/backend/set_default_backend.py b/python/dgl/backend/set_default_backend.py\n--- a/python/dgl/backend/set_default_backend.py\n+++ b/python/dgl/backend/set_default_backend.py\n@@ -3,8 +3,8 @@\n import json\n \n def set_default_backend(default_dir, backend_name):\n-    if not os.path.exists(default_dir):\n-        os.makedirs(default_dir)\n+    # the exists_ok requires python >= 3.2\n+    os.makedirs(default_dir, exists_ok=True)\n     config_path = os.path.join(default_dir, 'config.json')\n     with open(config_path, \"w\") as config_file: \n         json.dump({'backend': backend_name.lower()}, config_file)\n", "issue": "[Bug] FileExistsError when sometimes importing dgl from multiprocess training\n## \ud83d\udc1b Bug\r\nSometimes, when I launch my Pytorch distributed trainer (which spawns multiple trainer processes, eg once for each GPU for multi-gpu model training), my training job fails with the following error:\r\n\r\n```\r\n# pardon the possibly out-of-order stack trace, multiple processes are interleaving the stdout\r\n    import dgl\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.7/site-packages/dgl/__init__.py\", line 13, in <module>\r\n    from .backend import load_backend, backend_name\r\n  File \"/usr/local/lib/python3.7/os.py\", line 221, in makedirs\r\n    mkdir(name, mode)\r\n  File \"trainer/utils/cli.py\", line 137, in <module>\r\n    locals()[\"run_\" + args.which](args, extra)\r\n  File \"/usr/local/lib/python3.7/site-packages/dgl/backend/__init__.py\", line 107, in <module>\r\n    load_backend(get_preferred_backend())\r\n  File \"trainer/utils/cli.py\", line 27, in run_local\r\n    trainer_class = locate(args.trainer)\r\nFileExistsError: [Errno 17] File exists: '/root/.dgl'\r\n  File \"/usr/local/lib/python3.7/site-packages/dgl/backend/__init__.py\", line 103, in get_preferred_backend\r\n    set_default_backend(default_dir, 'pytorch')\r\nFileExistsError: [Errno 17] File exists: '/root/.dgl'\r\n```\r\n\r\nI see this occur fairly often, say ~10-20% of the time. Usually, retrying the train command fixes things.\r\n\r\nFor what it's worth: I am running this within a Docker container, using a DGL nightly build from `2021-10-18`\r\n\r\n## To Reproduce\r\n\r\nSteps to reproduce the behavior:\r\n\r\nI don't have a repro script. But, hopefully this stack trace can point out a diagnosis + fix.\r\n\r\n## Expected behavior\r\n\r\nImporting dgl shouldn't cause an error.\r\n\r\n## Environment\r\n\r\n - DGL Version (e.g., 1.0): >0.7 (Nightly build from 2021-10-18).\r\n - Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3):\r\n - OS (e.g., Linux): Linux\r\n - How you installed DGL (`conda`, `pip`, source): From nightly\r\n - Build command you used (if compiling from source):\r\n - Python version: 3.7\r\n - CUDA/cuDNN version (if applicable):\r\n - GPU models and configuration (e.g. V100):\r\n - Any other relevant information:\r\n\r\n## Additional context\r\n\n", "before_files": [{"content": "import argparse\nimport os\nimport json\n\ndef set_default_backend(default_dir, backend_name):\n    if not os.path.exists(default_dir):\n        os.makedirs(default_dir)\n    config_path = os.path.join(default_dir, 'config.json')\n    with open(config_path, \"w\") as config_file: \n        json.dump({'backend': backend_name.lower()}, config_file)\n    print('Setting the default backend to \"{}\". You can change it in the '\n          '~/.dgl/config.json file or export the DGLBACKEND environment variable.  '\n          'Valid options are: pytorch, mxnet, tensorflow (all lowercase)'.format(\n              backend_name))\n\nif __name__ == \"__main__\":\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"default_dir\", type=str, default=os.path.join(os.path.expanduser('~'), '.dgl'))\n    parser.add_argument(\"backend\", nargs=1, type=str, choices=[\n                        'pytorch', 'tensorflow', 'mxnet'], help=\"Set default backend\")\n    args = parser.parse_args()\n    set_default_backend(args.default_dir, args.backend[0])\n", "path": "python/dgl/backend/set_default_backend.py"}], "after_files": [{"content": "import argparse\nimport os\nimport json\n\ndef set_default_backend(default_dir, backend_name):\n    # the exists_ok requires python >= 3.2\n    os.makedirs(default_dir, exists_ok=True)\n    config_path = os.path.join(default_dir, 'config.json')\n    with open(config_path, \"w\") as config_file: \n        json.dump({'backend': backend_name.lower()}, config_file)\n    print('Setting the default backend to \"{}\". You can change it in the '\n          '~/.dgl/config.json file or export the DGLBACKEND environment variable.  '\n          'Valid options are: pytorch, mxnet, tensorflow (all lowercase)'.format(\n              backend_name))\n\nif __name__ == \"__main__\":\n    parser = argparse.ArgumentParser()\n    parser.add_argument(\"default_dir\", type=str, default=os.path.join(os.path.expanduser('~'), '.dgl'))\n    parser.add_argument(\"backend\", nargs=1, type=str, choices=[\n                        'pytorch', 'tensorflow', 'mxnet'], help=\"Set default backend\")\n    args = parser.parse_args()\n    set_default_backend(args.default_dir, args.backend[0])\n", "path": "python/dgl/backend/set_default_backend.py"}]}