Skip to content

Conversation

@dfvneto
Copy link
Contributor

@dfvneto dfvneto commented Oct 20, 2021

A instalação da PlatIA agora possui o MLFlow como um de seus componentes.
Uma das funcionalidades do MLFlow é o tracking de métricas, dependências e artefatos.

Nesta tarefas iremos usar o SDK do MLFlow para salvar métricas das tarefas nativas da Plataforma.

https://www.mlflow.org/docs/latest/tracking.html

A instalação da PlatIA agora possui o MLFlow como um de seus componentes.
Uma das funcionalidades do MLFlow é o tracking de métricas, dependências e artefatos.

Nesta tarefas iremos usar o SDK do MLFlow para salvar métricas das tarefas nativas da Plataforma.

https://www.mlflow.org/docs/latest/tracking.html
@dfvneto
Copy link
Contributor Author

dfvneto commented Oct 20, 2021

@fberanizo eu acabei utilizando em todos os casos o método "log_param" e não "log_metrics" não sei se tem diferença ou não.

changed log_param to log_metric
Copy link
Member

@fberanizo fberanizo left a comment

Choose a reason for hiding this comment

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

@dfvneto pelo que vi o log_metric parece que deu certo, mas vou deixar algumas orientações para terminar a tarefa:

O mlflow.sklearn.autolog() só faz sentido para Notebooks que usam o sklearn: linear regression, kmeans, isolation forest, logistic regression, mlp-classifier, mlp-regressor, random-forest classifier, random-forest regressor, svc, svr.
O autolog é algo que deve ser executado antes do treinamento (antes do .fit(X_train, y_train)) para que o mlflow detecte os parametros usados no sklearn.
Acredito que a melhor solução é criar uma célula logo após os parâmetros do notebook, lá no início com o start_run e o autolog.

mlflow.start_run()
mlflow.sklearn.autolog()

Por fim, só relembro de não deixar código-fonte comentado. Pode remover o platiagro.save_metrics

image

image

@fberanizo
Copy link
Member

fberanizo commented Oct 21, 2021

@dfvneto os notebooks falharam os testes por conta da dependência do MLflow:
image

Será necessário adicionar o @mock nos testes:

@mock.patch(
    "mlflow.log_metric",
)

Changed the placement of the initialization of the mlflow
Changed the placement of the initialization of the mlflow
Changed the placement of the initialization of the mlflow and removed wrong initialization of sklearn in notebooks where sklearn is not used
added mock to tests to include mlflow.log_metric
Changed cell description to fit new metric saving
@dfvneto dfvneto marked this pull request as ready for review October 21, 2021 19:28
Changed the number of arguments in mock.patch
Added mocked method as argument to test method so when called the method can assert true
Changed assert call location
Changed assert call location and formatted files
Removed unnecessary assert call
Removed unnecessary assert call
@dfvneto
Copy link
Contributor Author

dfvneto commented Nov 8, 2021

Lendo alguns resultados do CI percebi que está tendo problema no conda e no pickling na hora de serializar os objetos na hora de salvar

Removed wrong extra import
new utils file for mocked method
Removed sklearn autolog
Changed mock annotation placement
Removed mock of log metrics since it's possible to test and use inside the container
Removed usage of mlflow
Removed autolog
Removed log_metric state because log metric can't be used to log arrays or dataframes
Removed log_metric state because log metric can't be used to log arrays or dataframes
It is necessary to cause this tests to fail and catch the error because they take too long to execute then causing timeout on the continuous integration. The errors are caused passing wrong arguments at the paper_mill.execute_notebook method, triggering the PapermillExecutionError at the majority of the cases (one error in the isolation forest clustering triggers JSONDecodeError).
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

max_features=1.0,
),
)
with pytest.raises(JSONDecodeError):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

O statement desta linha ja faz o assert para o erro. Caso o erro ocorra, o teste é concluído com sucesso.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Esse foi o único caso que consegui criar outro erro além do PapermillExecutionError. Embora todos os erros seguintes sejam os mesmos, as causas são diferentes, mas o papermill trata todos como a mesma exceção. Para capturar a exceção correta e ter acesso aos dados da exceção é necessário encapsular a exceção do papermill com a exceção desejada.

Fonte: nteract/papermill#344

"Experiment.ipynb",
"/dev/null",
parameters=dict(

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nesse caso, o parâmetro removido foi o de dataset


max_samples="auto",
contamination=0.1,
max_features=105665,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nesse caso, max features excedeu o limite

C=1.0,
fit_intercept=True,
class_weight=None,
solver="arroz",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nesse caso, o solver foi alterado para um inválido

one_hot_features="",

hidden_layer_sizes=100,
activation="lulu",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nesse caso, o parâmetro activation foi alterado para um inválido

one_hot_features="",

n_estimators=10,
criterion="gina",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nesse caso, o parâmetro criterion foi alterado para um inválido

one_hot_features="",

C=1.0,
kernel="linux",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nesse caso, o parâmetro kernel foi alterado para um inválido

max_features=1.0,
),
)
with pytest.raises(JSONDecodeError):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Esse foi o único caso que consegui criar outro erro além do PapermillExecutionError. Embora todos os erros seguintes sejam os mesmos, as causas são diferentes, mas o papermill trata todos como a mesma exceção. Para capturar a exceção correta e ter acesso aos dados da exceção é necessário encapsular a exceção do papermill com a exceção desejada.

Fonte: nteract/papermill#344

@dfvneto
Copy link
Contributor Author

dfvneto commented Nov 17, 2021

Os testes que falharam são os testes que estão falhando na master atualmente. Neles foram removidas as alterações referentes ao mlflow e removidas as chamadas referentes ao platia.save_metrics conforme orientado

@fberanizo
Copy link
Member

@dfvneto vou aguardar uns merges de outros PRs, mas já vou fechar a tarefa no Jira.
Vlws!

removed unnecessary code block
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.

3 participants