Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ModelArts): add a data source to get the list of ModelArts model… #1087

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions docs/data-sources/modelarts_model_templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
subcategory: "AI Development Platform (ModelArts)"
---

# flexibleengine_modelarts_model_templates

Use this data source to get model templates of ModelArts.

## Example Usage

```hcl
data "flexibleengine_modelarts_model_templates" "test" {
type = "Classification"
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) Specifies the region in which to query the data source.
If omitted, the provider-level region will be used.

* `type` - (Optional, String) The type of model. The valid values are **Classification** and **Common**.

* `engine` - (Optional, String) The AI engine.
The valid values are **Caffe**, **Caffe1.0 CPU**, **Caffe1.0 GPU**, **MXNet**, **MXNet1.2.1**,
**MindSpore**, **PyTorch**, **PyTorch1.0**, **TensorFlow**, and **TensorFlow1.8**.

* `environment` - (Optional, String) Model runtime environment.
The valid values are **ascend-arm-py2.7**, **python2.7**, and **python3.6**.

* `keyword` - (Optional, String) Keywords to search in name or description. Fuzzy match is supported.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The data source ID.

* `templates` - The list of model templates.
The [templates](#ModelTemplate_templates) structure is documented below.

<a name="ModelTemplate_templates"></a>
The `templates` block supports:

* `id` - Template ID.

* `name` - Template name.

* `description` - Template description.

* `type` - The type of model. The valid values are **Classification** and **Common**.

* `engine` - The AI engine.
The valid values are **Caffe**, **MXNet**, **MindSpore**, **PyTorch**, and **TensorFlow**.

-> It may not be equal to the filter argument `engine`, it does not have a version information suffix.

* `environment` - Model runtime environment.
The valid values are **aarch64**, **python2.7**, **python2.7-cpu**, **python2.7-gpu**, **python3.6**,
**python3.6-gpu**, and **python3.6-gpu**.

-> It may not be equal to the filter argument `environment`.

* `template_docs` - List of template description documents.
The [template_docs](#ModelTemplate_TemplatestemplateDocs) structure is documented below.

* `template_inputs` - List of input parameters for the model.
The [template_inputs](#ModelTemplate_TemplatestemplateInputs) structure is documented below.

<a name="ModelTemplate_TemplatestemplateDocs"></a>
The `template_docs` block supports:

* `doc_url` - HTTP(S) link of the document.

* `doc_name` - Document name.

<a name="ModelTemplate_TemplatestemplateInputs"></a>
The `template_inputs` block supports:

* `id` - The ID of the input parameter.

* `type` - The type of the input parameter.

* `name` - The name of the input parameter.

* `description` - The description of the input parameter.
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package acceptance

import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
)

func TestAccDatasourceModelTemplates_basic(t *testing.T) {
rName := "data.flexibleengine_modelarts_model_templates.test"
dc := acceptance.InitDataSourceCheck(rName)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDatasourceModelTemplates_basic(),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(rName, "templates.0.id"),
resource.TestCheckResourceAttrSet(rName, "templates.0.name"),
resource.TestCheckResourceAttrSet(rName, "templates.0.description"),
resource.TestCheckResourceAttrSet(rName, "templates.0.type"),
resource.TestCheckResourceAttrSet(rName, "templates.0.engine"),
resource.TestCheckResourceAttrSet(rName, "templates.0.environment"),
resource.TestCheckResourceAttrSet(rName, "templates.0.template_docs.#"),
resource.TestCheckResourceAttrSet(rName, "templates.0.template_inputs.#"),

resource.TestCheckOutput("type_filter_is_useful", "true"),

resource.TestCheckOutput("engine_filter_is_useful", "true"),

resource.TestCheckOutput("environment_filter_is_useful", "true"),

resource.TestCheckOutput("keyword_filter_is_useful", "true"),
),
},
},
})
}

func testAccDatasourceModelTemplates_basic() string {
return `
data "flexibleengine_modelarts_model_templates" "test" {
}

data "flexibleengine_modelarts_model_templates" "type_filter" {
type = "Common"
}
output "type_filter_is_useful" {
value = length(data.flexibleengine_modelarts_model_templates.type_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_modelarts_model_templates.type_filter.templates[*].type : v == "Common"]
)
}

data "flexibleengine_modelarts_model_templates" "engine_filter" {
engine = "TensorFlow1.8"
}
output "engine_filter_is_useful" {
value = length(data.flexibleengine_modelarts_model_templates.engine_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_modelarts_model_templates.engine_filter.templates[*].engine : v == "TensorFlow1.8"]
)
}

data "flexibleengine_modelarts_model_templates" "environment_filter" {
environment = "python3.6"
}
output "environment_filter_is_useful" {
value = length(data.flexibleengine_modelarts_model_templates.environment_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_modelarts_model_templates.environment_filter.templates[*].environment : strcontains(v, "python3.6")]
)
}

data "flexibleengine_modelarts_model_templates" "keyword_filter" {
keyword = "CPU"
}
output "keyword_filter_is_useful" {
value = length(data.flexibleengine_modelarts_model_templates.keyword_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_modelarts_model_templates.keyword_filter.templates[*].description : strcontains(v, "CPU")]
)
}
`
}
1 change: 1 addition & 0 deletions flexibleengine/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ func Provider() *schema.Provider {

"flexibleengine_modelarts_datasets": modelarts.DataSourceDatasets(),
"flexibleengine_modelarts_dataset_versions": modelarts.DataSourceDatasetVerions(),
"flexibleengine_modelarts_model_templates": modelarts.DataSourceModelTemplates(),

"flexibleengine_obs_buckets": obs.DataSourceObsBuckets(),
"flexibleengine_obs_bucket_object": obs.DataSourceObsBucketObject(),
Expand Down
Loading