---
# System prepended metadata

title: Model version control
tags: [waiting for review]

---

# Model version control

[![hackmd-github-sync-badge](https://hackmd.io/raqWeURQSGm6u98zmxQpYA/badge)](https://hackmd.io/raqWeURQSGm6u98zmxQpYA)

{%hackmd theme-dark %}

###### tags: `waiting for review`

The following design will describe:

- The model-level version management.
- The elasticSearch query filter mechanism
- The mongo schema
- The floating model up selected model

unlike today the following design will allow the user to:

- Go back to an epoch, change HP, and train again.
- Apply optimizers that will change the model graph.
- Select the best model graph created among different model graph states in a training session.
- Reuse elasticsearch docs among different models.

## The usecase

Consider the following scenario:

1. A user set up training with a pruning plan that changing the model graph every two epochs
2. After a day, the user returns to the platform and decides to return 30 epoch.
Take the model graph and the weights and retrain a new model with a different pruning plan.
3. After the two models end the training session, the user compares the result of the two models.

### challenges

- While a user is revisiting one model, the platform should display only the model data.
- Reuse the elasticsearch training docs.

___

## Optional solution

Don't try to read this its just fo fun:
![board](https://hackmd.io/_uploads/By1meIwV_.png)

The current solution offering to add to mongo the following collections:

- Epoch - the current model graph id, weghits and an epoch uid.
- ModelGraph - the model graph reprsenting the NN.
- Weghits - the wegits location in gcs, and modelGraph hash.
- TrainingSession - list of epochs model name and session id.

And to add to every elstic doc:

- The epoch id.

***(The schema will be detailed below)***

And to implement the following flow for training:

```sequence
Note left of user: user at day 1
user->UI: training request.
UI-->Apiserver: Training+pruning request
Apiserver-->Apiserver: start session + push Session to mongo
Apiserver-->engine: request training
engine-->engine: start train
engine-->engine: generate epoch uid
Note right of engine: push docs to elastic with epoch uid
engine-->Apiserver: return epoch uid
Apiserver-->Apiserver: Add epoch uid to session
Note left of user: user at day 2
user->UI: retraining from epoch x.
UI->Apiserver: Training+pruning request
Apiserver-->Apiserver: start session + push Session to mongo
Apiserver-->Apiserver: add to session the all the epoch up to x
Apiserver-->engine: request training
engine-->engine: start train
engine-->engine: generate epoch uid
Note right of engine: push docs to elastic with epoch uid
```

And following flow for dashboards:

```sequence
user-> UI: visiting dashboards.
UI--> Apiserver: request the session.
UI--> dashboardServer: request session dashboard.
Note right of dashboardServer: build query using epochs uid's.
dashboardServer->UI: return dashboard with the model data
```

### Mongo interfaces

Weights:

```typescript=
 export  interface Weights {
     modelGraphHash: str;
     weghitsFileLocation: str;
}
```

Epoch:

```typescript=
 export  interface Epoch {
    _id: ObjectId;
    modelGraphId: ObjectId;
    weightsId: ObjectId;
}
```

ModelGraph:

```typescript=+
export interface ModelGraph {
  id: string;
  nodes: Record<string, Node>;
}

export interface Node {
  id: string;
  name: string;
  data: Record<string, any>;
  inputs: Record<string, ConnectionInput>;
  outputs: Record<string, ConnectionOutput>;
  pruning_plan_id?: string;
  wrapper?: NodeWrapper;
}

 export  interface ModelGraph {
    _id: ObjectId;
    weightsId: ObjectId;
    modelGraph: ModelGraph;
}
```

TrainingSession:

```typescript=
 export  interface TrainingSession {
    _id: ObjectId;
    epochs: Array<Epoch>;
    weightsId: ObjectId;
    modelName: str;
}
```

### ElasticSearch interface

Just add to all the docs epoch uid
