Hyphen in physical quantities before nouns?

There is no hard and fast rule but, as always, you should use common sense and choose what you think makes reading your piece easier. I personally favour hyphenating any "number+unit" complex modifier.

This practice is especially useful in scientific writing, as it mitigates ambiguity.

Moreover, it improves the reading flow, as hyphenated complex modifiers appear as blocks. Non-hyphenated complex modifiers, by contrast, tend to disrupt it; one often stumbles upon them, and then has to backtrack and read them again.

It's preferable to write:

a 2-kilogram potato

4-Gb memory devices

Although this practice remains valid for "number+abbreviated unit" complex modifiers, it can lead to difficult parsing. In cases with simple units like foot, meter or even light year, the unabbreviated form may be preferable, as they are easy enough to parse. On the other hand, using the unabbreviated form of more complex units tends to make parsing difficult.

a 5-meter-per-square-second acceleration

In those more complex cases, using the abbreviated form may be preferable.