Skip to content

Commit

Permalink
feat(ModelArts): add a data source to get the list of ModelArts model…
Browse files Browse the repository at this point in the history
… templates
  • Loading branch information
liwanting0517 committed Jan 4, 2024
1 parent ba09928 commit 2409c32
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 0 deletions.
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 resource 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

0 comments on commit 2409c32

Please sign in to comment.