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

Avoid retraining Core model if only templates section is changed #4251

Merged
merged 55 commits into from
Nov 5, 2019

Conversation

msamogh
Copy link
Contributor

@msamogh msamogh commented Aug 15, 2019

Proposed changes:

Status (please check what you already did):

  • made PR ready for code review
  • added some tests for the functionality
  • updated the documentation
  • updated the changelog
  • reformat files using black (please check Readme for instructions)

@tmbo
Copy link
Member

tmbo commented Sep 3, 2019

@msamogh what is missing to move this PR forward?

@msamogh
Copy link
Contributor Author

msamogh commented Sep 4, 2019

tests/core/conftest.py:239: in trained_model
    return train_model(project)
tests/core/conftest.py:232: in train_model
    rasa.train(domain, config, training_files, output)
rasa/train.py:40: in train
    kwargs=kwargs,
uvloop/loop.pyx:1417: in uvloop.loop.Loop.run_until_complete
    ???
rasa/train.py:87: in train_async
    kwargs,
rasa/train.py:170: in _train_async_internal
    kwargs=kwargs,
rasa/train.py:216: in _do_training
    kwargs=kwargs,
rasa/train.py:346: in _train_core_with_validated_data
    kwargs=kwargs,
rasa/core/train.py:71: in train
    agent.persist(output_path, dump_stories, replace_templates_only)
rasa/core/agent.py:799: in persist
    self.domain.persist(os.path.join(model_path, DEFAULT_DOMAIN_PATH))
rasa/core/domain.py:638: in persist
    utils.dump_obj_as_yaml_to_file(filename, domain_data)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

filename = '/var/folders/87/pnn5hwg11cb8qkgp_q4dm8280000gp/T/tmpl_ucro1v/core/domain.yml'
obj = {'actions': ['utter_cheer_up', 'utter_did_that_help', 'utter_goodbye', 'utter_greet', 'utter_happy'], 'config': {'store_entities_as_slots': True}, 'entities': [], 'forms': [], ...}

    def dump_obj_as_yaml_to_file(filename: Union[Text, Path], obj: Dict) -> None:
        """Writes data (python dict) to the filename in yaml repr."""
>       with open(str(filename), "w", encoding="utf-8") as output:
E       FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/87/pnn5hwg11cb8qkgp_q4dm8280000gp/T/tmpl_ucro1v/core/domain.yml'

rasa/core/utils.py:227: FileNotFoundError

I suspect that it could be because a temp directory somewhere is being cleaned up prematurely.

@msamogh msamogh force-pushed the granular-fingerprint branch from 7dbdfb8 to bf6c841 Compare September 4, 2019 09:13
@msamogh
Copy link
Contributor Author

msamogh commented Sep 4, 2019

Think I found the cause. Had switched the order of persists.

@msamogh msamogh marked this pull request as ready for review September 4, 2019 11:37
@msamogh msamogh requested a review from tmbo September 4, 2019 11:38
@msamogh
Copy link
Contributor Author

msamogh commented Sep 4, 2019

Travis job link - https://travis-ci.com/RasaHQ/rasa/builds/125875507

@msamogh
Copy link
Contributor Author

msamogh commented Sep 4, 2019

@tmbo Looks like good to go

@tmbo
Copy link
Member

tmbo commented Sep 4, 2019

great work ⭐

As far as I can see, can go into a patch. Will release as part of 1.3.1

@msamogh msamogh force-pushed the granular-fingerprint branch from 5e2eec7 to c1473ba Compare September 4, 2019 23:20
@msamogh msamogh changed the base branch from master to 1.3.x September 5, 2019 11:25
@msamogh msamogh force-pushed the granular-fingerprint branch from bcd5ff7 to 482388b Compare September 5, 2019 11:26
tmbo
tmbo previously requested changes Sep 30, 2019
Copy link
Member

@tmbo tmbo left a comment

Choose a reason for hiding this comment

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

I really like the idea, but I'd like to avoid adding the template flag to the retrain method. I'd rather directly only call the domain to persist from the method that checks the fingerprints

rasa/model.py Outdated
target_path = os.path.join(train_path, "core")
retrain_core = not merge_model(old_core, target_path)

if not nlu_fingerprint_changed(last_fingerprint, new_fingerprint):
else:
Copy link
Member

Choose a reason for hiding this comment

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

I don't think the logic is correct here, as this else will be run if core needs to be retrained.

Copy link
Contributor Author

@msamogh msamogh Oct 4, 2019

Choose a reason for hiding this comment

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

