【问题标题】:How to store DGL graphs in AWS S3 databucket?如何将 DGL 图存储在 AWS S3 数据桶中?
【发布时间】:2022-12-20 10:12:21
【问题描述】:

我正在尝试生成分子的 DGL 图并将它们存储在 S3 中,以便我可以直接从那里加载它们,而不必每次在 EC2 上使用新实例时都重新生成它们。

根据文档,使用 -DMLC_USE_S3 标志从源代码构建应该允许支持 S3 路径(例如 s3://path_to_data),但即使在从源代码构建之后,错误代码也提示“使用 -DMLC_USE_S3 从源代码构建”。我还尝试使用 -DUSE_S3 标志查看他们的 github。 (https://docs.dgl.ai/en/latest/generated/dgl.load_graphs.html)

错误代码是:

dgl._ffi.base.DGLError: /opt/dgl/third_party/dmlc-core/io.cc:57: Please compile with DMLC_USE_S3=1 to use S3

从源代码构建是按如下方式完成的:

python3 -m venv venv
source venv/bin/activate
git clone --recurse-submodules https://github.com/dmlc/dgl.git
git submodule update --init --recursive
sudo apt-get install -y build-essential python3-dev make cmake
mkdir build
cd build
cmake -DUSE_CUDA=ON -DMLC_USE_S3=1 ..
make -j32
cd ../python
pip install -e dgl

我们还尝试将 cmake 行交换为以下各项,以查看错误代码中的标志是否是问题所在:

cmake -DUSE_CUDA=ON -DMLC_USE_S3=1 ..
cmake -DUSE_CUDA=ON -DMLC_USE_S3=ON ..
cmake -DUSE_CUDA=ON -DUSE_S3=ON ..

还尝试在本地保存文件,然后使用 boto3 发送到 S3。从 S3 读取时无法解码字节串,但这不是首选方法,理想情况下希望从源代码构建工作!

权限是使用 IAM 角色授予的,并且在保存/加载图像文件和 csv 文件时没有问题。

在此先感谢您的帮助!

【问题讨论】:

    标签: python amazon-s3 cmake dgl


    【解决方案1】:

    要将 DGL 图存储在 AWS S3 存储桶中,您可以使用 DGL 中的 save_graphs 方法将图保存到本地文件,然后使用 AWS Python SDK (boto3) 中的 upload_file 方法将文件上传到您的S3 桶。以下是如何执行此操作的示例:

    import dgl
    import boto3
    
    # Create a DGLGraph object
    g = dgl.DGLGraph()
    # Add nodes and edges to the graph
    ...
    
    # Save the graph to a local file using the DGL save_graphs method
    dgl.save_graphs(g, 'my_graph.bin')
    
    # Create an S3 client
    s3 = boto3.client('s3')
    
    # Upload the file to the S3 bucket.
    # Replace 'my_bucket' and 'my_key' with the name of your S3 bucket and the key (i.e. file name)
    # where you want to store the graph.
    s3.upload_file('my_graph.bin', 'my_bucket', 'my_key')
    

    文件上传到您的 S3 存储桶后,您可以使用 download_file 方法将文件下载到本地计算机,然后使用 DGL 中的 load_graphs 方法从文件中加载图形。

    # Download the file from the S3 bucket.
    # Replace 'my_bucket' and 'my_key' with the name of your S3 bucket and the key (i.e. file name)
    # where the graph is stored.
    s3.download_file('my_bucket', 'my_key', 'my_graph.bin')
    
    # Load the graph from the file using the DGL load_graphs method
    g = dgl.load_graphs('my_graph.bin')
    

    看起来问题可能出在您用来从源代码构建 DGL 的 cmake 命令上。当您使用 -DMLC_USE_S3=1 标志时,您需要确保还包含 -DMLC_USE_S3=ON 标志,如下所示:

    cmake -DUSE_CUDA=ON -DMLC_USE_S3=ON ..
    

    当您从源代码构建时,这将在 DGL 中启用对 S3 的支持。

    或者,您可以尝试使用 -DUSE_S3=ON 标志而不是 -DMLC_USE_S3=ON,如下所示:

    cmake -DUSE_CUDA=ON -DUSE_S3=ON ..
    

    这也应该在 DGL 中启用对 S3 的支持。

    在启用 S3 支持的情况下从源构建 DGL 后,您应该能够将 S3 路径(例如 s3://path_to_data)与 dgl.load_graphs 和 dgl.save_graphs 方法一起使用。

    您也可以尝试使用 boto3 库直接与 S3 存储桶交互,如我之前的回答中所述。这将允许您在不使用 S3 路径的情况下向 S3 存储桶加载和保存 DGL 图。

    如果问题仍然存在,当您尝试对 S3 路径使用 dgl.load_graphs 或 dgl.save_graphs 方法时,查看您收到的确切错误消息会很有帮助。这将提供有关可能导致问题的原因的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-23
      • 1970-01-01
      • 2019-08-06
      • 1970-01-01
      • 2020-07-29
      • 2017-08-24
      • 2022-01-11
      • 2020-11-09
      相关资源
      最近更新 更多