Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
shivamshrirao
GitHub Repository: shivamshrirao/diffusers
Path: blob/main/tests/test_hub_utils.py
1440 views
1
# coding=utf-8
2
# Copyright 2023 HuggingFace Inc.
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
# http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
import unittest
16
from pathlib import Path
17
from tempfile import TemporaryDirectory
18
from unittest.mock import Mock, patch
19
20
import diffusers.utils.hub_utils
21
22
23
class CreateModelCardTest(unittest.TestCase):
24
@patch("diffusers.utils.hub_utils.get_full_repo_name")
25
def test_create_model_card(self, repo_name_mock: Mock) -> None:
26
repo_name_mock.return_value = "full_repo_name"
27
with TemporaryDirectory() as tmpdir:
28
# Dummy args values
29
args = Mock()
30
args.output_dir = tmpdir
31
args.local_rank = 0
32
args.hub_token = "hub_token"
33
args.dataset_name = "dataset_name"
34
args.learning_rate = 0.01
35
args.train_batch_size = 100000
36
args.eval_batch_size = 10000
37
args.gradient_accumulation_steps = 0.01
38
args.adam_beta1 = 0.02
39
args.adam_beta2 = 0.03
40
args.adam_weight_decay = 0.0005
41
args.adam_epsilon = 0.000001
42
args.lr_scheduler = 1
43
args.lr_warmup_steps = 10
44
args.ema_inv_gamma = 0.001
45
args.ema_power = 0.1
46
args.ema_max_decay = 0.2
47
args.mixed_precision = True
48
49
# Model card mush be rendered and saved
50
diffusers.utils.hub_utils.create_model_card(args, model_name="model_name")
51
self.assertTrue((Path(tmpdir) / "README.md").is_file())
52
53