From 3cf4f941f76498b264d70cf03212e49ca18a2163 Mon Sep 17 00:00:00 2001 From: Hu Junhao <150254585+wujiu0411@users.noreply.github.com> Date: Mon, 12 May 2025 18:14:50 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=BC=80=E6=BA=90=E5=AE=9E=E4=B9=A0?= =?UTF-8?q?=E3=80=91=E6=8A=80=E6=9C=AF=E5=85=AC=E5=BC=80=E8=AF=BE=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E6=B5=8B=E8=AF=95=E4=BB=BB=E5=8A=A110?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../13.musicgen/run_musicgen.ipynb | 610 ++++++++++-------- 1 file changed, 351 insertions(+), 259 deletions(-) diff --git a/Season2.step_into_llm/13.musicgen/run_musicgen.ipynb b/Season2.step_into_llm/13.musicgen/run_musicgen.ipynb index e04f60f..5a6b8ef 100644 --- a/Season2.step_into_llm/13.musicgen/run_musicgen.ipynb +++ b/Season2.step_into_llm/13.musicgen/run_musicgen.ipynb @@ -1,5 +1,193 @@ { "cells": [ + { + "cell_type": "markdown", + "id": "9072f734-fbcd-4278-a037-bd8dcfe9565c", + "metadata": {}, + "source": [ + "# 环境配置\n", + "第一步:设置python版本为3.9.0" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "ae97a783-1017-4a55-9c53-fa1511cbe27c", + "metadata": {}, + "outputs": [], + "source": [ + "%%capture captured_output\n", + "!/home/ma-user/anaconda3/bin/conda create -n python-3.9.0 python=3.9.0 -y --override-channels --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main\n", + "!/home/ma-user/anaconda3/envs/python-3.9.0/bin/pip install ipykernel" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "180fdca0-3eb1-4bdb-b14a-1c92396edb47", + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import os\n", + "\n", + "data = {\n", + " \"display_name\": \"python-3.9.0\",\n", + " \"env\": {\n", + " \"PATH\": \"/home/ma-user/anaconda3/envs/python-3.9.0/bin:/home/ma-user/anaconda3/envs/python-3.7.10/bin:/modelarts/authoring/notebook-conda/bin:/opt/conda/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ma-user/modelarts/ma-cli/bin:/home/ma-user/modelarts/ma-cli/bin\"\n", + " },\n", + " \"language\": \"python\",\n", + " \"argv\": [\n", + " \"/home/ma-user/anaconda3/envs/python-3.9.0/bin/python\",\n", + " \"-m\",\n", + " \"ipykernel\",\n", + " \"-f\",\n", + " \"{connection_file}\"\n", + " ]\n", + "}\n", + "\n", + "if not os.path.exists(\"/home/ma-user/anaconda3/share/jupyter/kernels/python-3.9.0/\"):\n", + " os.mkdir(\"/home/ma-user/anaconda3/share/jupyter/kernels/python-3.9.0/\")\n", + "\n", + "with open('/home/ma-user/anaconda3/share/jupyter/kernels/python-3.9.0/kernel.json', 'w') as f:\n", + " json.dump(data, f, indent=4)" + ] + }, + { + "cell_type": "markdown", + "id": "3574f753-b80a-41cd-a941-896407df6069", + "metadata": {}, + "source": [ + "#### 注:以上代码运行完成后,需要重新设置kernel为python-3.9.0" + ] + }, + { + "cell_type": "markdown", + "id": "4e5d2cd6-8b13-4bfd-8c53-dbe92787aca4", + "metadata": {}, + "source": [ + "第二步:安装MindSpore框架和MindNLP套件" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "b8c6c48c-5d40-44ca-896c-8029ffb9062b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n", + "Collecting mindspore==2.2.14\n", + " Downloading https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.2.14/MindSpore/unified/x86_64/mindspore-2.2.14-cp39-cp39-linux_x86_64.whl (743.0 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m743.0/743.0 MB\u001b[0m \u001b[31m66.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", + "\u001b[?25hCollecting numpy>=1.17.0 (from mindspore==2.2.14)\n", + " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b9/14/78635daab4b07c0930c919d451b8bf8c164774e6a3413aed04a6d95758ce/numpy-2.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (19.5 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m19.5/19.5 MB\u001b[0m \u001b[31m3.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", + "\u001b[?25hCollecting protobuf>=3.13.0 (from mindspore==2.2.14)\n", + " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/28/50/1925de813499546bc8ab3ae857e3ec84efe7d2f19b34529d0c7c3d02d11d/protobuf-6.30.2-cp39-abi3-manylinux2014_x86_64.whl (316 kB)\n", + "Requirement already satisfied: asttokens>=2.0.4 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindspore==2.2.14) (3.0.0)\n", + "Collecting pillow>=6.2.0 (from mindspore==2.2.14)\n", + " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8b/ee/0e5e51db34de1690264e5f30dcd25328c540aa11d50a3bc0b540e2a445b6/pillow-11.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m4.5/4.5 MB\u001b[0m \u001b[31m4.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\n", + "\u001b[?25hCollecting scipy>=1.5.4 (from mindspore==2.2.14)\n", + " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/35/f5/d0ad1a96f80962ba65e2ce1de6a1e59edecd1f0a7b55990ed208848012e0/scipy-1.13.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (38.6 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m38.6/38.6 MB\u001b[0m \u001b[31m5.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: packaging>=20.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindspore==2.2.14) (25.0)\n", + "Requirement already satisfied: psutil>=5.6.1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindspore==2.2.14) (7.0.0)\n", + "Collecting astunparse>=1.6.3 (from mindspore==2.2.14)\n", + " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2b/03/13dde6512ad7b4557eb792fbcf0c653af6076b81e5941d36ec61f7ce6028/astunparse-1.6.3-py2.py3-none-any.whl (12 kB)\n", + "Requirement already satisfied: wheel<1.0,>=0.23.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from astunparse>=1.6.3->mindspore==2.2.14) (0.45.1)\n", + "Requirement already satisfied: six<2.0,>=1.6.1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from astunparse>=1.6.3->mindspore==2.2.14) (1.17.0)\n", + "Installing collected packages: protobuf, pillow, numpy, astunparse, scipy, mindspore\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6/6\u001b[0m [mindspore]/6\u001b[0m [mindspore]\n", + "\u001b[1A\u001b[2KSuccessfully installed astunparse-1.6.3 mindspore-2.2.14 numpy-2.0.2 pillow-11.2.1 protobuf-6.30.2 scipy-1.13.1\n" + ] + } + ], + "source": [ + "!pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.2.14/MindSpore/unified/x86_64/mindspore-2.2.14-cp39-cp39-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "4b0ce521-a741-4ffb-a025-b2488ed2ab39", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Looking in indexes: http://repo.myhuaweicloud.com/repository/pypi/simple\n", + "Requirement already satisfied: mindnlp==0.3.1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (0.3.1)\n", + "Requirement already satisfied: mindspore in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (2.2.14)\n", + "Requirement already satisfied: tqdm in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (4.67.1)\n", + "Requirement already satisfied: requests in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (2.32.3)\n", + "Requirement already satisfied: datasets in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (3.6.0)\n", + "Requirement already satisfied: evaluate in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (0.4.3)\n", + "Requirement already satisfied: tokenizers in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (0.21.1)\n", + "Requirement already satisfied: safetensors in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (0.5.3)\n", + "Requirement already satisfied: sentencepiece in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (0.2.0)\n", + "Requirement already satisfied: regex in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (2024.11.6)\n", + "Requirement already satisfied: addict in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (2.4.0)\n", + "Requirement already satisfied: ml-dtypes in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (0.5.1)\n", + "Requirement already satisfied: pyctcdecode in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (0.5.0)\n", + "Requirement already satisfied: jieba in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (0.42.1)\n", + "Requirement already satisfied: pytest==7.2.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindnlp==0.3.1) (7.2.0)\n", + "Requirement already satisfied: attrs>=19.2.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pytest==7.2.0->mindnlp==0.3.1) (25.3.0)\n", + "Requirement already satisfied: iniconfig in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pytest==7.2.0->mindnlp==0.3.1) (2.1.0)\n", + "Requirement already satisfied: packaging in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pytest==7.2.0->mindnlp==0.3.1) (25.0)\n", + "Requirement already satisfied: pluggy<2.0,>=0.12 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pytest==7.2.0->mindnlp==0.3.1) (1.5.0)\n", + "Requirement already satisfied: exceptiongroup>=1.0.0rc8 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pytest==7.2.0->mindnlp==0.3.1) (1.3.0)\n", + "Requirement already satisfied: tomli>=1.0.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pytest==7.2.0->mindnlp==0.3.1) (2.2.1)\n", + "Requirement already satisfied: typing-extensions>=4.6.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from exceptiongroup>=1.0.0rc8->pytest==7.2.0->mindnlp==0.3.1) (4.13.2)\n", + "Requirement already satisfied: filelock in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from datasets->mindnlp==0.3.1) (3.18.0)\n", + "Requirement already satisfied: numpy>=1.17 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from datasets->mindnlp==0.3.1) (1.26.4)\n", + "Requirement already satisfied: pyarrow>=15.0.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from datasets->mindnlp==0.3.1) (20.0.0)\n", + "Requirement already satisfied: dill<0.3.9,>=0.3.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from datasets->mindnlp==0.3.1) (0.3.8)\n", + "Requirement already satisfied: pandas in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from datasets->mindnlp==0.3.1) (2.2.3)\n", + "Requirement already satisfied: xxhash in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from datasets->mindnlp==0.3.1) (3.5.0)\n", + "Requirement already satisfied: multiprocess<0.70.17 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from datasets->mindnlp==0.3.1) (0.70.16)\n", + "Requirement already satisfied: fsspec<=2025.3.0,>=2023.1.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from fsspec[http]<=2025.3.0,>=2023.1.0->datasets->mindnlp==0.3.1) (2025.3.0)\n", + "Requirement already satisfied: huggingface-hub>=0.24.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from datasets->mindnlp==0.3.1) (0.31.1)\n", + "Requirement already satisfied: pyyaml>=5.1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from datasets->mindnlp==0.3.1) (6.0.2)\n", + "Requirement already satisfied: aiohttp!=4.0.0a0,!=4.0.0a1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from fsspec[http]<=2025.3.0,>=2023.1.0->datasets->mindnlp==0.3.1) (3.11.18)\n", + "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets->mindnlp==0.3.1) (2.6.1)\n", + "Requirement already satisfied: aiosignal>=1.1.2 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets->mindnlp==0.3.1) (1.3.2)\n", + "Requirement already satisfied: async-timeout<6.0,>=4.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets->mindnlp==0.3.1) (5.0.1)\n", + "Requirement already satisfied: frozenlist>=1.1.1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets->mindnlp==0.3.1) (1.6.0)\n", + "Requirement already satisfied: multidict<7.0,>=4.5 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets->mindnlp==0.3.1) (6.4.3)\n", + "Requirement already satisfied: propcache>=0.2.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets->mindnlp==0.3.1) (0.3.1)\n", + "Requirement already satisfied: yarl<2.0,>=1.17.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets->mindnlp==0.3.1) (1.20.0)\n", + "Requirement already satisfied: idna>=2.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from yarl<2.0,>=1.17.0->aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]<=2025.3.0,>=2023.1.0->datasets->mindnlp==0.3.1) (3.10)\n", + "Requirement already satisfied: hf-xet<2.0.0,>=1.1.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from huggingface-hub>=0.24.0->datasets->mindnlp==0.3.1) (1.1.0)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from requests->mindnlp==0.3.1) (3.4.2)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from requests->mindnlp==0.3.1) (2.4.0)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from requests->mindnlp==0.3.1) (2025.4.26)\n", + "Requirement already satisfied: protobuf>=3.13.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindspore->mindnlp==0.3.1) (6.30.2)\n", + "Requirement already satisfied: asttokens>=2.0.4 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindspore->mindnlp==0.3.1) (3.0.0)\n", + "Requirement already satisfied: pillow>=6.2.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindspore->mindnlp==0.3.1) (11.2.1)\n", + "Requirement already satisfied: scipy>=1.5.4 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindspore->mindnlp==0.3.1) (1.13.1)\n", + "Requirement already satisfied: psutil>=5.6.1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindspore->mindnlp==0.3.1) (7.0.0)\n", + "Requirement already satisfied: astunparse>=1.6.3 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from mindspore->mindnlp==0.3.1) (1.6.3)\n", + "Requirement already satisfied: wheel<1.0,>=0.23.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from astunparse>=1.6.3->mindspore->mindnlp==0.3.1) (0.45.1)\n", + "Requirement already satisfied: six<2.0,>=1.6.1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from astunparse>=1.6.3->mindspore->mindnlp==0.3.1) (1.17.0)\n", + "Requirement already satisfied: python-dateutil>=2.8.2 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pandas->datasets->mindnlp==0.3.1) (2.9.0.post0)\n", + "Requirement already satisfied: pytz>=2020.1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pandas->datasets->mindnlp==0.3.1) (2025.2)\n", + "Requirement already satisfied: tzdata>=2022.7 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pandas->datasets->mindnlp==0.3.1) (2025.2)\n", + "Requirement already satisfied: pygtrie<3.0,>=2.1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pyctcdecode->mindnlp==0.3.1) (2.5.0)\n", + "Requirement already satisfied: hypothesis<7,>=6.14 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pyctcdecode->mindnlp==0.3.1) (6.131.15)\n", + "Requirement already satisfied: sortedcontainers<3.0.0,>=2.1.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from hypothesis<7,>=6.14->pyctcdecode->mindnlp==0.3.1) (2.4.0)\n" + ] + } + ], + "source": [ + "!pip install mindnlp==0.3.1" + ] + }, { "cell_type": "markdown", "id": "70300319-d206-43ce-b3bf-3da6b079f20f", @@ -29,25 +217,6 @@ "**Figure 1:** Codebook delay pattern used by MusicGen. Figure taken from the [MusicGen paper](https://arxiv.org/abs/2306.05284).\n" ] }, - { - "cell_type": "markdown", - "id": "640da8c2", - "metadata": {}, - "source": [ - "## Environment Setup\n", - "\n", - " python =3.9\n", - " mindspore = 2.3.1\n", - " mindnlp = 0.4.0\n", - " jieba\n", - " soundfile \n", - " librosa\n", - "\n", - "**在线运行代码平台链接:**\n", - "- 1. [华为云AI Gallery](https://pangu.huaweicloud.com/gallery/asset-detail.html?id=c72241ed-465f-418d-b58a-ed4aabb0eb73)\n", - "- 2. [大模型平台AI实验室统一入口](https://xihe.mindspore.cn/projects)" - ] - }, { "cell_type": "markdown", "id": "77ee39cc-654b-4f0e-b601-013e484c16f0", @@ -68,84 +237,34 @@ "id": "b0d87424-9f38-4658-ba47-2a465d52ad77" }, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages/numpy/core/getlimits.py:549: UserWarning: The value of the smallest subnormal for type is zero.\n", - " setattr(self, word, getattr(machar, word).flat[0])\n", - "/home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for type is zero.\n", - " return self._float_to_str(self.smallest_subnormal)\n", - "/home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages/numpy/core/getlimits.py:549: UserWarning: The value of the smallest subnormal for type is zero.\n", - " setattr(self, word, getattr(machar, word).flat[0])\n", - "/home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for type is zero.\n", - " return self._float_to_str(self.smallest_subnormal)\n", - "Building prefix dict from the default dictionary ...\n", - "Dumping model to file cache /tmp/jieba.cache\n", - "Loading model cost 1.012 seconds.\n", - "Prefix dict has been built successfully.\n" - ] - }, - { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "75a95ec53fc947d5988d6827e7d5053c", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - " 0%| | 0.00/1.55k [00:00\n", - " \n", + " \n", " Your browser does not support the audio element.\n", " \n", " " @@ -318,80 +429,14 @@ }, "outputs": [ { - "data": { - "application/vnd.jupyter.widget-view+json": { - "model_id": "58ec6de737fd4523ae119fb576f5d490", - "version_major": 2, - "version_minor": 0 - }, - "text/plain": [ - " 0%| | 0.00/275 [00:00\n", - " \n", + " \n", " Your browser does not support the audio element.\n", " \n", " " @@ -414,9 +459,9 @@ } ], "source": [ - "from mindnlp.transformers import AutoProcessor\n", + "from mindnlp.transformers import MusicgenProcessor\n", "\n", - "processor = AutoProcessor.from_pretrained(\"facebook/musicgen-small\")\n", + "processor = MusicgenProcessor.from_pretrained(\"facebook/musicgen-small\")\n", "\n", "inputs = processor(\n", " text=[\"80s pop track with bassy drums and synth\", \"90s rock song with loud guitars and heavy drums\"],\n", @@ -459,95 +504,84 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 10, "id": "56a5c28a-f6c1-4ac8-ae08-6776a2b2c5b8", "metadata": { "id": "56a5c28a-f6c1-4ac8-ae08-6776a2b2c5b8" }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n", + "To disable this warning, you can either:\n", + "\t- Avoid using `tokenizers` before the fork if possible\n", + "\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n" + ] + }, { "name": "stdout", "output_type": "stream", "text": [ - "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n", - "Requirement already satisfied: soundfile in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (0.12.1)\n", + "Looking in indexes: http://repo.myhuaweicloud.com/repository/pypi/simple\n", + "Collecting soundfile\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/64/28/e2a36573ccbcf3d57c00626a21fe51989380636e821b341d36ccca0c1c3a/soundfile-0.13.1-py2.py3-none-any.whl (25 kB)\n", "Collecting librosa\n", - " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8c/8a/2d231b35456506b7c98b3ab9bbf07917b205fed8615d2e59e976ab497fff/librosa-0.10.2.post1-py3-none-any.whl (260 kB)\n", - "Requirement already satisfied: cffi>=1.0 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from soundfile) (1.17.0)\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/b5/ba/c63c5786dfee4c3417094c4b00966e61e4a63efecee22cb7b4c0387dda83/librosa-0.11.0-py3-none-any.whl (260 kB)\n", + "Collecting cffi>=1.0 (from soundfile)\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/bd/62/a1f468e5708a70b1d86ead5bab5520861d9c7eacce4a885ded9faa7729c3/cffi-1.17.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (445 kB)\n", + "Requirement already satisfied: numpy in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from soundfile) (1.26.4)\n", "Collecting audioread>=2.1.9 (from librosa)\n", - " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/57/8d/30aa32745af16af0a9a650115fbe81bde7c610ed5c21b381fca0196f3a7f/audioread-3.0.1-py3-none-any.whl (23 kB)\n", - "Requirement already satisfied: numpy!=1.22.0,!=1.22.1,!=1.22.2,>=1.20.3 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from librosa) (1.26.4)\n", - "Requirement already satisfied: scipy>=1.2.0 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from librosa) (1.13.1)\n", - "Requirement already satisfied: scikit-learn>=0.20.0 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from librosa) (1.5.1)\n", - "Requirement already satisfied: joblib>=0.14 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from librosa) (1.4.2)\n", - "Requirement already satisfied: decorator>=4.3.0 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from librosa) (5.1.1)\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/57/8d/30aa32745af16af0a9a650115fbe81bde7c610ed5c21b381fca0196f3a7f/audioread-3.0.1-py3-none-any.whl (23 kB)\n", "Collecting numba>=0.51.0 (from librosa)\n", - " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/3b/bd/f1985719ff34e37e07bb18f9d3acd17e5a21da255f550c8eae031e2ddf5f/numba-0.60.0-cp39-cp39-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (3.4 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.4/3.4 MB\u001b[0m \u001b[31m37.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hCollecting pooch>=1.1 (from librosa)\n", - " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a8/87/77cc11c7a9ea9fd05503def69e3d18605852cd0d4b0d3b8f15bbeb3ef1d1/pooch-1.8.2-py3-none-any.whl (64 kB)\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/54/9b/cd73d3f6617ddc8398a63ef97d8dc9139a9879b9ca8a7ca4b8789056ea46/numba-0.60.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (3.7 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.7/3.7 MB\u001b[0m \u001b[31m33.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: scipy>=1.6.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from librosa) (1.13.1)\n", + "Collecting scikit-learn>=1.1.0 (from librosa)\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/79/35/b1d2188967c3204c78fa79c9263668cf1b98060e8e58d1a730fe5b2317bb/scikit_learn-1.6.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (13.5 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13.5/13.5 MB\u001b[0m \u001b[31m129.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", + "\u001b[?25hCollecting joblib>=1.0 (from librosa)\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/da/d3/13ee227a148af1c693654932b8b0b02ed64af5e1f7406d56b088b57574cd/joblib-1.5.0-py3-none-any.whl (307 kB)\n", + "Requirement already satisfied: decorator>=4.3.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from librosa) (5.2.1)\n", + "Collecting pooch>=1.1 (from librosa)\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/a8/87/77cc11c7a9ea9fd05503def69e3d18605852cd0d4b0d3b8f15bbeb3ef1d1/pooch-1.8.2-py3-none-any.whl (64 kB)\n", "Collecting soxr>=0.3.2 (from librosa)\n", - " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c3/c6/f3d54e8c579aa5f192d62c87cd86b88e0b1d6fcab7b541663a3816f1eb06/soxr-0.4.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.2/1.2 MB\u001b[0m \u001b[31m57.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: typing-extensions>=4.1.1 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from librosa) (4.11.0)\n", - "Collecting lazy-loader>=0.1 (from librosa)\n", - " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/83/60/d497a310bde3f01cb805196ac61b7ad6dc5dcf8dce66634dc34364b20b4f/lazy_loader-0.4-py3-none-any.whl (12 kB)\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/25/d1/83a66e795381ddfc5c3ebf34cc0ac68735c7c459ed1fe65a2193a52c57b1/soxr-0.5.0.post1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (253 kB)\n", + "Requirement already satisfied: typing_extensions>=4.1.1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from librosa) (4.13.2)\n", + "Collecting lazy_loader>=0.1 (from librosa)\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/83/60/d497a310bde3f01cb805196ac61b7ad6dc5dcf8dce66634dc34364b20b4f/lazy_loader-0.4-py3-none-any.whl (12 kB)\n", "Collecting msgpack>=1.0 (from librosa)\n", - " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ad/61/225d64e983e51f960cac41fd1084188764fcc7430e75f609ad9d86e47839/msgpack-1.0.8-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (375 kB)\n", - "Requirement already satisfied: pycparser in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from cffi>=1.0->soundfile) (2.22)\n", - "Requirement already satisfied: packaging in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from lazy-loader>=0.1->librosa) (24.1)\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/f7/0a/8a213cecea7b731c540f25212ba5f9a818f358237ac51a44d448bd753690/msgpack-1.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (377 kB)\n", + "Collecting pycparser (from cffi>=1.0->soundfile)\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/13/a3/a812df4e2dd5696d1f351d58b8fe16a405b234ad2886a0dab9183fb78109/pycparser-2.22-py3-none-any.whl (117 kB)\n", + "Requirement already satisfied: packaging in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from lazy_loader>=0.1->librosa) (25.0)\n", "Collecting llvmlite<0.44,>=0.43.0dev0 (from numba>=0.51.0->librosa)\n", - " Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c8/c6/9324eb5de2ba9d99cbed853d85ba7a318652a48e077797bec27cf40f911d/llvmlite-0.43.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (42.9 MB)\n", - "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m42.9/42.9 MB\u001b[0m \u001b[31m95.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\n", - "\u001b[?25hRequirement already satisfied: platformdirs>=2.5.0 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from pooch>=1.1->librosa) (4.2.2)\n", - "Requirement already satisfied: requests>=2.19.0 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from pooch>=1.1->librosa) (2.32.3)\n", - "Requirement already satisfied: threadpoolctl>=3.1.0 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from scikit-learn>=0.20.0->librosa) (3.5.0)\n", - "Requirement already satisfied: charset-normalizer<4,>=2 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (3.3.2)\n", - "Requirement already satisfied: idna<4,>=2.5 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (3.7)\n", - "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (2.2.2)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /home/mindspore/miniconda/envs/jupyter/lib/python3.9/site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (2024.7.4)\n", - "Installing collected packages: soxr, msgpack, llvmlite, lazy-loader, audioread, pooch, numba, librosa\n", - "Successfully installed audioread-3.0.1 lazy-loader-0.4 librosa-0.10.2.post1 llvmlite-0.43.0 msgpack-1.0.8 numba-0.60.0 pooch-1.8.2 soxr-0.4.0\n" + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/e0/d0/889e9705107db7b1ec0767b03f15d7b95b4c4f9fdf91928ab1c7e9ffacf6/llvmlite-0.43.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (43.9 MB)\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m43.9/43.9 MB\u001b[0m \u001b[31m177.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m\n", + "\u001b[?25hRequirement already satisfied: platformdirs>=2.5.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pooch>=1.1->librosa) (4.3.8)\n", + "Requirement already satisfied: requests>=2.19.0 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from pooch>=1.1->librosa) (2.32.3)\n", + "Requirement already satisfied: charset-normalizer<4,>=2 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (3.4.2)\n", + "Requirement already satisfied: idna<4,>=2.5 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (3.10)\n", + "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (2.4.0)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /home/ma-user/anaconda3/envs/python-3.9.0/lib/python3.9/site-packages (from requests>=2.19.0->pooch>=1.1->librosa) (2025.4.26)\n", + "Collecting threadpoolctl>=3.1.0 (from scikit-learn>=1.1.0->librosa)\n", + " Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/32/d5/f9a850d79b0851d1d4ef6456097579a9005b31fea68726a4ae5f2d82ddd9/threadpoolctl-3.6.0-py3-none-any.whl (18 kB)\n", + "Installing collected packages: threadpoolctl, soxr, pycparser, msgpack, llvmlite, lazy_loader, joblib, audioread, scikit-learn, pooch, numba, cffi, soundfile, librosa\n", + "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m14/14\u001b[0m [librosa]3/14\u001b[0m [librosa]earn]\n", + "\u001b[1A\u001b[2KSuccessfully installed audioread-3.0.1 cffi-1.17.1 joblib-1.5.0 lazy_loader-0.4 librosa-0.11.0 llvmlite-0.43.0 msgpack-1.1.0 numba-0.60.0 pooch-1.8.2 pycparser-2.22 scikit-learn-1.6.1 soundfile-0.13.1 soxr-0.5.0.post1 threadpoolctl-3.6.0\n" ] - } - ], - "source": [ - "from mindnlp.dataset import load_dataset\n", - "\n", - "dataset = load_dataset(\"sanchit-gandhi/gtzan\", split=\"train\", streaming=True)\n", - "sample = next(iter(dataset.create_dict_iterator(output_numpy=True)))[\"audio\"]" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "79fd7ab3-4d1f-4838-aff8-13d6fa568b3c", - "metadata": {}, - "outputs": [], - "source": [ - "# take the first half of the audio sample\n", - "sample[\"array\"] = sample[\"array\"][: len(sample[\"array\"]) // 2]\n", - "\n", - "inputs = processor(\n", - " audio=sample[\"array\"],\n", - " sampling_rate=sample[\"sampling_rate\"],\n", - " text=[\"80s blues track with groovy saxophone\"],\n", - " padding=True,\n", - " return_tensors=\"ms\",\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "3787d4e6-6d1c-479b-8c92-c8a58d176144", - "metadata": {}, - "outputs": [ + }, { - "name": "stdout", + "name": "stderr", "output_type": "stream", "text": [ - "/\r" + "huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...\n", + "To disable this warning, you can either:\n", + "\t- Avoid using `tokenizers` before the fork if possible\n", + "\t- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)\n", + "'HTTPSConnectionPool(host='cdn-lfs.hf-mirror.com', port=443): Read timed out.' thrown while requesting GET https://hf-mirror.com/datasets/sanchit-gandhi/gtzan/resolve/4bd857132cb0e731bef3ec68558e7acc0a85f144/data/train-00000-of-00003-abaaa5719027ce5c.parquet\n", + "Retrying in 1s [Retry 1/5].\n" ] }, { @@ -555,7 +589,7 @@ "text/html": [ "\n", " \n", " " @@ -564,12 +598,30 @@ "" ] }, - "execution_count": 14, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "!pip install soundfile librosa\n", + "\n", + "from datasets import load_dataset\n", + "\n", + "dataset = load_dataset(\"sanchit-gandhi/gtzan\", split=\"train\", streaming=True)\n", + "sample = next(iter(dataset))[\"audio\"]\n", + "\n", + "# take the first half of the audio sample\n", + "sample[\"array\"] = sample[\"array\"][: len(sample[\"array\"]) // 2]\n", + "\n", + "inputs = processor(\n", + " audio=sample[\"array\"],\n", + " sampling_rate=sample[\"sampling_rate\"],\n", + " text=[\"80s blues track with groovy saxophone\"],\n", + " padding=True,\n", + " return_tensors=\"ms\",\n", + ")\n", + "\n", "audio_values = model.generate(**inputs, do_sample=True, guidance_scale=3, max_new_tokens=256)\n", "\n", "Audio(audio_values[0].asnumpy(), rate=sampling_rate)" @@ -590,7 +642,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 11, "id": "5495f568-51ca-439d-b47b-8b52e89b78f1", "metadata": { "id": "5495f568-51ca-439d-b47b-8b52e89b78f1" @@ -601,7 +653,7 @@ "text/html": [ "\n", " \n", " " @@ -610,13 +662,13 @@ "" ] }, - "execution_count": 15, + "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "sample = next(iter(dataset.create_dict_iterator(output_numpy=True)))[\"audio\"]\n", + "sample = next(iter(dataset))[\"audio\"]\n", "\n", "# take the first quater of the audio sample\n", "sample_1 = sample[\"array\"][: len(sample[\"array\"]) // 4]\n", @@ -654,7 +706,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 12, "id": "0zM4notb8Y1g", "metadata": { "id": "0zM4notb8Y1g" @@ -663,17 +715,10 @@ { "data": { "text/plain": [ - "GenerationConfig {\n", - " \"bos_token_id\": 2048,\n", - " \"decoder_start_token_id\": 2048,\n", - " \"do_sample\": true,\n", - " \"guidance_scale\": 3.0,\n", - " \"max_length\": 1500,\n", - " \"pad_token_id\": 2048\n", - "}" + "" ] }, - "execution_count": 16, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -682,6 +727,42 @@ "model.generation_config" ] }, + { + "cell_type": "code", + "execution_count": 20, + "id": "406ac942-457a-430f-adce-fcce7315b6e7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "GenerationConfig {\n", + " \"bos_token_id\": 2048,\n", + " \"decoder_start_token_id\": 2048,\n", + " \"do_sample\": true,\n", + " \"guidance_scale\": 3.0,\n", + " \"max_length\": 1500,\n", + " \"pad_token_id\": 2048\n", + "}\n" + ] + } + ], + "source": [ + "config = model.generation_config\n", + "config_dict = {\n", + " \"bos_token_id\": config.bos_token_id,\n", + " \"decoder_start_token_id\": config.decoder_start_token_id,\n", + " \"do_sample\": config.do_sample,\n", + " \"guidance_scale\": config.guidance_scale,\n", + " \"max_length\": config.max_length,\n", + " \"pad_token_id\": config.pad_token_id,\n", + "}\n", + "\n", + "import json\n", + "print(\"GenerationConfig \" + json.dumps(config_dict, indent=2))" + ] + }, { "cell_type": "markdown", "id": "DLSnSwau8jyW", @@ -694,7 +775,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 19, "id": "ensSj1IB81dA", "metadata": { "id": "ensSj1IB81dA" @@ -723,7 +804,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 14, "id": "KAExrhDl9YvS", "metadata": { "id": "KAExrhDl9YvS" @@ -745,13 +826,24 @@ } ], "metadata": { + "AIGalleryInfo": { + "item_id": "c72241ed-465f-418d-b58a-ed4aabb0eb73" + }, "colab": { "provenance": [] }, + "flavorInfo": { + "architecture": "X86_64", + "category": "GPU" + }, + "imageInfo": { + "id": "e1a07296-22a8-4f05-8bc8-e936c8e54202", + "name": "mindspore1.7.0-cuda10.1-py3.7-ubuntu18.04" + }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "python-3.9.0", "language": "python", - "name": "python3" + "name": "python-3.9.0" }, "language_info": { "codemirror_mode": { @@ -763,7 +855,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.19" + "version": "3.9.0" } }, "nbformat": 4,