I'm not sure if I understood your concern here correctly. Perhaps you can mention a specific combination of values for retrain_core and retrain_nlg that you think this will fail for?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think Tom means: why do we need to merge core in case retrain_core=True?
In general I don't like that should_retrain already does some modifications. I think that's unexpected behavior when I call a function should_xy_be_done. And I also think that's part of the reason why this seems so complicated (to me 😄 ).

Copy link
Contributor

Choose a reason for hiding this comment

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

The docstring also indicates a totally different behavior of the function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So the objectives are as follows:

  1. should_retrain.nlg should return the value specific to whether only the NLG section has changed regardless of the value of should_retrain.core. This is to ensure the returned values make logical sense.
  2. Given that its value should be independent of should_retrain.core, we also want to check whether it's possible to merge the directories, because in the following case when Core needn't be retrained and merging directories is failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But have updated the condition now to make it cleaner and less confusing.

rasa/train.py Outdated Show resolved Hide resolved
rasa/train.py Outdated Show resolved Hide resolved
@msamogh msamogh requested a review from tmbo October 4, 2019 15:02
@tmbo tmbo requested review from wochinge and removed request for tmbo October 9, 2019 07:04
@tmbo tmbo dismissed their stale review October 9, 2019 07:04

outdated

Copy link
Contributor

@wochinge wochinge left a comment

Choose a reason for hiding this comment

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

The functionality seems great. However, I think the check for the NLG section is the cherry on top of some technical debt we are having here, and we should untangle some of the things first to make it easier understandable / maintainable.

CHANGELOG.rst Outdated Show resolved Hide resolved
rasa/model.py Outdated Show resolved Hide resolved
rasa/model.py Show resolved Hide resolved
rasa/model.py Outdated Show resolved Hide resolved
rasa/model.py Outdated Show resolved Hide resolved
rasa/train.py Outdated Show resolved Hide resolved
tests/core/test_model.py Outdated Show resolved Hide resolved
tests/core/test_model.py Outdated Show resolved Hide resolved
rasa/model.py Outdated
target_path = os.path.join(train_path, "core")
retrain_core = not merge_model(old_core, target_path)

if not nlu_fingerprint_changed(last_fingerprint, new_fingerprint):
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think Tom means: why do we need to merge core in case retrain_core=True?
In general I don't like that should_retrain already does some modifications. I think that's unexpected behavior when I call a function should_xy_be_done. And I also think that's part of the reason why this seems so complicated (to me 😄 ).

rasa/model.py Outdated
target_path = os.path.join(train_path, "core")
retrain_core = not merge_model(old_core, target_path)

if not nlu_fingerprint_changed(last_fingerprint, new_fingerprint):
else:
Copy link
Contributor

Choose a reason for hiding this comment

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

The docstring also indicates a totally different behavior of the function

msamogh and others added 3 commits October 9, 2019 17:43
Co-Authored-By: Tobias Wochinger <t.wochinger@rasa.com>
Co-Authored-By: Tobias Wochinger <t.wochinger@rasa.com>
@wochinge wochinge requested a review from tabergma October 29, 2019 16:03
@wochinge
Copy link
Contributor

@tabergma I took this over from Amogh. I actually think this should not go into 1.4.x but master, what do you think?

Copy link
Contributor

@tabergma tabergma left a comment

Choose a reason for hiding this comment

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

Looks good 👍 Added a few minor comments.

Yes, let's merge into master.

rasa/model.py Outdated Show resolved Hide resolved
rasa/model.py Outdated
retrain.core = core_merge_failed

if not retrain.nlg:
retrain.nlg = core_merge_failed
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment here why we overwrite retrain.nlg with core_merge_failed?

Copy link
Contributor

Choose a reason for hiding this comment

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

also changed the code to make it a bit easier to read

rasa/model.py Outdated Show resolved Hide resolved
rasa/model.py Outdated Show resolved Hide resolved
rasa/model.py Outdated Show resolved Hide resolved
rasa/model.py Outdated Show resolved Hide resolved
rasa/model.py Outdated Show resolved Hide resolved
@wochinge wochinge changed the base branch from 1.4.x to master October 30, 2019 10:31
@wochinge wochinge requested a review from tabergma October 30, 2019 10:33
@wochinge wochinge dismissed their stale review October 30, 2019 10:34

tanja did a new one

Copy link
Contributor

@tabergma tabergma left a comment

Choose a reason for hiding this comment

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

🚀 good to go!

rasa/model.py Outdated Show resolved Hide resolved
rasa/model.py Outdated Show resolved Hide resolved
@wochinge wochinge merged commit ff08484 into master Nov 5, 2019
@wochinge wochinge deleted the granular-fingerprint branch November 5, 2019 08:01
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.

The whole Core model is retrained even if only the templates section is changed
5 participants