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

added backend implementation for model templating #1419

Merged
merged 9 commits into from
Aug 28, 2024

Conversation

ARADDCC002
Copy link
Member

No description provided.

GB27247
GB27247 previously requested changes Aug 6, 2024
checkModelRestriction(model)
const template = await getModelById(user, templateId)
checkModelRestriction(template)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check that modelId !== templateId

Comment on lines 359 to 361
if (!modelAuth.success) {
throw Forbidden(modelAuth.info, { userDn: user.dn, modelId })
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already checked by the _setModelCard function

const model = await getModelById(user, modelId)
checkModelRestriction(model)
const template = await getModelById(user, templateId)
checkModelRestriction(template)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this check is necessary

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's necessary to check that new model is not a mirrored model - there could be an instance that someone makes a mirrored model but doesn't create a model card, then tries to base it off a template.

As we are not changing the metadata of the template, however, I think we can safely remove this check.

}

if (!template.card) {
throw BadReq('The template model is missing a modelcard', { modelId })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the templateId should be given as context

throw Forbidden(templateAuth.info, { userDn: user.dn, modelId })
}

if (!template.card) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default card seems to be set as an empty object so this won't catch the error. Instead you can use !template.card?.schemaId

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you first create a model card doesn't exist - I'm not sure where you're seeing it being set as an empty object, but if it is somehow being set let me know!

throw BadReq('The model and template ID must be different', { modelId, templateId })
}
const model = await getModelById(user, modelId)
checkModelRestriction(model)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to checkModelRestriction for the model being used as a template also?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. All it does is check to see if it's "mirrored" which is basically read only. As we're not editing the template in any way, I think it's fine to use it if it's read only.

// Check to make sure user can access the template. We already check for the model auth later on in _setModelCard
const templateAuth = await authorisation.model(user, template, ModelAction.View)
if (!templateAuth.success) {
throw Forbidden(templateAuth.info, { userDn: user.dn, modelId })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be reporting the templateId?

throw Forbidden(templateAuth.info, { userDn: user.dn, modelId: templateId })

): Promise<ModelCardRevisionDoc> {
throw NotImplemented({}, 'This feature is not yet implemented')
if (modelId === templateId) {
throw BadReq('The model and template ID must be different', { modelId, templateId })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a unit test that covers this

// Check to make sure user can access the template. We already check for the model auth later on in _setModelCard
const templateAuth = await authorisation.model(user, template, ModelAction.View)
if (!templateAuth.success) {
throw Forbidden(templateAuth.info, { userDn: user.dn, modelId })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a unit test that covers this

@@ -311,4 +312,17 @@ describe('services > model', () => {
)
expect(modelMocks.save).not.toBeCalled()
})

test('crateModelCardFromTemplate > requesting to use a template without a model card will throw an error', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also have a "happy day" test

if (!template.card?.schemaId) {
throw BadReq('The template model is missing a model card', { modelId, templateId })
}
const revision = await _setModelCard(user, modelId, template.card.schemaId, 1, template.card.metadata)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything to stop a user from calling this with a modelId that references a model that already has model card versions? If this were to happen then this line would set the first version to be the model card of the template and all later versions would be from the pre-existing model card.

@ARADDCC002 ARADDCC002 dismissed stale reviews from GB27247 and ARADDCC012 August 28, 2024 16:12

.

@ARADDCC002 ARADDCC002 merged commit ab0f308 into main Aug 28, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants