- [Instructor] 在这段视频中，我们将了解如何 - [Instructor] In this video, we're going to understand how
管理模型仓库 to manage a model repository
在 Hugging Face Hub 模型中心。 on the Hugging Face Hub Model Hub.
为了处理仓库 In order to handle a repository
你应该首先拥有一个 Hugging Face 帐户。 you should first have a Hugging Face account.
在描述中有创建新帐户 A link to create a new account is available
的链接。 in the description.
登录后，你可以创建一个新的仓库 Once you are logged in, you can create a new repository
通过单击 New Model 选项。 by clicking on the New Model option.
你会看到类似下面的模型。 You should be facing a similar model to the following.
在 Owner 输入框中，你可以放置自己的命名空间 In the owner input, you can put either your own namespace
或你组织的任何命名空间。 or any of your organization's namespaces.
Model name 是模型标识符 The Model name is the model identifier
它将被用于 that will then be used
在所选命名空间上识别你的模型。 to identify your model on the chosen namespace.
最后可以在 Public(公共) 和 Private(私有) 之间选择。 The final choice is between public and private.
任何人都可以访问公共模型。 Public models are accessible by anyone.
这是推荐的免费选项， This is the recommended free option,
因为这使你的模型易于访问和共享。 as this makes your model easily accessible and shareable.
你的命名空间的所有者 The owners of your namespace are the only ones
是唯一可以更新和更改你的模型。 who can update and change your model.
一个更高级的选项是私有选项。 A more advanced option is the private option.
在这种情况下， In this case,
只有你的命名空间的所有者 only the owners of your namespace
对你的模型有可见性。 will have visibility over your model.
其他用户不会知道它的存在 Other users won't know it exists
并且将无法使用它。 and will not be able to use it.
让我们创建一个虚拟模型来试试看。 Let's create a dummy model to play with.
创建模型后， Once your model is created,
来自该模型的管理。 comes the management of that model.
你可以使用三个选项卡。 Three tabs are available to you.
你面对的是第一个，这是 Model card 页面。 You're facing the first one, which is the Model card page.
这是你用来向全世界展示模型 This is the page you use to showcase your model
的页面。 to the world.
我们稍后会看到它是如何完成的。 We'll see how it can be completed in a bit.
第二个是 Files and Versions 选项卡。 The second one is the Files and Versions tab.
你的模型本身就是一个 Git 仓库。 Your model itself is a Git repository.
如果你不知道什么是 Git 仓库， If you're unaware of what is a Git repository,
你可以将其视为包含文件的文件夹。 you can think of it as a folder containing files.
如果你以前从未使用过 Git， If you have never used Git before,
我们建议观看视频描述中 we recommend looking at an introduction
提供的介绍内容。 like the one provided in this video's description.
Git 仓库支持按照时间推移 The Git repository allows you to see the changes happening
查看本文件夹中的变化，也就是版本。 over time in this folder, hence the term versions.
我们稍后会看到如何添加文件和版本。 We'll see how to add files and versions in a bit.
最后一个选项卡是 Settings 选项卡， The final tab is the settings tab,
可以管理模型的可见性 which allows you to manage your model's visibility
和可用性。 and availability.
让我们首先从将文件添加到仓库开始。 Let's first start by adding files to the repository.
还好有 add file 按钮 Files can be added
通过网页操作即可添加文件。 through the web interface thanks to the add file button.
添加的文件可以是任何类型，python，JSON，纯文本， The added files can be of any type, python, JSON, text,
任君选择。 you name it.
除了你添加的文件及其内容， Alongside your added file and its content,
你还应该命名你的 change 或 commit。 you should name your change or commit.
通常，使用 Hugging Face Hub Python 库 Generally, adding files is simpler
或使用命令行添加文件 by using the Hugging Face Hub Python library
比较简单。 or by using the command-line.
我们将展示如何使用 We'll showcase how to do this
Hugging Face Hub Python 库做到这一点 using the Hugging Face Hub Python library,
并且在描述中有一个链接 and there is a link in the description
可以指向这个视频的前一个版本， to the previous version of this video,
展示如何使用 Git 和命令行执行此操作。 showcasing how to do this using Git and the command-line.
首先，确保你已登录 First, make sure you're logged
进入你的 Hugging Face 帐户， into your Hugging Face account,
可以通过命令行或者 Python 运行时中操作。 either through the command-line or in a Python runtime.
我们要看的第一种方法 The first approach we'll take a look at
正在使用 upload_file 方法。 is using the upload file method.
这提供了一个极其简单的 API This offers an extremely simple API
通过 hub 上传文件。 to upload files through the hub.
其中三个必需的参数 The three required parameters
是文件的当前位置， are the current location of the file,
该文件在仓库中的路径， the path of that file in the repository,
以及你要推送到的仓库的标识符。 and the id of the repository to which you're pushing.
还有一些额外的参数。 There are a few additional parameters.
token 参数， The token parameter,
如果你想指定一个和登录时 if you would like to specify a different token
所保存的不同的 token， than the one saved in your cache with your login,
repo_type 参数， the repo type parameter,
如果你想推送到 dataset 或 space。 if you would like to push to a dataset or a space.
我们将使用这种方法上传一个名为 readme.md 的文件 We'll upload a file called readme.md to the repository
到仓库。 using this method.
我们首先用那个名字保存一个文件， We first start by saving a file with that name,
其中包含一些关于 which contains some information
仓库本身的信息。 about the repository itself.
在这里，一个标题。 Here, a title.
现在文件已保存， Now that the file is saved,
让我们使用 upload_file 方法将其上传到 hub。 let's use the upload file method to upload it to the hub.
如果我们切换到 Web 界面一秒钟 If we switch to the web interface for a second
并刷新页面，我们会看到显示了 README。 and refresh the page, we'll see that the README is shown.
文件上传成功。 The file upload was a success.
除了这个方法之外还有一个 delete_file 方法 Alongside this method exists a delete file method
这样你就可以完全管理你的仓库。 so that you may manage your repository fully.
我们将使用它来删除我们刚刚创建的文件。 We'll use it to delete the file we have just created.
如果我们再次刷新页面，很好， If we refresh the page once again, good,
该文件确实被删除了。 the file was indeed deleted.
这两种方法操作起来非常简单。 This approach using only these two methods is super simple.
它不需要安装 Git 或 Git LFS， It doesn't need Git or Git LFS installed,
但它确实有一个限制。 but it does come with a limitation.
一个人可以上传的最大文件大小 The maximum file size one can upload
限制为 5 GB。 is limited to five gigabytes.
为了克服这个限制， To overcome this limit,
我们来看看第二种方法 let's take a look at the second method
这是仓库实用程序。 which is the repository utility.
该类封装了 Git 和 Git LFS 方法， This class is a wrapper over Git and Git LFS methods,
它抽象了大部分的复杂性 which abstracts most of the complexity
并提供灵活的 API and offers a flexible API
管理你的在线仓库。 to manage your online repositories.
让我们来看看它是如何工作的。 Let's take a look at how it works.
我们首先从实例化仓库实用程序开始。 We first start by instantiating the repository utility.
为了克隆我们刚刚创建的仓库 We provide the clone from parameter,
我们可以通过传递参数进行克隆。 in order to clone the repository we just created.
仓库现已克隆到本地文件夹中。 The repository is now cloned in the local folder.
我们刚刚初始化的 repo 对象 The repo object that we have just initialized
提供了很多对我们有用的方法。 offers quite a few methods which are useful for us.
我们有兴趣将模型推送到 hub。 We're interested in pushing a model to the hub.
我将从加载模型和分词器开始 I'll start by loading a model and tokenizer
这是几个小时前训练过的。 I trained a few hours ago.
我们现在将遵循传统的 Git 方法 We'll now follow the traditional Git approach
首先 pull 最新的更改内容 by first pulling latest changes
使用 git_pull 方法。 using the git_pull method.
我们刚刚克隆了仓库， We just cloned the repository,
所以除非这是一个超级活跃的仓库， so unless this is a super active repository,
否则不太可能内容的变化。 it's unlikely that new changes are available.
但在做任何新的事情之前养成 pull 最新内容 But it's always a good idea to pull the latest changes
的好习惯也是不错的。 before doing anything new.
现在我们已经 pull 了仓库， Now that we have pulled the repository,
我会将模型和分词器保存在该文件夹中。 I'll save the model and tokenizer inside that folder.
这包括模型权重、配置文件、 This includes the model weights, configuration file,
和分词器文件。 and tokenizer files.
现在模型已保存， Now that the model is saved,
我们将继续使用传统的 Git 方法 we'll continue with the traditional Git approach
并将其推送到远程仓库。 and push it to the remote repository.
如果我们使用命令行， If we were using the command-line,
我们将不得不调用一些 there are a few Git LFS specific commands
特定的 Git LFS 命令。 we would have to invoke.
但是在这里，huggingface_hub 包 But here, the Hugging Face hub package
会处理所有这些。 takes care of all of that.
我们将从使用 git_add 方法暂存文件开始。 We'll start by staging the files using the git_add method.
然后我们将使用 git_commit 方法提交这些更改， We'll then commit these changes using Git commit method,
并提供有用的 commit 信息。 and providing a helpful commit message.
最后，我们将更改推送到远端， Finally, we'll push the changes to the remote,
使用 git_push 方法。 using the Git push method.
如果我们回到 Files and Versions 选项卡， If we go back to the Files and Versions tab,
我们现在可以看到新提交的文件。 we can now see the newly committed files.
我们甚至可以在 inference API 中使用模型。 We can even play with the model in the inference API.
不幸的是，我们模型的首页 Unfortunately, the front page of our model
还是显得非常空。 is still very empty.
让我们添加一个 README markdown 文件 Let's add a README markdown file
让整体显得完整一点点。 to complete it a little bit.
这个 README 被称为 Model card This README is known as the Model card
可以说它同样重要 and it's arguably as important
作为模型仓库中的模型和分词器文件。 as the model and tokenizer files in the model repository.
这是你的模型的综合定义 It is the central definition
和模型文档， and documentation of your model,
确保社区成员的可重用性 ensuring reusability by fellow community members
和结果的可重复性。 and reproducibility of results.
提供一个平台，让其他成员 Providing a platform on which other members
可以构建他们的工件。 may build their artifacts.
为了简单起见我们只会在此处添加标题 We'll only add a title and a small description here
和简短描述， for simplicity's sake,
但我们鼓励你添加相关信息 but we encourage you to add information relevant
说明模型是如何训练的， to how was the model trained,
它的预期用途和限制， it's intended use and limitations,
以及目前一直的潜在偏差， as well as it's identified potential biases,
评估结果， evaluation results,
以及有关如何使用你的模型的代码示例。 and code samples on how to use your model.
为 Model Hub 贡献出色的模型。 Great work contributing a model to the Model Hub.
该模型现在可以在下游库中使用 This model can now be used in downstream libraries
只需指定你的模型标识符。 simply by specifying your model identifier.